diff --git a/lib/classes/animated_sprite_state_receiver.gd b/lib/classes/animated_sprite_state_receiver.gd index 10ad5d0..e1eb72a 100644 --- a/lib/classes/animated_sprite_state_receiver.gd +++ b/lib/classes/animated_sprite_state_receiver.gd @@ -217,16 +217,18 @@ func set_previous_animation( old_state: StateAnimatedActor, new_state: StateAnim # Handle state change from subscribed state machine. #From signal state_changed(old_state_name, new_state) func _on_state_change(old_state_name:String, new_state :State): - print ("1? got the state change signal ", new_state.name) + #print ("1? got the state change signal ", new_state.name) # set current state to new_state + previous_state_name = old_state_name #TODO: Confirm that this is a reference to the state in the ###### State machine if new_state is StateAnimatedActor: #Testing this. Update: It works current_state = new_state - change_animation() if has_method('_on_state_change_' + current_state.name): call('_on_state_change_' + current_state.name) - print("It's an animated Actor state!") + else: + change_animation() + #print("It's an animated Actor state!") else: push_warning("Received non animated Actor state.") #current_state = new_state diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index b21d272..dc24ebb 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -28,6 +28,8 @@ var acceleration = Vector2(0,0) #Removing Probably not used #var sim_velocity = Vector2(0,0) +var physics_delta:float +var process_delta:float #Can't use floats here, switched to constants. @@ -50,17 +52,21 @@ func _ready(): # These get called by the parent ############ func process_physics(delta): - move_actor_as_desired(delta) + physics_delta = delta if has_method('_state_process_physics_' + current_state.name): call('_state_process_physics_' + current_state.name) + else: + move_actor_as_desired() # more likely needed for Players func process_physics_input(delta): + physics_delta = delta if has_method('_state_process_physics_input_' + current_state.name): call('_state_process_physics_input_' + current_state.name) # More likely needed for NPCs func process(delta): + process_delta = delta if has_method('_state_process_' + current_state.name): call('_state_process_' + current_state.name) @@ -126,8 +132,8 @@ func _on_state_change(old_state_name:String, new_state :State): #current_state = new_state -func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): - +func move_actor_as_desired( x_move_direction_override: float = 0): + var delta:float = physics_delta var _move_speed = current_state.move_speed var _move_speed_modifier = current_state.move_speed_modifier var _move_modifier_move_acceleration = current_state.move_modifier_move_acceleration diff --git a/lib/classes/state.gd b/lib/classes/state.gd index 4baf8e1..b023e61 100644 --- a/lib/classes/state.gd +++ b/lib/classes/state.gd @@ -45,7 +45,8 @@ func copy(state: State) -> void: return func enter() -> void: - print("Got call to enter state ", name) + if debug_state: + print("Got call to enter state ", name) if state_timeout != null: print(name, "-Starting Timer") state_timeout.start() diff --git a/src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd b/src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd index d064b22..6ec3a9c 100644 --- a/src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd +++ b/src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd @@ -2,9 +2,12 @@ extends AnimatedSprite_StateReceiver func _ready(): # Lets see if this nutty thing works - #var state_ref :State + var state_ref :State #state_ref = get_node(callable_state_machine).get_state_reference('fall') #state_ref.connect("state_entered", self, "_on_state_entered_fall") + state_ref = get_node(callable_state_machine).get_state_reference('attack_sword') + state_ref.connect("state_exited", self, "_on_state_exited_attack_sword") + pass # I don't need this right now but I proved it can be done! @@ -31,6 +34,15 @@ func _ready(): # frame = 2 # stop() +func _on_state_change_idle(): + change_animation() + if previous_state_name == 'attack_sword': + animation = 'idle-attack-sword' + func _on_state_change_fall(): + change_animation() frame = 2 stop() + +func _on_state_exited_attack_sword(): + print("you just swung your sword, you should get a modifier.") diff --git a/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd b/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd index 0c9038b..192b54b 100644 --- a/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd +++ b/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd @@ -25,7 +25,7 @@ func get_movement_direction() -> float: var _wants_jump :bool func wants_jump() -> bool: if Input.is_action_just_pressed("jump_" + str(player_number)): - desired_movement_vector.y = 1 + desired_movement_vector.y = UP _wants_jump = true return true else: @@ -79,7 +79,6 @@ func wants_roll() -> bool: #func _state_process_physics_input_move(): # get_movement_direction() -var physics_delta # Probably better to do it this way then allocating individual # state functions that all do the same thing. func process_physics_input(delta): @@ -94,9 +93,12 @@ func process_physics_input(delta): wants_dash() wants_roll() +func flip_sprite_to_movement_direction(): + if desired_movement_vector.x != 0.0: + parent.transform.x.x = desired_movement_vector.x func _state_process_physics_idle(): - if desired_movement_vector.y == 1: + if desired_movement_vector.y == UP: request_state_change.call_func('jump') #TODO: May need that 'bump' logic to make velocity work. @@ -137,7 +139,9 @@ func _state_process_physics_roll(): if current_state.animation_finished == true: request_state_change.call_func('idle') - move_actor_as_desired(physics_delta, parent.transform.x.x) + # Force role in facing direction + # instead of movement direction + move_actor_as_desired(parent.transform.x.x) if !parent.is_on_floor(): #return fall_state @@ -151,15 +155,17 @@ func _state_process_physics_land(): if !parent.is_on_floor(): #return fall_state request_state_change.call_func('fall') - + move_actor_as_desired() + func _state_process_physics_fall(): - if desired_movement_vector.x != 0.0: - parent.transform.x.x = desired_movement_vector.x + flip_sprite_to_movement_direction() if parent.is_on_floor(): #modifier.reference() #idle_state.modifier = landing_modifier request_state_change.call_func('land') + + move_actor_as_desired() func _state_process_physics_jump(): if desired_movement_vector.x != 0.0: @@ -171,17 +177,23 @@ func _state_process_physics_jump(): #modifier.reference() #idle_state.modifier = landing_modifier request_state_change.call_func('idle') + + move_actor_as_desired() func _state_process_physics_move(): # flip sprite in direction - if desired_movement_vector.x != 0.0: - parent.transform.x.x = desired_movement_vector.x + flip_sprite_to_movement_direction() + + if desired_movement_vector.y == UP: + request_state_change.call_func('jump') if desired_movement_vector.x == 0: request_state_change.call_func('idle') if !parent.is_on_floor(): request_state_change.call_func('fall') + + move_actor_as_desired() #func _on_state_entered_idle(): # print("Movement State Idle State Entered!")