summaryrefslogtreecommitdiff
path: root/Effects
diff options
context:
space:
mode:
Diffstat (limited to 'Effects')
-rw-r--r--Effects/Effect.gd46
-rw-r--r--Effects/SlowEffect.gd33
-rw-r--r--Effects/SlowEffect.tscn6
3 files changed, 85 insertions, 0 deletions
diff --git a/Effects/Effect.gd b/Effects/Effect.gd
new file mode 100644
index 0000000..f1662a7
--- /dev/null
+++ b/Effects/Effect.gd
@@ -0,0 +1,46 @@
+class_name Effect
+extends Node
+
+
+signal duration_finished
+signal tick_finished
+
+var duration: float = 0.0
+var DurationTimer: Timer
+
+var tick: float = 0.0
+var TickTimer: Timer
+
+
+func _ready():
+ pass
+
+
+func set_duration(value: float):
+ duration = value
+
+ if not DurationTimer:
+ DurationTimer = Timer.new()
+ DurationTimer.timeout.connect(func():
+ duration_finished.emit()
+ queue_free()
+ )
+ add_child(DurationTimer)
+
+ DurationTimer.wait_time = duration
+ DurationTimer.start()
+
+
+func set_tick(value: float):
+ tick = value
+
+ if not TickTimer:
+ TickTimer = Timer.new()
+ TickTimer.timeout.connect(func():
+ tick_finished.emit()
+ TickTimer.start()
+ )
+ add_child(TickTimer)
+
+ TickTimer.wait_time = tick
+ TickTimer.start()
diff --git a/Effects/SlowEffect.gd b/Effects/SlowEffect.gd
new file mode 100644
index 0000000..27dcc59
--- /dev/null
+++ b/Effects/SlowEffect.gd
@@ -0,0 +1,33 @@
+extends Effect
+
+
+@onready var unit: Unit = get_parent()
+
+var base_speed: float
+
+
+var magnitude: float = 0.5 :
+ set(value):
+ magnitude = clamp(value, 0.0, 1.0)
+
+
+func _ready():
+ if self.name != "SlowEffect" and unit.has_node("SlowEffect"):
+ unit.get_node("SlowEffect").set_duration(5.0)
+ queue_free()
+ else:
+ add()
+ set_duration(5.0)
+ duration_finished.connect(func():
+ remove()
+ )
+
+
+func add():
+ unit.get_node("Sprite2D").self_modulate = Color(0, 0, 1)
+ unit.speed -= unit.base_speed * magnitude
+
+
+func remove():
+ unit.get_node("Sprite2D").self_modulate = Color(1, 1, 1)
+ unit.speed += unit.base_speed * magnitude
diff --git a/Effects/SlowEffect.tscn b/Effects/SlowEffect.tscn
new file mode 100644
index 0000000..ceef7b4
--- /dev/null
+++ b/Effects/SlowEffect.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://chay02kqn73gv"]
+
+[ext_resource type="Script" path="res://Effects/SlowEffect.gd" id="1_8smja"]
+
+[node name="SlowEffect" type="Node2D"]
+script = ExtResource("1_8smja")