Initial movement added

This commit is contained in:
2025-02-17 08:09:14 -05:00
parent 8332b30d4f
commit 94795e4c77
4 changed files with 288 additions and 33 deletions

View File

@ -1,33 +1,46 @@
extends CharacterBody2D
@export var max_speed: float = 200.0
@export var acceleration: float = 50.0
@export var jump_force: float = -300.0
@export var base_weight: float = 1
@export var min_weight: float = 0.5
@export var max_weight: float = 2.0
@export var speed: float = 200.0
@export var jump_velocity: float = -150.0
@export var double_jump_velocity: float = -150.0
var has_double_jumped: bool = false
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
var animation_locked: bool = false
var direction: Vector2 = Vector2.ZERO
var was_in_air: bool = false
var current_speed: float = 0.0
var current_weight: float = base_weight
var is_jumping: bool = false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
has_double_jumped = false
# Handle jump.
if Input.is_action_just_pressed("jump"):
if is_on_floor():
velocity.y = jump_velocity
elif not has_double_jumped:
velocity.y = double_jump_velocity;
has_double_jumped = true
func update_animation():
if not animation_locked:
if direction.x != 0:
animated_sprite.play("run")
else:
animated_sprite.play("idle")
func update_facing_direction():
if direction.x > 0:
animated_sprite.flip_h = false
elif direction.x < 0:
animated_sprite.flip_h = true
# 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("left", "right")
if direction:
velocity.x = direction * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
func jump():
velocity.y = jump_force
animated_sprite.play("jump_start")
animation_locked = true
move_and_slide()
func land():
animated_sprite.play("jump_end")
animation_locked = true
func _on_animated_sprite_2d_animation_finished() -> void:
if animated_sprite.animation == "jump_end":
animation_locked = false

View File

@ -1,7 +1,223 @@
[gd_scene load_steps=4 format=3 uid="uid://4qv7ygwuks70"]
[gd_scene load_steps=36 format=3 uid="uid://4qv7ygwuks70"]
[ext_resource type="Texture2D" uid="uid://ce5lrej8gpo3i" path="res://Art/Character/Idle/Idle-Sheet.png" id="1_caaw0"]
[ext_resource type="Script" path="res://Characters/player.gd" id="1_mhe8q"]
[ext_resource type="Texture2D" uid="uid://v0gldv0dn60i" path="res://Art/Character/Jumlp-All/Jump-All-Sheet.png" id="3_ev3y7"]
[ext_resource type="Texture2D" uid="uid://nsp2svj4hkeq" path="res://Art/Character/Jump-End/Jump-End-Sheet.png" id="4_g152q"]
[ext_resource type="Texture2D" uid="uid://u60b2nhdqhns" path="res://Art/Character/Jump-Start/Jump-Start-Sheet.png" id="5_ui06i"]
[ext_resource type="Texture2D" uid="uid://b0tk3jppsqjcl" path="res://Art/Character/Run/Run-Sheet.png" id="6_e0ril"]
[sub_resource type="AtlasTexture" id="AtlasTexture_btfh1"]
atlas = ExtResource("1_caaw0")
region = Rect2(0, 0, 64, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_rpfl6"]
atlas = ExtResource("1_caaw0")
region = Rect2(64, 0, 64, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_lk0kr"]
atlas = ExtResource("1_caaw0")
region = Rect2(128, 0, 64, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_416rt"]
atlas = ExtResource("1_caaw0")
region = Rect2(192, 0, 64, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_7pp1r"]
atlas = ExtResource("4_g152q")
region = Rect2(0, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_sv0rn"]
atlas = ExtResource("4_g152q")
region = Rect2(64, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_naty2"]
atlas = ExtResource("4_g152q")
region = Rect2(128, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_rtj8h"]
atlas = ExtResource("5_ui06i")
region = Rect2(0, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_goiod"]
atlas = ExtResource("5_ui06i")
region = Rect2(64, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_u4two"]
atlas = ExtResource("5_ui06i")
region = Rect2(128, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_nd2k7"]
atlas = ExtResource("5_ui06i")
region = Rect2(192, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_hsc5u"]
atlas = ExtResource("3_ev3y7")
region = Rect2(256, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_1ufd4"]
atlas = ExtResource("3_ev3y7")
region = Rect2(320, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_0fchy"]
atlas = ExtResource("3_ev3y7")
region = Rect2(384, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_of2e2"]
atlas = ExtResource("3_ev3y7")
region = Rect2(448, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_6ar74"]
atlas = ExtResource("3_ev3y7")
region = Rect2(512, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_3fr5v"]
atlas = ExtResource("3_ev3y7")
region = Rect2(576, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_dh3qg"]
atlas = ExtResource("3_ev3y7")
region = Rect2(640, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_lctin"]
atlas = ExtResource("3_ev3y7")
region = Rect2(704, 0, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_a83ak"]
atlas = ExtResource("6_e0ril")
region = Rect2(0, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_0rhp5"]
atlas = ExtResource("6_e0ril")
region = Rect2(80, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_xs4ja"]
atlas = ExtResource("6_e0ril")
region = Rect2(160, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_im2g8"]
atlas = ExtResource("6_e0ril")
region = Rect2(240, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_if710"]
atlas = ExtResource("6_e0ril")
region = Rect2(320, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_f5phe"]
atlas = ExtResource("6_e0ril")
region = Rect2(400, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_rgyyg"]
atlas = ExtResource("6_e0ril")
region = Rect2(480, 0, 80, 80)
[sub_resource type="AtlasTexture" id="AtlasTexture_jn4q8"]
atlas = ExtResource("6_e0ril")
region = Rect2(560, 0, 80, 80)
[sub_resource type="SpriteFrames" id="SpriteFrames_k0v45"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_btfh1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_rpfl6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_lk0kr")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_416rt")
}],
"loop": true,
"name": &"idle",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_7pp1r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_sv0rn")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_naty2")
}],
"loop": false,
"name": &"jump_end",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_rtj8h")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_goiod")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_u4two")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_nd2k7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_hsc5u")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1ufd4")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_0fchy")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_of2e2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_6ar74")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_3fr5v")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_dh3qg")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_lctin")
}],
"loop": false,
"name": &"jump_start",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_a83ak")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_0rhp5")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xs4ja")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_im2g8")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_if710")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f5phe")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_rgyyg")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_jn4q8")
}],
"loop": true,
"name": &"run",
"speed": 10.0
}]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4mr7i"]
radius = 8.0
@ -10,10 +226,15 @@ height = 44.0
[node name="Player" type="CharacterBody2D"]
script = ExtResource("1_mhe8q")
[node name="Sprite" type="Sprite2D" parent="."]
texture = ExtResource("1_caaw0")
hframes = 4
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_k0v45")
animation = &"jump_end"
autoplay = "idle"
centered = false
offset = Vector2(-32, -40)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 2)
shape = SubResource("CapsuleShape2D_4mr7i")
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]

File diff suppressed because one or more lines are too long

View File

@ -52,10 +52,6 @@ jump={
]
}
[physics]
2d/default_gravity=490.0
[rendering]
textures/canvas_textures/default_texture_filter=0