add unit creation from anthill
This commit is contained in:
@@ -1,4 +1,22 @@
|
|||||||
extends Interactable
|
extends Interactable
|
||||||
|
class_name Anthill
|
||||||
|
|
||||||
|
const SPAWN_RADIUS: float = 1
|
||||||
|
|
||||||
var honeydew: int = 0
|
var honeydew: int = 0
|
||||||
|
|
||||||
|
var ant_nitwit := preload("res://scenes/units/ant_nitwit.tscn")
|
||||||
|
|
||||||
|
@onready var nitwits_holder: Node = $/root/World/Units/Nitwits
|
||||||
|
|
||||||
|
func _click() -> void:
|
||||||
|
var spawn_pos_angle := randf_range(0, 360)
|
||||||
|
var new_pos_offset := Vector3.BACK.rotated(Vector3.UP, spawn_pos_angle)
|
||||||
|
var new_pos := global_position + (new_pos_offset * SPAWN_RADIUS)
|
||||||
|
var new_unit := (
|
||||||
|
(ant_nitwit.instantiate() as AntNitwit).initialize(
|
||||||
|
self,
|
||||||
|
new_pos
|
||||||
|
)
|
||||||
|
)
|
||||||
|
nitwits_holder.add_child(new_unit)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ class_name ControlledUnit
|
|||||||
signal moving_started
|
signal moving_started
|
||||||
signal moving_ended
|
signal moving_ended
|
||||||
|
|
||||||
|
var anthill: Anthill
|
||||||
|
|
||||||
var selected: bool = false
|
var selected: bool = false
|
||||||
var moving_to_target: bool = false
|
var moving_to_target: bool = false
|
||||||
var ground_plane: Plane = Plane(Vector3.UP, 0)
|
var ground_plane: Plane = Plane(Vector3.UP, 0)
|
||||||
@@ -48,6 +50,12 @@ func _input(event: InputEvent) -> void:
|
|||||||
_set_target_click(button_event.position)
|
_set_target_click(button_event.position)
|
||||||
|
|
||||||
|
|
||||||
|
func initialize(from: Anthill, pos: Vector3) -> ControlledUnit:
|
||||||
|
anthill = from
|
||||||
|
global_position = pos
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
func set_selected(on: bool) -> void:
|
func set_selected(on: bool) -> void:
|
||||||
selected = on
|
selected = on
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user