mirror of
https://github.com/GDQuest/godot-platformer-2d.git
synced 2026-01-23 02:14:19 +00:00
Add a controllable charge mechanic after hooking onto a hooking point.
This commit is contained in:
parent
1da812db3d
commit
7f95e15f1f
4 changed files with 54 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=25 format=2]
|
||||
[gd_scene load_steps=26 format=2]
|
||||
|
||||
[ext_resource path="res://src/Player/Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/Player/Hook/Hook.tscn" type="PackedScene" id=2]
|
||||
|
|
@ -15,13 +15,14 @@
|
|||
[ext_resource path="res://src/Player/States/Wall.gd" type="Script" id=13]
|
||||
[ext_resource path="res://src/Player/States/Ledge.gd" type="Script" id=14]
|
||||
[ext_resource path="res://src/Player/States/Hook.gd" type="Script" id=15]
|
||||
[ext_resource path="res://src/Player/States/Debug.gd" type="Script" id=16]
|
||||
[ext_resource path="res://src/Player/States/Stagger.gd" type="Script" id=17]
|
||||
[ext_resource path="res://src/Player/States/Spawn.gd" type="Script" id=18]
|
||||
[ext_resource path="res://src/Player/States/Die.gd" type="Script" id=19]
|
||||
[ext_resource path="res://src/Combat/Stats.tscn" type="PackedScene" id=20]
|
||||
[ext_resource path="res://src/Combat/HitBox/HitBox.tscn" type="PackedScene" id=21]
|
||||
[ext_resource path="res://src/Player/PassThroughDetector.gd" type="Script" id=22]
|
||||
[ext_resource path="res://src/Player/States/Charge.gd" type="Script" id=16]
|
||||
[ext_resource path="res://src/Player/States/Debug.gd" type="Script" id=17]
|
||||
[ext_resource path="res://src/Player/States/Stagger.gd" type="Script" id=18]
|
||||
[ext_resource path="res://src/Player/States/Spawn.gd" type="Script" id=19]
|
||||
[ext_resource path="res://src/Player/States/Die.gd" type="Script" id=20]
|
||||
[ext_resource path="res://src/Combat/Stats.tscn" type="PackedScene" id=21]
|
||||
[ext_resource path="res://src/Combat/HitBox/HitBox.tscn" type="PackedScene" id=22]
|
||||
[ext_resource path="res://src/Player/PassThroughDetector.gd" type="Script" id=23]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 30, 30 )
|
||||
|
|
@ -56,10 +57,6 @@ remote_path = NodePath("../../CameraRig")
|
|||
|
||||
[node name="CameraRig" parent="." instance=ExtResource( 6 )]
|
||||
|
||||
[node name="ShakingCamera" parent="CameraRig" index="0"]
|
||||
DAMP_EASING = 1.0
|
||||
is_shaking = false
|
||||
|
||||
[node name="Skin" parent="." instance=ExtResource( 7 )]
|
||||
|
||||
[node name="StateMachine" type="Node" parent="."]
|
||||
|
|
@ -109,31 +106,39 @@ script = ExtResource( 14 )
|
|||
[node name="Hook" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 15 )
|
||||
|
||||
[node name="Debug" type="Node" parent="StateMachine"]
|
||||
[node name="Timer" type="Timer" parent="StateMachine/Hook"]
|
||||
process_mode = 0
|
||||
wait_time = 0.4
|
||||
one_shot = true
|
||||
|
||||
[node name="Charge" type="Node" parent="StateMachine/Hook"]
|
||||
script = ExtResource( 16 )
|
||||
|
||||
[node name="Stagger" type="Node" parent="StateMachine"]
|
||||
[node name="Debug" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 17 )
|
||||
|
||||
[node name="Stagger" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 18 )
|
||||
|
||||
[node name="Duration" type="Timer" parent="StateMachine/Stagger"]
|
||||
one_shot = true
|
||||
|
||||
[node name="Spawn" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 18 )
|
||||
|
||||
[node name="Die" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 19 )
|
||||
|
||||
[node name="Stats" parent="." instance=ExtResource( 20 )]
|
||||
[node name="Die" type="Node" parent="StateMachine"]
|
||||
script = ExtResource( 20 )
|
||||
|
||||
[node name="HitBox" parent="." instance=ExtResource( 21 )]
|
||||
[node name="Stats" parent="." instance=ExtResource( 21 )]
|
||||
|
||||
[node name="HitBox" parent="." instance=ExtResource( 22 )]
|
||||
position = Vector2( 0, -30 )
|
||||
|
||||
[node name="PassThroughDetector" type="Area2D" parent="."]
|
||||
position = Vector2( 0, -30 )
|
||||
collision_layer = 0
|
||||
collision_mask = 8
|
||||
script = ExtResource( 22 )
|
||||
script = ExtResource( 23 )
|
||||
actor_path = NodePath("..")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PassThroughDetector"]
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func unhandled_input(event: InputEvent) -> void:
|
|||
if event.is_action_pressed("jump"):
|
||||
if move.velocity.y >= 0.0 and jump_delay.time_left > 0.0:
|
||||
move.velocity = move.calculate_velocity(
|
||||
move.velocity, move.speed, Vector2(0.0, move.JUMP_SPEED), 1.0, Vector2.UP)
|
||||
move.velocity, move.max_speed, Vector2(0.0, move.JUMP_SPEED), 1.0, Vector2.UP)
|
||||
emit_signal("jumped")
|
||||
else:
|
||||
move.unhandled_input(event)
|
||||
|
|
@ -46,6 +46,7 @@ func physics_process(delta: float) -> void:
|
|||
func enter(msg: Dictionary = {}) -> void:
|
||||
var move: = get_parent()
|
||||
move.velocity = msg.velocity if "velocity" in msg else move.velocity
|
||||
move.max_speed = msg.max_speed if "max_speed" in msg else move.max_speed
|
||||
move.acceleration = Vector2(X_ACCELERATION, move.ACCELERATION.y)
|
||||
jump_delay.start()
|
||||
|
||||
|
|
|
|||
24
hook!-full-game/src/Player/States/Charge.gd
Normal file
24
hook!-full-game/src/Player/States/Charge.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
extends State
|
||||
"""
|
||||
Lets the player aim and propel themselves from a hooking point
|
||||
"""
|
||||
|
||||
|
||||
export var launch_power: = 1400.0
|
||||
|
||||
func unhandled_input(event: InputEvent) -> void:
|
||||
var direction: = Vector2.ZERO
|
||||
|
||||
match Settings.controls:
|
||||
Settings.KBD_MOUSE:
|
||||
direction = owner.get_local_mouse_position().normalized()
|
||||
Settings.GAMEPAD:
|
||||
direction = ControlUtils.get_aim_joystick_direction()
|
||||
|
||||
if event.is_action_released("hook"):
|
||||
var launch_velocity: = direction * launch_power
|
||||
var msg: = {
|
||||
velocity = launch_velocity,
|
||||
max_speed = launch_velocity.abs()
|
||||
}
|
||||
_state_machine.transition_to("Move/Air", msg)
|
||||
|
|
@ -13,9 +13,6 @@ var velocity: = Vector2.ZERO setget set_velocity
|
|||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
var to_target: Vector2 = target_global_position - owner.global_position
|
||||
var distance: = to_target.length()
|
||||
|
||||
self.velocity = Steering.arrive_to(
|
||||
velocity,
|
||||
owner.global_position,
|
||||
|
|
@ -29,6 +26,9 @@ func physics_process(delta: float) -> void:
|
|||
var distance: = to_target.length()
|
||||
|
||||
if distance < velocity.length() * delta:
|
||||
if Input.is_action_pressed("hook"):
|
||||
_state_machine.transition_to("Hook/Charge")
|
||||
else:
|
||||
self.velocity = velocity.normalized() * arrive_push
|
||||
_state_machine.transition_to("Move/Air", {velocity = velocity})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue