rework physics, move_x now only used for graphics logic

This commit is contained in:
binarycat 2022-02-26 16:57:54 -05:00 committed by lustlion
parent 7ca46a9a01
commit 4ae314f422
1 changed files with 16 additions and 6 deletions

View File

@ -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