add logic for checkpoints

This commit is contained in:
Chris Cromer 2022-11-19 23:07:56 -03:00
parent 70a2292f10
commit 2a9f4fe500
2 changed files with 34 additions and 2 deletions

View File

@ -0,0 +1,26 @@
using Godot;
public class Checkpoint : Area2D
{
private AnimatedSprite _sprite;
public override void _Ready()
{
_sprite = GetNode<AnimatedSprite>("AnimatedSprite");
}
public void OnCheckpointBodyEntered(Node body)
{
SetCollisionMaskBit((int) Game.PhysicsLayer.Player, false);
SetCollisionLayerBit((int) Game.PhysicsLayer.Checkpoint, false);
Disconnect("body_entered", this, "OnCheckpointBodyEntered");
_sprite.Play("reached");
_sprite.Connect("animation_finished", this, "OnReachedAnimationFinished");
}
public void OnReachedAnimationFinished()
{
_sprite.Disconnect("animation_finished", this, "OnReachedAnimationFinished");
_sprite.Play("activated");
}
}

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=10 format=2] [gd_scene load_steps=11 format=2]
[ext_resource path="res://assets/checkpoint/checkpoint.png" type="Texture" id=1] [ext_resource path="res://assets/checkpoint/checkpoint.png" type="Texture" id=1]
[ext_resource path="res://scenes/checkpoint/Checkpoint.cs" type="Script" id=2]
[sub_resource type="AtlasTexture" id=1] [sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 1 ) atlas = ExtResource( 1 )
@ -48,12 +49,17 @@ animations = [ {
extents = Vector2( 5, 10.5 ) extents = Vector2( 5, 10.5 )
[node name="Checkpoint" type="Area2D"] [node name="Checkpoint" type="Area2D"]
collision_layer = 16
script = ExtResource( 2 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."] [node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = SubResource( 7 ) frames = SubResource( 7 )
animation = "deactivated" animation = "deactivated"
centered = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false visible = false
position = Vector2( 0, 5.5 ) position = Vector2( 8, 21.5 )
shape = SubResource( 8 ) shape = SubResource( 8 )
[connection signal="body_entered" from="." to="." method="OnCheckpointBodyEntered"]