GodotComponentTest/Game.gd

26 lines
969 B
GDScript

extends Node2D
onready var SimpleEntity = preload("res://Entities/SimpleEntity.tscn")
onready var WanderingEntity = preload("res://Entities/WanderingEntity.tscn")
onready var entities = $Entities
signal world_location_clicked
# Called when the node enters the scene tree for the first time.
func _ready():
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]))