Implement joke button signaling

This commit is contained in:
Waldemar Tomme 2024-01-27 12:36:06 +01:00
parent 515c9eefc7
commit f224391f30
4 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,6 @@
extends Node2D extends Node2D
signal button_pressed signal button_pressed(joke)
@export_enum("joke_button_1", "joke_button_2", "joke_button_3") var action: String @export_enum("joke_button_1", "joke_button_2", "joke_button_3") var action: String
@ -16,4 +16,4 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if Input.is_action_just_pressed(action): if Input.is_action_just_pressed(action):
emit_signal("button_pressed", current_joke) button_pressed.emit(current_joke)

View File

@ -21,3 +21,7 @@ func _process(delta):
global_position += Vector2.LEFT * delta * move_speed global_position += Vector2.LEFT * delta * move_speed
if global_position.x < boundary.get_most_left_position(): if global_position.x < boundary.get_most_left_position():
global_position = Vector2(boundary.get_most_left_position(), global_position.y) global_position = Vector2(boundary.get_most_left_position(), global_position.y)
func _on_joke_button_button_pressed(joke):
pass # Replace with function body.

View File

@ -34,12 +34,14 @@ position = Vector2(0, -25)
[node name="Joke Button 1" type="Node2D" parent="Tim/Joke Buttons"] [node name="Joke Button 1" type="Node2D" parent="Tim/Joke Buttons"]
script = ExtResource("3_opgtx") script = ExtResource("3_opgtx")
action = "joke_button_1"
[node name="Sprite2D" type="Sprite2D" parent="Tim/Joke Buttons/Joke Button 1"] [node name="Sprite2D" type="Sprite2D" parent="Tim/Joke Buttons/Joke Button 1"]
texture = SubResource("PlaceholderTexture2D_k2q2d") texture = SubResource("PlaceholderTexture2D_k2q2d")
[node name="Joke Button 2" type="Node2D" parent="Tim/Joke Buttons"] [node name="Joke Button 2" type="Node2D" parent="Tim/Joke Buttons"]
script = ExtResource("3_opgtx") script = ExtResource("3_opgtx")
action = "joke_button_2"
[node name="Sprite2D" type="Sprite2D" parent="Tim/Joke Buttons/Joke Button 2"] [node name="Sprite2D" type="Sprite2D" parent="Tim/Joke Buttons/Joke Button 2"]
position = Vector2(-150, -50) position = Vector2(-150, -50)
@ -47,6 +49,7 @@ texture = SubResource("PlaceholderTexture2D_k2q2d")
[node name="Joke Button 3" type="Node2D" parent="Tim/Joke Buttons"] [node name="Joke Button 3" type="Node2D" parent="Tim/Joke Buttons"]
script = ExtResource("3_opgtx") script = ExtResource("3_opgtx")
action = "joke_button_3"
[node name="Sprite2D" type="Sprite2D" parent="Tim/Joke Buttons/Joke Button 3"] [node name="Sprite2D" type="Sprite2D" parent="Tim/Joke Buttons/Joke Button 3"]
position = Vector2(150, -50) position = Vector2(150, -50)
@ -54,3 +57,7 @@ texture = SubResource("PlaceholderTexture2D_k2q2d")
[node name="Boundary" type="Node2D" parent="."] [node name="Boundary" type="Node2D" parent="."]
script = ExtResource("2_8p6ir") script = ExtResource("2_8p6ir")
[connection signal="button_pressed" from="Tim/Joke Buttons/Joke Button 1" to="Tim" method="_on_joke_button_button_pressed"]
[connection signal="button_pressed" from="Tim/Joke Buttons/Joke Button 2" to="Tim" method="_on_joke_button_button_pressed"]
[connection signal="button_pressed" from="Tim/Joke Buttons/Joke Button 3" to="Tim" method="_on_joke_button_button_pressed"]

View File

@ -6,5 +6,7 @@ enum JokeType {
Joke3 Joke3
} }
var type: JokeType
func _init(type): func _init(type):
self.type = type self.type = type