added modular animation system for drones

This commit is contained in:
2026-02-24 10:49:50 +01:00
parent 772858f04f
commit d036169237
23 changed files with 268 additions and 119 deletions

View File

@@ -3,13 +3,85 @@ extends Machine
class_name Drone
@export_category("Dash")
@export var dodge_cd : float
@export var dodge_cd := 5.0
@export var dodge_speed := 650.0
@export var dodge_duration := 0.18
var dodge_duration_timer : Timer
#region animation dictionaries
@export var idle_anim_front : Dictionary
@export var idle_anim_back : Dictionary
@export var idle_anim_left : Dictionary
@export var idle_anim_right : Dictionary
@export var walking_anim_front : Dictionary
@export var walking_anim_back : Dictionary
@export var walking_anim_left : Dictionary
@export var walking_anim_right : Dictionary
@export var dashing_anim_front : Dictionary
@export var dashing_anim_back : Dictionary
@export var dashing_anim_left : Dictionary
@export var dashing_anim_right : Dictionary
@export var interacting_anim_front : Dictionary
@export var interacting_anim_back : Dictionary
@export var interacting_anim_left : Dictionary
@export var interacting_anim_right : Dictionary
var anim_dictionary_idle : Dictionary
var anim_dictionary_walking : Dictionary
var anim_dictionary_dashing : Dictionary
var anim_dictionary_interacting : Dictionary
#endregion
func _ready() -> void:
add_on_slots = 1
#region init animation dictionaries
anim_dictionary_idle.set(MachineGlobals.look_direction.UP, idle_anim_back)
anim_dictionary_idle.set(MachineGlobals.look_direction.DOWN, idle_anim_front)
anim_dictionary_idle.set(MachineGlobals.look_direction.LEFT, idle_anim_left)
anim_dictionary_idle.set(MachineGlobals.look_direction.RIGHT, idle_anim_right)
anim_dictionary_walking.set(MachineGlobals.look_direction.UP, walking_anim_back)
anim_dictionary_walking.set(MachineGlobals.look_direction.DOWN, walking_anim_front)
anim_dictionary_walking.set(MachineGlobals.look_direction.LEFT, walking_anim_left)
anim_dictionary_walking.set(MachineGlobals.look_direction.RIGHT, walking_anim_right)
anim_dictionary_interacting.set(MachineGlobals.look_direction.UP, interacting_anim_back)
anim_dictionary_interacting.set(MachineGlobals.look_direction.DOWN, interacting_anim_front)
anim_dictionary_interacting.set(MachineGlobals.look_direction.LEFT, interacting_anim_left)
anim_dictionary_interacting.set(MachineGlobals.look_direction.RIGHT, interacting_anim_right)
anim_dictionary_dashing.set(MachineGlobals.look_direction.UP, dashing_anim_back)
anim_dictionary_dashing.set(MachineGlobals.look_direction.DOWN, dashing_anim_front)
anim_dictionary_dashing.set(MachineGlobals.look_direction.LEFT, dashing_anim_left)
anim_dictionary_dashing.set(MachineGlobals.look_direction.RIGHT, dashing_anim_right)
#endregion
for a in self.get_children() :
if a.name == "DodgeDurationTimer" :
dodge_duration_timer = a
for a in MachineGlobals.drone_body_slots :
machine_upgrades.set(a,null)
animation_state_machine = MachineGlobals.regular_states.IDLING
func class_ability() -> float:
#do dash
return dodge_cd
func listen_to_animation_signals(next_anim_state : MachineGlobals.regular_states) -> void:
match next_anim_state :
MachineGlobals.regular_states.IDLING :
for a : AnimatedSprite2D in _get_body_parts() :
a.play(anim_dictionary_idle.get(look_dir).get(a.name))
MachineGlobals.regular_states.WALKING :
for a : AnimatedSprite2D in _get_body_parts() :
a.play(anim_dictionary_walking.get(look_dir).get(a.name))
MachineGlobals.regular_states.DASHING :
for a : AnimatedSprite2D in _get_body_parts() :
a.play(anim_dictionary_dashing.get(look_dir).get(a.name))
MachineGlobals.regular_states.INTERACTING :
for a : AnimatedSprite2D in _get_body_parts() :
a.play(anim_dictionary_interacting.get(look_dir).get(a.name))

