Player Movement

This commit is contained in:
siyahas 2024-11-01 20:33:00 +03:00
parent 8f286384b7
commit c97a46ca59
4 changed files with 55 additions and 2 deletions

View file

@ -11,6 +11,7 @@ config_version=5
[application]
config/name="Martian Mike"
run/main_scene="res://scenes/level.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"

View file

@ -1,6 +1,33 @@
[gd_scene load_steps=2 format=3 uid="uid://cchf5vmjp6ahj"]
[gd_scene load_steps=7 format=3 uid="uid://cchf5vmjp6ahj"]
[ext_resource type="Script" path="res://scripts/level.gd" id="1_84g5v"]
[ext_resource type="PackedScene" uid="uid://c7y3ileam1twx" path="res://scenes/player.tscn" id="2_d65cs"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_mvbjk"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5f3h6"]
size = Vector2(326, 12)
[sub_resource type="Gradient" id="Gradient_de2k8"]
offsets = PackedFloat32Array(0)
colors = PackedColorArray(0, 0, 0, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_v33b1"]
gradient = SubResource("Gradient_de2k8")
[node name="Level" type="Node2D"]
script = ExtResource("1_84g5v")
[node name="Player" parent="." instance=ExtResource("2_d65cs")]
position = Vector2(230, 110)
[node name="StaticBody2D" type="StaticBody2D" parent="."]
position = Vector2(204, 173)
physics_material_override = SubResource("PhysicsMaterial_mvbjk")
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
shape = SubResource("RectangleShape2D_5f3h6")
[node name="Sprite2D" type="Sprite2D" parent="StaticBody2D"]
scale = Vector2(1.275, 12.325)
texture = SubResource("GradientTexture1D_v33b1")

View file

@ -1,5 +1,6 @@
[gd_scene load_steps=30 format=3 uid="uid://c7y3ileam1twx"]
[gd_scene load_steps=31 format=3 uid="uid://c7y3ileam1twx"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_eck75"]
[ext_resource type="Texture2D" uid="uid://g6dy0j2lbcso" path="res://assets/textures/player/Fall (32x32).png" id="1_ujg18"]
[ext_resource type="Texture2D" uid="uid://bckhu0vpmij88" path="res://assets/textures/player/Idle (32x32).png" id="2_enuvh"]
[ext_resource type="Texture2D" uid="uid://dehumidunwvt6" path="res://assets/textures/player/Jump (32x32).png" id="3_7ohnv"]
@ -199,6 +200,7 @@ animations = [{
size = Vector2(14, 20)
[node name="Player" type="CharacterBody2D"]
script = ExtResource("1_eck75")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -16)
@ -209,3 +211,5 @@ autoplay = "idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -10)
shape = SubResource("RectangleShape2D_ereyp")
[node name="Camera2D" type="Camera2D" parent="."]

21
scripts/player.gd Normal file
View file

@ -0,0 +1,21 @@
extends CharacterBody2D
@export var speed = 300.0
@export var jump_velocity = 400.0
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("jump") and is_on_floor():
velocity.y = -jump_velocity
# Get the input direction and handle the movement/deceleration.
var direction := Input.get_axis("move_left", "move_right")
velocity.x = direction * speed
move_and_slide()