Files
qbert.love2d/main.lua
2022-07-02 23:00:27 +01:00

68 lines
1.1 KiB
Lua

local mkArena = require "arena"
local mkQbert = require "qbert"
local mkBall = require "ball"
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)
time = time + dt
if time > 10 then
time = 0
table.insert(mobs, mkBall(arena))
end
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