fix: better angle position in player
This commit is contained in:
parent
9dd96e2a86
commit
e676439431
1 changed files with 29 additions and 10 deletions
|
@ -18,6 +18,7 @@ function Player:new(world, x, y, z, id)
|
||||||
|
|
||||||
self.rings = 0
|
self.rings = 0
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
self.angle = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:initPlayer()
|
function Player:initPlayer()
|
||||||
|
@ -39,11 +40,32 @@ function Player:updateStart(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.keys["B"].isPressed then
|
if self.keys["B"].isPressed then
|
||||||
self.weapons:shoot(self.x, self.y+1, self.z+8, 1)
|
self.weapons:shoot(self.x, self.y+1, self.z+8, self.angle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:basicMovements()
|
function Player:basicMovements()
|
||||||
|
if (self.world.autorun == true) then
|
||||||
|
self:basicMovementsAutorun()
|
||||||
|
else
|
||||||
|
self:basicMovementsFree()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:basicMovementsAutorun()
|
||||||
|
local xsp, ysp = 0, 0
|
||||||
|
local speed = 160
|
||||||
|
self.xsp = speed
|
||||||
|
if self.keys["up"].isDown then
|
||||||
|
self.ysp = -speed
|
||||||
|
end
|
||||||
|
if self.keys["down"].isDown then
|
||||||
|
self.ysp = speed
|
||||||
|
end
|
||||||
|
self.angle = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:basicMovementsFree()
|
||||||
local xsp, ysp = 0, 0
|
local xsp, ysp = 0, 0
|
||||||
local speed = 160
|
local speed = 160
|
||||||
if self.keys["up"].isDown then
|
if self.keys["up"].isDown then
|
||||||
|
@ -52,19 +74,16 @@ function Player:basicMovements()
|
||||||
if self.keys["down"].isDown then
|
if self.keys["down"].isDown then
|
||||||
ysp = 1
|
ysp = 1
|
||||||
end
|
end
|
||||||
if (self.world.autorun == true) then
|
|
||||||
xsp = 1
|
|
||||||
else
|
|
||||||
if self.keys["left"].isDown then
|
if self.keys["left"].isDown then
|
||||||
xsp = -1
|
xsp = -1
|
||||||
end
|
end
|
||||||
if self.keys["right"].isDown then
|
if self.keys["right"].isDown then
|
||||||
xsp = 1
|
xsp = 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if (xsp ~= 0 or ysp ~= 0) then
|
if (xsp ~= 0 or ysp ~= 0) then
|
||||||
local angle = utils.math.pointDirection(0, 0, xsp, ysp)
|
local angle = utils.math.pointDirection(0, 0, xsp, ysp)
|
||||||
|
self.angle = angle
|
||||||
self.xsp, self.ysp = utils.math.lengthdir(160, angle)
|
self.xsp, self.ysp = utils.math.lengthdir(160, angle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue