Unit spawning. Added moving marker.

This commit is contained in:
gdz
2025-12-14 02:37:34 +01:00
parent c8859d5e9f
commit a500e7ac3e
3 changed files with 34 additions and 12 deletions

View File

@@ -1,18 +1,28 @@
extends Node
@onready var _Map: Node = $Map
@onready var _Unit = $Unit
@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:
_createUnit(Vector2i(150, 150))
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:
@@ -20,5 +30,19 @@ func _process(delta: float) -> void:
func _createUnit(pos: Vector2i):
var newUnit = _UnitScene.instantiate()
newUnit.global_position = pos
add_child(newUnit)
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)

View File

@@ -1,9 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://d05j5yuhlsxp0"]
[gd_scene load_steps=4 format=3 uid="uid://d05j5yuhlsxp0"]
[ext_resource type="PackedScene" uid="uid://cywuuce71rmgb" path="res://Scenes/Map/map.tscn" id="1_1r6ip"]
[ext_resource type="Script" uid="uid://btdvxp8ckmeb3" path="res://Scenes/Main/main.gd" id="1_qw60k"]
[ext_resource type="PackedScene" uid="uid://bfvijh611aggp" path="res://Scenes/Camera/camera_controller.tscn" id="3_qw60k"]
[ext_resource type="PackedScene" uid="uid://dy7rltpxyqyw7" path="res://Scenes/Unit/unit.tscn" id="4_5yls4"]
[node name="Main" type="Node"]
script = ExtResource("1_qw60k")
@@ -11,5 +10,3 @@ script = ExtResource("1_qw60k")
[node name="Map" parent="." instance=ExtResource("1_1r6ip")]
[node name="CameraController" parent="." instance=ExtResource("3_qw60k")]
[node name="Unit" parent="." instance=ExtResource("4_5yls4")]