player state

This commit is contained in:
OddlyTimbot 2026-07-06 13:31:26 -04:00
parent 5fb367e082
commit 2e494502a8
8 changed files with 361 additions and 7 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://bhjnspvqa20rc"
path="res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/idle/Player Idle 48x48.png"
dest_files=["res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.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://c84o6tpt2h0s8"
path="res://.godot/imported/player jump 48x48.png-bb6ba8ccf76c9bd3765199af95f48c3c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/jump_fall/player jump 48x48.png"
dest_files=["res://.godot/imported/player jump 48x48.png-bb6ba8ccf76c9bd3765199af95f48c3c.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://jdvo0dp5qvnd"
path="res://.godot/imported/player run 48x48.png-3529730a2a1b5884902527ab512e774d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/running/player run 48x48.png"
dest_files=["res://.godot/imported/player run 48x48.png-3529730a2a1b5884902527ab512e774d.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 format=3 uid="uid://byl4bdrupii3k"]
[ext_resource type="Script" uid="uid://b1obldvd2etx7" path="res://scripts/player.gd" id="1_3vyb7"]
[ext_resource type="Texture2D" uid="uid://c84o6tpt2h0s8" path="res://assets/graphics/player/jump_fall/player jump 48x48.png" id="2_dqkch"]
[ext_resource type="Texture2D" uid="uid://bhjnspvqa20rc" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="3_qlg0r"]
[ext_resource type="Texture2D" uid="uid://jdvo0dp5qvnd" path="res://assets/graphics/player/running/player run 48x48.png" id="4_tuyoq"]
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
atlas = ExtResource("2_dqkch")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
atlas = ExtResource("3_qlg0r")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
atlas = ExtResource("3_qlg0r")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
atlas = ExtResource("3_qlg0r")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
atlas = ExtResource("3_qlg0r")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_3v2ag"]
atlas = ExtResource("3_qlg0r")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
atlas = ExtResource("3_qlg0r")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"]
atlas = ExtResource("3_qlg0r")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_oprun"]
atlas = ExtResource("3_qlg0r")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
atlas = ExtResource("3_qlg0r")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qfm1y"]
atlas = ExtResource("3_qlg0r")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fulsm"]
atlas = ExtResource("2_dqkch")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_4r5pv"]
atlas = ExtResource("2_dqkch")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_60mlk"]
atlas = ExtResource("4_tuyoq")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"]
atlas = ExtResource("4_tuyoq")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a38lo"]
atlas = ExtResource("4_tuyoq")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_4ni07"]
atlas = ExtResource("4_tuyoq")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_l71n6"]
atlas = ExtResource("4_tuyoq")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ke2ow"]
atlas = ExtResource("4_tuyoq")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ujl30"]
atlas = ExtResource("4_tuyoq")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_31cv2"]
atlas = ExtResource("4_tuyoq")
region = Rect2(336, 0, 48, 48)
[sub_resource type="SpriteFrames" id="SpriteFrames_pf23h"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fjrip")
}],
"loop": false,
"name": &"falling",
"speed": 12.0
}, {
"frames": [{
"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")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_jej6c")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f1ej7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_oprun")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_a8ls1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qfm1y")
}],
"loop": true,
"name": &"idle",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fulsm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4r5pv")
}],
"loop": false,
"name": &"jumping",
"speed": 12.0
}, {
"frames": [{
"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")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_l71n6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ke2ow")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ujl30")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_31cv2")
}],
"loop": true,
"name": &"running",
"speed": 12.0
}]
[node name="Player" type="CharacterBody2D" unique_id=2145223914]
scale = Vector2(1.4799998, 1.4799998)
script = ExtResource("1_3vyb7")
@ -24,3 +197,12 @@ position = Vector2(12.837839, -8.1081085)
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=374152113]
position = Vector2(-12.837839, -8.108109)
[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=1317034627]
texture_filter = 1
position = Vector2(0, -6.081082)
sprite_frames = SubResource("SpriteFrames_pf23h")
animation = &"falling"
autoplay = "idle"
[connection signal="animation_finished" from="PlayerGraphic" to="." method="_on_animation_finished"]

View File

@ -6,6 +6,7 @@ signal fireSignal(markerPosition, direction, speed)
@onready var left_cast: RayCast2D = $LeftCast
@onready var right_spawn: Marker2D = $RightSpawn
@onready var left_spawn: Marker2D = $LeftSpawn
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
var pushRightEnabled = false
var pushLeftEnabled = false
@ -17,15 +18,28 @@ const JUMP_VELOCITY = -400.0
enum FaceDirection {RIGHT,LEFT}
var facing:FaceDirection = FaceDirection.RIGHT
#State Handling
enum PlayerState {IDLE, RUNNING, JUMPING, FALLING}
var current_player_state:PlayerState = PlayerState.IDLE
var upJump:bool = false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
handle_input()
handle_movement(delta)
#States and Animation
handle_update_states()
handle_update_animation()
move_and_slide()
handle_collisions()
func handle_input()->void:
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
current_player_state = PlayerState.JUMPING
upJump = true
# Handle shove.
if Input.is_action_just_pressed("shove"):
print("I want to shove")
@ -47,7 +61,7 @@ func _physics_process(delta: float) -> void:
FaceDirection.RIGHT:
shootSignal.emit(right_spawn.global_transform, 800)
FaceDirection.LEFT:
shootSignal.emit(left_spawn.global_transform, 800)
shootSignal.emit(left_spawn.global_transform, -800)
#Handle fire rocket
if Input.is_action_just_pressed("fire"):
print("Ima fire rocket")
@ -63,12 +77,17 @@ func _physics_process(delta: float) -> void:
velocity.x = direction * SPEED
if direction >0:
facing = FaceDirection.RIGHT
player_graphic.flip_h = false
else:
facing = FaceDirection.LEFT
player_graphic.flip_h = true
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
func handle_movement(delta)->void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
func handle_collisions()->void:
if right_cast.is_colliding():
print("Right raycast collision")
var collider = right_cast.get_collider()
@ -94,3 +113,36 @@ func _physics_process(delta: float) -> void:
if c.get_collider() is RigidBody2D:
#c.get_collider().apply_central_impulse(-c.get_normal() * 100)
pushSignal.emit(c.get_collider(), -c.get_normal() * 100)
#New functions for state handling
func handle_update_states()->void:
match current_player_state:
PlayerState.IDLE when velocity.x !=0:
current_player_state = PlayerState.RUNNING
PlayerState.RUNNING when velocity.x == 0:
current_player_state = PlayerState.IDLE
PlayerState.JUMPING when velocity.y>0:
current_player_state = PlayerState.FALLING
PlayerState.FALLING when is_on_floor():
if velocity.x == 0:
current_player_state = PlayerState.IDLE
else:
current_player_state = PlayerState.RUNNING
func handle_update_animation()->void:
match current_player_state:
PlayerState.IDLE:
player_graphic.play("idle")
PlayerState.RUNNING:
player_graphic.play("running")
PlayerState.JUMPING:
if upJump:
player_graphic.play("jumping")
PlayerState.FALLING:
player_graphic.play("falling")
func _on_animation_finished() -> void:
match current_player_state:
PlayerState.JUMPING:
upJump = false