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-27 18:33:33 +00:00
|
|
|
|
2024-01-26 20:01:22 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2024-01-27 19:46:22 +00:00
|
|
|
Signals.hit_tim.connect(ouch)
|
|
|
|
|
2024-01-26 20:01:22 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
|
|
|
if Input.is_action_pressed("move_right"):
|
2024-01-26 20:22:33 +00:00
|
|
|
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-26 20:01:22 +00:00
|
|
|
if Input.is_action_pressed("move_left"):
|
2024-01-26 20:22:33 +00:00
|
|
|
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-27 19:25:10 +00:00
|
|
|
func _on_joke_button_button_pressed(joke: Joke):
|
2024-01-27 19:46:22 +00:00
|
|
|
$AnimationPlayer.play("talking")
|
2024-01-27 19:25:10 +00:00
|
|
|
stamina -= joke.required_stamina
|
2024-01-27 19:46:22 +00:00
|
|
|
|
2024-01-27 12:08:34 +00:00
|
|
|
for body in transmitter_area.get_overlapping_bodies():
|
|
|
|
var person = body.find_parent("Person")
|
2024-01-27 12:58:26 +00:00
|
|
|
if not (person is AudienceMember):
|
2024-01-27 12:08:34 +00:00
|
|
|
continue
|
2024-01-27 19:34:39 +00:00
|
|
|
|
2024-01-27 12:08:34 +00:00
|
|
|
person.on_joke(joke)
|
2024-01-27 11:36:06 +00:00
|
|
|
|
2024-01-27 19:25:10 +00:00
|
|
|
if stamina <= 0:
|
|
|
|
_on_stamina_empty()
|
2024-01-27 11:36:06 +00:00
|
|
|
|
2024-01-27 19:34:39 +00:00
|
|
|
|
2024-01-27 19:25:10 +00:00
|
|
|
func _on_stamina_empty():
|
|
|
|
pass
|
2024-01-27 19:34:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
func ouch():
|
2024-01-27 19:46:22 +00:00
|
|
|
$Sprite2D.texture = ducking_texture
|
|
|
|
await get_tree().create_timer(1).timeout
|
|
|
|
$Sprite2D.texture = default_texture
|