浏览代码

initial commit!

master
Isabelle L. 5 年前
当前提交
4e86a22776
共有 10 个文件被更改,包括 144 次插入0 次删除
  1. +0
    -0
      README.md
  2. +5
    -0
      conf.lua
  3. 二进制
      img/tiles/dirt.png
  4. 二进制
      img/tiles/grass.png
  5. 二进制
      img/tiles/nothing.png
  6. 二进制
      img/tiles/select.png
  7. 二进制
      img/tiles/water.png
  8. +72
    -0
      main.lua
  9. +17
    -0
      util.lua
  10. +50
    -0
      world.lua

+ 0
- 0
README.md 查看文件


+ 5
- 0
conf.lua 查看文件

@@ -0,0 +1,5 @@
function love.conf(t)
t.window.width = 640
t.window.height = 480
t.window.title = "unnamed"
end

二进制
img/tiles/dirt.png 查看文件

之前 之后
宽度: 32  |  高度: 32  |  大小: 289 B

二进制
img/tiles/grass.png 查看文件

之前 之后
宽度: 32  |  高度: 32  |  大小: 366 B

二进制
img/tiles/nothing.png 查看文件

之前 之后
宽度: 32  |  高度: 32  |  大小: 448 B

二进制
img/tiles/select.png 查看文件

之前 之后
宽度: 32  |  高度: 32  |  大小: 246 B

二进制
img/tiles/water.png 查看文件

之前 之后
宽度: 32  |  高度: 32  |  大小: 284 B

+ 72
- 0
main.lua 查看文件

@@ -0,0 +1,72 @@
-- world module
local world = require("world")

-- love's load function
function love.load()
-- set the overall map offset
offset = {
x = 0,
y = 0
}
-- generate the world and load the files
world.new(10, 10)
world.loadTiles()
-- store the mouse position
mouse = {
x = love.mouse.getX(),
y = love.mouse.getY()
}
end

-- love's update function
function love.update(dt)
-- get the current mouse location
local mouseNow = {
x = love.mouse.getX(),
y = love.mouse.getY()
}
-- if mouse is pressed move the offset
if love.mouse.isDown(1) then
local mouseDelta = {
x = mouse.x - mouseNow.x,
y = mouse.y - mouseNow.y,
}

offset.x = offset.x - mouseDelta.x
offset.y = offset.y - mouseDelta.y
end

mouse = mouseNow
end

-- love's key press funciton
function love.keypressed(key, scanCode, isRepeat)
-- arrow keys for moving offset
if key == "left" then
offset.x = offset.x - 16
end

if key == "right" then
offset.x = offset.x + 16
end

if key == "up" then
offset.y = offset.y - 16
end
if key == "down" then
offset.y = offset.y + 16
end
end

-- love's draw function
function love.draw()
-- clear the window
love.graphics.clear()
-- draw the map
world.render(offset)
end

+ 17
- 0
util.lua 查看文件

@@ -0,0 +1,17 @@
local util = {}

function util.cartToIso(cart)
local iso = {}
iso.x = cart.x - cart.y
iso.y = (cart.x + cart.y) / 2
return iso
end

function util.isoToCart(iso)
local cart = {}
cart.x = (2 * iso.y + iso.x) / 2
cart.y = (2 * iso.y - iso.x) / 2
return cart
end

return util

+ 50
- 0
world.lua 查看文件

@@ -0,0 +1,50 @@
-- bring in the util module
local util = require("util")

-- world stuffs
local world = {}
-- create a new world with given height and width
function world.new(width, height)
world.width = width
world.height = height

for x = 1, world.width do
world[x] = {}
for y = 1, world.height do
world[x][y] = "nothing"
end
end
end

-- load the tile files
function world.loadTiles()
world.grass = love.graphics.newImage("img/tiles/grass.png")
world.dirt = love.graphics.newImage("img/tiles/dirt.png")
world.water = love.graphics.newImage("img/tiles/water.png")
world.nothing = love.graphics.newImage("img/tiles/nothing.png")
world.select = love.graphics.newImage("img/tiles/select.png")
end

-- render the world
function world.render(offset)
for x = 1, world.width do
for y = 1, world.height do
local tile = world[x][y]
local loc = util.cartToIso({x = x, y = y})
if tile == "grass" then
image = world.grass
elseif tile == "dirt" then
image = world.dirt
elseif tile == "water" then
image = world.water
else
image = world.nothing
end
love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y)
end
end
end

return world

正在加载...
取消
保存