Files
doodlejump/scripts/player.gd
2025-05-23 10:58:01 +02:00

34 lines
818 B
GDScript

extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -800.0
var width
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
width = get_viewport().size.x
velocity.y = JUMP_VELOCITY * 2
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
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)
if position.x > width:
position.x -= width
elif position.x < 0:
position.x += width
move_and_slide()