49 lines
1.2 KiB
GDScript
49 lines
1.2 KiB
GDScript
extends Node
|
|
|
|
@onready var _Map: Node = $Map
|
|
@onready var _Camera = $CameraController
|
|
|
|
# Units
|
|
var _UnitScene = preload("res://Scenes/Unit/unit.tscn")
|
|
var _Units: Array[Unit] = []
|
|
|
|
# MovingMarker
|
|
var _MovingMarkerScene = preload("res://Scenes/Unit/marker.tscn")
|
|
var _MovingMarker: Node2D = _MovingMarkerScene.instantiate()
|
|
#@export var mapSize: int = 15
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
add_child(_MovingMarker)
|
|
_MovingMarker.hide()
|
|
|
|
_createUnit(Vector2i(10,10))
|
|
for unit in _Units:
|
|
add_child(unit)
|
|
pass
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
func _createUnit(pos: Vector2i):
|
|
var newUnit = _UnitScene.instantiate()
|
|
newUnit.set("_spawnPosition", pos)
|
|
_Units.append(newUnit as Unit)
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("SetMarker"):
|
|
print("Action is SetMarker")
|
|
_MovingMarker.global_position = _getMousePosition(event).position
|
|
_MovingMarker.show()
|
|
|
|
|
|
func _getScreenCenter():
|
|
return get_viewport().get_camera_2d().get_screen_center_position()
|
|
|
|
|
|
func _getMousePosition(event: InputEvent):
|
|
return get_viewport().get_camera_2d().make_input_local(event)
|