feat: add switch node; add user interaction logic with signals to the switch node;
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
extends StaticBody2D
|
||||
|
||||
signal switch_activated
|
||||
signal switch_deactivated
|
||||
|
||||
var is_activated: bool = false
|
||||
var can_interact: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
$AnimatedSprite2D.play("deactivated")
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("Interact") and can_interact:
|
||||
if !is_activated:
|
||||
$AnimatedSprite2D.play("activated")
|
||||
is_activated = true
|
||||
switch_activated.emit()
|
||||
else:
|
||||
$AnimatedSprite2D.play("deactivated")
|
||||
is_activated = false
|
||||
switch_deactivated.emit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://t4xp5st31yvj
|
||||
@@ -0,0 +1,45 @@
|
||||
[gd_scene format=3 uid="uid://bdu180bpjrn5h"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://t4xp5st31yvj" path="res://Scenes/Switch/switch.gd" id="1_c5yrt"]
|
||||
[ext_resource type="Texture2D" uid="uid://c0v63n2kjtvvu" path="res://Ninja Adventure - Asset Pack/Backgrounds/Tilesets/TilesetDungeon.png" id="1_g65jv"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3rdvi"]
|
||||
size = Vector2(16, 8)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_c5yrt"]
|
||||
atlas = ExtResource("1_g65jv")
|
||||
region = Rect2(64, 32, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_sln40"]
|
||||
atlas = ExtResource("1_g65jv")
|
||||
region = Rect2(48, 32, 16, 16)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_chgu2"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_c5yrt")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"activated",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_sln40")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"deactivated",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="Switch" type="StaticBody2D" unique_id=78052327 groups=["interactable"]]
|
||||
script = ExtResource("1_c5yrt")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1474874931]
|
||||
position = Vector2(0, 4)
|
||||
shape = SubResource("RectangleShape2D_3rdvi")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1373433038]
|
||||
sprite_frames = SubResource("SpriteFrames_chgu2")
|
||||
animation = &"activated"
|
||||
Reference in New Issue
Block a user