22 lines
496 B
GDScript
22 lines
496 B
GDScript
class_name Player
|
|
extends Node2D
|
|
|
|
@export var speed = 80
|
|
var velocity := Vector2.ZERO
|
|
|
|
func get_input():
|
|
if Input.is_action_pressed("Slow Mode"):
|
|
speed = 40
|
|
else:
|
|
speed = 80
|
|
|
|
velocity = Input.get_vector("Left", "Right", "Up", "Down") * speed
|
|
|
|
func _physics_process(delta: float):
|
|
get_input()
|
|
|
|
# Bounds checking
|
|
var attempted_position := position + (velocity * delta)
|
|
attempted_position = attempted_position.clamp(Vector2(0, 0), Globals.SERVER_SIZE)
|
|
|
|
position = attempted_position
|