Let's get to the code first.
Code: Select all
-- in movingTestThing.lua
mtt = {}
function mtt:load()
self.x = 100
self.y = 100
self.w = 32
self.h = 32
self.speed = 500
self.loaded = true
world:add(mtt, self.x, self.y, self.w, self.y)
end
function mtt:move(dt)
if love.keyboard.isDown("w") then
local actualX, actualY, cols, len = world:move(mtt, self.x, self.y - self.speed * dt)
self.x = actualX
self.y = actualY
end
if love.keyboard.isDown("a") then
local actualX, actualY, cols, len = world:move(mtt, self.x - self.speed * dt, self.y)
self.x = actualX
self.y = actualY
end
if love.keyboard.isDown("s") then
local actualX, actualY, cols, len = world:move(mtt, self.x, self.y + self.speed * dt)
self.x = actualX
self.y = actualY
end
if love.keyboard.isDown("d") then
local actualX, actualY, cold, len = world:move(mtt, self.x + self.speed * dt, self.y)
self.x = actualX
self.y = actualY
end
end
function mtt:draw()
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("fill", self.x, self.y, self.w, self.h)
end
Code: Select all
-- in entity.lua
entity = {}
local entitySize = 32
local entityList = {}
function entity:load(name, x, y)
entityList[#entityList + 1] = {name = name, x = x, y = y}
world:add(name, x, y, entitySize, entitySize)
end
function entity:draw()
love.graphics.setColor(0, 255, 0)
for i = 1, #entityList do
love.graphics.rectangle("fill", entityList[i].x, entityList[i].y, entitySize, entitySize)
end
end
I'll attach the .love file if you have the time to examine it.
Thanks in advance!