basic player movement
This commit is contained in:
parent
c225cc6edf
commit
ee79aad06e
1 changed files with 27 additions and 0 deletions
|
|
@ -10,10 +10,37 @@ function Player:new(area, x, y, opts)
|
||||||
|
|
||||||
self.w, self.h = 12, 12
|
self.w, self.h = 12, 12
|
||||||
self.collider = self.area.world:circle(self.x, self.y, math.floor(self.w*0.8))
|
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
|
end
|
||||||
|
|
||||||
function Player:update(dt)
|
function Player:update(dt)
|
||||||
Player.super.update(self, 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
|
end
|
||||||
|
|
||||||
function Player:draw()
|
function Player:draw()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue