basic player movement

This commit is contained in:
yuki 2025-11-11 03:41:05 -03:00
parent c225cc6edf
commit ee79aad06e

View file

@ -10,10 +10,37 @@ function Player:new(area, x, y, opts)
self.w, self.h = 12, 12
self.collider = self.area.world:circle(self.x, self.y, math.floor(self.w*0.8))
-- player angle
self.r = -math.pi/2
-- velocity of player angle rotation
self.rv = 1.66*math.pi
-- player velocity
self.v = 0
-- max player velocity
self.max_v = 100
-- player acceleration
self.a = 100
end
function Player:update(dt)
Player.super.update(self, dt)
-- controls
if input:down('left') then self.r = self.r - self.rv*dt end
if input:down('right') then self.r = self.r + self.rv*dt end
-- update velocity
self.v = math.min(self.v + self.a*dt, self.max_v)
-- update position
local vx = self.v * math.cos(self.r) -- velocity X
local vy = self.v * math.sin(self.r) -- velocity Y
self.x = self.x + vx * dt -- update position X
self.y = self.y + vy * dt -- update position Y
-- move collision area
self.collider:moveTo(self.x, self.y)
end
function Player:draw()