1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-29 02:44:19 +00:00
swear-jar/converters/converter.gd

60 lines
1.6 KiB
GDScript3
Raw Normal View History

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
2023-10-14 00:27:55 +00:00
@onready var sprite_front: AnimatedSprite2D = find_children("SpriteFront", "AnimatedSprite2D", false, true).pop_front()
@onready var sprite_back: AnimatedSprite2D = find_children("SpriteBack", "AnimatedSprite2D", false, true).pop_front()
@onready var working_timer: Timer = $WorkingTimer
2023-10-02 00:53:12 +00:00
@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
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):
2023-10-14 00:27:55 +00:00
if to_produce >= 1 and working_timer.is_stopped():
2023-10-02 20:09:19 +00:00
to_produce -= 1
produce()
2023-10-02 00:53:12 +00:00
2023-10-02 20:09:19 +00:00
func produce():
2023-10-14 00:27:55 +00:00
working_timer.start()
2023-10-02 20:09:19 +00:00
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()
2023-10-02 00:53:12 +00:00
2023-10-14 00:27:55 +00:00
func _on_working_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()
2023-10-02 18:06:28 +00:00
var is_pending_deletion: bool = false
func pending_deletion():
modulate = Color.RED
2023-10-02 18:06:28 +00:00
is_pending_deletion = true
func ending_deletion():
modulate = Color.WHITE
2023-10-02 18:06:28 +00:00
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()
func _on_gold_converter_spawner_spawned(what: RigidBody2D):
# Randomize gem colors.
var colored: Colored = what.get_node("CollisionShape2D/Sprite/Colored")
colored.randomize_hue()