update player animations and set physics fps to 144

This commit is contained in:
2025-10-21 12:37:38 +01:00
parent add900d0f5
commit 1fdb4ff578
4 changed files with 176 additions and 6 deletions

View File

@@ -19,6 +19,30 @@ config/icon="res://icon.svg"
NodeTypes="*res://scripts/NodeTypes.gd" NodeTypes="*res://scripts/NodeTypes.gd"
[input]
jump={
"deadzone": 0.2,
"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)
]
}
move_left={
"deadzone": 0.2,
"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.2,
"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)
]
}
[physics]
common/physics_ticks_per_second=144
[rendering] [rendering]
textures/canvas_textures/default_texture_filter=0 textures/canvas_textures/default_texture_filter=0

View File

@@ -423,4 +423,4 @@ libraries = {
autoplay = "move" autoplay = "move"
[node name="Slime" parent="." instance=ExtResource("6_p57ef")] [node name="Slime" parent="." instance=ExtResource("6_p57ef")]
position = Vector2(569, 96) position = Vector2(569, 97)

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://3wumh6kpw3ai"] [gd_scene load_steps=26 format=3 uid="uid://3wumh6kpw3ai"]
[ext_resource type="Texture2D" uid="uid://pc081i405fo4" path="res://assets/sprites/knight.png" id="1_3vyb7"] [ext_resource type="Texture2D" uid="uid://pc081i405fo4" path="res://assets/sprites/knight.png" id="1_3vyb7"]
[ext_resource type="Script" uid="uid://dkpsredq14h2l" path="res://scripts/player.gd" id="1_g2els"] [ext_resource type="Script" uid="uid://dkpsredq14h2l" path="res://scripts/player.gd" id="1_g2els"]
@@ -19,6 +19,74 @@ region = Rect2(64, 0, 32, 32)
atlas = ExtResource("1_3vyb7") atlas = ExtResource("1_3vyb7")
region = Rect2(96, 0, 32, 32) region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
atlas = ExtResource("1_3vyb7")
region = Rect2(64, 160, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
atlas = ExtResource("1_3vyb7")
region = Rect2(0, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
atlas = ExtResource("1_3vyb7")
region = Rect2(32, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
atlas = ExtResource("1_3vyb7")
region = Rect2(64, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
atlas = ExtResource("1_3vyb7")
region = Rect2(96, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
atlas = ExtResource("1_3vyb7")
region = Rect2(128, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_3v2ag"]
atlas = ExtResource("1_3vyb7")
region = Rect2(160, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
atlas = ExtResource("1_3vyb7")
region = Rect2(192, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"]
atlas = ExtResource("1_3vyb7")
region = Rect2(224, 64, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_oprun"]
atlas = ExtResource("1_3vyb7")
region = Rect2(0, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
atlas = ExtResource("1_3vyb7")
region = Rect2(32, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_qfm1y"]
atlas = ExtResource("1_3vyb7")
region = Rect2(64, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_fulsm"]
atlas = ExtResource("1_3vyb7")
region = Rect2(96, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_4r5pv"]
atlas = ExtResource("1_3vyb7")
region = Rect2(128, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_60mlk"]
atlas = ExtResource("1_3vyb7")
region = Rect2(160, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"]
atlas = ExtResource("1_3vyb7")
region = Rect2(192, 96, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_a38lo"]
atlas = ExtResource("1_3vyb7")
region = Rect2(224, 96, 32, 32)
[sub_resource type="SpriteFrames" id="SpriteFrames_tuyoq"] [sub_resource type="SpriteFrames" id="SpriteFrames_tuyoq"]
animations = [{ animations = [{
"frames": [{ "frames": [{
@@ -37,6 +105,67 @@ animations = [{
"loop": true, "loop": true,
"name": &"idle", "name": &"idle",
"speed": 7.0 "speed": 7.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_tuyoq")
}],
"loop": true,
"name": &"jump",
"speed": 5.0
}, {
"frames": [{
"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")
}, {
"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")
}, {
"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")
}],
"loop": true,
"name": &"run",
"speed": 10.0
}] }]
[sub_resource type="CircleShape2D" id="CircleShape2D_fjrip"] [sub_resource type="CircleShape2D" id="CircleShape2D_fjrip"]
@@ -52,9 +181,8 @@ jump_velocity = -300.0
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -12) position = Vector2(0, -12)
sprite_frames = SubResource("SpriteFrames_tuyoq") sprite_frames = SubResource("SpriteFrames_tuyoq")
animation = &"idle" animation = &"jump"
autoplay = "idle" autoplay = "idle"
frame_progress = 0.33528003
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -5) position = Vector2(0, -5)

View File

@@ -4,6 +4,7 @@ extends CharacterBody2D
@export var speed = 300.0 @export var speed = 300.0
@export var jump_velocity = -400.0 @export var jump_velocity = -400.0
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
# Add the gravity. # Add the gravity.
@@ -11,15 +12,32 @@ func _physics_process(delta: float) -> void:
velocity += get_gravity() * delta velocity += get_gravity() * delta
# Handle jump. # Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor(): if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocity velocity.y = jump_velocity
# Get the input direction and handle the movement/deceleration. # Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions. # 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")
if direction > 0:
animated_sprite.flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
set_animation(direction)
if direction: if direction:
velocity.x = direction * speed velocity.x = direction * speed
else: else:
velocity.x = move_toward(velocity.x, 0, speed) velocity.x = move_toward(velocity.x, 0, speed)
move_and_slide() move_and_slide()
func set_animation(direction: float):
if is_on_floor():
if direction == 0:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")