Movement animation

This commit is contained in:
2024-10-25 18:07:30 +02:00
parent 5dc5c305e3
commit ce82a8b5f7
5 changed files with 179 additions and 7 deletions

View File

@ -15,6 +15,28 @@ run/main_scene="res://scenes/game.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"
[input]
jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
]
}
[rendering]
textures/canvas_textures/default_texture_filter=0

View File

@ -7,7 +7,7 @@ collision_mask = 2
script = ExtResource("1_dutdq")
[node name="Timer" type="Timer" parent="."]
wait_time = 0.254
wait_time = 0.6
one_shot = true
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://cxdkngh6fo5p7"]
[gd_scene load_steps=26 format=3 uid="uid://cxdkngh6fo5p7"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_btp1f"]
[ext_resource type="Texture2D" uid="uid://bebck3y4sy2c8" path="res://assets/sprites/knight.png" id="1_uiil0"]
@ -19,6 +19,74 @@ region = Rect2(64, 0, 32, 32)
atlas = ExtResource("1_uiil0")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_npshh"]
atlas = ExtResource("1_uiil0")
region = Rect2(64, 160, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_qgwdj"]
atlas = ExtResource("1_uiil0")
region = Rect2(0, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_wv0rq"]
atlas = ExtResource("1_uiil0")
region = Rect2(32, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_kqrkm"]
atlas = ExtResource("1_uiil0")
region = Rect2(64, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_2j53a"]
atlas = ExtResource("1_uiil0")
region = Rect2(96, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_58bgj"]
atlas = ExtResource("1_uiil0")
region = Rect2(128, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_npl2r"]
atlas = ExtResource("1_uiil0")
region = Rect2(160, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_iiw8n"]
atlas = ExtResource("1_uiil0")
region = Rect2(192, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_on6th"]
atlas = ExtResource("1_uiil0")
region = Rect2(224, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_844j4"]
atlas = ExtResource("1_uiil0")
region = Rect2(0, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_4nq6e"]
atlas = ExtResource("1_uiil0")
region = Rect2(32, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_k3ce1"]
atlas = ExtResource("1_uiil0")
region = Rect2(64, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_1bpnc"]
atlas = ExtResource("1_uiil0")
region = Rect2(96, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_l0cuk"]
atlas = ExtResource("1_uiil0")
region = Rect2(128, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_f78wu"]
atlas = ExtResource("1_uiil0")
region = Rect2(160, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_2tnwu"]
atlas = ExtResource("1_uiil0")
region = Rect2(192, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_1kmnq"]
atlas = ExtResource("1_uiil0")
region = Rect2(224, 96, 32, 32)
[sub_resource type="SpriteFrames" id="SpriteFrames_j6wpo"]
animations = [{
"frames": [{
@ -37,6 +105,67 @@ animations = [{
"loop": true,
"name": &"idle",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_npshh")
}],
"loop": true,
"name": &"jump",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_qgwdj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_wv0rq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_kqrkm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_2j53a")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_58bgj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_npl2r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_iiw8n")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_on6th")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_844j4")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4nq6e")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_k3ce1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1bpnc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_l0cuk")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f78wu")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_2tnwu")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1kmnq")
}],
"loop": true,
"name": &"run",
"speed": 10.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_lh46r"]
@ -49,9 +178,8 @@ script = ExtResource("1_btp1f")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -12)
sprite_frames = SubResource("SpriteFrames_j6wpo")
animation = &"idle"
animation = &"jump"
autoplay = "idle"
frame_progress = 0.414056
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -6)

View File

@ -3,9 +3,11 @@ extends Area2D
@onready var timer: Timer = $Timer
func _on_body_entered(body: Node2D) -> void:
print("YouveDied!")
Engine.time_scale = 0.5
body.get_node("CollisionShape2D").queue_free()
timer.start()
func _on_timer_timeout() -> void:
Engine.time_scale = 1
get_tree().reload_current_scene()

View File

@ -5,18 +5,38 @@ const SPEED = 130.0
const JUMP_VELOCITY = -300.0
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if (Input.is_action_just_pressed("ui_accept") or Input.is_action_just_pressed("ui_up")) and is_on_floor():
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
var direction := Input.get_axis("move_left", "move_right")
#flip the character faceing
if direction > 0:
animated_sprite_2d.flip_h = false
elif direction < 0:
animated_sprite_2d.flip_h = true
#play animation
if is_on_floor():
if direction == 0:
animated_sprite_2d.play("idle")
else:
animated_sprite_2d.play("run")
else:
animated_sprite_2d.play("jump")
#apply movement
if direction:
velocity.x = direction * SPEED
else: