Starting to wonder if I need modifiers again.
This commit is contained in:
parent
209c75ba16
commit
a8c6391ee9
|
|
@ -217,16 +217,18 @@ func set_previous_animation( old_state: StateAnimatedActor, new_state: StateAnim
|
||||||
# Handle state change from subscribed state machine.
|
# Handle state change from subscribed state machine.
|
||||||
#From signal state_changed(old_state_name, new_state)
|
#From signal state_changed(old_state_name, new_state)
|
||||||
func _on_state_change(old_state_name:String, new_state :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
|
# set current state to new_state
|
||||||
|
previous_state_name = old_state_name
|
||||||
#TODO: Confirm that this is a reference to the state in the
|
#TODO: Confirm that this is a reference to the state in the
|
||||||
###### State machine
|
###### State machine
|
||||||
if new_state is StateAnimatedActor: #Testing this. Update: It works
|
if new_state is StateAnimatedActor: #Testing this. Update: It works
|
||||||
current_state = new_state
|
current_state = new_state
|
||||||
change_animation()
|
|
||||||
if has_method('_on_state_change_' + current_state.name):
|
if has_method('_on_state_change_' + current_state.name):
|
||||||
call('_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:
|
else:
|
||||||
push_warning("Received non animated Actor state.")
|
push_warning("Received non animated Actor state.")
|
||||||
#current_state = new_state
|
#current_state = new_state
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ var acceleration = Vector2(0,0)
|
||||||
|
|
||||||
#Removing Probably not used
|
#Removing Probably not used
|
||||||
#var sim_velocity = Vector2(0,0)
|
#var sim_velocity = Vector2(0,0)
|
||||||
|
var physics_delta:float
|
||||||
|
var process_delta:float
|
||||||
|
|
||||||
|
|
||||||
#Can't use floats here, switched to constants.
|
#Can't use floats here, switched to constants.
|
||||||
|
|
@ -50,17 +52,21 @@ func _ready():
|
||||||
# These get called by the parent
|
# These get called by the parent
|
||||||
############
|
############
|
||||||
func process_physics(delta):
|
func process_physics(delta):
|
||||||
move_actor_as_desired(delta)
|
physics_delta = delta
|
||||||
if has_method('_state_process_physics_' + current_state.name):
|
if has_method('_state_process_physics_' + current_state.name):
|
||||||
call('_state_process_physics_' + current_state.name)
|
call('_state_process_physics_' + current_state.name)
|
||||||
|
else:
|
||||||
|
move_actor_as_desired()
|
||||||
|
|
||||||
# more likely needed for Players
|
# more likely needed for Players
|
||||||
func process_physics_input(delta):
|
func process_physics_input(delta):
|
||||||
|
physics_delta = delta
|
||||||
if has_method('_state_process_physics_input_' + current_state.name):
|
if has_method('_state_process_physics_input_' + current_state.name):
|
||||||
call('_state_process_physics_input_' + current_state.name)
|
call('_state_process_physics_input_' + current_state.name)
|
||||||
|
|
||||||
# More likely needed for NPCs
|
# More likely needed for NPCs
|
||||||
func process(delta):
|
func process(delta):
|
||||||
|
process_delta = delta
|
||||||
if has_method('_state_process_' + current_state.name):
|
if has_method('_state_process_' + current_state.name):
|
||||||
call('_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
|
#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 = current_state.move_speed
|
||||||
var _move_speed_modifier = current_state.move_speed_modifier
|
var _move_speed_modifier = current_state.move_speed_modifier
|
||||||
var _move_modifier_move_acceleration = current_state.move_modifier_move_acceleration
|
var _move_modifier_move_acceleration = current_state.move_modifier_move_acceleration
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ func copy(state: State) -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
|
if debug_state:
|
||||||
print("Got call to enter state ", name)
|
print("Got call to enter state ", name)
|
||||||
if state_timeout != null:
|
if state_timeout != null:
|
||||||
print(name, "-Starting Timer")
|
print(name, "-Starting Timer")
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@ extends AnimatedSprite_StateReceiver
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Lets see if this nutty thing works
|
# 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 = get_node(callable_state_machine).get_state_reference('fall')
|
||||||
#state_ref.connect("state_entered", self, "_on_state_entered_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
|
pass
|
||||||
|
|
||||||
# I don't need this right now but I proved it can be done!
|
# I don't need this right now but I proved it can be done!
|
||||||
|
|
@ -31,6 +34,15 @@ func _ready():
|
||||||
# frame = 2
|
# frame = 2
|
||||||
# stop()
|
# stop()
|
||||||
|
|
||||||
|
func _on_state_change_idle():
|
||||||
|
change_animation()
|
||||||
|
if previous_state_name == 'attack_sword':
|
||||||
|
animation = 'idle-attack-sword'
|
||||||
|
|
||||||
func _on_state_change_fall():
|
func _on_state_change_fall():
|
||||||
|
change_animation()
|
||||||
frame = 2
|
frame = 2
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
|
func _on_state_exited_attack_sword():
|
||||||
|
print("you just swung your sword, you should get a modifier.")
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func get_movement_direction() -> float:
|
||||||
var _wants_jump :bool
|
var _wants_jump :bool
|
||||||
func wants_jump() -> bool:
|
func wants_jump() -> bool:
|
||||||
if Input.is_action_just_pressed("jump_" + str(player_number)):
|
if Input.is_action_just_pressed("jump_" + str(player_number)):
|
||||||
desired_movement_vector.y = 1
|
desired_movement_vector.y = UP
|
||||||
_wants_jump = true
|
_wants_jump = true
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
|
|
@ -79,7 +79,6 @@ func wants_roll() -> bool:
|
||||||
#func _state_process_physics_input_move():
|
#func _state_process_physics_input_move():
|
||||||
# get_movement_direction()
|
# get_movement_direction()
|
||||||
|
|
||||||
var physics_delta
|
|
||||||
# Probably better to do it this way then allocating individual
|
# Probably better to do it this way then allocating individual
|
||||||
# state functions that all do the same thing.
|
# state functions that all do the same thing.
|
||||||
func process_physics_input(delta):
|
func process_physics_input(delta):
|
||||||
|
|
@ -94,9 +93,12 @@ func process_physics_input(delta):
|
||||||
wants_dash()
|
wants_dash()
|
||||||
wants_roll()
|
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():
|
func _state_process_physics_idle():
|
||||||
if desired_movement_vector.y == 1:
|
if desired_movement_vector.y == UP:
|
||||||
request_state_change.call_func('jump')
|
request_state_change.call_func('jump')
|
||||||
|
|
||||||
#TODO: May need that 'bump' logic to make velocity work.
|
#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:
|
if current_state.animation_finished == true:
|
||||||
request_state_change.call_func('idle')
|
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():
|
if !parent.is_on_floor():
|
||||||
#return fall_state
|
#return fall_state
|
||||||
|
|
@ -151,16 +155,18 @@ func _state_process_physics_land():
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
#return fall_state
|
#return fall_state
|
||||||
request_state_change.call_func('fall')
|
request_state_change.call_func('fall')
|
||||||
|
move_actor_as_desired()
|
||||||
|
|
||||||
func _state_process_physics_fall():
|
func _state_process_physics_fall():
|
||||||
if desired_movement_vector.x != 0.0:
|
flip_sprite_to_movement_direction()
|
||||||
parent.transform.x.x = desired_movement_vector.x
|
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
#modifier.reference()
|
#modifier.reference()
|
||||||
#idle_state.modifier = landing_modifier
|
#idle_state.modifier = landing_modifier
|
||||||
request_state_change.call_func('land')
|
request_state_change.call_func('land')
|
||||||
|
|
||||||
|
move_actor_as_desired()
|
||||||
|
|
||||||
func _state_process_physics_jump():
|
func _state_process_physics_jump():
|
||||||
if desired_movement_vector.x != 0.0:
|
if desired_movement_vector.x != 0.0:
|
||||||
parent.transform.x.x = desired_movement_vector.x
|
parent.transform.x.x = desired_movement_vector.x
|
||||||
|
|
@ -172,10 +178,14 @@ func _state_process_physics_jump():
|
||||||
#idle_state.modifier = landing_modifier
|
#idle_state.modifier = landing_modifier
|
||||||
request_state_change.call_func('idle')
|
request_state_change.call_func('idle')
|
||||||
|
|
||||||
|
move_actor_as_desired()
|
||||||
|
|
||||||
func _state_process_physics_move():
|
func _state_process_physics_move():
|
||||||
# flip sprite in direction
|
# flip sprite in direction
|
||||||
if desired_movement_vector.x != 0.0:
|
flip_sprite_to_movement_direction()
|
||||||
parent.transform.x.x = desired_movement_vector.x
|
|
||||||
|
if desired_movement_vector.y == UP:
|
||||||
|
request_state_change.call_func('jump')
|
||||||
|
|
||||||
if desired_movement_vector.x == 0:
|
if desired_movement_vector.x == 0:
|
||||||
request_state_change.call_func('idle')
|
request_state_change.call_func('idle')
|
||||||
|
|
@ -183,6 +193,8 @@ func _state_process_physics_move():
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
request_state_change.call_func('fall')
|
request_state_change.call_func('fall')
|
||||||
|
|
||||||
|
move_actor_as_desired()
|
||||||
|
|
||||||
#func _on_state_entered_idle():
|
#func _on_state_entered_idle():
|
||||||
# print("Movement State Idle State Entered!")
|
# print("Movement State Idle State Entered!")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user