-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.gd
More file actions
24 lines (19 loc) · 773 Bytes
/
player.gd
File metadata and controls
24 lines (19 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
extends Area2D
@export var speed = 400
var screen_size
# Called when the node enters the scene tree for the first time.
func _ready():
screen_size = get_viewport_rect().size
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var velocity = Vector2.ZERO # The player's movement vector.
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
position += velocity * delta
var half_height = $Sprite2D.texture.get_height() * $Sprite2D.scale.y / 2
var margin = 50 # Adjust this value as needed
position.y = clamp(position.y, half_height + margin, screen_size.y - half_height - margin)