Add fire/attack state modifier for idle and run animations.
This commit is contained in:
parent
e5e8c030f6
commit
89208475fe
|
|
@ -323,8 +323,8 @@ animations = [ {
|
||||||
"name": "climb_fire",
|
"name": "climb_fire",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ SubResource( 86 ), SubResource( 87 ), SubResource( 88 ), SubResource( 86 ) ],
|
"frames": [ SubResource( 86 ), SubResource( 87 ), SubResource( 88 ), SubResource( 86 ), SubResource( 86 ) ],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": "fire",
|
"name": "fire",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -338,6 +338,11 @@ animations = [ {
|
||||||
"name": "idle",
|
"name": "idle",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
|
"frames": [ SubResource( 86 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "idle_fire",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
"frames": [ SubResource( 93 ), SubResource( 94 ), SubResource( 95 ), SubResource( 96 ), SubResource( 97 ), SubResource( 98 ), SubResource( 98 ), SubResource( 97 ), SubResource( 96 ), SubResource( 95 ), SubResource( 94 ), SubResource( 93 ) ],
|
"frames": [ SubResource( 93 ), SubResource( 94 ), SubResource( 95 ), SubResource( 96 ), SubResource( 97 ), SubResource( 98 ), SubResource( 98 ), SubResource( 97 ), SubResource( 96 ), SubResource( 95 ), SubResource( 94 ), SubResource( 93 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "jump",
|
"name": "jump",
|
||||||
|
|
@ -379,8 +384,8 @@ animations = [ {
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ SubResource( 133 ) ],
|
"frames": [ SubResource( 133 ) ],
|
||||||
"loop": true,
|
"loop": false,
|
||||||
"name": "stepfire",
|
"name": "step_fire",
|
||||||
"speed": 10.0
|
"speed": 10.0
|
||||||
}, {
|
}, {
|
||||||
"frames": [ SubResource( 134 ), SubResource( 135 ), SubResource( 136 ), SubResource( 135 ) ],
|
"frames": [ SubResource( 134 ), SubResource( 135 ), SubResource( 136 ), SubResource( 135 ) ],
|
||||||
|
|
@ -408,8 +413,7 @@ script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 147 )
|
frames = SubResource( 147 )
|
||||||
animation = "idle"
|
animation = "idle_fire"
|
||||||
frame = 1
|
|
||||||
playing = true
|
playing = true
|
||||||
flip_h = true
|
flip_h = true
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
|
@ -442,7 +446,7 @@ starting_state = NodePath("idle")
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
animation_name = "idle"
|
animation_name = "idle"
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
transition_state_nodes = [ NodePath("../jump") ]
|
animation_sequence = [ "idle" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
move_node = NodePath("../move")
|
move_node = NodePath("../move")
|
||||||
|
|
@ -452,6 +456,7 @@ fire_node = NodePath("../fire")
|
||||||
script = ExtResource( 7 )
|
script = ExtResource( 7 )
|
||||||
animation_name = "jump"
|
animation_name = "jump"
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
|
animation_sequence = [ "jump" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
move_node = NodePath("../move")
|
move_node = NodePath("../move")
|
||||||
|
|
@ -470,6 +475,7 @@ dash_node = NodePath(".")
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
animation_name = "jump"
|
animation_name = "jump"
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
|
animation_sequence = [ "jump" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
move_node = NodePath("../move")
|
move_node = NodePath("../move")
|
||||||
|
|
||||||
|
|
@ -478,17 +484,23 @@ script = ExtResource( 8 )
|
||||||
animation_name = "hit"
|
animation_name = "hit"
|
||||||
move_speed = -25.0
|
move_speed = -25.0
|
||||||
timeout_seconds = 1.0
|
timeout_seconds = 1.0
|
||||||
|
animation_sequence = [ "hit" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
|
|
||||||
[node name="fire" type="Node" parent="Controllers/state_machine"]
|
[node name="fire" type="Node" parent="Controllers/state_machine"]
|
||||||
script = ExtResource( 10 )
|
script = ExtResource( 10 )
|
||||||
animation_name = "fire"
|
animation_name = "fire"
|
||||||
timeout_seconds = 1.0
|
timeout_seconds = 1.0
|
||||||
|
animation_sequence = [ "fire" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
|
fall_node = NodePath("../fall")
|
||||||
|
move_node = NodePath("../move")
|
||||||
|
|
||||||
[node name="attack" type="Node" parent="Controllers/state_machine"]
|
[node name="attack" type="Node" parent="Controllers/state_machine"]
|
||||||
script = ExtResource( 13 )
|
script = ExtResource( 13 )
|
||||||
|
animation_name = "_fire"
|
||||||
timeout_seconds = 2.0
|
timeout_seconds = 2.0
|
||||||
|
animation_suffix = true
|
||||||
|
|
||||||
[node name="AttackStateMachine" type="Node" parent="Controllers"]
|
[node name="AttackStateMachine" type="Node" parent="Controllers"]
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
extends State
|
extends State
|
||||||
|
|
||||||
export (NodePath) var idle_node
|
export (NodePath) var idle_node
|
||||||
|
export (NodePath) var fall_node
|
||||||
|
export (NodePath) var move_node
|
||||||
|
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
|
onready var fall_state: State = get_node(fall_node)
|
||||||
|
onready var move_state: State = get_node(move_node)
|
||||||
|
|
||||||
var can_fire = true
|
var can_fire = true
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
|
|
@ -11,7 +16,7 @@ func enter() -> void:
|
||||||
state_timeout.start()
|
state_timeout.start()
|
||||||
can_fire = true
|
can_fire = true
|
||||||
if modifier_stack_ref.has($"../attack") == false:
|
if modifier_stack_ref.has($"../attack") == false:
|
||||||
$"../attack".state_timeout.start()
|
$"../attack".enter()
|
||||||
modifier_stack_ref.push_front($"../attack")
|
modifier_stack_ref.push_front($"../attack")
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
func process_input(_event: InputEvent) -> State:
|
||||||
|
|
@ -39,6 +44,14 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
parent.velocity.y += gravity * delta
|
parent.velocity.y += gravity * delta
|
||||||
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
||||||
|
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
||||||
|
|
||||||
|
if parent.velocity.x != 0.0:
|
||||||
|
return move_state
|
||||||
|
|
||||||
|
if !parent.is_on_floor():
|
||||||
|
return fall_state
|
||||||
|
|
||||||
# if move_component.flipped_sprite == true:
|
# if move_component.flipped_sprite == true:
|
||||||
# animations.flip_h = parent.direction.x > 0
|
# animations.flip_h = parent.direction.x > 0
|
||||||
|
|
@ -49,6 +62,8 @@ func process_physics(delta: float) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
|
# force timer reset
|
||||||
|
$"../attack".state_timeout.start()
|
||||||
for mods in modifier_stack_ref:
|
for mods in modifier_stack_ref:
|
||||||
print(mods.name)
|
print(mods.name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ func process_input(_event: InputEvent) -> State:
|
||||||
|
|
||||||
if move_component.wants_jump() and parent.is_on_floor():
|
if move_component.wants_jump() and parent.is_on_floor():
|
||||||
return jump_state
|
return jump_state
|
||||||
|
|
||||||
# if move_component.get_movement_direction() != 0.0:
|
# if move_component.get_movement_direction() != 0.0:
|
||||||
# return move_state
|
# return move_state
|
||||||
if move_component.wants_shoot():
|
if move_component.wants_shoot():
|
||||||
|
|
|
||||||
35
src/state.gd
35
src/state.gd
|
|
@ -9,16 +9,24 @@ extends Node
|
||||||
##
|
##
|
||||||
## @WIP
|
## @WIP
|
||||||
|
|
||||||
|
# export (NodePath) var jump_node
|
||||||
|
|
||||||
|
# onready var jump_state: State = get_node(jump_node)
|
||||||
|
|
||||||
export var animation_name: String
|
export var animation_name: String
|
||||||
export var move_speed: float = 60
|
export var move_speed: float = 60
|
||||||
export var timeout_seconds: float = 0.0
|
export var timeout_seconds: float = 0.0
|
||||||
|
|
||||||
export(Array, String) var animation_sequence
|
export(Array, String) var animation_sequence
|
||||||
export(Array, NodePath) var transition_state_nodes
|
# this just wouldn't work well. Maybe I can try a resource
|
||||||
|
# export(Array, NodePath) var transition_state_nodes
|
||||||
|
|
||||||
|
#TODO: I think these two variables accidentally serve the same purpose
|
||||||
|
# I think one was intended to be a string of the current animation name.
|
||||||
var animation_index: int = 0
|
var animation_index: int = 0
|
||||||
var current_animation_sequence: int = 0
|
var current_animation_sequence: int = 0
|
||||||
|
var animation_suffix: String = '';
|
||||||
|
|
||||||
var modifier_stack_ref: Array # Well this didn't work
|
var modifier_stack_ref: Array # Well this didn't work
|
||||||
|
|
||||||
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
|
@ -42,14 +50,28 @@ func _ready():
|
||||||
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
|
# Reset animation suffix in case there isn't one
|
||||||
|
animation_suffix = ''
|
||||||
print(parent.name, " entering State: ", self.name)
|
print(parent.name, " entering State: ", self.name)
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
if animation_name != '':
|
if modifier_stack_ref.empty() == false:
|
||||||
animations.play(animation_name)
|
if modifier_stack_ref[-1].animation_name != '':
|
||||||
elif animation_sequence.size() > 0:
|
if modifier_stack_ref[-1].animation_suffix:
|
||||||
|
if animation_sequence.size() > 0:
|
||||||
animation_index = 0
|
animation_index = 0
|
||||||
current_animation_sequence = 0
|
current_animation_sequence = 0
|
||||||
animations.play(animation_sequence[animation_index])
|
# Guess I don't need this one anymore
|
||||||
|
#if animations.frames.get_animation_names().has(animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name):
|
||||||
|
if animations.frames.has_animation(animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name):
|
||||||
|
animation_suffix = modifier_stack_ref[-1].animation_name
|
||||||
|
else:
|
||||||
|
animations.play(modifier_stack_ref[-1].animation_name)
|
||||||
|
return
|
||||||
|
if animation_sequence.size() > 0:
|
||||||
|
animation_index = 0
|
||||||
|
current_animation_sequence = 0
|
||||||
|
animations.play(animation_sequence[animation_index] + animation_suffix)
|
||||||
|
return
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
@ -61,7 +83,8 @@ func process_frame(_delta: float) -> State:
|
||||||
if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
||||||
if animation_index >= animation_sequence.size():
|
if animation_index >= animation_sequence.size():
|
||||||
animation_index = 0
|
animation_index = 0
|
||||||
animations.play(animation_sequence[animation_index])
|
##TODO: Add a safety check here.
|
||||||
|
animations.play(animation_sequence[animation_index] + animation_suffix)
|
||||||
print("An animation sequence: ", animations.animation , animation_index)
|
print("An animation sequence: ", animations.animation , animation_index)
|
||||||
current_animation_sequence = animation_index
|
current_animation_sequence = animation_index
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,11 @@ func process_frame(delta: float) -> void:
|
||||||
if state_modifiers[-1].state_timeout.time_left == 0:
|
if state_modifiers[-1].state_timeout.time_left == 0:
|
||||||
print("Pop State Modifier: ", state_modifiers[-1].name)
|
print("Pop State Modifier: ", state_modifiers[-1].name)
|
||||||
state_modifiers.pop_back()
|
state_modifiers.pop_back()
|
||||||
|
# Reset animation suffix
|
||||||
|
current_state.animation_suffix = ''
|
||||||
|
var current_frame = current_state.animations.frame
|
||||||
|
current_state.animations.play(current_state.animation_sequence[current_state.animation_index])
|
||||||
|
current_state.animations.frame = current_frame;
|
||||||
var new_state = current_state.process_frame(delta)
|
var new_state = current_state.process_frame(delta)
|
||||||
if new_state:
|
if new_state:
|
||||||
change_state(new_state)
|
change_state(new_state)
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,15 @@ export var animation_name: String
|
||||||
export var move_speed: float = 60
|
export var move_speed: float = 60
|
||||||
export var timeout_seconds: float = 0.0
|
export var timeout_seconds: float = 0.0
|
||||||
|
|
||||||
export(Array, String) var animation_sequence
|
# Attempting to use this as an animation suffix that can linger after
|
||||||
export(Array, NodePath) var transition_state_nodes
|
# state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc.
|
||||||
var animation_index: int = 0
|
export var animation_suffix: bool = false
|
||||||
var current_animation_sequence: int = 0
|
|
||||||
|
# not sure if I can do the array thing from state change. Maybe?
|
||||||
|
# disabling this sequencing for now.
|
||||||
|
# export(Array, String) var animation_sequence
|
||||||
|
# var animation_index: int = 0
|
||||||
|
# var current_animation_sequence: int = 0
|
||||||
|
|
||||||
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
|
||||||
|
|
@ -33,5 +38,14 @@ func _ready():
|
||||||
state_timeout.autostart = false
|
state_timeout.autostart = false
|
||||||
add_child(state_timeout)
|
add_child(state_timeout)
|
||||||
|
|
||||||
|
func enter() -> void:
|
||||||
|
print("Apply State Modifier: ", self.name)
|
||||||
|
state_timeout.start()
|
||||||
|
#modifier_stack_ref = state_modifiers
|
||||||
|
return
|
||||||
|
|
||||||
|
func exit() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
func _update():
|
func _update():
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user