mirror of
https://github.com/MoonlitJolteon/crasher-sidescroller.git
synced 2025-12-18 15:58:50 +00:00
Basic test level added using free assets
Signed-off-by: Moonlit Jolteon <moonlit@munebase.dev>
This commit is contained in:
33
Characters/player.gd
Normal file
33
Characters/player.gd
Normal file
@ -0,0 +1,33 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
@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
|
||||
|
||||
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
|
||||
|
||||
# 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)
|
||||
|
||||
move_and_slide()
|
||||
19
Characters/player.tscn
Normal file
19
Characters/player.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=4 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"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_4mr7i"]
|
||||
radius = 8.0
|
||||
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="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("CapsuleShape2D_4mr7i")
|
||||
Reference in New Issue
Block a user