xyz Got it!
extends Node2D
const PRE_LASER = preload("res://scripts/laser.gd")
var vel = 90
Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var dirX = 0
var dirY = 0
if Input.is_action_pressed("ui_left"):
dirX += -2
if Input.is_action_pressed("ui_right"):
dirX += 2
if Input.is_action_pressed("ui_up"):
dirY += -2
if Input.is_action_pressed("ui_down"):
dirY += 2
if Input.is_action_just_pressed("ui_accept"):
var laser_instance = PRE_LASER.instantiate()
if laser_instance:
var laser = laser_instance as PRE_LASER
get_parent().add_child(laser)
laser.global_position = global_position
translate(Vector2(dirX, dirY) * vel * delta)
global_position.x = clamp(global_position.x, 20, 140)
global_position.y = clamp(global_position.y, 15, 273)