85 lines
2.2 KiB
GDScript
85 lines
2.2 KiB
GDScript
extends Sprite2D
|
|
|
|
@onready var player = $"../"
|
|
|
|
var spinAccel = 0
|
|
|
|
func spin(veloc, delta):
|
|
var vertSpinMult = abs(veloc.y) * clamp(veloc.x, -1, 1) / 1.5
|
|
var spinFactor = (veloc.x + vertSpinMult) / 30
|
|
|
|
if player.direction or abs(player.velocity.x) > 100:
|
|
rotation = lerp(rotation, rotation + (spinFactor), delta)
|
|
else:
|
|
rotation = lerp(rotation, snappedf(rotation + (spinFactor * delta * 2), PI / 2), delta * 5)
|
|
|
|
var landed = 0
|
|
|
|
@onready var slidingVariants = [$"WallslidingNeutral", $"WallslidingUp", $"WallslidingDown"]
|
|
|
|
func disableSlidingVariants(keep=null):
|
|
for variant in slidingVariants:
|
|
if variant != keep:
|
|
variant.emitting = false
|
|
|
|
func _process(delta):
|
|
var velocity = player.velocity
|
|
var grapple = $"GrappleCore"
|
|
|
|
var floored = player.is_on_floor()
|
|
|
|
if player.isWallSliding():
|
|
var wallSlidingParticles = slidingVariants[0]
|
|
if abs(velocity.y) < 150:
|
|
wallSlidingParticles = slidingVariants[1]
|
|
elif abs(velocity.y) > 300:
|
|
wallSlidingParticles = slidingVariants[2]
|
|
|
|
disableSlidingVariants(wallSlidingParticles)
|
|
wallSlidingParticles.emitting = true
|
|
wallSlidingParticles.global_position = player.position + (player.get_wall_normal() * -8 * player.scale.x)
|
|
wallSlidingParticles.global_rotation = player.get_wall_normal().x * deg_to_rad(45)
|
|
|
|
else:
|
|
disableSlidingVariants()
|
|
|
|
if not floored:
|
|
spin(velocity, delta)
|
|
landed = velocity.y
|
|
|
|
#scale = Vector2.ONE
|
|
|
|
if player.isWallSliding():
|
|
rotation = lerp(rotation, deg_to_rad(30) * player.get_wall_normal().x + snappedf(rotation, PI / 2), delta * 15)
|
|
else:
|
|
var floorRot = player.get_floor_normal().angle() + (PI / 2)
|
|
|
|
if abs(rotation - floorRot) > 0.9:
|
|
rotation = floorRot
|
|
|
|
rotation = lerp(rotation, floorRot, delta * 10)
|
|
|
|
if landed:
|
|
rotation = 0
|
|
scale.y = 1 - (landed / 800)
|
|
scale.x = 1 + (landed / 800)
|
|
landed = 0
|
|
|
|
scale.y = lerp(scale.y, 1.0, delta * 7)
|
|
scale.x = lerp(scale.x, 1.0, delta * 7)
|
|
|
|
scale.y = clamp(scale.y, 0.25, INF)
|
|
scale.x = clamp(scale.x, 0.1, INF)
|
|
|
|
#modulate.h = abs(player.position.x / 400.)
|
|
offset.y = (8 * pow(scale.y, -1) - 8)
|
|
offset.x = 0
|
|
|
|
grapple.offset = offset
|
|
|
|
|
|
func _on_character_jumped():
|
|
if not player.direction:
|
|
rotation = 0
|
|
scale.y = 1.5
|
|
scale.x = 0.5
|