diff --git a/src/playerD/Player.tscn b/src/playerD/Player.tscn index c4ea759..e4336a8 100644 --- a/src/playerD/Player.tscn +++ b/src/playerD/Player.tscn @@ -539,12 +539,14 @@ pre_append_animation = true script = ExtResource( 5 ) animation_sequence = [ "step", "run" ] jump_node = NodePath("../jump") +attack_node = NodePath("../attack") [node name="jump" type="Node" parent="movement_state_machine" index="3"] script = ExtResource( 8 ) animation_sequence = [ "jump" ] idle_node = NodePath("../idle") fall_node = NodePath("../fall") +attack_node = NodePath("../attack") jump_force = 250.0 [node name="attack" type="Node" parent="movement_state_machine" index="4"] diff --git a/src/playerD/states/jump.gd b/src/playerD/states/jump.gd index 1515319..498ee58 100644 --- a/src/playerD/states/jump.gd +++ b/src/playerD/states/jump.gd @@ -3,9 +3,12 @@ extends StateAnimatedActor export (NodePath) var idle_node export (NodePath) var fall_node +export (NodePath) var attack_node + onready var idle_state: State = get_node(idle_node) onready var fall_state: State = get_node(fall_node) +onready var attack_state: State = get_node(attack_node) export var jump_force: float = 200.0 @@ -18,6 +21,9 @@ func process_physics(delta: float) -> State: if move_component.velocity.y > 0: return fall_state + + if move_component.wants_shoot(): + return attack_state # First allow horizontal movement. move_actor_as_desired(delta) diff --git a/src/playerD/states/move.gd b/src/playerD/states/move.gd index 5497006..3e066a5 100644 --- a/src/playerD/states/move.gd +++ b/src/playerD/states/move.gd @@ -3,15 +3,20 @@ extends StateAnimatedActor export (NodePath) var fall_node export (NodePath) var idle_node export (NodePath) var jump_node +export (NodePath) var attack_node onready var fall_state: State = get_node(fall_node) onready var idle_state: State = get_node(idle_node) onready var jump_state: State = get_node(jump_node) +onready var attack_state: State = get_node(attack_node) func process_physics(delta: float) -> State: if move_component.wants_jump() and parent.is_on_floor(): return jump_state + if move_component.wants_shoot(): + return attack_state + move_actor_as_desired(delta) if move_component.velocity.x == 0.0: diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index 6ef7f77..72a5ff2 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -92,7 +92,7 @@ func enter() -> void: "Animation Suffix": if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name): - animation_suffix = modifier_stack_ref[-1].animation_name + animation_suffix = modifier_stack_ref[i].animation_name else: print("Warning!: Animation suffix that doesn't exist ", mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name) @@ -126,6 +126,8 @@ func enter() -> void: # return if mod_animation_sequence.size() > 0: + if debug_state: + print("Starting Animation: " , mod_animation_sequence[animation_index] + animation_suffix) animations.play(mod_animation_sequence[animation_index] + animation_suffix) #TODO: maybe check current animatio has this frame animations.frame = enter_frame @@ -143,9 +145,10 @@ func process_input(_event: InputEvent) -> State: func process_frame(_delta: float) -> State: #if animation_sequence.size() > 0 and current_animation_sequence != animation_index: - if mod_animation_sequence.size() > current_animation_sequence and current_animation_sequence != animation_index: - if animation_index >= mod_animation_sequence.size(): - animation_index = 0 + if mod_animation_sequence.size() > animation_index and current_animation_sequence != animation_index: + #TODO: why was I doing this +# if animation_index >= mod_animation_sequence.size(): +# animation_index = 0 ##TODO: Add a safety check here. animations.play(mod_animation_sequence[animation_index] + animation_suffix) if debug_state: @@ -217,7 +220,9 @@ func push_animation_state_modifier(modifier: StateModifier): "Animation Suffix": if modifier.modifier_type == "Exit Animation": # We have to place this one right before maybe? - modifier_stack_ref.push_back(modifier) + # Whoops! Forgot to actually do this + #modifier_stack_ref.push_back(modifier) + modifier_stack_ref.insert(modifier_stack_ref.size() - 1, modifier) # if last_modifer.animation_name != '': # and if an animation applies # if last_modifer.pre_append_animation == modifier.pre_append_animation: # They're the same type # if modifier.pre_append_animation == true and modifier_stack_ref[-1].animation_suffix == true: diff --git a/src/state_machine_animated_actor.gd b/src/state_machine_animated_actor.gd index 4bbbe5a..91f47b4 100644 --- a/src/state_machine_animated_actor.gd +++ b/src/state_machine_animated_actor.gd @@ -29,28 +29,44 @@ func process_frame(delta: float) -> void: for i in range(state_modifiers.size()): # if this modifer is a timer based one if state_modifiers[i].state_timeout.time_left == 0 and state_modifiers[i].timeout_seconds !=0: - # Need to do extra stuff if it's an animation based one if state_modifiers[i].modifier_type == "Animation Suffix": + if debug_state_machine: + print("State Modifier Timeout: ", state_modifiers[i].name, " -> ", state_modifiers[i].animation_name) # Reset animation suffix current_anim_state.animation_suffix = '' + # Get the current frame of animation var current_frame = current_anim_state.animations.frame + + # Set the animation index to the current one current_anim_state.animation_index = current_anim_state.current_animation_sequence #current_anim_state.current_animation_sequence #current_anim_state.animations.play() - if current_anim_state.animation_sequence.size() >= current_anim_state.current_animation_sequence: - current_anim_state.animations.play( - current_state.animation_sequence[current_anim_state.current_animation_sequence]) - current_anim_state.animations.frames.frames.size() >= current_frame - current_anim_state.animations.frame = current_frame - else: - current_anim_state.animations.play( - current_state.animation_sequence[0]) + + current_anim_state.animations.play( + current_anim_state.mod_animation_sequence[current_anim_state.animation_index]) + # Try to set the current frame to the same as before. + current_anim_state.animations.frames.frames.size() >= current_frame + current_anim_state.animations.frame = current_frame + + ##TODO: + # no longer needed this way maybe. way to overengineer man. +# if current_anim_state.animation_sequence.size() >= current_anim_state.mod_animation_sequence.size(): +# print("Change sequence!: ", current_anim_state.mod_animation_sequence) +# print("Origin sequence!: ", current_state.mod_animation_sequence) +# current_anim_state.animations.play( +# current_anim_state.mod_animation_sequence[current_anim_state.animation_index]) +# # Try to set the current frame to the same as before. +# current_anim_state.animations.frames.frames.size() >= current_frame +# current_anim_state.animations.frame = current_frame +# else: +# current_anim_state.animations.play( +# current_anim_state.animation_sequence[0]) - if debug_state_machine: - print("Pop State Modifier: ", state_modifiers[i].name) - state_modifiers.pop_at(i) + if debug_state_machine: + print("Pop State Modifier: ", state_modifiers[i].name) + state_modifiers.pop_at(i) # if state_modifiers[-1].state_timeout.time_left == 0 and state_modifiers[-1].pre_append_animation == false: # if debug_state_machine: @@ -71,9 +87,19 @@ func process_frame(delta: float) -> void: func _on_AnimatedSprite_animation_finished(): + + ##TODO: + # It's hard to pop an exit animation off when it's stacked with another kind of animation. for i in state_modifiers.size(): - if state_modifiers[i].animation_name == current_state.animations.animation: - state_modifiers.pop_at(i) + if state_modifiers[i].modifier_type == "Exit Animation": + #print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation + current_state.animation_suffix) + if (state_modifiers[i].animation_name + current_state.animation_suffix) == current_state.animations.animation: + print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation ) + print(current_state.mod_animation_sequence) + state_modifiers.pop_at(i) + current_state.animation_index += 1 + break + # if state_modifiers.empty() == false: # if state_modifiers[-1].pre_append_animation == true: @@ -83,6 +109,7 @@ func _on_AnimatedSprite_animation_finished(): if current_state.animations.frames.get_animation_loop( current_state.animations.animation) == false: if current_state.animation_sequence.size() > 0: + print("<-- next anim.") current_state.animation_index += 1 diff --git a/src/state_modifier.gd b/src/state_modifier.gd index bb01c4b..f71c87d 100644 --- a/src/state_modifier.gd +++ b/src/state_modifier.gd @@ -48,7 +48,8 @@ func _ready(): if animation_name != '' and modifier_type == "None": modifier_type = "Replace Animation" state_timeout = Timer.new() - state_timeout.wait_time = timeout_seconds + if timeout_seconds > 0: + state_timeout.wait_time = timeout_seconds state_timeout.one_shot = true state_timeout.autostart = false add_child(state_timeout)