From c7e2b20ebdbc37370dfc670d98cffc84453b7328 Mon Sep 17 00:00:00 2001 From: Isabelle L Date: Thu, 2 Jul 2020 20:54:03 -0500 Subject: [PATCH] multi layer iso shit idfk i'm really high fam --- main.lua | 10 +++++++--- world.lua | 47 +++++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/main.lua b/main.lua index 1ee5293..5804149 100644 --- a/main.lua +++ b/main.lua @@ -5,12 +5,12 @@ local world = require("world") function love.load() -- set the overall map offset offset = { - x = 0, - y = 0 + x = 304, + y = 48 } -- generate the world and load the files - world.new(20, 20) + world.new(20, 20, 3) world.loadTiles() end @@ -37,6 +37,10 @@ function love.keypressed(key, scanCode, isRepeat) if key == "down" then offset.y = offset.y - 16 end + + if key == "escape" then + love.event.quit(0) + end end -- love's draw function diff --git a/world.lua b/world.lua index 63e7448..f40ed77 100644 --- a/world.lua +++ b/world.lua @@ -3,21 +3,30 @@ local util = require("util") -- world stuffs local world = {} - -- create a new world with given height and width - function world.new(width, height) + -- create a new world with given depth and width + function world.new(width, depth, height) world.width = width + world.depth = depth world.height = height world.hover = nil - world.select = love.graphics.newImage("img/tiles/select.png") + world.select = love.graphics.newImage("img/tiles/select.png") for x = 1, world.width do world[x] = {} - for y = 1, world.height do - world[x][y] = "nothing" + for y = 1, world.depth do + world[x][y] = {} + for z = 1, world.height do + world[x][y][z] = "nothing" + end end end end + -- generates a world, should be called after world.new() + function world.generate() + + end + -- load the tile files function world.loadTiles() world.tiles = {} @@ -30,21 +39,23 @@ local world = {} -- 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}) + for y = 1, world.depth do + for z = 1, world.height do + local tile = world[x][y][z] + local loc = util.cartToIso({x = x, y = y}) - if tile == "grass" then - image = world.tiles.grass - elseif tile == "dirt" then - image = world.tiles.dirt - elseif tile == "water" then - image = world.tiles.water - else - image = world.tiles.nothing - end + if tile == "grass" then + image = world.tiles.grass + elseif tile == "dirt" then + image = world.tiles.dirt + elseif tile == "water" then + image = world.tiles.water + else + image = world.tiles.nothing + end - love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y) + love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - z * 16) + end end end