summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-23 11:44:21 -0400
committerbd <bdunahu@operationnull.com>2025-05-23 11:44:21 -0400
commita677a3e8ed63241e7931265941d562284a15d16a (patch)
tree265c3f353525ae462236417298ff7f0f272870e1
parentbc3589db94692fc4cdd4388dacff0f44fe8a2030 (diff)
Move enemy logic to base_crawler, add crawler flip animation
-rw-r--r--scenes/fodder.tscn (renamed from scenes/soldier.tscn)10
-rw-r--r--scripts/base_crawler.gd44
-rw-r--r--scripts/base_crawler.gd.uid1
-rw-r--r--scripts/fodder.gd11
-rw-r--r--scripts/fodder.gd.uid (renamed from scripts/soldier.gd.uid)0
-rw-r--r--scripts/game_stats_config.gd4
-rw-r--r--scripts/soldier.gd27
-rw-r--r--scripts/wave_spawner.gd2
8 files changed, 66 insertions, 33 deletions
diff --git a/scenes/soldier.tscn b/scenes/fodder.tscn
index d6aae63..05813e6 100644
--- a/scenes/soldier.tscn
+++ b/scenes/fodder.tscn
@@ -1,21 +1,21 @@
[gd_scene load_steps=5 format=3 uid="uid://rp5orgc6ae7j"]
-[ext_resource type="Script" uid="uid://gn1504blq1pf" path="res://scripts/soldier.gd" id="1_q2rr1"]
-[ext_resource type="Texture2D" uid="uid://di2vybjsniag4" path="res://assets/tilemap.png" id="2_2oslh"]
+[ext_resource type="Script" uid="uid://gn1504blq1pf" path="res://scripts/fodder.gd" id="1_4lnnv"]
+[ext_resource type="Texture2D" uid="uid://di2vybjsniag4" path="res://assets/tilemap.png" id="2_eps3e"]
[sub_resource type="CircleShape2D" id="CircleShape2D_220eh"]
radius = 8.06226
[sub_resource type="Curve2D" id="Curve2D_q2rr1"]
-[node name="CrawlerSoldier" type="CharacterBody2D"]
-script = ExtResource("1_q2rr1")
+[node name="CrawlerFodder" type="CharacterBody2D"]
+script = ExtResource("1_4lnnv")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_220eh")
[node name="Sprite2D" type="Sprite2D" parent="."]
-texture = ExtResource("2_2oslh")
+texture = ExtResource("2_eps3e")
region_enabled = true
region_rect = Rect2(432, 0, 16, 16)
diff --git a/scripts/base_crawler.gd b/scripts/base_crawler.gd
new file mode 100644
index 0000000..3525e97
--- /dev/null
+++ b/scripts/base_crawler.gd
@@ -0,0 +1,44 @@
+extends CharacterBody2D
+
+@onready var sprite_node = $Sprite2D
+
+var damage : int
+var speed : float
+var max_health : float
+var worth : int
+
+var _health : float
+var _timer : Timer
+
+func _ready() -> void:
+ _health = max_health
+
+ _timer = Timer.new()
+ _timer.wait_time = speed / 60
+ _timer.autostart = true
+ _timer.connect("timeout", Callable(self, "_on_animate_timeout"))
+ add_child(_timer)
+
+
+func _process(delta):
+ get_parent().set_progress(get_parent().get_progress() + speed * delta)
+ if get_parent().get_progress_ratio() == 1:
+ GameData.subtract_morale(damage)
+ queue_free()
+
+func deal_damage(tower_damage):
+ _health -= tower_damage
+ if _health <= 0:
+ GameData.add_life(worth)
+ queue_free()
+ else:
+ _update_color()
+
+func _update_color():
+ var ratio : float = _health / max_health
+ var target_color = Color(1, ratio, ratio)
+
+ sprite_node.modulate = target_color
+
+func _on_animate_timeout():
+ sprite_node.scale.x = -sprite_node.scale.x
diff --git a/scripts/base_crawler.gd.uid b/scripts/base_crawler.gd.uid
new file mode 100644
index 0000000..a520313
--- /dev/null
+++ b/scripts/base_crawler.gd.uid
@@ -0,0 +1 @@
+uid://cc77hhy8s2pe
diff --git a/scripts/fodder.gd b/scripts/fodder.gd
new file mode 100644
index 0000000..3c1dd22
--- /dev/null
+++ b/scripts/fodder.gd
@@ -0,0 +1,11 @@
+extends "res://scripts/base_crawler.gd"
+
+var game_stats_config = preload("res://resources/game_stats_config.tres")
+
+func _ready() -> void:
+ damage = game_stats_config.fodder_damage
+ speed = game_stats_config.fodder_speed
+ max_health = game_stats_config.fodder_health
+ worth = game_stats_config.fodder_worth
+
+ super()
diff --git a/scripts/soldier.gd.uid b/scripts/fodder.gd.uid
index 917b467..917b467 100644
--- a/scripts/soldier.gd.uid
+++ b/scripts/fodder.gd.uid
diff --git a/scripts/game_stats_config.gd b/scripts/game_stats_config.gd
index 671e146..ce71b74 100644
--- a/scripts/game_stats_config.gd
+++ b/scripts/game_stats_config.gd
@@ -1,9 +1,11 @@
extends Resource
class_name GameStatsConfig
+# game stats
@export var starting_life : int = 20
@export var starting_morale : int = 10
+# defenders
@export var warlock_damage : float = 5.0
@export var warlock_fire_rate : float = 1.0
@export var warlock_defender_range : float = 75.0
@@ -15,6 +17,8 @@ class_name GameStatsConfig
@export var wyvern_defender_range : float = 35.0
@export var wyvern_defender_cost : int = 15
+# crawlers
@export var fodder_damage : float = 1.0
@export var fodder_speed : float = 30.0
@export var fodder_health : float = 25.0
+@export var fodder_worth : float = 2.0
diff --git a/scripts/soldier.gd b/scripts/soldier.gd
deleted file mode 100644
index d373237..0000000
--- a/scripts/soldier.gd
+++ /dev/null
@@ -1,27 +0,0 @@
-extends CharacterBody2D
-
-@export var worth : int = 5
-@export var damage : int = 1
-@export var speed : float = 50.0
-@export var max_health : float = 30.0
-var _health : float = max_health
-
-func _process(delta):
- get_parent().set_progress(get_parent().get_progress() + speed * delta)
- if get_parent().get_progress_ratio() == 1:
- GameData.subtract_morale(damage)
- queue_free()
-
-func deal_damage(tower_damage):
- _health -= tower_damage
- if _health <= 0:
- GameData.add_life(worth)
- queue_free()
- else:
- _update_color()
-
-func _update_color():
- var ratio : float = _health / max_health
- var target_color = Color(1, ratio, ratio)
-
- $Sprite2D.modulate = target_color
diff --git a/scripts/wave_spawner.gd b/scripts/wave_spawner.gd
index 7c54dfc..0b4ca2e 100644
--- a/scripts/wave_spawner.gd
+++ b/scripts/wave_spawner.gd
@@ -1,7 +1,7 @@
extends Node2D
@onready var map_config = preload("res://resources/map_generator_resource.tres")
-@onready var fodder_enemy = preload("res://scenes/soldier.tscn")
+@onready var fodder_enemy = preload("res://scenes/fodder.tscn")
@onready var map = get_node("../Map")
var curve : Curve2D