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