From e6764394317525797542990855113b0ebee44627 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Nov 2021 13:10:53 +0100 Subject: [PATCH] fix: better angle position in player --- .../subgames/world/actors/player/init.lua | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/sonic-bluestreak.love/game/modules/subgames/world/actors/player/init.lua b/sonic-bluestreak.love/game/modules/subgames/world/actors/player/init.lua index e94f56a..765546e 100644 --- a/sonic-bluestreak.love/game/modules/subgames/world/actors/player/init.lua +++ b/sonic-bluestreak.love/game/modules/subgames/world/actors/player/init.lua @@ -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