2022-04-19 21:31:46 +00:00
|
|
|
import "CoreLibs/math"
|
2022-04-24 18:15:38 +00:00
|
|
|
import "CoreLibs/animator"
|
2022-04-19 21:31:46 +00:00
|
|
|
|
2022-04-19 21:22:15 +00:00
|
|
|
local velocity = {x=0,y=0}
|
|
|
|
local lerpmnt <const> = 0.5
|
|
|
|
local grav <const> = 0.2
|
2022-04-23 23:54:00 +00:00
|
|
|
scale = 1
|
2022-04-24 18:15:38 +00:00
|
|
|
local dead = false
|
2022-04-19 21:22:15 +00:00
|
|
|
|
2022-04-22 18:02:47 +00:00
|
|
|
local exists = false
|
|
|
|
local active = false
|
|
|
|
local gfx <const> = playdate.graphics
|
2022-04-19 21:22:15 +00:00
|
|
|
local imgRocket = gfx.image.new("gfx/rocket")
|
|
|
|
assert(imgRocket)
|
|
|
|
local sprRocket = gfx.sprite.new(imgRocket)
|
|
|
|
sprRocket:setCollideRect(7, 7, 14, 14)
|
2022-04-22 18:02:47 +00:00
|
|
|
local startpos = {x=0,y=0}
|
2022-04-19 21:22:15 +00:00
|
|
|
|
2022-04-23 23:54:00 +00:00
|
|
|
local imgBigRocket = gfx.image.new("gfx/bigrocket")
|
|
|
|
assert(imgBigRocket)
|
|
|
|
local sprBigRocket = gfx.sprite.new(imgBigRocket)
|
|
|
|
sprBigRocket:setCollideRect(8,8,48,48)
|
|
|
|
sprBigRocket:setGroups({2})
|
|
|
|
|
|
|
|
function addPlayer(_x,_y,__x,__y)
|
2022-04-22 18:02:47 +00:00
|
|
|
exists = true
|
2022-04-24 18:15:38 +00:00
|
|
|
dead = false
|
2022-04-23 23:54:00 +00:00
|
|
|
scale = 1
|
2022-04-22 18:02:47 +00:00
|
|
|
active = false
|
|
|
|
velocity = {x=0,y=0}
|
|
|
|
startpos = {x= _x,y=_y}
|
2022-04-23 23:54:00 +00:00
|
|
|
sprBigRocket:moveTo(__x,__y)
|
|
|
|
sprBigRocket:add()
|
2022-04-22 18:02:47 +00:00
|
|
|
sprRocket:moveTo(_x,_y)
|
2022-04-19 21:22:15 +00:00
|
|
|
sprRocket:add()
|
|
|
|
end
|
|
|
|
|
2022-04-22 18:02:47 +00:00
|
|
|
function killPlayer()
|
|
|
|
exists = false
|
|
|
|
active = false
|
|
|
|
sprRocket:remove()
|
2022-04-23 06:54:45 +00:00
|
|
|
gfx.setDrawOffset(0,0)
|
2022-04-22 18:02:47 +00:00
|
|
|
end
|
|
|
|
|
2022-04-23 23:54:00 +00:00
|
|
|
local function playerWin()
|
|
|
|
active = false
|
|
|
|
exists = false
|
2022-04-24 18:15:38 +00:00
|
|
|
dead = true
|
2022-04-23 23:54:00 +00:00
|
|
|
end
|
|
|
|
|
2022-04-22 18:02:47 +00:00
|
|
|
local function die()
|
|
|
|
active = false
|
|
|
|
velocity = {x=0,y=0}
|
|
|
|
sprRocket:moveTo(startpos.x, startpos.y)
|
|
|
|
end
|
|
|
|
|
2022-04-19 21:22:15 +00:00
|
|
|
function updatePlayer()
|
2022-04-22 18:02:47 +00:00
|
|
|
if active == true then
|
2022-04-19 21:22:15 +00:00
|
|
|
if playdate.buttonIsPressed(playdate.kButtonUp) then
|
2022-04-23 06:54:45 +00:00
|
|
|
velocity.x = velocity.x + math.sin(math.rad(playdate.getCrankPosition())) /2
|
|
|
|
velocity.y = velocity.y - math.cos(math.rad(playdate.getCrankPosition())) /2
|
2022-04-19 21:22:15 +00:00
|
|
|
end
|
|
|
|
sprRocket:moveBy(velocity.x,velocity.y)
|
|
|
|
|
|
|
|
local cx, cy = gfx.getDrawOffset()
|
|
|
|
gfx.setDrawOffset(playdate.math.lerp(cx,(-sprRocket.x + 200), lerpmnt), playdate.math.lerp(cy,(-sprRocket.y + 120), lerpmnt))
|
|
|
|
|
|
|
|
sprRocket:setRotation(0)
|
|
|
|
sprRocket:update()
|
|
|
|
--print(#sprRocket:overlappingSprites())
|
|
|
|
|
|
|
|
velocity.y += grav
|
2022-04-22 18:02:47 +00:00
|
|
|
|
|
|
|
if #sprRocket:overlappingSprites() > 0 then
|
|
|
|
die()
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif exists == true then
|
|
|
|
if playdate.buttonIsPressed(playdate.kButtonUp) then
|
|
|
|
active = true
|
|
|
|
end
|
|
|
|
local cx, cy = gfx.getDrawOffset()
|
|
|
|
gfx.setDrawOffset(playdate.math.lerp(cx,(-sprRocket.x + 200), lerpmnt), playdate.math.lerp(cy,(-sprRocket.y + 120), lerpmnt))
|
2022-04-24 18:15:38 +00:00
|
|
|
elseif dead == true then
|
|
|
|
if scale > 0.1 then
|
|
|
|
scale -= 0.05
|
|
|
|
end
|
2022-04-19 21:22:15 +00:00
|
|
|
end
|
2022-04-23 23:54:00 +00:00
|
|
|
updateExit()
|
|
|
|
|
|
|
|
sprRocket:setScale(scale,scale)
|
|
|
|
|
2022-04-22 18:02:47 +00:00
|
|
|
sprRocket:setRotation(playdate.getCrankPosition())
|
2022-04-23 23:54:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function updateExit()
|
|
|
|
if sprBigRocket:alphaCollision(sprRocket) then
|
|
|
|
playerWin()
|
|
|
|
end
|
2022-04-19 21:22:15 +00:00
|
|
|
end
|