2024-02-26 08:28:11 -06:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
@onready var player = $"../../"
|
|
|
|
@onready var sprite = $"../"
|
|
|
|
|
|
|
|
@onready var grappleCore = $"../GrappleCore"
|
|
|
|
|
|
|
|
@onready var Smoother = $"../../../Smoother"
|
|
|
|
|
|
|
|
var grappleProjectile = preload("res://Player/GrappleHook/GrappleHookProjectile/GrappleHookProjectile.tscn")
|
|
|
|
|
|
|
|
var proj = null
|
|
|
|
|
|
|
|
var grappleSpeed = Vector2.ZERO
|
|
|
|
var retractDur = 0
|
|
|
|
var retractStart = Vector2.ZERO
|
|
|
|
|
|
|
|
var grappleDur = 0
|
|
|
|
|
|
|
|
var grappling = false
|
|
|
|
var retracting = false
|
|
|
|
|
|
|
|
func launch(delta):
|
|
|
|
if proj:
|
|
|
|
player.jumps = player.MAX_JUMPS - 1
|
|
|
|
var grappleVeloc = (proj.position - player.position).normalized() * grappleSpeed
|
|
|
|
player.launch(grappleVeloc.x)
|
|
|
|
player.velocity.y = grappleVeloc.y
|
|
|
|
|
|
|
|
func grappleStart():
|
|
|
|
grappleSpeed = (500 + clamp(player.velocity.length(), 500, 1000))
|
2024-02-26 09:11:08 -06:00
|
|
|
grappleDur = 1
|
2024-02-26 08:28:11 -06:00
|
|
|
grappling = true
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
grappleDur -= delta
|
|
|
|
|
|
|
|
var moveVector = (get_global_mouse_position() - player.position).normalized()
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("pullGrapple") and not proj:
|
|
|
|
#player.velocity.y = player.JUMP_VELOCITY / 2
|
|
|
|
|
|
|
|
proj = grappleProjectile.instantiate()
|
|
|
|
|
|
|
|
proj.position = player.position
|
|
|
|
proj.rotation = moveVector.angle()
|
|
|
|
|
|
|
|
proj.velocity = (moveVector * 1500) + player.velocity
|
|
|
|
#grappleDur = 10
|
|
|
|
add_child(proj)
|
|
|
|
#else:
|
|
|
|
|
|
|
|
if proj and grappleDur > 0 and (player.position - proj.position).length() > 15 and not Input.is_action_just_pressed("jump"):
|
|
|
|
launch(delta)
|
|
|
|
elif proj and grappling:
|
|
|
|
player.jumps = 1
|
2024-02-26 09:11:08 -06:00
|
|
|
#player.velocity.y = player.JUMP_VELOCITY
|
2024-02-26 08:28:11 -06:00
|
|
|
grappleDur = 0
|
|
|
|
|
|
|
|
retractStart = proj.position
|
|
|
|
retracting = true
|
|
|
|
grappling = false
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if proj and retracting == true:
|
|
|
|
proj.position = lerp(retractStart, player.position, retractDur)
|
|
|
|
retractDur += delta * 4
|
|
|
|
if retractDur >= 1:
|
|
|
|
proj.queue_free()
|
|
|
|
proj = null
|
|
|
|
retracting = false
|
|
|
|
retractDur = 0
|
|
|
|
|
|
|
|
if proj:
|
|
|
|
#Engine.time_scale = 0.1
|
|
|
|
var grappleLine = proj.get_node("GrappleLine")
|
|
|
|
var grappleBord = proj.get_node("GrappleBord")
|
|
|
|
|
|
|
|
var grapOffset = grappleCore.offset * sprite.scale
|
|
|
|
|
|
|
|
grappleLine.set_point_position(1, player.position + grapOffset)
|
|
|
|
grappleBord.set_point_position(1, player.position + grapOffset)
|
|
|
|
|
|
|
|
grappleLine.set_point_position(0, proj.position)
|
|
|
|
grappleBord.set_point_position(0, proj.position)
|
|
|
|
|
|
|
|
var curve = Curve.new()
|
|
|
|
curve.add_point(Vector2(0, 1))
|
|
|
|
curve.add_point(Vector2(1, sprite.scale.y))
|
|
|
|
|
|
|
|
grappleLine.width_curve = curve
|
|
|
|
grappleBord.width_curve = curve
|
|
|
|
|