add player movement
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
[gd_scene load_steps=2 format=3 uid="uid://cy3dg66pt8abt"]
|
[gd_scene load_steps=3 format=3 uid="uid://cy3dg66pt8abt"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://3wumh6kpw3ai" path="res://scenes/player.tscn" id="1_uwrxv"]
|
[ext_resource type="PackedScene" uid="uid://3wumh6kpw3ai" path="res://scenes/player.tscn" id="1_uwrxv"]
|
||||||
|
|
||||||
|
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_uwrxv"]
|
||||||
|
|
||||||
[node name="Game" type="Node2D"]
|
[node name="Game" type="Node2D"]
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource("1_uwrxv")]
|
[node name="Player" parent="." instance=ExtResource("1_uwrxv")]
|
||||||
@@ -10,3 +12,9 @@ position = Vector2(33, 49)
|
|||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
position = Vector2(39, 27)
|
position = Vector2(39, 27)
|
||||||
zoom = Vector2(4, 4)
|
zoom = Vector2(4, 4)
|
||||||
|
|
||||||
|
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||||
|
position = Vector2(1, 61)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||||
|
shape = SubResource("WorldBoundaryShape2D_uwrxv")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=8 format=3 uid="uid://3wumh6kpw3ai"]
|
[gd_scene load_steps=9 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"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_g2els"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_g2els"]
|
||||||
atlas = ExtResource("1_3vyb7")
|
atlas = ExtResource("1_3vyb7")
|
||||||
@@ -42,6 +43,9 @@ animations = [{
|
|||||||
radius = 5.0
|
radius = 5.0
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D"]
|
[node name="Player" type="CharacterBody2D"]
|
||||||
|
script = ExtResource("1_g2els")
|
||||||
|
speed = 130.0
|
||||||
|
jump_velocity = -300.0
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
position = Vector2(0, -12)
|
position = Vector2(0, -12)
|
||||||
|
|||||||
25
scripts/player.gd
Normal file
25
scripts/player.gd
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
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("ui_accept") 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")
|
||||||
|
if direction:
|
||||||
|
velocity.x = direction * speed
|
||||||
|
else:
|
||||||
|
velocity.x = move_toward(velocity.x, 0, speed)
|
||||||
|
|
||||||
|
move_and_slide()
|
||||||
1
scripts/player.gd.uid
Normal file
1
scripts/player.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dkpsredq14h2l
|
||||||
Reference in New Issue
Block a user