Almost jumping.

This commit is contained in:
Dustin 2025-03-18 14:55:42 -07:00
parent 522e409dab
commit d9d5860d63
4 changed files with 91 additions and 22 deletions

View File

@ -1,6 +1,13 @@
extends Movement_StateReceiver
#func _ready():
func _ready():
var state_ref :State
var state_name :String
state_name = 'jump'
state_ref = get_node(callable_state_machine).get_state_reference(state_name)
#TODO Should probably assert here or something.
state_ref.connect("state_entered", self, "_on_state_entered_" + state_name)
# 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")
@ -15,16 +22,38 @@ func get_movement_direction() -> float:
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))
func wants_jump() -> bool:
if Input.is_action_just_pressed("jump_" + str(player_number)):
desired_movement_vector.y = 1
return true
else:
return false
#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_idle():
# get_movement_direction()
#
#func _state_process_physics_input_move():
# get_movement_direction()
func _state_process_physics_input_move():
# Probably better to do it this way then allocating individual
# state functions that all do the same thing.
func process_physics_input(delta):
# call the parent, Which would call the individuals
.process_physics_input(delta)
# then process movement controls
get_movement_direction()
wants_jump()
func _state_process_physics_idle():
if desired_movement_vector.y == 1:
request_state_change.call_func('jump')
#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')
@ -42,6 +71,17 @@ func _state_process_physics_fall():
#idle_state.modifier = landing_modifier
request_state_change.call_func('idle')
func _state_process_physics_jump():
if get_movement_direction() != 0.0:
parent.transform.x.x = get_movement_direction()
if velocity.y > 0:
request_state_change.call_func('fall')
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:
@ -56,4 +96,9 @@ func _state_process_physics_move():
#func _on_state_entered_idle():
# print("Movement State Idle State Entered!")
func _on_state_entered_jump():
#TODO: Make this a state variable
# I used to call it 'jump_force' like an idiot.
velocity.y = -200

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=12 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]
@ -7,22 +7,8 @@
[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 = {
}
[ext_resource path="res://src/actors/players/playerE/states/jump.tres" type="Resource" id=8]
[ext_resource path="res://src/actors/players/playerE/states/fall.tres" type="Resource" id=9]
[sub_resource type="Resource" id=3]
resource_name = "move"
@ -48,7 +34,7 @@ actor_type = "Player"
[node name="Movement_StateMachine" parent="." index="0"]
starting_state_name = "idle"
states = [ ExtResource( 4 ), SubResource( 2 ), SubResource( 3 ) ]
states = [ ExtResource( 4 ), ExtResource( 9 ), SubResource( 3 ), ExtResource( 8 ) ]
[node name="AnimatedSprite_StateReceiver" parent="." index="1"]
frames = ExtResource( 2 )

View File

@ -0,0 +1,19 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
resource_name = "fall"
script = ExtResource( 1 )
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 = {
}

View File

@ -0,0 +1,19 @@
[gd_resource type="Resource" load_steps=2 format=2]
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=1]
[resource]
resource_local_to_scene = true
resource_name = "jump"
script = ExtResource( 1 )
debug_state = false
timeout_seconds = 0.0
name = "jump"
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 = {
}