2024-01-26 20:01:22 +00:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
@export var move_speed = 100
|
|
|
|
@export var boundary: Boundary
|
2024-01-26 20:22:33 +00:00
|
|
|
@export var tim_sprite : Sprite2D
|
2024-01-26 20:01:22 +00:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2024-01-27 14:50:20 +00:00
|
|
|
pass # Replace with function body.
|
2024-01-26 20:01:22 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
2024-01-27 14:50:20 +00:00
|
|
|
if Input.is_action_pressed("move_right"):
|
|
|
|
tim_sprite.flip_h = true
|
|
|
|
global_position += Vector2.RIGHT * delta * move_speed
|
|
|
|
if global_position.x > boundary.get_most_right_position():
|
|
|
|
global_position = Vector2(boundary.get_most_right_position(), global_position.y)
|
|
|
|
|
|
|
|
if Input.is_action_pressed("move_left"):
|
|
|
|
tim_sprite.flip_h = false
|
|
|
|
global_position += Vector2.LEFT * delta * move_speed
|
|
|
|
if global_position.x < boundary.get_most_left_position():
|
|
|
|
global_position = Vector2(boundary.get_most_left_position(), global_position.y)
|