diff --git a/assets/graphics/animations/player/idle/Player Idle 48x48.png b/assets/graphics/animations/player/idle/Player Idle 48x48.png new file mode 100644 index 0000000..b618511 Binary files /dev/null and b/assets/graphics/animations/player/idle/Player Idle 48x48.png differ diff --git a/assets/graphics/animations/player/idle/Player Idle 48x48.png.import b/assets/graphics/animations/player/idle/Player Idle 48x48.png.import new file mode 100644 index 0000000..9e7fc55 --- /dev/null +++ b/assets/graphics/animations/player/idle/Player Idle 48x48.png.import @@ -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 diff --git a/assets/graphics/animations/player/jump/player jump 48x48.png b/assets/graphics/animations/player/jump/player jump 48x48.png new file mode 100644 index 0000000..dff105c Binary files /dev/null and b/assets/graphics/animations/player/jump/player jump 48x48.png differ diff --git a/assets/graphics/animations/player/jump/player jump 48x48.png.import b/assets/graphics/animations/player/jump/player jump 48x48.png.import new file mode 100644 index 0000000..3abce44 --- /dev/null +++ b/assets/graphics/animations/player/jump/player jump 48x48.png.import @@ -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 diff --git a/assets/graphics/animations/player/run/player run 48x48.png b/assets/graphics/animations/player/run/player run 48x48.png new file mode 100644 index 0000000..aca5b55 Binary files /dev/null and b/assets/graphics/animations/player/run/player run 48x48.png differ diff --git a/assets/graphics/animations/player/run/player run 48x48.png.import b/assets/graphics/animations/player/run/player run 48x48.png.import new file mode 100644 index 0000000..4b2a099 --- /dev/null +++ b/assets/graphics/animations/player/run/player run 48x48.png.import @@ -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 diff --git a/assets/graphics/projectiles/pixel_bullet.png b/assets/graphics/projectiles/pixel_bullet.png new file mode 100644 index 0000000..900d030 Binary files /dev/null and b/assets/graphics/projectiles/pixel_bullet.png differ diff --git a/assets/graphics/projectiles/pixel_bullet.png.import b/assets/graphics/projectiles/pixel_bullet.png.import new file mode 100644 index 0000000..f62cf5b --- /dev/null +++ b/assets/graphics/projectiles/pixel_bullet.png.import @@ -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 diff --git a/scenes/player.tscn b/scenes/player.tscn index eb858ed..65ae08a 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -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"] diff --git a/scripts/player.gd b/scripts/player.gd index 5f5b65c..aa94349 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -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