2019-12-19 20:04:08 +01:00
|
|
|
extends Node2D
|
2020-01-02 23:42:41 +01:00
|
|
|
# Access helper class for children to access window boundaries.
|
2019-12-19 20:04:08 +01:00
|
|
|
|
2019-12-21 19:07:43 +01:00
|
|
|
|
2019-12-19 20:04:08 +01:00
|
|
|
onready var player: KinematicBody2D = $Player
|
2019-12-21 19:07:43 +01:00
|
|
|
onready var spawner: Node2D = $Spawner
|
2019-12-23 17:38:27 +01:00
|
|
|
onready var gui: = $GUI
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
var camera_boundaries: Rect2
|
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
camera_boundaries = Rect2(
|
|
|
|
Vector2.ZERO,
|
|
|
|
Vector2(
|
|
|
|
ProjectSettings["display/window/size/width"],
|
|
|
|
ProjectSettings["display/window/size/height"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
var rng: = RandomNumberGenerator.new()
|
|
|
|
rng.randomize()
|
|
|
|
|
2019-12-21 19:07:43 +01:00
|
|
|
for i in range(spawner.entity_count):
|
|
|
|
var new_pos: = Vector2(
|
|
|
|
rng.randf_range(-camera_boundaries.size.x/2, camera_boundaries.size.x/2),
|
|
|
|
rng.randf_range(-camera_boundaries.size.y/2, camera_boundaries.size.y/2)
|
|
|
|
)
|
|
|
|
var entity: KinematicBody2D = spawner.Entity.instance()
|
|
|
|
entity.global_position = new_pos
|
|
|
|
entity.player_agent = player.agent
|
|
|
|
entity.speed = rng.randf_range(spawner.min_speed, spawner.max_speed)
|
|
|
|
entity.color = spawner.entity_color
|
2019-12-23 17:38:27 +01:00
|
|
|
gui.connect("mode_changed", entity, "_on_GUI_mode_changed")
|
2019-12-21 19:07:43 +01:00
|
|
|
spawner.add_child(entity)
|