added jump animation

This commit is contained in:
Jdevadas 2026-05-11 18:57:56 -04:00
parent a245ebc135
commit 579397cd8b
4 changed files with 106 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1021 B

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d2e455oxjbsf5"
path="res://.godot/imported/player jump 48x48.png-1ccba0c36041038682bf917e1f6cf991.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/jump/player jump 48x48.png"
dest_files=["res://.godot/imported/player jump 48x48.png-1ccba0c36041038682bf917e1f6cf991.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,11 +1,20 @@
[gd_scene format=3 uid="uid://bhsvqyhsemekq"]
[ext_resource type="Script" uid="uid://dlmf1p0vfitcx" path="res://scripts/player.gd" id="1_3vyb7"]
[ext_resource type="Texture2D" uid="uid://d2e455oxjbsf5" path="res://assets/graphics/player/jump/player jump 48x48.png" id="2_dqkch"]
[ext_resource type="Texture2D" uid="uid://dio2ufnpnihce" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"]
[ext_resource type="Texture2D" uid="uid://bl7p2n2kgw2qx" path="res://assets/graphics/player/idle/player run 48x48.png" id="3_qhqgy"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_elsnr"]
[sub_resource type="AtlasTexture" id="AtlasTexture_4ni07"]
atlas = ExtResource("2_dqkch")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"]
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)
@ -46,6 +55,10 @@ region = Rect2(384, 0, 48, 48)
atlas = ExtResource("2_g2els")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a38lo"]
atlas = ExtResource("2_dqkch")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
atlas = ExtResource("3_qhqgy")
region = Rect2(0, 0, 48, 48)
@ -82,6 +95,22 @@ region = Rect2(336, 0, 48, 48)
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_4ni07")
}],
"loop": false,
"name": &"apex",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_i4ail")
}],
"loop": false,
"name": &"fall",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_qhqgy")
}, {
"duration": 1.0,
@ -117,6 +146,14 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_a38lo")
}],
"loop": false,
"name": &"jump",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_jej6c")
}, {
"duration": 1.0,
@ -169,6 +206,7 @@ position = Vector2(-10, -12)
texture_filter = 1
position = Vector2(0, -1)
sprite_frames = SubResource("SpriteFrames_jej6c")
animation = &"run"
animation = &"apex"
autoplay = "idle"
frame_progress = 0.8670586
[connection signal="animation_finished" from="graphic" to="." method="_on_graphic_animation_finished"]

View File

@ -12,8 +12,9 @@ var direction : float = 0
enum FaceDirection { LEFT, RIGHT }
var facing: FaceDirection = FaceDirection.LEFT
var shove_target: RigidBody2D
enum State { IDLE, RUNNING }
enum State { IDLE, RUN, JUMP, APEX, FALL }
var state: State = State.IDLE
var up_jump:bool = false
func _physics_process(delta: float):
handle_input()
@ -73,13 +74,34 @@ func handle_collisions():
func handle_state():
match state:
State.IDLE when velocity.x != 0:
state = State.RUNNING
State.RUNNING when velocity.x == 0:
state = State.RUN
State.RUN when velocity.x == 0:
state = State.IDLE
State.RUN when velocity.y < 0:
state = State.JUMP
State.IDLE when velocity.y < 0:
state = State.JUMP
State.JUMP when velocity.y > 0:
state = State.APEX
# from APEX to FALL is handled when apex animation finishes
State.FALL when velocity.y == 0:
state = State.IDLE
func handle_animation():
match state:
State.IDLE:
graphic.play("idle")
State.RUNNING:
State.RUN:
graphic.play("run")
State.JUMP:
graphic.play("jump")
State.APEX:
graphic.play("apex")
State.FALL:
graphic.play("fall")
func _on_graphic_animation_finished() -> void:
# switch state from apex to fall
match state:
State.APEX:
state = State.FALL