From 6628362c8c3ed838e70c98fac41f37c816b063fa Mon Sep 17 00:00:00 2001 From: Waldemar Tomme Date: Sat, 27 Jan 2024 19:58:18 +0100 Subject: [PATCH 1/2] Add required joke stamina data --- godot/scenes/Joke Button.gd | 20 +++++++++++++++----- godot/scenes/joke_button.tscn | 6 ++++++ godot/types/joke.gd | 4 +++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/godot/scenes/Joke Button.gd b/godot/scenes/Joke Button.gd index 9beb8cd..c06a19c 100644 --- a/godot/scenes/Joke Button.gd +++ b/godot/scenes/Joke Button.gd @@ -5,27 +5,37 @@ signal button_pressed(joke) @export_enum("joke_button_1", "joke_button_2", "joke_button_3") var action: String @export var sprite: Sprite2D +@export var stamina_categories: Array[int] @export var type_sprites: Array[Texture2D] +var stamina_label: RichTextLabel + var current_joke: Joke -func _map_action_to_joke(): +func _map_action_to_joke_type(): match action: "joke_button_1": - return Joke.new(Joke.JokeType.Joke1) + return Joke.JokeType.Joke1 "joke_button_2": - return Joke.new(Joke.JokeType.Joke2) + return Joke.JokeType.Joke2 "joke_button_3": - return Joke.new(Joke.JokeType.Joke3) + return Joke.JokeType.Joke3 + +func _get_joke(type): + return Joke.new(type, stamina_categories[randi_range(0, stamina_categories.size() - 1)]) func _ready(): - set_current_joke(_map_action_to_joke()) + stamina_label = find_child("StaminaLabel") + set_current_joke(_get_joke(_map_action_to_joke_type())) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if Input.is_action_just_pressed(action): button_pressed.emit(current_joke) + set_current_joke(_get_joke(_map_action_to_joke_type())) func set_current_joke(joke: Joke): current_joke = joke sprite.texture = type_sprites[joke.type] + stamina_label.text = "%s" % joke.required_stamina + print("stamina: ", joke.required_stamina) diff --git a/godot/scenes/joke_button.tscn b/godot/scenes/joke_button.tscn index 45a10d1..f9991e7 100644 --- a/godot/scenes/joke_button.tscn +++ b/godot/scenes/joke_button.tscn @@ -9,7 +9,13 @@ script = ExtResource("1_lofpb") action = "joke_button_1" sprite = NodePath("Sprite2D") +stamina_categories = Array[int]([1, 5, 10]) type_sprites = Array[Texture2D]([ExtResource("3_26ki8"), ExtResource("2_ivsb5"), ExtResource("4_o1r21")]) [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("2_ivsb5") + +[node name="StaminaLabel" type="RichTextLabel" parent="."] +offset_right = 40.0 +offset_bottom = 40.0 +text = "xx" diff --git a/godot/types/joke.gd b/godot/types/joke.gd index f7652fd..3c6c33a 100644 --- a/godot/types/joke.gd +++ b/godot/types/joke.gd @@ -7,6 +7,8 @@ enum JokeType { } var type: JokeType +var required_stamina: int -func _init(type): +func _init(type, required_stamina): self.type = type + self.required_stamina = required_stamina From 677a7c518a5fc003cc8dd0a8ee3ec7d393b18373 Mon Sep 17 00:00:00 2001 From: Waldemar Tomme Date: Sat, 27 Jan 2024 20:25:10 +0100 Subject: [PATCH 2/2] Add hook stub for empty stamina --- godot/scenes/Tim.gd | 11 ++++++++++- godot/scenes/crowd/crowd.tscn | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/godot/scenes/Tim.gd b/godot/scenes/Tim.gd index 5254eba..77ec04b 100644 --- a/godot/scenes/Tim.gd +++ b/godot/scenes/Tim.gd @@ -27,10 +27,19 @@ func _process(delta): global_position = Vector2(boundary.get_most_left_position(), global_position.y) -func _on_joke_button_button_pressed(joke): +func _on_joke_button_button_pressed(joke: Joke): + stamina -= joke.required_stamina + for body in transmitter_area.get_overlapping_bodies(): var person = body.find_parent("Person") if not (person is AudienceMember): continue person.on_joke(joke) + + + if stamina <= 0: + _on_stamina_empty() + +func _on_stamina_empty(): + pass diff --git a/godot/scenes/crowd/crowd.tscn b/godot/scenes/crowd/crowd.tscn index d681e30..9f61b72 100644 --- a/godot/scenes/crowd/crowd.tscn +++ b/godot/scenes/crowd/crowd.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://scenes/crowd/crowd.gd" id="1_y7wyj"] [ext_resource type="Texture2D" uid="uid://b6p145ne8x013" path="res://sprites/room/table.svg" id="2_bax5s"] -[ext_resource type="PackedScene" uid="uid://bbehbuw5lvfkr" path="res://sprites/room/chair.tscn" id="3_y4hpm"] +[ext_resource type="PackedScene" path="res://sprites/room/chair.tscn" id="3_y4hpm"] [node name="Crowd" type="Node2D"] position = Vector2(240, 232)