diff --git a/src/playerD/Player.tscn b/src/playerD/Player.tscn index e4336a8..5824d16 100644 --- a/src/playerD/Player.tscn +++ b/src/playerD/Player.tscn @@ -458,7 +458,7 @@ animations = [ { "speed": 10.0 }, { "frames": [ SubResource( 161 ), SubResource( 162 ), SubResource( 163 ) ], -"loop": true, +"loop": false, "name": "shoot", "speed": 10.0 }, { diff --git a/src/playerD/states/attack.gd b/src/playerD/states/attack.gd index 7a2effa..68409d6 100644 --- a/src/playerD/states/attack.gd +++ b/src/playerD/states/attack.gd @@ -17,18 +17,48 @@ var can_fire = true signal do_attack() func enter() -> void: - .enter() + #.enter() + ##TODO: Turn this to clear only the animation modifiers. + modifier_stack_ref.clear() + mod_animation_sequence.clear() + #mod_animation_sequence = animation_sequence.duplicate(true) + mod_animation_sequence.append_array(animation_sequence) + # Reset animation suffix in case there isn't one + animation_suffix = '' + animation_index = 0 + current_animation_sequence = 0 + #var enter_animation = '' + var enter_frame = 0 + + if debug_state: + print(parent.name, " entering State: ", self.name) + move_component.current_movement_state = self.name + emit_signal("state_entered") + state_timeout.start() can_fire = true # if modifier_stack_ref.has($"../draw_weapon") == false: # $"../draw_weapon".enter() # modifier_stack_ref.push_front($"../draw_weapon") - push_animation_state_modifier(weapon_state_modifier) + if debug_state: + print("Previous State Info: ", previous_animation_name, " ", + previous_state_frame_number, " ", previous_state_name) + match previous_animation_name: + "idle": + animations.play("shoot") + "run": + animations.play("run_shoot") + animations.frame = previous_state_frame_number + "jump": + animations.play("jump_shoot") + animations.frame = previous_state_frame_number + _: + print("Warning!: Attack state encountered unhandled prev animation: ", previous_animation_name) func process_frame(delta: float) -> State: - if animations.frame == 2: - animations.stop() - if state_timeout.time_left == 0: +# if animations.frame == 2: +# animations.stop() + if state_timeout.time_left == 0 and animations.animation == "shoot": return idle_state return null @@ -43,9 +73,18 @@ func process_physics(delta: float) -> State: return jump_state move_actor_as_desired(delta) - - if move_component.velocity.x != 0.0: + + if previous_state_name == "move" and move_component.velocity.x == 0.0: + return idle_state + + if previous_state_name == "idle" and move_component.velocity.x != 0.0: return move_state + + if move_component.get_movement_direction() != 0.0: + parent.transform.x.x = move_component.get_movement_direction() + +# if move_component.velocity.x != 0.0: +# return move_state if !parent.is_on_floor(): return fall_state @@ -56,6 +95,7 @@ func process_physics(delta: float) -> State: func exit() -> void: # force timer reset weapon_state_modifier.state_timeout.start() + push_animation_state_modifier(weapon_state_modifier) #$"../draw_weapon".state_timeout.start() return diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index 72a5ff2..14a7b2c 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -41,6 +41,11 @@ var animations: AnimatedSprite var move_component: MovementComponent var parent: KinematicBody2D +#animation_name :String, frame_number : int, animation_sequence :Array +var previous_animation_name : String +var previous_state_frame_number : int +var previous_state_name: String + #var animation_sequence_timer: Timer diff --git a/src/state_machine_animated_actor.gd b/src/state_machine_animated_actor.gd index 91f47b4..8ef449f 100644 --- a/src/state_machine_animated_actor.gd +++ b/src/state_machine_animated_actor.gd @@ -1,5 +1,28 @@ class_name StateMachineAnimatedActor extends StateMachine +func change_state(new_state: State) -> void: + if current_state: + current_state.exit() + + # Set parameters for information + if new_state is StateAnimatedActor and current_state is StateAnimatedActor: + set_previous_animation( current_state, new_state) + + current_state = new_state + current_state.enter() + if(state_modifiers.size() > 0 and debug_state_machine): + print("Active Modifiers:") + for mods in state_modifiers: + print(mods.name) + +func set_previous_animation( old_state: StateAnimatedActor, new_state: StateAnimatedActor ) -> void: + new_state.previous_animation_name = old_state.mod_animation_sequence[old_state.current_animation_sequence] + new_state.previous_state_frame_number = old_state.animations.frame + new_state.previous_state_name = old_state.name + + #animation_name :String, frame_number : int, animation_sequence :Array + return + # Initialize the state machine by giving each child state a reference to the # parent object it belongs to and enter the default starting_state. func init_animated_actor(parent: KinematicBody2D, animations: AnimatedSprite, move_component: MovementComponent) -> void: