Compare commits

...

4 Commits

Author SHA1 Message Date
522e409dab Running. 2025-03-17 21:41:29 -07:00
702782def7 Falling. 2025-03-17 21:11:09 -07:00
1b7715746e Almost made fall happen. 2025-03-17 20:45:48 -07:00
27de78f02a Switch player input processing routines from event based to polling based in process_physics 2025-03-17 20:19:44 -07:00
8 changed files with 132 additions and 33 deletions

View File

@ -49,6 +49,10 @@ func _unhandled_input(event: InputEvent) -> void:
#movement_state_machine.process_input(event)
func _physics_process(delta: float) -> void:
# Input based or polling input is not done in _unhandled_input
# gives us the ability to turn off polling this way
if actor_type == "Player":
movement_component.process_physics_input(delta)
movement_component.process_physics(delta)
#movement_state_machine.process_physics(delta)
#

View File

@ -9,7 +9,7 @@ export var callable_state_machine :NodePath
onready var current_state = StateAnimatedActor.new()
var animation_finished: bool = false
#var animation_finished: bool = false
var request_state_change: FuncRef
# this just wouldn't work well. Maybe I can try a resource
@ -42,13 +42,16 @@ func _ready():
# Sprites should only have a process function
# but if I have this will the sprite still animate?
func _process(delta):
if current_state.state_timeout != null:
if current_state.state_timeout.time_left == 0:
print("You're out of time! I saw it!")
request_state_change.call_func('idle')
#play()
else:
print("what, no current_state?")
# Shouldn't need this anymore!
# if current_state.state_timeout != null:
# if current_state.state_timeout.time_left == 0:
# print("You're out of time! I saw it!")
# request_state_change.call_func('idle')
# #play()
# else:
# print("what, no current_state?")
# Not sure what should be called first here.
if has_method('_state_process_' + current_state.name):
call('_state_process_' + current_state.name)
process_animations()

View File

@ -53,10 +53,17 @@ func process_physics(delta):
if has_method('_state_process_physics_' + current_state.name):
call('_state_process_physics_' + current_state.name)
# Shouldn't need a proces function
#func process(delta):
# pass
# more likely needed for Players
func process_physics_input(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):
if has_method('_state_process_' + current_state.name):
call('_state_process_' + current_state.name)
# For event based input polling (Hadouken?)
func process_input(event: InputEvent):
if has_method('_state_process_input_' + current_state.name):
call('_state_process_input_' + current_state.name)

View File

@ -28,6 +28,8 @@ var jerk: float
var physics_modifier :StateModifier
var animation_finished: bool = false
# Not sure if this should be here. probably not
export(Array, String) var animation_sequence
@ -42,9 +44,10 @@ var modifier: StateModifier
func enter() -> void:
# Call parent class enter
.enter()
animation_finished = false
jerk = 0
return

View File

@ -2,8 +2,12 @@ extends AnimatedSprite_StateReceiver
func _ready():
# Lets see if this nutty thing works
var state_ref :State = get_node(callable_state_machine).get_state_reference('idle')
state_ref.connect("state_entered", self, "_on_state_entered_idle")
var state_ref :State
# state_ref = get_node(callable_state_machine).get_state_reference('idle')
# state_ref.connect("state_entered", self, "_on_state_entered_idle")
state_ref = get_node(callable_state_machine).get_state_reference('fall')
state_ref.connect("state_entered", self, "_on_state_entered_fall")
# It works but node order really mattered.
# State machine needed to be processed first probably for ready function.
# good to know!
@ -12,5 +16,13 @@ func _ready():
#func _state_process_idle():
# print("I got called!")
func _on_state_entered_idle():
print("Anim Knows Idle State Entered!")
#func _state_process_fall():
# print("I got called!")
#func _on_state_entered_idle():
# print("Anim Knows Idle State Entered!")
func _on_state_entered_fall():
print("Anim Knows Fall State Entered!")
frame = 2
stop()

View File

@ -1,22 +1,59 @@
extends Movement_StateReceiver
func _ready():
#func _ready():
# Lets see if this nutty thing works
var state_ref :State = get_node(callable_state_machine).get_state_reference('idle')
state_ref.connect("state_entered", self, "_on_state_entered_idle")
# var state_ref :State = get_node(callable_state_machine).get_state_reference('idle')
# state_ref.connect("state_entered", self, "_on_state_entered_idle")
# It works but node order really mattered.
# State machine needed to be processed first probably for ready function.
# good to know!
var fire_a_note:bool = false
# I don't need this right now but I proved it can be done!
var player_number: int = 1
func get_movement_direction() -> float:
#return Input.get_axis('move_left', 'move_right')
desired_movement_vector.x = Input.get_axis("move_left_" + str(player_number), "move_right_" + str(player_number))
return Input.get_axis("move_left_" + str(player_number), "move_right_" + str(player_number))
#TODO: This is probably not a good way to do this.
# we want to check input once and make decisions based on
# velocity and desired movement.
func _state_process_physics_input_idle():
get_movement_direction()
func _state_process_physics_input_move():
get_movement_direction()
func _state_process_physics_idle():
if fire_a_note == true:
print("I got called! (MC)")
fire_a_note = false
#TODO: May need that 'bump' logic to make velocity work.
if desired_movement_vector.x != 0: # and velocity.x != 0:
request_state_change.call_func('move')
func _on_state_entered_idle():
print("Movement State Idle State Entered!")
fire_a_note = true
if !parent.is_on_floor():
#return fall_state
request_state_change.call_func('fall')
func _state_process_physics_fall():
if get_movement_direction() != 0.0:
parent.transform.x.x = get_movement_direction()
if parent.is_on_floor():
#modifier.reference()
#idle_state.modifier = landing_modifier
request_state_change.call_func('idle')
func _state_process_physics_move():
# flip sprite in direction
if get_movement_direction() != 0.0:
parent.transform.x.x = get_movement_direction()
if desired_movement_vector.x == 0:
request_state_change.call_func('idle')
if !parent.is_on_floor():
request_state_change.call_func('fall')
#func _on_state_entered_idle():
# print("Movement State Idle State Entered!")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
@ -6,6 +6,38 @@
[ext_resource path="res://src/actors/players/playerE/states/idle.tres" type="Resource" id=4]
[ext_resource path="res://src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd" type="Script" id=5]
[ext_resource path="res://src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd" type="Script" id=6]
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=7]
[sub_resource type="Resource" id=2]
resource_local_to_scene = true
resource_name = "fall"
script = ExtResource( 7 )
debug_state = false
timeout_seconds = 0.0
name = "fall"
move_speed = 90.0
move_acceleration = 0.0
move_speed_modifier = 0.0
move_modifier_move_acceleration = 0.0
jerk_factor = 0.0
animation_sequence = [ "jump" ]
emitter_frame_subscriptions = {
}
[sub_resource type="Resource" id=3]
resource_name = "move"
script = ExtResource( 7 )
debug_state = false
timeout_seconds = 0.0
name = "move"
move_speed = 90.0
move_acceleration = 0.0
move_speed_modifier = 0.0
move_modifier_move_acceleration = 0.0
jerk_factor = 0.0
animation_sequence = [ "run" ]
emitter_frame_subscriptions = {
}
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 7, 14 )
@ -16,7 +48,7 @@ actor_type = "Player"
[node name="Movement_StateMachine" parent="." index="0"]
starting_state_name = "idle"
states = [ ExtResource( 4 ) ]
states = [ ExtResource( 4 ), SubResource( 2 ), SubResource( 3 ) ]
[node name="AnimatedSprite_StateReceiver" parent="." index="1"]
frames = ExtResource( 2 )

View File

@ -3,12 +3,13 @@
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
resource_name = "idle"
script = ExtResource( 1 )
debug_state = false
timeout_seconds = 2.0
timeout_seconds = 0.0
name = "idle"
move_speed = 60.0
move_speed = 1.36422e-12
move_acceleration = 0.0
move_speed_modifier = 0.0
move_modifier_move_acceleration = 0.0