reimplemented hook swing movement >:3
This commit is contained in:
parent
a3cfe1fed3
commit
ce43e48723
|
@ -33,22 +33,31 @@ function Player:New(x,y)
|
|||
o.dashAmount = 10 -- int
|
||||
|
||||
-- hook values
|
||||
o.hookSwingSpeed = math.rad(0.05)
|
||||
o.hookAnchor = {
|
||||
x = nil,
|
||||
y = nil
|
||||
}
|
||||
|
||||
-- walljump values
|
||||
o.walljumpNoDriftAmount = 7
|
||||
|
||||
-- light values
|
||||
o.lightRange = 40 -- screen pixels
|
||||
|
||||
-- status
|
||||
o.isDashing = false
|
||||
o.isJumping = false
|
||||
o.isHooked = false
|
||||
o.isOnGround = true
|
||||
o.isOnLadder = false
|
||||
o.canJump = true
|
||||
o.canFall = true
|
||||
o.canFriction = true
|
||||
o.canHook = true
|
||||
o.canWalljump = true
|
||||
|
||||
o.isDashing = false
|
||||
o.isHooked = false
|
||||
o.isJumping = false
|
||||
o.isOnGround = true
|
||||
o.isOnLadder = false
|
||||
|
||||
o.maskType = animation.moth_mask
|
||||
o.wallHit = 0
|
||||
|
||||
|
@ -88,26 +97,27 @@ function Player:Smart()
|
|||
-- not dashing, normal movment
|
||||
if self.dashTimer <= 0 then
|
||||
-- horizontal movement
|
||||
if not self.isHooked then
|
||||
if self.noDriftFrames > 0 then
|
||||
self.move_x = 0
|
||||
elseif Keybind:CheckDown(Keybind.move.left) then
|
||||
self.move_x = -self.moveSpeed
|
||||
self.move_x = -1
|
||||
self.vel.x = math.min(self.vel.x, -self.moveSpeed)
|
||||
elseif Keybind:CheckDown(Keybind.move.right) then
|
||||
self.move_x = 1
|
||||
self.vel.x = math.max(self.vel.x, self.moveSpeed)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- jump if on ground (coyotevalue) or if 0
|
||||
if Keybind:CheckPressed(Keybind.move.jump) then
|
||||
if self.canJump and Keybind:CheckPressed(Keybind.move.jump) then
|
||||
if self.coyoteValue > 0 then
|
||||
self.vel.y = -self.jumpImpulse
|
||||
self.coyoteValue = 0
|
||||
elseif self.wallHit ~= 0 then
|
||||
elseif self.canWalljump and self.wallHit ~= 0 then
|
||||
self.vel.y = -self.wallJumpImpulse.y
|
||||
self.vel.x = -self.wallJumpImpulse.x * self.wallHit
|
||||
self.noDriftFrames = 7
|
||||
self.noDriftFrames = self.walljumpNoDriftAmount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -148,7 +158,7 @@ function Player:Smart()
|
|||
self.isDashing = false
|
||||
end
|
||||
|
||||
if Keybind:CheckPressed(Keybind.move.hook) then
|
||||
if self.canHook and Keybind:CheckPressed(Keybind.move.hook) then
|
||||
if self.isHooked then
|
||||
self:Unhook()
|
||||
else
|
||||
|
@ -181,6 +191,7 @@ function Player:DoPhysics()
|
|||
-- reset state
|
||||
self.canFall = true
|
||||
self.isOnGround = false
|
||||
|
||||
-- adjust timers
|
||||
self.dashTimer = self.dashTimer - current_dt
|
||||
self.noDriftFrames = self.noDriftFrames - 1
|
||||
|
@ -207,17 +218,17 @@ function Player:DoPhysics()
|
|||
|
||||
-- hook state
|
||||
if self.isHooked then
|
||||
self.move_x = 0
|
||||
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
|
||||
local dist = math.min(GetVectorValue(hook), self.hookDistance)
|
||||
|
||||
if GetVectorValue(hook) > self.hookDistance then
|
||||
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
|
||||
|
||||
if Keybind:CheckDown(Keybind.move.right) then
|
||||
hook_angle = hook_angle - math.rad(0.1)
|
||||
self.move_x = 0
|
||||
hook_angle = hook_angle - self.hookSwingSpeed
|
||||
end
|
||||
|
||||
if Keybind:CheckDown(Keybind.move.left) then
|
||||
hook_angle = hook_angle + math.rad(0.1)
|
||||
self.move_x = 0
|
||||
hook_angle = hook_angle + self.hookSwingSpeed
|
||||
end
|
||||
|
||||
local particle_data = {
|
||||
|
@ -231,13 +242,14 @@ function Player:DoPhysics()
|
|||
}
|
||||
Particle:New(self.pos.x,self.pos.y,particle_data)
|
||||
|
||||
local pos_x = self.hookAnchor.x + dist * math.cos(hook_angle)
|
||||
local pos_y = self.hookAnchor.y + dist * math.sin(hook_angle)
|
||||
local pos_x = self.hookAnchor.x + self.hookDistance * math.cos(hook_angle)
|
||||
local pos_y = self.hookAnchor.y + self.hookDistance * math.sin(hook_angle)
|
||||
self.vel.x = self.vel.x + pos_x - self.pos.x
|
||||
self.vel.y = self.vel.y + pos_y - self.pos.y
|
||||
self.pos.x = pos_x
|
||||
self.pos.y = pos_y
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.canFall then
|
||||
|
|
Loading…
Reference in New Issue