117 lines
2.3 KiB
Lua
117 lines
2.3 KiB
Lua
-- Collision groups:
|
|
-- 0x1 - top and bottom walls
|
|
-- 0x2 - player
|
|
-- 0x4 - enemies
|
|
-- 0x8 - side walls
|
|
-- 0x10 - bullets
|
|
import "CoreLibs/object"
|
|
import "CoreLibs/graphics"
|
|
import "CoreLibs/sprites"
|
|
import "CoreLibs/timer"
|
|
import "kani"
|
|
import "enemies"
|
|
import "wave"
|
|
|
|
local gfx <const> = playdate.graphics
|
|
local geom <const> = playdate.geometry
|
|
|
|
local player = nil
|
|
local ui = nil
|
|
local currentWave = nil
|
|
|
|
function setup()
|
|
ui = UI()
|
|
player = Kani(ui)
|
|
player:moveTo(16, 120)
|
|
player:addInputHandlers()
|
|
player:add()
|
|
ui:add()
|
|
currentWave = newWave()
|
|
currentWave:add()
|
|
|
|
makeWalls()
|
|
drawBackground()
|
|
|
|
-- debug, TODO remove this code
|
|
playdate.inputHandlers.push({
|
|
BButtonUp = function()
|
|
print(gfx.sprite.spriteCount())
|
|
end
|
|
})
|
|
end
|
|
|
|
function makeWalls()
|
|
makeWall(200, 0, 400, 1, 0x1)
|
|
makeWall(0, 120, 1, 240, 0x8)
|
|
makeWall(200, 240, 400, 1, 0x1)
|
|
makeWall(400, 120, 1, 240, 0x8)
|
|
end
|
|
|
|
function makeWall(x, y, w, h, mask)
|
|
local wall = gfx.sprite.new()
|
|
wall:setSize(w, h)
|
|
wall:setCollideRect(0, 0, wall:getSize())
|
|
wall:moveTo(x, y)
|
|
wall:setGroupMask(mask)
|
|
wall:add()
|
|
end
|
|
|
|
function drawBackground()
|
|
local backgroundImage = gfx.image.new(400, 240, gfx.kColorWhite)
|
|
gfx.sprite.setBackgroundDrawingCallback(
|
|
function(x, y, width, height)
|
|
backgroundImage:draw(0, 0)
|
|
end
|
|
)
|
|
end
|
|
|
|
-- Right now we only have a single wave and we repeat it forever
|
|
function newWave()
|
|
wave = Wave.new()
|
|
|
|
local startPosition = geom.point.new(410,120)
|
|
|
|
local enemy = Ika(player)
|
|
enemy.introAnimator = gfx.animator.new(
|
|
5000,
|
|
startPosition,
|
|
geom.point.new(350,120)
|
|
)
|
|
|
|
wave:addEntity(enemy)
|
|
|
|
local y = 50
|
|
for x=270, 300, 10 do
|
|
local dir = 1
|
|
if math.random(2) == 1 then
|
|
dir = -1
|
|
end
|
|
local vector = geom.vector2D.new(0, dir)
|
|
|
|
enemy = Ebi()
|
|
enemy.vector = vector
|
|
enemy.introAnimator = gfx.animator.new(
|
|
2500,
|
|
startPosition,
|
|
geom.point.new(x,y)
|
|
)
|
|
|
|
wave:addEntity(enemy)
|
|
|
|
y += 50
|
|
end
|
|
|
|
return wave
|
|
end
|
|
|
|
function playdate.update()
|
|
gfx.sprite.update()
|
|
if currentWave:update() then
|
|
-- fight forever lol
|
|
currentWave = newWave()
|
|
currentWave:add()
|
|
end
|
|
playdate.timer.updateTimers()
|
|
end
|
|
|
|
setup()
|