GodotComponentTest/Game.gd

30 lines
1.1 KiB
GDScript

extends Node2D
onready var SimpleEntity = preload("res://Entities/SimpleEntity.tscn")
onready var WanderingEntity = preload("res://Entities/WanderingEntity.tscn")
onready var entities = $Entities
# 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):
# pass
func _on_AddEntityButton_pressed():
var entity_instance = SimpleEntity.instance()
var viewport_rect = get_viewport_rect()
entity_instance.transform.origin = Vector2(randf() * viewport_rect.size[0], randf() * viewport_rect.size[1])
entities.add_child(entity_instance)
func _on_AddWanderingEntity_pressed():
var entity_instance = WanderingEntity.instance()
var viewport_rect = get_viewport_rect()
entity_instance.transform.origin = Vector2(randf() * viewport_rect.size[0], randf() * viewport_rect.size[1])
entities.add_child(entity_instance)
entity_instance.set_target(Vector2(randf() * viewport_rect.size[0], randf() * viewport_rect.size[1]))