create BunchSpawner
This commit is contained in:
7
scenes/static/bunch_spawner.tscn
Normal file
7
scenes/static/bunch_spawner.tscn
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://bk3ers4qaleu2"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/bunch_spawner.gd" id="1_kccg7"]
|
||||||
|
|
||||||
|
[node name="BunchSpawner" type="Marker3D"]
|
||||||
|
gizmo_extents = 1.0
|
||||||
|
script = ExtResource("1_kccg7")
|
||||||
File diff suppressed because one or more lines are too long
27
scripts/bunch_spawner.gd
Normal file
27
scripts/bunch_spawner.gd
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
extends Marker3D
|
||||||
|
|
||||||
|
enum WhatToSpawn {
|
||||||
|
APHID
|
||||||
|
}
|
||||||
|
|
||||||
|
@export var what: WhatToSpawn = WhatToSpawn.APHID
|
||||||
|
@export var amount: int = 5
|
||||||
|
|
||||||
|
var aphid := preload("res://scenes/units/aphid.tscn")
|
||||||
|
|
||||||
|
@onready var aphids_holder: Node = $/root/World/Units/Aphids
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
assert(aphids_holder != null, "aphids_holder missing!")
|
||||||
|
for i in amount:
|
||||||
|
match what:
|
||||||
|
WhatToSpawn.APHID:
|
||||||
|
_spawn(aphid, global_position, aphids_holder)
|
||||||
|
|
||||||
|
|
||||||
|
func _spawn(scene: PackedScene, where: Vector3, holder: Node) -> void:
|
||||||
|
var new_node := scene.instantiate() as Node3D
|
||||||
|
if new_node is Unit:
|
||||||
|
(new_node as Unit).spawn_pos = where
|
||||||
|
holder.add_child(new_node)
|
||||||
|
new_node.global_position = where
|
||||||
@@ -9,13 +9,12 @@ var honeydew_scene := preload("res://scenes/items/honeydew.tscn")
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
assert(items_holder != null, "items_holder missing!")
|
assert(items_holder != null, "items_holder missing!")
|
||||||
spawn_a_bunch(Vector3.ZERO, 125, 3)
|
|
||||||
|
|
||||||
|
|
||||||
func spawn_honeydew(pos: Vector3) -> Honeydew:
|
func spawn_honeydew(pos: Vector3) -> Honeydew:
|
||||||
var honeydew := honeydew_scene.instantiate() as Honeydew
|
var honeydew := honeydew_scene.instantiate() as Honeydew
|
||||||
items_holder.add_child(honeydew)
|
|
||||||
honeydew.global_position = pos
|
honeydew.global_position = pos
|
||||||
|
items_holder.add_child(honeydew)
|
||||||
return honeydew
|
return honeydew
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ signal moving_started
|
|||||||
signal moving_ended
|
signal moving_ended
|
||||||
|
|
||||||
var anthill: Anthill
|
var anthill: Anthill
|
||||||
var spawn_pos: Vector3
|
|
||||||
|
|
||||||
var hovered_rect: bool = false
|
var hovered_rect: bool = false
|
||||||
var selected: bool = false
|
var selected: bool = false
|
||||||
@@ -30,9 +29,6 @@ func _ready() -> void:
|
|||||||
assert(camera != null, "camera missing!")
|
assert(camera != null, "camera missing!")
|
||||||
assert(selection_sprite != null, "selection_sprite missing!")
|
assert(selection_sprite != null, "selection_sprite missing!")
|
||||||
nav_agent.navigation_finished.connect(_on_nav_agent_navigation_finished)
|
nav_agent.navigation_finished.connect(_on_nav_agent_navigation_finished)
|
||||||
|
|
||||||
if spawn_pos != null and spawn_pos != Vector3.ZERO:
|
|
||||||
global_position = spawn_pos
|
|
||||||
super._ready()
|
super._ready()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ var max_wander_interval: float = 5
|
|||||||
var is_on_screen: bool = false
|
var is_on_screen: bool = false
|
||||||
var wandering_timer: float = 0
|
var wandering_timer: float = 0
|
||||||
var wandering_center: Vector3 = Vector3.ZERO
|
var wandering_center: Vector3 = Vector3.ZERO
|
||||||
|
var spawn_pos: Vector3
|
||||||
|
|
||||||
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
||||||
@onready var ui_origin: Node3D = $UiOrigin
|
@onready var ui_origin: Node3D = $UiOrigin
|
||||||
@@ -27,6 +28,9 @@ func _ready() -> void:
|
|||||||
assert(ui_origin != null, "ui_origin missing!")
|
assert(ui_origin != null, "ui_origin missing!")
|
||||||
super._ready()
|
super._ready()
|
||||||
|
|
||||||
|
if spawn_pos != null and spawn_pos != Vector3.ZERO:
|
||||||
|
global_position = spawn_pos
|
||||||
|
|
||||||
wandering_center = global_position
|
wandering_center = global_position
|
||||||
nav_agent.max_speed = MOVE_SPEED
|
nav_agent.max_speed = MOVE_SPEED
|
||||||
nav_agent.velocity_computed.connect(_on_nav_agent_velocity_computed)
|
nav_agent.velocity_computed.connect(_on_nav_agent_velocity_computed)
|
||||||
|
|||||||
Reference in New Issue
Block a user