GodotComponentTest/Game.gd

33 lines
1.1 KiB
GDScript
Raw Normal View History

2022-08-17 00:50:30 +02:00
extends Node2D
2022-08-25 14:10:02 +02:00
onready var SimpleEntity = preload("res://entities/SimpleEntity.tscn")
onready var WanderingEntity = preload("res://entities/WanderingEntity.tscn")
2022-08-20 14:36:17 +02:00
onready var player_movable_target_label = $UI/PlayerMovableTarget
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 19:13:39 +02:00
pass
2022-08-20 14:36:17 +02:00
func _process(delta):
player_movable_target_label.text = str(player.movable_component.target)
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]))