GodotComponentTest/Game.gd

33 lines
1.2 KiB
GDScript
Raw Normal View History

2022-08-17 00:50:30 +02:00
extends Node2D
onready var SimpleEntity = preload("res://Entities/SimpleEntity.tscn")
onready var WanderingEntity = preload("res://Entities/WanderingEntity.tscn")
2022-08-19 18:48:54 +02:00
onready var player = $PlayerEntity
2022-08-17 00:50:30 +02:00
onready var entities = $Entities
2022-08-19 18:48:54 +02:00
signal world_location_clicked
2022-08-17 00:50:30 +02:00
# Called when the node enters the scene tree for the first time.
func _ready():
2022-08-19 18:48:54 +02:00
self.connect("world_location_clicked", player, "on_world_location_clicked")
2022-08-17 00:50:30 +02:00
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]))
2022-08-19 18:48:54 +02:00
func _unhandled_input(event):
if event is InputEventMouseButton and event.pressed:
#get_tree().get_root().set_input_as_handled()
emit_signal("world_location_clicked", event.position)
pass