From 579397cd8be287a7c3f678ec1f3d018c07352046 Mon Sep 17 00:00:00 2001 From: Jdevadas Date: Mon, 11 May 2026 18:57:56 -0400 Subject: [PATCH] added jump animation --- .../player/jump/player jump 48x48.png | Bin 0 -> 1021 bytes .../player/jump/player jump 48x48.png.import | 40 +++++++++++++++++ scenes/player.tscn | 42 +++++++++++++++++- scripts/player.gd | 30 +++++++++++-- 4 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 assets/graphics/player/jump/player jump 48x48.png create mode 100644 assets/graphics/player/jump/player jump 48x48.png.import diff --git a/assets/graphics/player/jump/player jump 48x48.png b/assets/graphics/player/jump/player jump 48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..dff105cfac881171ef96781bd9bbd40e413dd6a7 GIT binary patch literal 1021 zcmVmEQ7U} zLs5iSL^ysQndjn_Z_)cK!3y?8`13c+Y_To1lzKf`rD(zM^$i(L=C%6^9Hexzmp9TP7J z3x2D_5a!4t4@Lw;++IjPL?TE)*M!XouFOAKKtr?u-6Zv(YkUXdi)sf zak0Mh>nO11+UfNJza4o$n<0Rk1Z07%>MV|KH|Cnd*}PH={w!JoU_k}q;T@2{2S2OR zD+a#QyBe@rHR$i1USRL^qA`5(r#B^2wb1c{XQEaxHcV>?NY(}bx#42)8SNHPEAhx+ zwgbTUmm?2ozQJTIB3(a3CTazbJxT1)Zea|u@~8|2{NOX;WZ4432(zCtQ7d>^3MYza z`pO61;cUJh#UB&2?YppT6D78R|4^6h|6#?IDsW4&75XzcI( zI|u+6TJ`se!ZF#4lOpqh+0S5p*beUt&(-{yaUWs}2=GNDGqzgZXbL{yCx91`EdrAH za5aCX+;6jxRN?`E{`@|6r*cN^Po;%Do_#4@uM~^*CnFzWVt7lNu6Os9ze}qfq(y&z zAN~3LRNk#6AiixSnJ2yu4LOwnk>Ay7)+Q(!7+wzKMJ61R2SEE47DYJB3DHoS125zG z=NfjWa)C7$d|>gvJRb?fU-ZQUv9Iw_V7=DGio;H>%!gN%iq-8`MjGM)49-BT&x$2f zCLY@o5T)$9hFE?0!P#ULO;mw=BX5G;-Lu&+QdMkLz^zYNPI6;W(H&45@yQ*hzGvh%)2y re59^(3$vL{@`WG>f*=TjXb=AZ>!Ac3Jx|zZ00000NkvXXu0mjfKxWs7 literal 0 HcmV?d00001 diff --git a/assets/graphics/player/jump/player jump 48x48.png.import b/assets/graphics/player/jump/player jump 48x48.png.import new file mode 100644 index 0000000..420bd32 --- /dev/null +++ b/assets/graphics/player/jump/player jump 48x48.png.import @@ -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 diff --git a/scenes/player.tscn b/scenes/player.tscn index 2643e2e..940845a 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -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"] diff --git a/scripts/player.gd b/scripts/player.gd index 614007e..d4e4f8a 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -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