From d1a26eb478fc10f87d6a0952bbf3c3bf0385b5e4 Mon Sep 17 00:00:00 2001 From: Isabelle L Date: Thu, 2 Jul 2020 15:03:37 -0500 Subject: [PATCH] small changes --- img/tiles/select.png | Bin 246 -> 250 bytes justfile | 4 ++++ main.lua | 33 +++++---------------------------- world.lua | 26 ++++++++++++++++---------- 4 files changed, 25 insertions(+), 38 deletions(-) create mode 100644 justfile diff --git a/img/tiles/select.png b/img/tiles/select.png index 8c67ce3da949f820b37edd11457df70389cefcc8..6e4b5764acb961ff894bf6bbd26079e9cc047c60 100644 GIT binary patch delta 209 zcmV;?051Rb0r~-uF@Lm4L_t(oh3%9*4ul{OMrRVcy@1IUV&fgSf8iarSuHl%3s|!i zMsdmf0F9Z~fn>gi3?L}k!Z#ep5A0D>r_%;c&i|d4im(OJ;LrL#1x?NejR?7j3Ql>IRD diff --git a/justfile b/justfile new file mode 100644 index 0000000..f63228a --- /dev/null +++ b/justfile @@ -0,0 +1,4 @@ +alias r := run + +run: + love . \ No newline at end of file diff --git a/main.lua b/main.lua index 8ec5f7b..1ee5293 100644 --- a/main.lua +++ b/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 diff --git a/world.lua b/world.lua index 5a5425c..63e7448 100644 --- a/world.lua +++ b/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 \ No newline at end of file