2024-01-27 18:33:33 +00:00
|
|
|
class_name Comedian
|
2024-01-26 20:01:22 +00:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
@export var move_speed = 100
|
|
|
|
@export var boundary: Boundary
|
2024-01-27 19:46:22 +00:00
|
|
|
@export var tim_sprite: Sprite2D
|
2024-01-27 12:08:34 +00:00
|
|
|
@export var transmitter_area: Area2D
|
2024-01-27 19:46:22 +00:00
|
|
|
@export var stamina: int = 100
|
2024-01-26 20:01:22 +00:00
|
|
|
|
2024-01-27 19:34:39 +00:00
|
|
|
var default_texture: Texture2D = load("res://sprites/tim_side.png")
|
|
|
|
var ducking_texture: Texture2D = load("res://sprites/tim_ducking.svg")
|
2024-01-28 08:45:33 +00:00
|
|
|
var last_joke: Joke
|
2024-01-27 18:33:33 +00:00
|
|
|
|
2024-01-28 14:16:29 +00:00
|
|
|
var blabla_sounds = [
|
|
|
|
preload("res://audio/tim_blabla_1.wav"),
|
|
|
|
preload("res://audio/tim_blabla_2.wav"),
|
|
|
|
preload("res://audio/tim_blabla_3.wav"),
|
|
|
|
preload("res://audio/tim_blabla_4.wav")
|
|
|
|
]
|
|
|
|
|
2024-01-26 20:01:22 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2024-01-28 14:16:29 +00:00
|
|
|
Signals.hit_tim.connect(ouch)
|
2024-01-27 19:46:22 +00:00
|
|
|
|
2024-01-26 20:01:22 +00:00
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
2024-01-28 14:16:29 +00:00
|
|
|
if $AnimationPlayer.is_playing():
|
|
|
|
return
|
2024-01-28 05:59:32 +00:00
|
|
|
|
2024-01-28 14:16:29 +00:00
|
|
|
if Input.is_action_pressed("move_right"):
|
|
|
|
tim_sprite.flip_h = true
|
|
|
|
global_position += Vector2.RIGHT * delta * move_speed
|
|
|
|
if global_position.x > boundary.get_most_right_position():
|
|
|
|
global_position = Vector2(boundary.get_most_right_position(), global_position.y)
|
2024-01-27 19:46:22 +00:00
|
|
|
|
2024-01-28 14:16:29 +00:00
|
|
|
if Input.is_action_pressed("move_left"):
|
|
|
|
tim_sprite.flip_h = false
|
|
|
|
global_position += Vector2.LEFT * delta * move_speed
|
|
|
|
if global_position.x < boundary.get_most_left_position():
|
|
|
|
global_position = Vector2(boundary.get_most_left_position(), global_position.y)
|
2024-01-27 11:36:06 +00:00
|
|
|
|
2024-01-28 05:59:32 +00:00
|
|
|
func _disable_buttons():
|
2024-01-28 14:16:29 +00:00
|
|
|
$"Joke Buttons".hide()
|
|
|
|
$"Joke Buttons".process_mode = Node.PROCESS_MODE_DISABLED
|
2024-01-28 05:59:32 +00:00
|
|
|
|
|
|
|
func _enable_buttons():
|
2024-01-28 14:16:29 +00:00
|
|
|
$"Joke Buttons".show()
|
|
|
|
$"Joke Buttons".process_mode = Node.PROCESS_MODE_INHERIT
|
2024-01-27 11:36:06 +00:00
|
|
|
|
2024-01-27 19:25:10 +00:00
|
|
|
func _on_joke_button_button_pressed(joke: Joke):
|
2024-01-28 14:16:29 +00:00
|
|
|
last_joke = joke
|
|
|
|
stamina -= joke.required_stamina
|
|
|
|
_disable_buttons()
|
|
|
|
_start_joke_for_audience()
|
|
|
|
$AnimationPlayer.play("talking")
|
|
|
|
$Speaker.stream = blabla_sounds[randi() % blabla_sounds.size()]
|
|
|
|
$Speaker.play()
|
2024-01-27 19:46:22 +00:00
|
|
|
|
2024-01-28 10:51:33 +00:00
|
|
|
func _get_targeted_audience_members(target_all: bool):
|
2024-01-28 14:16:29 +00:00
|
|
|
if target_all:
|
|
|
|
return _get_all_targeted_audience_members()
|
|
|
|
return _get_targeted_audience_members_in_target_area()
|
2024-01-28 10:51:33 +00:00
|
|
|
|
|
|
|
func _get_all_targeted_audience_members() -> Array[AudienceMember]:
|
2024-01-28 14:16:29 +00:00
|
|
|
var crowd = get_node("/root/IngameScene/Crowd")
|
|
|
|
return crowd.audience
|
2024-01-28 10:51:33 +00:00
|
|
|
|
|
|
|
func _get_targeted_audience_members_in_target_area() -> Array[AudienceMember]:
|
2024-01-28 14:16:29 +00:00
|
|
|
var arr: Array[AudienceMember]
|
|
|
|
for body in transmitter_area.get_overlapping_bodies():
|
|
|
|
var person = body.find_parent("Person")
|
|
|
|
if not (person is AudienceMember):
|
|
|
|
continue
|
|
|
|
arr.append(person)
|
|
|
|
return arr
|
2024-01-28 09:02:41 +00:00
|
|
|
|
2024-01-28 11:19:52 +00:00
|
|
|
func _start_joke_for_audience():
|
2024-01-28 14:16:29 +00:00
|
|
|
for person in _get_targeted_audience_members(true):
|
|
|
|
person.on_joke_start()
|
2024-01-28 09:02:41 +00:00
|
|
|
|
2024-01-28 11:19:52 +00:00
|
|
|
func _tell_joke_for_audience(joke: Joke, target_all: bool):
|
2024-01-28 14:16:29 +00:00
|
|
|
for person in _get_targeted_audience_members(target_all):
|
|
|
|
person.on_hear_joke(joke)
|
2024-01-28 11:19:52 +00:00
|
|
|
|
|
|
|
func _finish_joke_for_audience():
|
2024-01-28 14:16:29 +00:00
|
|
|
for person in _get_targeted_audience_members(true):
|
|
|
|
person.on_joke_finish()
|
2024-01-27 11:36:06 +00:00
|
|
|
|
2024-01-27 19:25:10 +00:00
|
|
|
func _on_stamina_empty():
|
2024-01-28 14:16:29 +00:00
|
|
|
get_node("../DisplayGUI").visible = false
|
|
|
|
|
|
|
|
var fade = get_node("/root/IngameScene/UI/FadeOverlay")
|
|
|
|
fade.modulate.a = fade.minimum_opacity
|
|
|
|
fade.visible = true
|
|
|
|
get_node("/root/IngameScene/UI/Curtain").visible = true
|
|
|
|
|
|
|
|
get_viewport().set_input_as_handled()
|
|
|
|
get_tree().paused = true
|
|
|
|
|
|
|
|
var score_overlay = get_node("/root/IngameScene/UI/ScoreOverlay")
|
|
|
|
score_overlay.get_node("VBoxContainer3/FinalScore").text = str(int(get_node("/root/IngameScene/Crowd").overall_mood))
|
|
|
|
score_overlay.grab_button_focus()
|
|
|
|
score_overlay.visible = true
|
|
|
|
pass
|
2024-01-27 19:34:39 +00:00
|
|
|
|
|
|
|
func ouch():
|
2024-01-28 14:16:29 +00:00
|
|
|
$Sprite2D.texture = ducking_texture
|
|
|
|
_start_joke_for_audience()
|
|
|
|
await get_tree().create_timer(1).timeout
|
|
|
|
$Sprite2D.texture = default_texture
|
|
|
|
_tell_joke_for_audience(Joke.get_bottle_joke(), true)
|
|
|
|
_finish_joke_for_audience()
|
2024-01-28 05:59:32 +00:00
|
|
|
|
|
|
|
func _on_animation_player_animation_finished(anim_name):
|
2024-01-28 14:16:29 +00:00
|
|
|
_tell_joke_for_audience(last_joke, false)
|
|
|
|
_finish_joke_for_audience()
|
|
|
|
if stamina <= 0:
|
|
|
|
_on_stamina_empty()
|
|
|
|
else:
|
|
|
|
_enable_buttons()
|