@@ -0,0 +1,47 @@ | |||||
-- bring in the util module | |||||
local util = require("util") | |||||
local entities = {} | |||||
-- initialize the entities table | |||||
function entities.init() | |||||
entities.staticEntities = {} | |||||
entities.dynamicEntities = {} | |||||
end | |||||
-- load all sprites to memory | |||||
function entities.loadSprites() | |||||
entities.sprites = {} | |||||
entities.sprites.town = love.graphics.newImage("img/building.png") | |||||
end | |||||
-- create a new static entity that will always align with the map grid | |||||
function entities.newStatic(x, y, z, type) | |||||
local static = {} | |||||
static.x = x | |||||
static.y = y | |||||
static.z = z | |||||
static.type = type | |||||
table.insert(entities.staticEntities, static) | |||||
end | |||||
-- render all entities | |||||
function entities.render(offset) | |||||
-- render static entities | |||||
for _, entity in ipairs(entities.staticEntities) do | |||||
local type = entity.type | |||||
local loc = util.cartToIso({x = entity.x, y = entity.y}) | |||||
if type == "town" then | |||||
image = entities.sprites.town | |||||
end | |||||
if image ~= nil then | |||||
love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - entity.z * 16) | |||||
end | |||||
end | |||||
end | |||||
return entities |
@@ -1,5 +1,7 @@ | |||||
-- world module | -- world module | ||||
local world = require("world") | local world = require("world") | ||||
-- entities module | |||||
local entities = require("entities") | |||||
-- love's load function | -- love's load function | ||||
function love.load() | function love.load() | ||||
@@ -8,10 +10,16 @@ function love.load() | |||||
x = 304, | x = 304, | ||||
y = 48 | y = 48 | ||||
} | } | ||||
-- generate the world and load the files | -- generate the world and load the files | ||||
world.new(20, 20, 3) | world.new(20, 20, 3) | ||||
world.generate() | |||||
world.loadTiles() | world.loadTiles() | ||||
-- entities initialization | |||||
entities.init() | |||||
entities.loadSprites() | |||||
entities.newStatic(7, 7, 3, "town") | |||||
end | end | ||||
-- love's update function | -- love's update function | ||||
@@ -50,4 +58,7 @@ function love.draw() | |||||
-- draw the map | -- draw the map | ||||
world.render(offset) | world.render(offset) | ||||
-- draw the entities | |||||
entities.render(offset) | |||||
end | end |
@@ -16,7 +16,7 @@ local world = {} | |||||
for y = 1, world.depth do | for y = 1, world.depth do | ||||
world[x][y] = {} | world[x][y] = {} | ||||
for z = 1, world.height do | for z = 1, world.height do | ||||
world[x][y][z] = "nothing" | |||||
world[x][y][z] = "air" | |||||
end | end | ||||
end | end | ||||
end | end | ||||
@@ -24,7 +24,22 @@ local world = {} | |||||
-- generates a world, should be called after world.new() | -- generates a world, should be called after world.new() | ||||
function world.generate() | function world.generate() | ||||
-- draw the bottom layer of dirt | |||||
for x = 1, world.width do | |||||
for y = 1, world.depth do | |||||
world[x][y][1] = "dirt" | |||||
end | |||||
end | |||||
-- draw the grass | |||||
for x = 1, world.width do | |||||
for y = 1, world.depth do | |||||
world[x][y][2] = "grass" | |||||
end | |||||
end | |||||
-- draw a stream | |||||
for x = 1, world.width do | |||||
world[x][5][2] = "water" | |||||
end | |||||
end | end | ||||
-- load the tile files | -- load the tile files | ||||
@@ -50,16 +65,20 @@ local world = {} | |||||
image = world.tiles.dirt | image = world.tiles.dirt | ||||
elseif tile == "water" then | elseif tile == "water" then | ||||
image = world.tiles.water | image = world.tiles.water | ||||
elseif tile == "air" then | |||||
image = nil | |||||
else | else | ||||
image = world.tiles.nothing | image = world.tiles.nothing | ||||
end | end | ||||
love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - z * 16) | |||||
if image ~= nil then | |||||
love.graphics.draw(image, loc.x * 16 + offset.x, loc.y * 16 + offset.y - z * 16) | |||||
end | |||||
end | end | ||||
end | end | ||||
end | end | ||||
if not world.hover == nil then | |||||
if world.hover ~= nil then | |||||
love.graphics.draw(world.select, world.hover.x, world.hover.y) | love.graphics.draw(world.select, world.hover.x, world.hover.y) | ||||
end | end | ||||
end | end | ||||