reimplemented hook swing movement >:3

This commit is contained in:
lustlion 2022-02-27 00:09:50 +01:00
parent a3cfe1fed3
commit ce43e48723
1 changed files with 38 additions and 26 deletions

View File

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