浏览代码

small changes

master
Isabelle L. 5 年前
父节点
当前提交
d1a26eb478
共有 4 个文件被更改,包括 25 次插入38 次删除
  1. 二进制
      img/tiles/select.png
  2. +4
    -0
      justfile
  3. +5
    -28
      main.lua
  4. +16
    -10
      world.lua

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

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

+ 4
- 0
justfile 查看文件

@@ -0,0 +1,4 @@
alias r := run

run:
love .

+ 5
- 28
main.lua 查看文件

@@ -10,55 +10,32 @@ function love.load()
}
-- generate the world and load the files
world.new(10, 10)
world.new(20, 20)
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
offset.x = offset.x + 16
end

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

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



+ 16
- 10
world.lua 查看文件

@@ -7,6 +7,8 @@ local world = {}
function world.new(width, height)
world.width = width
world.height = height
world.hover = nil
world.select = love.graphics.newImage("img/tiles/select.png")

for x = 1, world.width do
world[x] = {}
@@ -18,11 +20,11 @@ local world = {}

-- 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")
world.tiles = {}
world.tiles.grass = love.graphics.newImage("img/tiles/grass.png")
world.tiles.dirt = love.graphics.newImage("img/tiles/dirt.png")
world.tiles.water = love.graphics.newImage("img/tiles/water.png")
world.tiles.nothing = love.graphics.newImage("img/tiles/nothing.png")
end

-- render the world
@@ -33,18 +35,22 @@ local world = {}
local loc = util.cartToIso({x = x, y = y})
if tile == "grass" then
image = world.grass
image = world.tiles.grass
elseif tile == "dirt" then
image = world.dirt
image = world.tiles.dirt
elseif tile == "water" then
image = world.water
image = world.tiles.water
else
image = world.nothing
image = world.tiles.nothing
end
love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y)
end
end
end

if not world.hover == nil then
love.graphics.draw(world.select, world.hover.x, world.hover.y)
end
end

return world

正在加载...
取消
保存