var direction:int = 0
var speed:int = 450
var half_of_player:int = 15
var bullet_scene = preload(“res://scenes/bullet.tscn”)
var bullet_time = 0.5
var bullet_spawn = 0
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):
bullet_spawn += delta
if Input.is_action_pressed("shoot") and bullet_spawn> bullet_time:
var bullet_instance = bullet_scene.instantiate()
bullet_instance.position.x=position.x
bullet_instance.position.y=position.y-20
get_parent().get_node("bullets").add_child(bullet_instance)
if Input.is_action_pressed("move_left"):
direction = -1
elif Input.is_action_pressed("move_right"):
direction = 1
else:
direction = 0
position.x = clamp(position.x + direction * speed * delta, half_of_player,400- half_of_player )