Files
qbert.love2d/main.lua
Nick Stokoe cb49e2b933 main.lua, etc. - use a sorted list of mobs
The mobs are characters to animate.  They're sorted by screen depth,
so that nearer ones render over farther ones.
2022-07-02 22:59:14 +01:00

61 lines
999 B
Lua

local mkArena = require "arena"
local mkQbert = require "qbert"
local arena = mkArena(
7,
{3, -3},
{255, 0, 0}, {0, 255, 0}, {0, 0, 255}
)
local time = 0
local qbert = mkQbert(
arena
)
local mobs = { qbert, arena }
function love.load()
end
function love.draw()
for ix, mob in ipairs(mobs) do
mob.draw()
end
end
function love.update(dt)
if love.keyboard.isDown('i') then
qbert.jump('ne')
end
if love.keyboard.isDown('u') then
qbert.jump('nw')
end
if love.keyboard.isDown('k') then
qbert.jump('se')
end
if love.keyboard.isDown('j') then
qbert.jump('sw')
end
if love.keyboard.isDown('escape') then
love.event.quit(0)
end
for ix, mob in ipairs(mobs) do
mob.update(dt)
end
local mobs2 = {}
for ix, mob in ipairs(mobs) do
if not mob.dead then
mobs2[#mobs2+1] = mob
end
end
table.sort(mobs2, function(a, b) return a.getDepth() < b.getDepth(); end)
mobs = mobs2
end