Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Falling animation #234

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion new hole detector/hole_detector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,30 @@ signal fall_in_hole
@onready var hole_area: Area2D = $InHole
@onready var last_safe_position := global_position

@export var points: Array[Node2D]
var enabled := true

func hole_pointcast(point: Vector2) -> bool:
var params := PhysicsPointQueryParameters2D.new()
params.position = point
params.collision_mask = 8 # hole layer

var results := get_world_2d().direct_space_state.intersect_point(params)

return not results.is_empty()

func _process(delta: float) -> void:
if not enabled: return

if close_to_hole_area.get_overlapping_bodies().is_empty():
last_safe_position = global_position

if _has_unoccluded_hole(hole_area.get_overlapping_bodies()):
var raycast := true
for point in points:
raycast = raycast and hole_pointcast(point.global_position)
raycast = raycast and hole_pointcast(hole_area.global_position)

if _has_unoccluded_hole(hole_area.get_overlapping_bodies()) and raycast:
fall_in_hole.emit()

static func _has_unoccluded_hole(collisions: Array[Node2D]) -> bool:
Expand Down
17 changes: 13 additions & 4 deletions new hole detector/hole_detector.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ radius = 13.5093

[sub_resource type="CircleShape2D" id="CircleShape2D_axtq5"]

[node name="HoleDetector" type="Node2D"]
[node name="HoleDetector" type="Node2D" node_paths=PackedStringArray("points")]
script = ExtResource("1_l0wth")
points = [NodePath("Marker2D4"), NodePath("Marker2D3"), NodePath("Marker2D2"), NodePath("Marker2D")]

[node name="CloseToHole" type="Area2D" parent="."]
collision_layer = 8
Expand All @@ -25,6 +26,14 @@ collision_mask = 8
[node name="CollisionShape2D" type="CollisionShape2D" parent="InHole"]
shape = SubResource("CircleShape2D_axtq5")

[connection signal="body_entered" from="CloseToHole" to="." method="_on_close_to_hole_body_entered"]
[connection signal="body_entered" from="InHole" to="." method="_on_in_hole_body_entered"]
[connection signal="body_exited" from="InHole" to="." method="_on_in_hole_body_exited"]
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(10, 0)

[node name="Marker2D2" type="Marker2D" parent="."]
position = Vector2(-10, 0)

[node name="Marker2D3" type="Marker2D" parent="."]
position = Vector2(0, -10)

[node name="Marker2D4" type="Marker2D" parent="."]
position = Vector2(0, 10)
38 changes: 36 additions & 2 deletions player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ var last_aim_direction := Vector2.RIGHT

var invincible: bool = false

#Whether the players input is locked. Used when the falling animation is playing
var input_locked : bool = false
#The angle the player should spin as they fall
var fall_angle : int = 360
var fall_timer : float = 1.0

var facing_right: bool = true;
var rolling: bool = false
var roll_vector: Vector2 = Vector2(0, 0)
Expand Down Expand Up @@ -130,6 +136,11 @@ func throw_sword() -> void:
sword.tree_exited.connect(sword_caught.emit)

func _process(delta: float) -> void:

#State where the player is falling
if input_locked:
return

if Input.is_action_just_pressed("speak"):
if !$Speak.on_cooldown():
$Speak.speak()
Expand Down Expand Up @@ -246,9 +257,32 @@ func pickup_item(item: Item) -> void:
item.consume(self)

func fall_in_hole() -> void:
hurt(DamageEvent.new(1))
# todo: play animation
hole_detector.enabled = false

if(facing_right):
play_animation("idle_right")
else:
play_animation("idle_left")

input_locked = true
var tween : Tween = create_tween()

tween.tween_property($SkinChooser, "scale", Vector2.ZERO, fall_timer)
tween.parallel().tween_property($SkinChooser, "rotation_degrees", fall_angle if facing_right else -fall_angle, fall_timer)

$FallTimer.start(fall_timer)

func end_fall() -> void:
position = hole_detector.last_safe_position
$SkinChooser.rotation_degrees = 0
$SkinChooser.scale = Vector2(1,1)
input_locked = false
hurt(DamageEvent.new(1))

#Ok. I have no idea why, but falling retriggers even if the hole is enabled with 1 frame of delay
await get_tree().process_frame
await get_tree().process_frame
hole_detector.enabled = true

func activate_iframes() -> void:
invincible = true
Expand Down
8 changes: 6 additions & 2 deletions player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,12 @@ script = ExtResource("9_de2wb")

[node name="Skin1" type="AnimatedSprite2D" parent="SkinChooser"]
unique_name_in_owner = true
visible = false
position = Vector2(13, 15)
scale = Vector2(0.21, 0.21)
sprite_frames = SubResource("SpriteFrames_r4o7u")
animation = &"idle_left"
frame_progress = 0.050815
frame_progress = 0.815333

[node name="XRay" type="Node" parent="SkinChooser/Skin1"]
script = ExtResource("3_f3hsb")
Expand All @@ -763,7 +764,6 @@ x_ray_opacity = 0.4

[node name="Skin3" type="AnimatedSprite2D" parent="SkinChooser"]
unique_name_in_owner = true
visible = false
position = Vector2(13, 14)
scale = Vector2(0.23, 0.23)
sprite_frames = SubResource("SpriteFrames_80kpl")
Expand All @@ -786,6 +786,9 @@ speak_time = 0.5
wait_time = 0.75
one_shot = true

[node name="FallTimer" type="Timer" parent="."]
one_shot = true

[node name="HoleDetector" parent="." instance=ExtResource("6_eb6gp")]
scale = Vector2(3.3, 3.3)

Expand All @@ -802,4 +805,5 @@ volume_db = -7.0
bus = &"SFX"

[connection signal="timeout" from="RollTimer" to="." method="stop_roll"]
[connection signal="timeout" from="FallTimer" to="." method="end_fall"]
[connection signal="fall_in_hole" from="HoleDetector" to="." method="fall_in_hole"]
11 changes: 5 additions & 6 deletions world/latest_demo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
[ext_resource type="PackedScene" uid="uid://d3xngexqsy6m7" path="res://enemy_spawner/enemy_spawner.tscn" id="7_007xo"]
[ext_resource type="PackedScene" uid="uid://70lp7kfk3yw6" path="res://ui/hud/hud.tscn" id="8_6bf8d"]
[ext_resource type="Texture2D" uid="uid://dymucenpxmluo" path="res://icon.svg" id="8_umcft"]
[ext_resource type="PackedScene" uid="uid://cg2jt0166hik8" path="res://world/interactable/red_coin/red_coin_manager.tscn" id="9_svfaa"]
[ext_resource type="PackedScene" uid="uid://gp1o7iklljk2" path="res://world/interactable/red_coin/red_coin.tscn" id="10_kg0ye"]
[ext_resource type="PackedScene" uid="uid://cg2jt0166hik8" path="res://world/interactable/activators/red_coin/red_coin_manager.tscn" id="9_svfaa"]
[ext_resource type="PackedScene" uid="uid://gp1o7iklljk2" path="res://world/interactable/activators/red_coin/red_coin.tscn" id="10_kg0ye"]
[ext_resource type="PackedScene" uid="uid://bv2blm5myu3gk" path="res://world/interactable/pickups/pickup_health.tscn" id="11_4buq1"]
[ext_resource type="PackedScene" uid="uid://dbewnfb1psf22" path="res://world/interactable/pushable_block/pushable_block.tscn" id="12_dx3ra"]
[ext_resource type="PackedScene" uid="uid://b5bscusffqp5h" path="res://world/interactable/pressure_plate/pressure_plate.tscn" id="13_rhqn7"]
[ext_resource type="PackedScene" uid="uid://b5bscusffqp5h" path="res://world/interactable/activators/pressure_plate/pressure_plate.tscn" id="13_rhqn7"]
[ext_resource type="Texture2D" uid="uid://dc4pcxr2lfkka" path="res://demo_art/dungeon_entrance.png" id="14_v3o3r"]
[ext_resource type="Script" path="res://world/interactable/transition_trigger/transition_trigger.gd" id="15_4y615"]
[ext_resource type="PackedScene" uid="uid://blh1fs712dql8" path="res://world/interactable/locked_door/locked_door.tscn" id="16_ob7ry"]
[ext_resource type="PackedScene" uid="uid://blh1fs712dql8" path="res://world/interactable/activatable/locked_door/locked_door.tscn" id="16_ob7ry"]
[ext_resource type="PackedScene" uid="uid://dt3m30r5dehup" path="res://world/interactable/pickups/pickup_key.tscn" id="17_40pvk"]
[ext_resource type="PackedScene" uid="uid://be0wx1bwh443q" path="res://ui/pause_menu/pause_menu.tscn" id="18_be8nm"]

Expand Down Expand Up @@ -105,9 +105,8 @@ texture = ExtResource("8_umcft")
[node name="EnemySpawner" parent="." instance=ExtResource("7_007xo")]
position = Vector2(643, 624)

[node name="RedCoinManager" parent="." node_paths=PackedStringArray("reward") instance=ExtResource("9_svfaa")]
[node name="RedCoinManager" parent="." instance=ExtResource("9_svfaa")]
position = Vector2(-415, 100)
reward = NodePath("pickup_health")

[node name="RedCoin" parent="RedCoinManager" instance=ExtResource("10_kg0ye")]
position = Vector2(287, 464)
Expand Down