full state machine

This commit is contained in:
OddlyTimbot 2025-10-20 16:21:00 -04:00
parent b8cdde4763
commit edef8f7f8f
10 changed files with 379 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://y7gjdptxvjfu"
path="res://.godot/imported/Player Idle 48x48.png-b35e1ef309601cafc0161eed9f72d3a6.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/animations/player/idle/Player Idle 48x48.png"
dest_files=["res://.godot/imported/Player Idle 48x48.png-b35e1ef309601cafc0161eed9f72d3a6.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1021 B

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bpchnouakdsvk"
path="res://.godot/imported/player jump 48x48.png-49f79fd5510be01ac15a884acca16d43.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/animations/player/jump/player jump 48x48.png"
dest_files=["res://.godot/imported/player jump 48x48.png-49f79fd5510be01ac15a884acca16d43.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bqdop2arlx7rr"
path="res://.godot/imported/player run 48x48.png-d5efa0f3a9f0a70a93e094c3e7f118ec.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/animations/player/run/player run 48x48.png"
dest_files=["res://.godot/imported/player run 48x48.png-d5efa0f3a9f0a70a93e094c3e7f118ec.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bc8cpuacrbf0y"
path="res://.godot/imported/pixel_bullet.png-30d6d1e8b5e1332f8b2e2cee72a9e790.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/projectiles/pixel_bullet.png"
dest_files=["res://.godot/imported/pixel_bullet.png-30d6d1e8b5e1332f8b2e2cee72a9e790.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -1,9 +1,182 @@
[gd_scene load_steps=3 format=3 uid="uid://b1yy0sybg66hh"]
[gd_scene load_steps=28 format=3 uid="uid://b1yy0sybg66hh"]
[ext_resource type="Script" uid="uid://kv8w1gwuy3il" path="res://scripts/player.gd" id="1_3vyb7"]
[ext_resource type="Texture2D" uid="uid://bpchnouakdsvk" path="res://assets/graphics/animations/player/jump/player jump 48x48.png" id="2_dqkch"]
[ext_resource type="Texture2D" uid="uid://y7gjdptxvjfu" path="res://assets/graphics/animations/player/idle/Player Idle 48x48.png" id="2_g2els"]
[ext_resource type="Texture2D" uid="uid://bqdop2arlx7rr" path="res://assets/graphics/animations/player/run/player run 48x48.png" id="4_qlg0r"]
[sub_resource type="CircleShape2D" id="CircleShape2D_3vyb7"]
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
atlas = ExtResource("2_dqkch")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"]
atlas = ExtResource("2_g2els")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_dqkch"]
atlas = ExtResource("2_g2els")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
atlas = ExtResource("2_g2els")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
atlas = ExtResource("2_g2els")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
atlas = ExtResource("2_g2els")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
atlas = ExtResource("2_g2els")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
atlas = ExtResource("2_g2els")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
atlas = ExtResource("2_g2els")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
atlas = ExtResource("2_g2els")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_3v2ag"]
atlas = ExtResource("2_g2els")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"]
atlas = ExtResource("2_dqkch")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_oprun"]
atlas = ExtResource("2_dqkch")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
atlas = ExtResource("4_qlg0r")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qfm1y"]
atlas = ExtResource("4_qlg0r")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fulsm"]
atlas = ExtResource("4_qlg0r")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_4r5pv"]
atlas = ExtResource("4_qlg0r")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_60mlk"]
atlas = ExtResource("4_qlg0r")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"]
atlas = ExtResource("4_qlg0r")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a38lo"]
atlas = ExtResource("4_qlg0r")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_4ni07"]
atlas = ExtResource("4_qlg0r")
region = Rect2(336, 0, 48, 48)
[sub_resource type="SpriteFrames" id="SpriteFrames_jej6c"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_jej6c")
}],
"loop": false,
"name": &"fall",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_qhqgy")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_dqkch")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qlg0r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_tuyoq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fjrip")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_smehm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ur7pv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_y4r1p")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_d2wvv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_3v2ag")
}],
"loop": true,
"name": &"idle",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_f1ej7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_oprun")
}],
"loop": false,
"name": &"jump",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_a8ls1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qfm1y")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fulsm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4r5pv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_60mlk")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_i4ail")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_a38lo")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4ni07")
}],
"loop": true,
"name": &"run",
"speed": 12.0
}]
[node name="CharacterBody2D" type="CharacterBody2D"]
script = ExtResource("1_3vyb7")
@ -25,3 +198,12 @@ position = Vector2(-13, -8)
[node name="JumpBufferTimer" type="Timer" parent="."]
one_shot = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
position = Vector2(1, -6)
sprite_frames = SubResource("SpriteFrames_jej6c")
animation = &"fall"
autoplay = "idle"
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]

View File

@ -17,7 +17,9 @@ var pushEnabled:bool = false
@onready var right_spawn = $RightSpawn
@onready var left_spawn = $LeftSpawn
var upJump:bool = false
@onready var jump_buffer_timer: Timer = $JumpBufferTimer
@onready var player_graphic: AnimatedSprite2D = $AnimatedSprite2D
#For State Machine.............t.w.
enum State{IDLE, RUNNING, JUMP, FALLING}
@ -29,15 +31,38 @@ func _physics_process(delta):
handle_input()
handle_movement(delta)
update_states()
update_animation()
move_and_slide()
handle_collisions()
#Create a State Machine.........t.w.
func update_states()->void:
match current_state:
State.JUMP when velocity.y >0:
State.IDLE when velocity.x !=0:
current_state = State.RUNNING
State.RUNNING:
if velocity.x ==0:
current_state = State.IDLE
#jumping when reaching apex
State.JUMP when velocity.y > 0:
current_state = State.FALLING
State.FALLING when is_on_floor():
if velocity.x == 0:
current_state = State.IDLE
else:
current_state = State.RUNNING
func update_animation():
match current_state:
State.IDLE:
player_graphic.play("idle")
State.RUNNING:
player_graphic.play("run")
State.JUMP:
if upJump:
player_graphic.play("jump")
State.FALLING:
player_graphic.play("fall")
func handle_input()->void:
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
@ -46,8 +71,10 @@ func handle_input()->void:
direction = Input.get_axis("moveLeft", "moveRight")
if direction <0:
facing=FaceDirection.LEFT
player_graphic.flip_h = true
if direction >0:
facing=FaceDirection.RIGHT
player_graphic.flip_h = false
if Input.is_action_just_pressed("shove") && pushEnabled:
print("I want to shove")
@ -95,6 +122,7 @@ func handle_movement(_delta)->void:
velocity.y = JUMP_VELOCITY
#change state...........t.w.
current_state = State.JUMP
upJump = true
jump_buffer_timer.stop()
func handle_collisions()->void:
@ -119,3 +147,9 @@ func handle_collisions()->void:
if not right_cast.is_colliding() && not left_cast.is_colliding():
pushEnabled = false
func _on_animation_finished() -> void:
match current_state:
State.JUMP:
upJump=false