diff --git a/scenes/components/checkpoint.gd b/scenes/components/checkpoint.gd new file mode 100644 index 0000000..5e1ac88 --- /dev/null +++ b/scenes/components/checkpoint.gd @@ -0,0 +1,29 @@ +class_name Checkpoint +extends Area2D + +@onready var _sprite: AnimatedSprite2D = $AnimatedSprite2D + +var is_activated: bool = false + +func _ready() -> void: + add_to_group("checkpoints") + body_entered.connect(_on_body_entered) + +func _on_body_entered(body: Node2D) -> void: + if is_activated or not body.is_in_group("player"): + return + _activate() + +func _activate() -> void: + get_tree().call_group("checkpoints", "_deactivate") + is_activated = true + _sprite.play("activated") + EventBus.has_checkpoint = true + EventBus.last_checkpoint_position = global_position + EventBus.checkpoint_activated.emit(global_position) + +func _deactivate() -> void: + if not is_activated: + return + is_activated = false + _sprite.play("deactivated") diff --git a/scenes/components/checkpoint.gd.uid b/scenes/components/checkpoint.gd.uid new file mode 100644 index 0000000..8e27b2a --- /dev/null +++ b/scenes/components/checkpoint.gd.uid @@ -0,0 +1 @@ +uid://cx5f0pjl4r6kd diff --git a/scenes/components/checkpoint.tscn b/scenes/components/checkpoint.tscn new file mode 100644 index 0000000..606a3a9 --- /dev/null +++ b/scenes/components/checkpoint.tscn @@ -0,0 +1,120 @@ +[gd_scene format=3 uid="uid://51vdlyyqiph"] + +[ext_resource type="Texture2D" uid="uid://o7gjt82i1tuy" path="res://assets/images/sprites/World/Forest/Props/RedFlag.png" id="1_x5iex"] +[ext_resource type="Texture2D" uid="uid://bgva4soh5y13n" path="res://assets/images/sprites/World/Forest/Props/BlackFlag.png" id="2_on7kf"] +[ext_resource type="Script" uid="uid://cx5f0pjl4r6kd" path="res://scenes/components/checkpoint.gd" id="3_checkpoint"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_e0ilo"] +atlas = ExtResource("1_x5iex") +region = Rect2(0, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_cghdm"] +atlas = ExtResource("1_x5iex") +region = Rect2(29, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_easxk"] +atlas = ExtResource("1_x5iex") +region = Rect2(58, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7n62p"] +atlas = ExtResource("1_x5iex") +region = Rect2(87, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_lb7m4"] +atlas = ExtResource("1_x5iex") +region = Rect2(116, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fubdx"] +atlas = ExtResource("1_x5iex") +region = Rect2(145, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_owxlm"] +atlas = ExtResource("2_on7kf") +region = Rect2(0, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fymaq"] +atlas = ExtResource("2_on7kf") +region = Rect2(29, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8fx7f"] +atlas = ExtResource("2_on7kf") +region = Rect2(58, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_60pw6"] +atlas = ExtResource("2_on7kf") +region = Rect2(87, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_cgs4j"] +atlas = ExtResource("2_on7kf") +region = Rect2(116, 0, 29, 64) + +[sub_resource type="AtlasTexture" id="AtlasTexture_61o2w"] +atlas = ExtResource("2_on7kf") +region = Rect2(145, 0, 29, 64) + +[sub_resource type="SpriteFrames" id="SpriteFrames_uvqlf"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_e0ilo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_cghdm") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_easxk") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7n62p") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_lb7m4") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fubdx") +}], +"loop": 1, +"name": &"activated", +"speed": 7.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_owxlm") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fymaq") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8fx7f") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_60pw6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_cgs4j") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_61o2w") +}], +"loop": 1, +"name": &"deactivated", +"speed": 7.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_gy2im"] +size = Vector2(30, 61) + +[node name="Checkpoint" type="Area2D" unique_id=1489150355] +collision_layer = 0 +collision_mask = 16 +script = ExtResource("3_checkpoint") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1325906328] +position = Vector2(-0.5, -32) +sprite_frames = SubResource("SpriteFrames_uvqlf") +animation = &"deactivated" +autoplay = "deactivated" + +[node name="SpawnArea" type="CollisionShape2D" parent="." unique_id=1679679131] +position = Vector2(-0.5, -31.5) +shape = SubResource("RectangleShape2D_gy2im")