Rocket-Bytes/Source/Player.lua
2022-04-19 15:22:15 -06:00

37 lines
No EOL
1.1 KiB
Lua

local velocity = {x=0,y=0}
local lerpmnt <const> = 0.5
local grav <const> = 0.2
local gfx <const> = playdate.graphics
local active = false
local imgRocket = gfx.image.new("gfx/rocket")
assert(imgRocket)
local sprRocket = gfx.sprite.new(imgRocket)
sprRocket:setCollideRect(7, 7, 14, 14)
function addPlayer(x,y)
active = true
sprRocket:moveTo(x,y)
sprRocket:add()
end
function updatePlayer()
if active then
if playdate.buttonIsPressed(playdate.kButtonUp) then
velocity.x = velocity.x + math.sin(math.rad(playdate.getCrankPosition()))
velocity.y = velocity.y - math.cos(math.rad(playdate.getCrankPosition()))
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())
sprRocket:setRotation(playdate.getCrankPosition())
velocity.y += grav
end
end