2023-10-02 00:53:12 +00:00
|
|
|
extends StaticBody2D
|
2023-10-02 01:14:45 +00:00
|
|
|
class_name Converter
|
2023-10-02 00:53:12 +00:00
|
|
|
|
|
|
|
@export var sprite_front: AnimatedSprite2D
|
2023-10-02 14:32:23 +00:00
|
|
|
@export var sprite_back: AnimatedSprite2D
|
2023-10-02 00:53:12 +00:00
|
|
|
@export var conversion_timer: Timer
|
|
|
|
@export var sound_working: AudioStreamPlayer
|
|
|
|
@export var sound_complete: AudioStreamPlayer
|
|
|
|
@export var spawner: Spawner
|
2023-10-02 20:29:40 +00:00
|
|
|
@export var spawner_alt: Spawner
|
|
|
|
@export_range(0.0, 1.0, 0.01) var spawner_alt_chance: float
|
2023-10-02 00:53:12 +00:00
|
|
|
|
2023-10-02 20:09:19 +00:00
|
|
|
## Amount of scenes this converter should produce.
|
|
|
|
var to_produce: int = 0
|
|
|
|
|
|
|
|
## Amount of scenes this converter should spawn.
|
|
|
|
var to_spawn: int = 0
|
|
|
|
|
2023-10-02 00:53:12 +00:00
|
|
|
func _on_collector_goal():
|
2023-10-02 20:09:19 +00:00
|
|
|
to_produce += 1
|
|
|
|
|
|
|
|
func _physics_process(_delta):
|
|
|
|
if to_produce >= 1 and conversion_timer.is_stopped():
|
|
|
|
to_produce -= 1
|
|
|
|
produce()
|
2023-10-02 00:53:12 +00:00
|
|
|
|
2023-10-02 20:09:19 +00:00
|
|
|
func produce():
|
|
|
|
conversion_timer.start()
|
|
|
|
if sprite_front:
|
2023-10-02 00:53:12 +00:00
|
|
|
sprite_front.play()
|
2023-10-02 20:09:19 +00:00
|
|
|
if sprite_back:
|
|
|
|
sprite_back.play()
|
|
|
|
if sound_working:
|
2023-10-02 00:53:12 +00:00
|
|
|
sound_working.play()
|
|
|
|
|
|
|
|
func _on_timer_timeout():
|
2023-10-02 20:29:40 +00:00
|
|
|
if spawner_alt and Randomizer.rng.randf() < spawner_alt_chance:
|
|
|
|
spawner_alt.spawn()
|
|
|
|
else:
|
|
|
|
spawner.spawn()
|
2023-10-02 20:09:19 +00:00
|
|
|
if sprite_front:
|
|
|
|
sprite_front.stop()
|
|
|
|
if sprite_back:
|
|
|
|
sprite_back.stop()
|
|
|
|
if sound_working:
|
|
|
|
sound_working.stop()
|
|
|
|
|
2023-10-02 18:06:28 +00:00
|
|
|
|
|
|
|
var is_pending_deletion: bool = false
|
|
|
|
|
|
|
|
func pending_deletion():
|
|
|
|
sprite_front.modulate = Color.RED
|
|
|
|
is_pending_deletion = true
|
|
|
|
|
|
|
|
func ending_deletion():
|
|
|
|
sprite_front.modulate = Color.WHITE
|
|
|
|
is_pending_deletion = false
|
|
|
|
|
2023-10-02 20:09:19 +00:00
|
|
|
func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int):
|
2023-10-02 18:06:28 +00:00
|
|
|
if is_pending_deletion:
|
|
|
|
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
|
|
|
queue_free()
|