fix: better angle position in player

This commit is contained in:
Kazhnuz 2021-11-27 13:10:53 +01:00
parent 9dd96e2a86
commit e676439431

View file

@ -18,6 +18,7 @@ function Player:new(world, x, y, z, id)
self.rings = 0
self.score = 0
self.angle = 0
end
function Player:initPlayer()
@ -39,11 +40,32 @@ function Player:updateStart(dt)
end
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
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 speed = 160
if self.keys["up"].isDown then
@ -52,19 +74,16 @@ function Player:basicMovements()
if self.keys["down"].isDown then
ysp = 1
end
if (self.world.autorun == true) then
xsp = 1
else
if self.keys["left"].isDown then
xsp = -1
end
if self.keys["right"].isDown then
xsp = 1
end
if self.keys["left"].isDown then
xsp = -1
end
if self.keys["right"].isDown then
xsp = 1
end
if (xsp ~= 0 or ysp ~= 0) then
local angle = utils.math.pointDirection(0, 0, xsp, ysp)
self.angle = angle
self.xsp, self.ysp = utils.math.lengthdir(160, angle)
end
end