View File

@@ -7,8 +7,10 @@ extends CharacterBody2D
@export var hit_points : float
@export var fuel_tank_capacity : float
@export var movement_speed : float
signal change_animation(anim_to_change_to)
var animation_state_machine : MachineGlobals.regular_states
var look_dir : MachineGlobals.look_direction
var states : Array
var effects : Array
var add_on_slots : int
var machine_upgrades : Dictionary
var ability_timer : Timer
@@ -21,6 +23,11 @@ var current_fuel_in_tank : float
@abstract func model_ability() -> float
@abstract func class_ability() -> float
@abstract func listen_to_animation_signals(next_anim_state : MachineGlobals.regular_states) -> void
func _ready() -> void:
connect("change_animation",listen_to_animation_signals)
func interact() -> void :
pass
@@ -31,8 +38,21 @@ func _physics_process(delta: float) -> void:
move_and_slide()
func _movement(delta: float) -> void :
DebugGlobal.set_debug_info("Velocity", self.velocity )
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
self.velocity = input_direction * movement_speed
if self.velocity != Vector2.ZERO && animation_state_machine in [MachineGlobals.regular_states.IDLING,MachineGlobals.regular_states.INTERACTING] :
animation_state_machine = MachineGlobals.regular_states.WALKING
if self.velocity.y < 0 :
look_dir = MachineGlobals.look_direction.UP
elif self.velocity.y > 0 :
look_dir = MachineGlobals.look_direction.DOWN
elif self.velocity.x > 0 :
look_dir = MachineGlobals.look_direction.RIGHT
elif self.velocity.x < 0 :
look_dir = MachineGlobals.look_direction.LEFT
else :
animation_state_machine = MachineGlobals.regular_states.IDLING
func _action_process(delta:float) -> void :
if action_timer != null && action_timer.is_stopped():
@@ -47,3 +67,10 @@ func _ability_process(delta:float) -> void :
ability_timer.start(class_ability())
elif Input.is_action_just_pressed("model_ability") :
ability_timer.start(model_ability())
func _get_body_parts() -> Array :
var clist : Array
for a in self.get_children() :
if a is AnimatedSprite2D :
clist.append(a)
return clist

View File

@@ -1,3 +1,4 @@
class_name MachineGlobals
enum drone_body_slots{
BRAIN,
LEGS,

View File

@@ -1,7 +1,7 @@
extends Drone
func _ready() -> void:
self_body = self
pass
func primary_action() -> float:
return -1

View File

@@ -190,7 +190,7 @@ animations = [{
}],
"loop": true,
"name": &"base_head_idle_front",
"speed": 4.0
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
@@ -226,12 +226,8 @@ animations = [{
[node name="BaseDrone" unique_id=872770085 instance=ExtResource("1_j7lnw")]
script = ExtResource("2_njeil")
dodge_cd = null
model_name = &"Base"
carry_capacity = null
hit_points = null
fuel_tank_capacity = null
movement_speed = 5.0
movement_speed = 150.0
[node name="Brain" parent="." index="0" unique_id=1086286463]
position = Vector2(-4.7683716e-07, -0.9999995)
@@ -261,4 +257,6 @@ position = Vector2(-2.842171e-14, -5.9604645e-08)
scale = Vector2(0.6875, 0.6875)
sprite_frames = SubResource("SpriteFrames_wbero")
animation = &"base_head_idle_front"
frame_progress = 0.7447344
[node name="Camera2D" parent="." index="6" unique_id=2079743221]
zoom = Vector2(5, 5)

View File

@@ -7,6 +7,7 @@ size = Vector2(10, 8)
[node name="Drone" type="CharacterBody2D" unique_id=19986915]
texture_filter = 1
collision_layer = 3
[node name="Brain" type="AnimatedSprite2D" parent="." unique_id=1086286463]
sprite_frames = SubResource("SpriteFrames_bsvqd")
@@ -25,3 +26,7 @@ sprite_frames = SubResource("SpriteFrames_bsvqd")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1475205819]
shape = SubResource("RectangleShape2D_6pa52")
[node name="Camera2D" type="Camera2D" parent="." unique_id=2079743221]
[node name="DodgeDurationTimer" type="Timer" parent="." unique_id=656287999]