From 4ae314f422f694a6840898147ee118755857a724 Mon Sep 17 00:00:00 2001 From: binarycat Date: Sat, 26 Feb 2022 16:57:54 -0500 Subject: [PATCH] rework physics, move_x now only used for graphics logic --- code/entities/player.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/code/entities/player.lua b/code/entities/player.lua index af4d8ed..e5429ea 100644 --- a/code/entities/player.lua +++ b/code/entities/player.lua @@ -7,7 +7,9 @@ function Player:New(x,y) -- physics o.moveSpeed = 1.3 -- gameworld pixels o.zeroSpeed = 0.01 -- gameworld pixels + o.move_x = 0 -- gameworld pixels + o.noDriftFrames = 0 -- frames o.airFriction = 0.01 -- gameworld pixels o.groundFriction = 0.3 -- gameworld pixels @@ -83,14 +85,20 @@ function Player:Smart() self.coyoteValue = self.coyoteValue - 1 end + -- not dashing, normal movment if self.dashTimer <= 0 then -- horizontal movement - if Keybind:CheckDown(Keybind.move.left) then - self.move_x = -self.moveSpeed + if self.noDriftFrames > 0 then + self.move_x = 0 + elseif Keybind:CheckDown(Keybind.move.left) then + self.move_x = -1 + self.vel.x = math.min(self.vel.x, -self.moveSpeed) elseif Keybind:CheckDown(Keybind.move.right) then - self.move_x = self.moveSpeed + self.move_x = 1 + self.vel.x = math.max(self.vel.x, self.moveSpeed) end + -- jump if on ground (coyotevalue) or if 0 if Keybind:CheckPressed(Keybind.move.jump) then if self.coyoteValue > 0 then @@ -99,6 +107,7 @@ function Player:Smart() elseif self.wallHit ~= 0 then self.vel.y = -self.wallJumpImpulse.y self.vel.x = -self.wallJumpImpulse.x * self.wallHit + self.noDriftFrames = 7 end end end @@ -174,6 +183,7 @@ function Player:DoPhysics() self.isOnGround = false -- adjust timers self.dashTimer = self.dashTimer - current_dt + self.noDriftFrames = self.noDriftFrames - 1 -- DASH STATE if self.dashTimer > 0 then @@ -237,11 +247,11 @@ function Player:DoPhysics() end -- horizontal collision - if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then - self.pos.x = self.pos.x + self.vel.x + self.move_x + if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then + self.pos.x = self.pos.x + self.vel.x self.wallHit = 0 else - self.wallHit = math.sign(self.vel.x + self.move_x) + self.wallHit = math.sign(self.vel.x) self.vel.x = 0 end