Compare commits

...

2 Commits

Author SHA1 Message Date
gdz
4f9d5fc8bd Unit now does not handle the MovementMarker anymore. 2025-12-14 02:38:31 +01:00
gdz
a500e7ac3e Unit spawning. Added moving marker. 2025-12-14 02:37:34 +01:00
5 changed files with 70 additions and 25 deletions

View File

@@ -1,18 +1,28 @@
extends Node extends Node
@onready var _Map: Node = $Map @onready var _Map: Node = $Map
@onready var _Unit = $Unit
@onready var _Camera = $CameraController @onready var _Camera = $CameraController
# Units
var _UnitScene = preload("res://Scenes/Unit/unit.tscn") 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 #@export var mapSize: int = 15
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
_createUnit(Vector2i(150, 150)) add_child(_MovingMarker)
_MovingMarker.hide()
_createUnit(Vector2i(10,10))
for unit in _Units:
add_child(unit)
pass pass
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
@@ -20,5 +30,19 @@ func _process(delta: float) -> void:
func _createUnit(pos: Vector2i): func _createUnit(pos: Vector2i):
var newUnit = _UnitScene.instantiate() var newUnit = _UnitScene.instantiate()
newUnit.global_position = pos newUnit.set("_spawnPosition", pos)
add_child(newUnit) _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="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="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://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"] [node name="Main" type="Node"]
script = ExtResource("1_qw60k") script = ExtResource("1_qw60k")
@@ -11,5 +10,3 @@ script = ExtResource("1_qw60k")
[node name="Map" parent="." instance=ExtResource("1_1r6ip")] [node name="Map" parent="." instance=ExtResource("1_1r6ip")]
[node name="CameraController" parent="." instance=ExtResource("3_qw60k")] [node name="CameraController" parent="." instance=ExtResource("3_qw60k")]
[node name="Unit" parent="." instance=ExtResource("4_5yls4")]

View File

@@ -1,15 +1,16 @@
[gd_scene load_steps=3 format=3 uid="uid://bhcenjcsstaaf"] [gd_scene load_steps=3 format=3 uid="uid://bhcenjcsstaaf"]
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_4a8kw"] [ext_resource type="Texture2D" uid="uid://cxtkb8rqq0j6r" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tiles/tile_0407.png" id="1_y5thb"]
size = Vector2(8, 8)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4a8kw"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_4a8kw"]
size = Vector2(8, 8) size = Vector2(16, 16)
[node name="Marker" type="Node2D"] [node name="Marker" type="Node2D"]
top_level = true
z_index = 20
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
texture = SubResource("PlaceholderTexture2D_4a8kw") texture = ExtResource("1_y5thb")
[node name="Area2D" type="Area2D" parent="."] [node name="Area2D" type="Area2D" parent="."]

View File

@@ -2,26 +2,36 @@ extends Node2D
class_name Unit class_name Unit
var _spawnPosition: Vector2
### Marker ### Marker
# For now the marker will be spawned and deleted by the unit. # For now the marker will be spawned and deleted by the unit.
# Later it will be handled by the main scene. # Later it will be handled by the main scene.
# Load marker scene. # Load marker scene.
var marker_scene = preload("res://Scenes/Unit/marker.tscn") # var marker_scene: PackedScene = preload("res://Scenes/Unit/marker.tscn")
var marker # var marker
## WE NOW USE A SIMPLE SPRITE2D FOR THE MARKER
@onready var _readyToSelectMarker = $ReadyToSelectMarker
@onready var _selectedMarker = $SelectedMarker
var _selected = false @onready var _readyToSelectMarker: Sprite2D = $ReadyToSelectMarker
var _readyToSelect = false @onready var _selectedMarker: Sprite2D = $SelectedMarker
#@onready var _movingMarker: Sprite2D = $MovingMarker
var _readyToSelect: bool = false
var _selected: bool = false
#var _moving: bool = false
var TargetPosition: Vector2
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
marker = marker_scene.instantiate() # marker = marker_scene.instantiate()
marker.hide() # marker.hide()
global_position = _spawnPosition
_readyToSelectMarker.hide() _readyToSelectMarker.hide()
_selectedMarker.hide() _selectedMarker.hide()
# _movingMarker.hide()
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
@@ -36,10 +46,14 @@ func _input(event: InputEvent):
else: _deselectUnit() else: _deselectUnit()
if event.is_action_pressed("SetMarker") and _selected: # if event.is_action_pressed("SetMarker"):
marker.global_position = event.position # print("Action is SetMarker")
marker.show() # if _selected:
print_debug("Setting marker") # print("Setting marker to ", event.position)
# #marker.global_position = event.position
## marker.show()
## _movingMarker.position = get_global_mouse_position()
## _movingMarker.show()
func _getUnitPosition(): func _getUnitPosition():
return $AnimatedSprite2D.global_position return $AnimatedSprite2D.global_position
@@ -66,3 +80,6 @@ func _markUnit():
func _unMarkUnit(): func _unMarkUnit():
_readyToSelect = false _readyToSelect = false
_readyToSelectMarker.hide() _readyToSelectMarker.hide()
func moveToTarget():

View File

@@ -1,9 +1,10 @@
[gd_scene load_steps=91 format=3 uid="uid://dy7rltpxyqyw7"] [gd_scene load_steps=92 format=3 uid="uid://dy7rltpxyqyw7"]
[ext_resource type="Script" uid="uid://dpu6c0bpm0dvl" path="res://Scenes/Unit/unit.gd" id="1_15sed"] [ext_resource type="Script" uid="uid://dpu6c0bpm0dvl" path="res://Scenes/Unit/unit.gd" id="1_15sed"]
[ext_resource type="Texture2D" uid="uid://cgvyfsuri6vmx" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tilemap/tilemap.png" id="1_hgpyh"] [ext_resource type="Texture2D" uid="uid://cgvyfsuri6vmx" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tilemap/tilemap.png" id="1_hgpyh"]
[ext_resource type="Texture2D" uid="uid://bprproedmlhtr" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tiles/tile_0168.png" id="3_ladk0"] [ext_resource type="Texture2D" uid="uid://bprproedmlhtr" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tiles/tile_0168.png" id="3_ladk0"]
[ext_resource type="Texture2D" uid="uid://b7ra2w7rdeqij" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tiles/tile_0169.png" id="4_iuf4a"] [ext_resource type="Texture2D" uid="uid://b7ra2w7rdeqij" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tiles/tile_0169.png" id="4_iuf4a"]
[ext_resource type="Texture2D" uid="uid://cxtkb8rqq0j6r" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tiles/tile_0407.png" id="5_ulevp"]
[sub_resource type="AtlasTexture" id="AtlasTexture_15sed"] [sub_resource type="AtlasTexture" id="AtlasTexture_15sed"]
atlas = ExtResource("1_hgpyh") atlas = ExtResource("1_hgpyh")
@@ -642,6 +643,11 @@ position = Vector2(-0.225, -8)
scale = Vector2(0.5, 0.5) scale = Vector2(0.5, 0.5)
texture = ExtResource("4_iuf4a") texture = ExtResource("4_iuf4a")
[node name="MovingMarker" type="Sprite2D" parent="."]
visible = false
scale = Vector2(0.5, 0.5)
texture = ExtResource("5_ulevp")
[node name="Area2D" type="Area2D" parent="."] [node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]