rework physics, move_x now only used for graphics logic
This commit is contained in:
parent
7ca46a9a01
commit
4ae314f422
|
@ -7,7 +7,9 @@ function Player:New(x,y)
|
||||||
-- physics
|
-- physics
|
||||||
o.moveSpeed = 1.3 -- gameworld pixels
|
o.moveSpeed = 1.3 -- gameworld pixels
|
||||||
o.zeroSpeed = 0.01 -- gameworld pixels
|
o.zeroSpeed = 0.01 -- gameworld pixels
|
||||||
|
|
||||||
o.move_x = 0 -- gameworld pixels
|
o.move_x = 0 -- gameworld pixels
|
||||||
|
o.noDriftFrames = 0 -- frames
|
||||||
|
|
||||||
o.airFriction = 0.01 -- gameworld pixels
|
o.airFriction = 0.01 -- gameworld pixels
|
||||||
o.groundFriction = 0.3 -- gameworld pixels
|
o.groundFriction = 0.3 -- gameworld pixels
|
||||||
|
@ -83,14 +85,20 @@ function Player:Smart()
|
||||||
self.coyoteValue = self.coyoteValue - 1
|
self.coyoteValue = self.coyoteValue - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- not dashing, normal movment
|
||||||
if self.dashTimer <= 0 then
|
if self.dashTimer <= 0 then
|
||||||
-- horizontal movement
|
-- horizontal movement
|
||||||
if Keybind:CheckDown(Keybind.move.left) then
|
if self.noDriftFrames > 0 then
|
||||||
self.move_x = -self.moveSpeed
|
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
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
-- jump if on ground (coyotevalue) or if 0
|
-- jump if on ground (coyotevalue) or if 0
|
||||||
if Keybind:CheckPressed(Keybind.move.jump) then
|
if Keybind:CheckPressed(Keybind.move.jump) then
|
||||||
if self.coyoteValue > 0 then
|
if self.coyoteValue > 0 then
|
||||||
|
@ -99,6 +107,7 @@ function Player:Smart()
|
||||||
elseif self.wallHit ~= 0 then
|
elseif self.wallHit ~= 0 then
|
||||||
self.vel.y = -self.wallJumpImpulse.y
|
self.vel.y = -self.wallJumpImpulse.y
|
||||||
self.vel.x = -self.wallJumpImpulse.x * self.wallHit
|
self.vel.x = -self.wallJumpImpulse.x * self.wallHit
|
||||||
|
self.noDriftFrames = 7
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -174,6 +183,7 @@ function Player:DoPhysics()
|
||||||
self.isOnGround = false
|
self.isOnGround = false
|
||||||
-- adjust timers
|
-- adjust timers
|
||||||
self.dashTimer = self.dashTimer - current_dt
|
self.dashTimer = self.dashTimer - current_dt
|
||||||
|
self.noDriftFrames = self.noDriftFrames - 1
|
||||||
|
|
||||||
-- DASH STATE
|
-- DASH STATE
|
||||||
if self.dashTimer > 0 then
|
if self.dashTimer > 0 then
|
||||||
|
@ -237,11 +247,11 @@ function Player:DoPhysics()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- horizontal collision
|
-- horizontal collision
|
||||||
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
|
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.move_x
|
self.pos.x = self.pos.x + self.vel.x
|
||||||
self.wallHit = 0
|
self.wallHit = 0
|
||||||
else
|
else
|
||||||
self.wallHit = math.sign(self.vel.x + self.move_x)
|
self.wallHit = math.sign(self.vel.x)
|
||||||
self.vel.x = 0
|
self.vel.x = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue