From 0d36b74fcdf22f7be14e174f6a9869cc92246ba7 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Mon, 8 Dec 2025 17:59:07 +0300 Subject: [PATCH] Added base map drawing --- game/area_map/area_map.gd | 207 ++++++++++++++++++ game/area_map/area_map.gd.uid | 1 + game/area_map/area_map.tscn | 19 ++ .../indicators/absctact_passage_indicator.gd | 15 ++ .../absctact_passage_indicator.gd.uid | 1 + .../absctact_passage_indicator.tscn | 10 + .../indicators/abstract_sector_indicator.gd | 15 ++ .../abstract_sector_indicator.gd.uid | 1 + .../indicators/abstract_sector_indicator.tscn | 10 + .../indicators/current_sector_indicator.gd | 12 + .../current_sector_indicator.gd.uid | 1 + .../indicators/current_sector_indicator.tscn | 76 +++++++ .../minus_26_grad_passage_indicator.tscn | 22 ++ .../minus_45_grad_passage_indicator.tscn | 22 ++ .../plus_26_grad_passage_indicator.tscn | 22 ++ .../plus_45_grad_passage_indicator.tscn | 22 ++ .../passages/zero_grad_passage_indicator.tscn | 22 ++ .../sectors/boss_sector_indicator.tscn | 20 ++ .../sectors/debris_sector_indicator.tscn | 20 ++ .../sectors/empty_sector_indicator.tscn | 20 ++ .../sectors/repair_sector_indicator.tscn | 20 ++ .../sectors/shop_sector_indicator.tscn | 20 ++ .../sectors/start_sector_indicator.tscn | 20 ++ .../indicators/selected_sector_indicator.gd | 12 + .../selected_sector_indicator.gd.uid | 1 + .../indicators/selected_sector_indicator.tscn | 47 ++++ game/world/data/passage_data.gd | 10 + game/world/data/sector_data.gd | 12 + game/world/generators/area_generator.gd | 58 +++-- game/world/generators/sector_generator.gd | 28 ++- game/world/generators/stage_generator.gd | 20 +- 31 files changed, 768 insertions(+), 18 deletions(-) create mode 100644 game/area_map/area_map.gd create mode 100644 game/area_map/area_map.gd.uid create mode 100644 game/area_map/area_map.tscn create mode 100644 game/area_map/indicators/absctact_passage_indicator.gd create mode 100644 game/area_map/indicators/absctact_passage_indicator.gd.uid create mode 100644 game/area_map/indicators/absctact_passage_indicator.tscn create mode 100644 game/area_map/indicators/abstract_sector_indicator.gd create mode 100644 game/area_map/indicators/abstract_sector_indicator.gd.uid create mode 100644 game/area_map/indicators/abstract_sector_indicator.tscn create mode 100644 game/area_map/indicators/current_sector_indicator.gd create mode 100644 game/area_map/indicators/current_sector_indicator.gd.uid create mode 100644 game/area_map/indicators/current_sector_indicator.tscn create mode 100644 game/area_map/indicators/passages/minus_26_grad_passage_indicator.tscn create mode 100644 game/area_map/indicators/passages/minus_45_grad_passage_indicator.tscn create mode 100644 game/area_map/indicators/passages/plus_26_grad_passage_indicator.tscn create mode 100644 game/area_map/indicators/passages/plus_45_grad_passage_indicator.tscn create mode 100644 game/area_map/indicators/passages/zero_grad_passage_indicator.tscn create mode 100644 game/area_map/indicators/sectors/boss_sector_indicator.tscn create mode 100644 game/area_map/indicators/sectors/debris_sector_indicator.tscn create mode 100644 game/area_map/indicators/sectors/empty_sector_indicator.tscn create mode 100644 game/area_map/indicators/sectors/repair_sector_indicator.tscn create mode 100644 game/area_map/indicators/sectors/shop_sector_indicator.tscn create mode 100644 game/area_map/indicators/sectors/start_sector_indicator.tscn create mode 100644 game/area_map/indicators/selected_sector_indicator.gd create mode 100644 game/area_map/indicators/selected_sector_indicator.gd.uid create mode 100644 game/area_map/indicators/selected_sector_indicator.tscn diff --git a/game/area_map/area_map.gd b/game/area_map/area_map.gd new file mode 100644 index 0000000..c3221d4 --- /dev/null +++ b/game/area_map/area_map.gd @@ -0,0 +1,207 @@ +class_name AreaMap +extends Node2D + + +const SECTOR_XS = [ + 64 * 1, 64 * 2, 64 * 3, + 64 * 4, 64 * 5, 64 * 6, + 64 * 7, 64 * 8, 64 * 9, +] + +const SECTOR_YS_FOR_ONE = [ + 64 * 2 +] + +const SECTOR_YS_FOR_TWO = [ + 64 * 1.5, 64 * 2.5, +] + +const SECTOR_YS_FOR_THREE = [ + 64 * 1, 64 * 2, 64 * 3, +] + +const CURRENT_SECTOR_INDICATOR_OFFSET = Vector2(0, 16) + +const SECTOR_SCENES : Dictionary[SectorData.SectorType, PackedScene] = { + SectorData.SectorType.EmptySector: + preload("res://game/area_map/indicators/sectors/empty_sector_indicator.tscn"), + SectorData.SectorType.ShopSector: + preload("res://game/area_map/indicators/sectors/shop_sector_indicator.tscn"), + SectorData.SectorType.RepairSector: + preload("res://game/area_map/indicators/sectors/repair_sector_indicator.tscn"), + SectorData.SectorType.DebrisSector: + preload("res://game/area_map/indicators/sectors/debris_sector_indicator.tscn"), + SectorData.SectorType.StartSector: + preload("res://game/area_map/indicators/sectors/start_sector_indicator.tscn"), + SectorData.SectorType.BossSector: + preload("res://game/area_map/indicators/sectors/boss_sector_indicator.tscn"), +} +const PASSAGE_SCENES : Dictionary[PassageData.PassageAngle, PackedScene] = { + PassageData.PassageAngle.Minus45Grad: + preload("res://game/area_map/indicators/passages/minus_45_grad_passage_indicator.tscn"), + PassageData.PassageAngle.Minus26Grad: + preload("res://game/area_map/indicators/passages/minus_26_grad_passage_indicator.tscn"), + PassageData.PassageAngle.ZeroGrad: + preload("res://game/area_map/indicators/passages/zero_grad_passage_indicator.tscn"), + PassageData.PassageAngle.Plus26Grad: + preload("res://game/area_map/indicators/passages/plus_26_grad_passage_indicator.tscn"), + PassageData.PassageAngle.Plus45Grad: + preload("res://game/area_map/indicators/passages/plus_45_grad_passage_indicator.tscn"), +} + +const CURRENT_SECTOR_INDICATOR = \ + preload("res://game/area_map/indicators/current_sector_indicator.tscn") +const SELECTED_SECTOR_INDICATOR = \ + preload("res://game/area_map/indicators/selected_sector_indicator.tscn") + + +var area_data : AreaData = null: + set = _set_area_data + +var current_sector: SectorData = null: + set = _set_current_sector + +var selected_sector: SectorData = null: + set = _set_selected_sector + +var sector_positions : Dictionary[SectorData, Vector2] = {} + +var test_rng : RandomNumberGenerator = RandomNumberGenerator.new() + + +@onready var passages_node : Node2D = $Passages +@onready var sectors_node : Node2D = $Sectors + +@onready var current_sector_indicator : CurrentSectorIndicator = $CurrentSectorIndicator +@onready var selected_sector_indicator : SelectedSectorIndicator = $SelectedSectorIndicator + +@onready var test_area_generator : AreaGenerator = $TestAreaGenerator + + +func _ready() -> void: + area_data = test_area_generator.generate(4) + test_rng.seed = 0 + current_sector = _get_random_sector() + selected_sector = _get_random_sector() + + +func _set_area_data(data: AreaData) -> void: + area_data = data + + _fill_map() + + +func _get_random_sector() -> SectorData: + if area_data == null: return null + if area_data.stages.size() == 0: return null + + var stage_index := test_rng.randf_range(0, area_data.stages.size() - 1) + var stage := area_data.stages[stage_index] + + if stage.sectors.size() == 0: return null + var sector_index := test_rng.randf_range(0, stage.sectors.size() - 1) + + return stage.sectors[sector_index] + + +func _fill_sector_positions() -> void: + sector_positions.clear() + + if area_data == null: return + + for stage_index in area_data.stages.size(): + var stage := area_data.stages[stage_index] + + for sector_index in stage.sectors.size(): + var sector := stage.sectors[sector_index] + + var sector_position := _get_sector_position( + stage_index, sector_index, stage.sectors.size() + ) + sector_positions[sector] = sector_position + + +func _fill_map() -> void: + _clear_node(sectors_node) + _clear_node(passages_node) + _fill_sector_positions() + + if area_data == null: return + + for stage in area_data.stages: + _fill_sectors(stage) + + +func _fill_sectors(stage: StageData) -> void: + for sector_index in stage.sectors.size(): + var sector := stage.sectors[sector_index] + + if not sector in sector_positions: continue + + var sector_position := sector_positions[sector] + + _fill_passages(sector.next_passages, sector_position) + + if not sector.type in SECTOR_SCENES: continue + + var scene := SECTOR_SCENES[sector.type] + var sector_instance : AbstractSectorIndicator = scene.instantiate() + sector_instance.position = sector_position + sectors_node.add_child(sector_instance) + + +func _fill_passages(passages: Array[PassageData], sector_position: Vector2) -> void: + for passage in passages: + if not passage.angle in PASSAGE_SCENES: continue + + var scene := PASSAGE_SCENES[passage.angle] + var passage_instance : AbstractPassageIndicator = scene.instantiate() + passage_instance.position = sector_position + passages_node.add_child(passage_instance) + + +func _get_sector_position(stage_index: int, sector_index: int, sector_count: int) -> Vector2: + var sector_position : Vector2 + + sector_position.x = SECTOR_XS[stage_index] + match sector_count: + 1: + sector_position.y = SECTOR_YS_FOR_ONE[sector_index] + 2: + sector_position.y = SECTOR_YS_FOR_TWO[sector_index] + 3: + sector_position.y = SECTOR_YS_FOR_THREE[sector_index] + + return sector_position + + +func _clear_node(node: Node) -> void: + for n in node.get_children(): + node.remove_child(n) + n.queue_free() + + +func _set_current_sector(sector: SectorData) -> void: + if not sector in sector_positions: + current_sector_indicator.hide() + return + + current_sector = sector + + var sector_position := sector_positions[sector] + current_sector_indicator.position = sector_position + CURRENT_SECTOR_INDICATOR_OFFSET + + current_sector_indicator.show() + + +func _set_selected_sector(sector: SectorData) -> void: + if not sector in sector_positions: + selected_sector_indicator.hide() + return + + selected_sector = sector + + var sector_position := sector_positions[sector] + selected_sector_indicator.position = sector_position + + selected_sector_indicator.show() diff --git a/game/area_map/area_map.gd.uid b/game/area_map/area_map.gd.uid new file mode 100644 index 0000000..782e042 --- /dev/null +++ b/game/area_map/area_map.gd.uid @@ -0,0 +1 @@ +uid://bk8qn34w5cqmj diff --git a/game/area_map/area_map.tscn b/game/area_map/area_map.tscn new file mode 100644 index 0000000..40df8d9 --- /dev/null +++ b/game/area_map/area_map.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=5 format=3 uid="uid://dqkp7nlhnb7sh"] + +[ext_resource type="Script" uid="uid://bk8qn34w5cqmj" path="res://game/area_map/area_map.gd" id="1_hkcry"] +[ext_resource type="PackedScene" uid="uid://c4l1cv3o25lhv" path="res://game/world/generators/area_generator.tscn" id="2_0o0gd"] +[ext_resource type="PackedScene" uid="uid://b8qwok6v44la" path="res://game/area_map/indicators/current_sector_indicator.tscn" id="2_fx4fd"] +[ext_resource type="PackedScene" uid="uid://bwru7i7xetjth" path="res://game/area_map/indicators/selected_sector_indicator.tscn" id="3_oxnrh"] + +[node name="AreaMap" type="Node2D"] +script = ExtResource("1_hkcry") + +[node name="Passages" type="Node2D" parent="."] + +[node name="Sectors" type="Node2D" parent="."] + +[node name="CurrentSectorIndicator" parent="." instance=ExtResource("2_fx4fd")] + +[node name="SelectedSectorIndicator" parent="." instance=ExtResource("3_oxnrh")] + +[node name="TestAreaGenerator" parent="." instance=ExtResource("2_0o0gd")] diff --git a/game/area_map/indicators/absctact_passage_indicator.gd b/game/area_map/indicators/absctact_passage_indicator.gd new file mode 100644 index 0000000..cacb1ea --- /dev/null +++ b/game/area_map/indicators/absctact_passage_indicator.gd @@ -0,0 +1,15 @@ +class_name AbstractPassageIndicator +extends Node2D + + +@onready var active_texture : Sprite2D = $ActiveTexture +@onready var inactive_texture : Sprite2D = $InactiveTexture + + +func _ready() -> void: + inactive_texture.hide() + + +func set_active(is_active: bool) -> void: + active_texture.visible = is_active + inactive_texture.visible = not is_active diff --git a/game/area_map/indicators/absctact_passage_indicator.gd.uid b/game/area_map/indicators/absctact_passage_indicator.gd.uid new file mode 100644 index 0000000..e52b698 --- /dev/null +++ b/game/area_map/indicators/absctact_passage_indicator.gd.uid @@ -0,0 +1 @@ +uid://d1043b8skqr0j diff --git a/game/area_map/indicators/absctact_passage_indicator.tscn b/game/area_map/indicators/absctact_passage_indicator.tscn new file mode 100644 index 0000000..a1ac3c7 --- /dev/null +++ b/game/area_map/indicators/absctact_passage_indicator.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://b03vje74ld8ms"] + +[ext_resource type="Script" uid="uid://d1043b8skqr0j" path="res://game/area_map/indicators/absctact_passage_indicator.gd" id="1_c886g"] + +[node name="AbsctactPassageIndicator" type="Node2D"] +script = ExtResource("1_c886g") + +[node name="ActiveTexture" type="Sprite2D" parent="."] + +[node name="InactiveTexture" type="Sprite2D" parent="."] diff --git a/game/area_map/indicators/abstract_sector_indicator.gd b/game/area_map/indicators/abstract_sector_indicator.gd new file mode 100644 index 0000000..dcbcc1f --- /dev/null +++ b/game/area_map/indicators/abstract_sector_indicator.gd @@ -0,0 +1,15 @@ +class_name AbstractSectorIndicator +extends Node2D + + +@onready var active_texture : Sprite2D = $ActiveTexture +@onready var inactive_texture : Sprite2D = $InactiveTexture + + +func _ready() -> void: + inactive_texture.hide() + + +func set_active(is_active: bool) -> void: + active_texture.visible = is_active + inactive_texture.visible = not is_active diff --git a/game/area_map/indicators/abstract_sector_indicator.gd.uid b/game/area_map/indicators/abstract_sector_indicator.gd.uid new file mode 100644 index 0000000..777a6be --- /dev/null +++ b/game/area_map/indicators/abstract_sector_indicator.gd.uid @@ -0,0 +1 @@ +uid://br68v5vl7vyd6 diff --git a/game/area_map/indicators/abstract_sector_indicator.tscn b/game/area_map/indicators/abstract_sector_indicator.tscn new file mode 100644 index 0000000..21e06a0 --- /dev/null +++ b/game/area_map/indicators/abstract_sector_indicator.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://bofxdki5oelxe"] + +[ext_resource type="Script" uid="uid://br68v5vl7vyd6" path="res://game/area_map/indicators/abstract_sector_indicator.gd" id="1_mp2r3"] + +[node name="AbstractSectorIndicator" type="Node2D"] +script = ExtResource("1_mp2r3") + +[node name="ActiveTexture" type="Sprite2D" parent="."] + +[node name="InactiveTexture" type="Sprite2D" parent="."] diff --git a/game/area_map/indicators/current_sector_indicator.gd b/game/area_map/indicators/current_sector_indicator.gd new file mode 100644 index 0000000..1467d0d --- /dev/null +++ b/game/area_map/indicators/current_sector_indicator.gd @@ -0,0 +1,12 @@ +class_name CurrentSectorIndicator +extends Node2D + + +const ANIMATION = "animation" + + +@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D + + +func _ready() -> void: + sprite.play(ANIMATION) diff --git a/game/area_map/indicators/current_sector_indicator.gd.uid b/game/area_map/indicators/current_sector_indicator.gd.uid new file mode 100644 index 0000000..1c3e927 --- /dev/null +++ b/game/area_map/indicators/current_sector_indicator.gd.uid @@ -0,0 +1 @@ +uid://yf2bef674enx diff --git a/game/area_map/indicators/current_sector_indicator.tscn b/game/area_map/indicators/current_sector_indicator.tscn new file mode 100644 index 0000000..fac70ce --- /dev/null +++ b/game/area_map/indicators/current_sector_indicator.tscn @@ -0,0 +1,76 @@ +[gd_scene load_steps=12 format=3 uid="uid://b8qwok6v44la"] + +[ext_resource type="Script" uid="uid://yf2bef674enx" path="res://game/area_map/indicators/current_sector_indicator.gd" id="1_7irmv"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_l75qw"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_iqys3"] +atlas = ExtResource("2_l75qw") +region = Rect2(256, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ua7c8"] +atlas = ExtResource("2_l75qw") +region = Rect2(272, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8a5ox"] +atlas = ExtResource("2_l75qw") +region = Rect2(288, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_nmkab"] +atlas = ExtResource("2_l75qw") +region = Rect2(304, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_a5b5h"] +atlas = ExtResource("2_l75qw") +region = Rect2(256, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gekak"] +atlas = ExtResource("2_l75qw") +region = Rect2(272, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_02s10"] +atlas = ExtResource("2_l75qw") +region = Rect2(288, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_do7pi"] +atlas = ExtResource("2_l75qw") +region = Rect2(304, 16, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_2biry"] +animations = [{ +"frames": [{ +"duration": 25.0, +"texture": SubResource("AtlasTexture_iqys3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ua7c8") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8a5ox") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_nmkab") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_a5b5h") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gekak") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_02s10") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_do7pi") +}], +"loop": true, +"name": &"animation", +"speed": 10.0 +}] + +[node name="CurrentSectorIndicator" type="Node2D"] +script = ExtResource("1_7irmv") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +sprite_frames = SubResource("SpriteFrames_2biry") +animation = &"animation" +frame_progress = 0.8128894 diff --git a/game/area_map/indicators/passages/minus_26_grad_passage_indicator.tscn b/game/area_map/indicators/passages/minus_26_grad_passage_indicator.tscn new file mode 100644 index 0000000..215d439 --- /dev/null +++ b/game/area_map/indicators/passages/minus_26_grad_passage_indicator.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://befadmr5b8mij"] + +[ext_resource type="PackedScene" uid="uid://b03vje74ld8ms" path="res://game/area_map/indicators/absctact_passage_indicator.tscn" id="1_6yx0l"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_ihw22"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_dencp"] +atlas = ExtResource("2_ihw22") +region = Rect2(80, 48, 80, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3eblp"] +atlas = ExtResource("2_ihw22") +region = Rect2(240, 48, 80, 48) + +[node name="PassageIndicatorMinus26Grad" instance=ExtResource("1_6yx0l")] + +[node name="ActiveTexture" parent="." index="0"] +position = Vector2(32, -16) +texture = SubResource("AtlasTexture_dencp") + +[node name="InactiveTexture" parent="." index="1"] +position = Vector2(32, -16) +texture = SubResource("AtlasTexture_3eblp") diff --git a/game/area_map/indicators/passages/minus_45_grad_passage_indicator.tscn b/game/area_map/indicators/passages/minus_45_grad_passage_indicator.tscn new file mode 100644 index 0000000..002e5da --- /dev/null +++ b/game/area_map/indicators/passages/minus_45_grad_passage_indicator.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://6wh5paopwa6m"] + +[ext_resource type="PackedScene" uid="uid://b03vje74ld8ms" path="res://game/area_map/indicators/absctact_passage_indicator.tscn" id="1_ejr0u"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_o52wh"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_auxhg"] +atlas = ExtResource("2_o52wh") +region = Rect2(80, 96, 80, 80) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8xe3k"] +atlas = ExtResource("2_o52wh") +region = Rect2(240, 96, 80, 80) + +[node name="PassageIndicatorMinus45Grad" instance=ExtResource("1_ejr0u")] + +[node name="ActiveTexture" parent="." index="0"] +position = Vector2(32, -32) +texture = SubResource("AtlasTexture_auxhg") + +[node name="InactiveTexture" parent="." index="1"] +position = Vector2(32, -32) +texture = SubResource("AtlasTexture_8xe3k") diff --git a/game/area_map/indicators/passages/plus_26_grad_passage_indicator.tscn b/game/area_map/indicators/passages/plus_26_grad_passage_indicator.tscn new file mode 100644 index 0000000..b407b79 --- /dev/null +++ b/game/area_map/indicators/passages/plus_26_grad_passage_indicator.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://chtid8advqc7c"] + +[ext_resource type="PackedScene" uid="uid://b03vje74ld8ms" path="res://game/area_map/indicators/absctact_passage_indicator.tscn" id="1_ke7h2"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_ugcaf"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_o7a4k"] +atlas = ExtResource("2_ugcaf") +region = Rect2(0, 48, 80, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ghd4p"] +atlas = ExtResource("2_ugcaf") +region = Rect2(160, 48, 80, 48) + +[node name="PassageIndicator26Grad" instance=ExtResource("1_ke7h2")] + +[node name="ActiveTexture" parent="." index="0"] +position = Vector2(32, 16) +texture = SubResource("AtlasTexture_o7a4k") + +[node name="InactiveTexture" parent="." index="1"] +position = Vector2(32, 16) +texture = SubResource("AtlasTexture_ghd4p") diff --git a/game/area_map/indicators/passages/plus_45_grad_passage_indicator.tscn b/game/area_map/indicators/passages/plus_45_grad_passage_indicator.tscn new file mode 100644 index 0000000..5330df7 --- /dev/null +++ b/game/area_map/indicators/passages/plus_45_grad_passage_indicator.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://dv68sytyj5bd3"] + +[ext_resource type="PackedScene" uid="uid://b03vje74ld8ms" path="res://game/area_map/indicators/absctact_passage_indicator.tscn" id="1_nk4h4"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_qtofm"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_1wcf5"] +atlas = ExtResource("2_qtofm") +region = Rect2(0, 96, 80, 80) + +[sub_resource type="AtlasTexture" id="AtlasTexture_lqbnh"] +atlas = ExtResource("2_qtofm") +region = Rect2(160, 96, 80, 80) + +[node name="PassageIndicator45Grad" instance=ExtResource("1_nk4h4")] + +[node name="ActiveTexture" parent="." index="0"] +position = Vector2(32, 32) +texture = SubResource("AtlasTexture_1wcf5") + +[node name="InactiveTexture" parent="." index="1"] +position = Vector2(32, 32) +texture = SubResource("AtlasTexture_lqbnh") diff --git a/game/area_map/indicators/passages/zero_grad_passage_indicator.tscn b/game/area_map/indicators/passages/zero_grad_passage_indicator.tscn new file mode 100644 index 0000000..ef5170c --- /dev/null +++ b/game/area_map/indicators/passages/zero_grad_passage_indicator.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://d24hqpbq2yqfn"] + +[ext_resource type="PackedScene" uid="uid://b03vje74ld8ms" path="res://game/area_map/indicators/absctact_passage_indicator.tscn" id="1_q65pt"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_4t74o"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_f73ej"] +atlas = ExtResource("2_4t74o") +region = Rect2(0, 32, 80, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_b8pmf"] +atlas = ExtResource("2_4t74o") +region = Rect2(160, 32, 80, 16) + +[node name="PassageIndicator0Grad" instance=ExtResource("1_q65pt")] + +[node name="ActiveTexture" parent="." index="0"] +position = Vector2(32, 0) +texture = SubResource("AtlasTexture_f73ej") + +[node name="InactiveTexture" parent="." index="1"] +position = Vector2(32, 0) +texture = SubResource("AtlasTexture_b8pmf") diff --git a/game/area_map/indicators/sectors/boss_sector_indicator.tscn b/game/area_map/indicators/sectors/boss_sector_indicator.tscn new file mode 100644 index 0000000..cac6935 --- /dev/null +++ b/game/area_map/indicators/sectors/boss_sector_indicator.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://cf5487fdaju3h"] + +[ext_resource type="PackedScene" uid="uid://bofxdki5oelxe" path="res://game/area_map/indicators/abstract_sector_indicator.tscn" id="1_qx624"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_t7m7p"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_qx624"] +atlas = ExtResource("2_t7m7p") +region = Rect2(80, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_t7m7p"] +atlas = ExtResource("2_t7m7p") +region = Rect2(80, 16, 16, 16) + +[node name="BossSectorIndicator" instance=ExtResource("1_qx624")] + +[node name="ActiveTexture" parent="." index="0"] +texture = SubResource("AtlasTexture_qx624") + +[node name="InactiveTexture" parent="." index="1"] +texture = SubResource("AtlasTexture_t7m7p") diff --git a/game/area_map/indicators/sectors/debris_sector_indicator.tscn b/game/area_map/indicators/sectors/debris_sector_indicator.tscn new file mode 100644 index 0000000..4a4e94b --- /dev/null +++ b/game/area_map/indicators/sectors/debris_sector_indicator.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://dysw7f3fxxdgg"] + +[ext_resource type="PackedScene" uid="uid://bofxdki5oelxe" path="res://game/area_map/indicators/abstract_sector_indicator.tscn" id="1_1il3o"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_yiddm"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_1il3o"] +atlas = ExtResource("2_yiddm") +region = Rect2(48, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yiddm"] +atlas = ExtResource("2_yiddm") +region = Rect2(48, 16, 16, 16) + +[node name="DebrisSectorIndicator" instance=ExtResource("1_1il3o")] + +[node name="ActiveTexture" parent="." index="0"] +texture = SubResource("AtlasTexture_1il3o") + +[node name="InactiveTexture" parent="." index="1"] +texture = SubResource("AtlasTexture_yiddm") diff --git a/game/area_map/indicators/sectors/empty_sector_indicator.tscn b/game/area_map/indicators/sectors/empty_sector_indicator.tscn new file mode 100644 index 0000000..48b9044 --- /dev/null +++ b/game/area_map/indicators/sectors/empty_sector_indicator.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://bmhjspcsdim4a"] + +[ext_resource type="PackedScene" uid="uid://bofxdki5oelxe" path="res://game/area_map/indicators/abstract_sector_indicator.tscn" id="1_ywgpn"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_p04dw"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_ywgpn"] +atlas = ExtResource("2_p04dw") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_p04dw"] +atlas = ExtResource("2_p04dw") +region = Rect2(0, 16, 16, 16) + +[node name="EmptySectorIndicator" instance=ExtResource("1_ywgpn")] + +[node name="ActiveTexture" parent="." index="0"] +texture = SubResource("AtlasTexture_ywgpn") + +[node name="InactiveTexture" parent="." index="1"] +texture = SubResource("AtlasTexture_p04dw") diff --git a/game/area_map/indicators/sectors/repair_sector_indicator.tscn b/game/area_map/indicators/sectors/repair_sector_indicator.tscn new file mode 100644 index 0000000..9faded8 --- /dev/null +++ b/game/area_map/indicators/sectors/repair_sector_indicator.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://c7d6jylti6bea"] + +[ext_resource type="PackedScene" uid="uid://bofxdki5oelxe" path="res://game/area_map/indicators/abstract_sector_indicator.tscn" id="1_5phms"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_e1mcs"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_5phms"] +atlas = ExtResource("2_e1mcs") +region = Rect2(32, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_e1mcs"] +atlas = ExtResource("2_e1mcs") +region = Rect2(32, 16, 16, 16) + +[node name="RepairSectorIndicator" instance=ExtResource("1_5phms")] + +[node name="ActiveTexture" parent="." index="0"] +texture = SubResource("AtlasTexture_5phms") + +[node name="InactiveTexture" parent="." index="1"] +texture = SubResource("AtlasTexture_e1mcs") diff --git a/game/area_map/indicators/sectors/shop_sector_indicator.tscn b/game/area_map/indicators/sectors/shop_sector_indicator.tscn new file mode 100644 index 0000000..343e5ee --- /dev/null +++ b/game/area_map/indicators/sectors/shop_sector_indicator.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://webm7iahkjgh"] + +[ext_resource type="PackedScene" uid="uid://bofxdki5oelxe" path="res://game/area_map/indicators/abstract_sector_indicator.tscn" id="1_4uu3o"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_j10ah"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_4uu3o"] +atlas = ExtResource("2_j10ah") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_j10ah"] +atlas = ExtResource("2_j10ah") +region = Rect2(16, 16, 16, 16) + +[node name="ShopSectorIndicator" instance=ExtResource("1_4uu3o")] + +[node name="ActiveTexture" parent="." index="0"] +texture = SubResource("AtlasTexture_4uu3o") + +[node name="InactiveTexture" parent="." index="1"] +texture = SubResource("AtlasTexture_j10ah") diff --git a/game/area_map/indicators/sectors/start_sector_indicator.tscn b/game/area_map/indicators/sectors/start_sector_indicator.tscn new file mode 100644 index 0000000..0516450 --- /dev/null +++ b/game/area_map/indicators/sectors/start_sector_indicator.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=5 format=3 uid="uid://g05q5dxwktr8"] + +[ext_resource type="PackedScene" uid="uid://bofxdki5oelxe" path="res://game/area_map/indicators/abstract_sector_indicator.tscn" id="1_glpdm"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_37krw"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_glpdm"] +atlas = ExtResource("2_37krw") +region = Rect2(64, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_37krw"] +atlas = ExtResource("2_37krw") +region = Rect2(64, 16, 16, 16) + +[node name="StartSectorIndicator" instance=ExtResource("1_glpdm")] + +[node name="ActiveTexture" parent="." index="0"] +texture = SubResource("AtlasTexture_glpdm") + +[node name="InactiveTexture" parent="." index="1"] +texture = SubResource("AtlasTexture_37krw") diff --git a/game/area_map/indicators/selected_sector_indicator.gd b/game/area_map/indicators/selected_sector_indicator.gd new file mode 100644 index 0000000..f892889 --- /dev/null +++ b/game/area_map/indicators/selected_sector_indicator.gd @@ -0,0 +1,12 @@ +class_name SelectedSectorIndicator +extends Node2D + + +const ANIMATION = "animation" + + +@onready var sprite : AnimatedSprite2D = $AnimatedSprite2D + + +func _ready() -> void: + sprite.play(ANIMATION) diff --git a/game/area_map/indicators/selected_sector_indicator.gd.uid b/game/area_map/indicators/selected_sector_indicator.gd.uid new file mode 100644 index 0000000..5a0515c --- /dev/null +++ b/game/area_map/indicators/selected_sector_indicator.gd.uid @@ -0,0 +1 @@ +uid://d3eqb5341h7y0 diff --git a/game/area_map/indicators/selected_sector_indicator.tscn b/game/area_map/indicators/selected_sector_indicator.tscn new file mode 100644 index 0000000..da14f8b --- /dev/null +++ b/game/area_map/indicators/selected_sector_indicator.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=8 format=3 uid="uid://bwru7i7xetjth"] + +[ext_resource type="Script" uid="uid://d3eqb5341h7y0" path="res://game/area_map/indicators/selected_sector_indicator.gd" id="1_06a3o"] +[ext_resource type="Texture2D" uid="uid://orutjsnhhruf" path="res://images/map.png" id="2_485wc"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_gx6w1"] +atlas = ExtResource("2_485wc") +region = Rect2(128, 0, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_igqhl"] +atlas = ExtResource("2_485wc") +region = Rect2(160, 0, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_5vw2o"] +atlas = ExtResource("2_485wc") +region = Rect2(192, 0, 32, 32) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ih4lp"] +atlas = ExtResource("2_485wc") +region = Rect2(224, 0, 32, 32) + +[sub_resource type="SpriteFrames" id="SpriteFrames_5e44l"] +animations = [{ +"frames": [{ +"duration": 25.0, +"texture": SubResource("AtlasTexture_gx6w1") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_igqhl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_5vw2o") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ih4lp") +}], +"loop": true, +"name": &"animation", +"speed": 10.0 +}] + +[node name="SelectedSectorIndicator" type="Node2D"] +script = ExtResource("1_06a3o") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +sprite_frames = SubResource("SpriteFrames_5e44l") +animation = &"animation" diff --git a/game/world/data/passage_data.gd b/game/world/data/passage_data.gd index d093f89..951a280 100644 --- a/game/world/data/passage_data.gd +++ b/game/world/data/passage_data.gd @@ -2,9 +2,19 @@ class_name PassageData extends Resource +enum PassageAngle { + Minus45Grad, + Minus26Grad, + ZeroGrad, + Plus26Grad, + Plus45Grad, +} + @export var previous_sector : SectorData @export var next_sector : SectorData @export var enemies : Array[EnemyData] = [] @export var seed_value : int = 0 + +@export var angle : PassageAngle = PassageAngle.ZeroGrad diff --git a/game/world/data/sector_data.gd b/game/world/data/sector_data.gd index 59d85d5..7e91d85 100644 --- a/game/world/data/sector_data.gd +++ b/game/world/data/sector_data.gd @@ -2,7 +2,19 @@ class_name SectorData extends Resource +enum SectorType { + EmptySector, + ShopSector, + RepairSector, + DebrisSector, + StartSector, + BossSector, +} + + @export var previous_passages : Array[PassageData] = [] @export var next_passages : Array[PassageData] = [] @export var seed_value : int = 0 + +@export var type : SectorType = SectorType.EmptySector diff --git a/game/world/generators/area_generator.gd b/game/world/generators/area_generator.gd index 47e67d5..258d5fd 100644 --- a/game/world/generators/area_generator.gd +++ b/game/world/generators/area_generator.gd @@ -36,12 +36,22 @@ func generate(seed_value: int) -> AreaData: func _fill_stages(data : AreaData) -> void: for i in range(STAGE_COUNT): - var is_endpoint := i == 0 or i == STAGE_COUNT - 1 + var stage_type := _get_stage_type(i) var seed_value := stage_seed_rng.randi() - var stage := stage_generator.generate(seed_value, is_endpoint) + var stage := stage_generator.generate(seed_value, stage_type) data.stages.append(stage) +func _get_stage_type(stage_index: int) -> StageGenerator.StageType: + match stage_index: + 0: + return StageGenerator.StageType.Start + STAGE_COUNT - 1: + return StageGenerator.StageType.Boss + _: + return StageGenerator.StageType.Inner + + func _fill_passages(data : AreaData) -> void: for i in range(data.stages.size() - 1): var first_stage := data.stages[i] @@ -92,21 +102,43 @@ func _fill_passages_for_unequal_pair( is_sectors_flipped: bool ) -> void: var lesser_size := lesser_sectors.size() - var greater_size := greater_sectors.size() match lesser_size: 1: - for i in range(greater_size): - _connect_sectors(data, lesser_sectors[0], greater_sectors[i], is_sectors_flipped) + _fill_passages_for_unequal_pair_1_to_2_3( + data, lesser_sectors, greater_sectors, is_sectors_flipped + ) 2: - _connect_sectors(data, lesser_sectors[0], greater_sectors[0], is_sectors_flipped) - _connect_sectors(data, lesser_sectors[1], greater_sectors[2], is_sectors_flipped) - if _extra_passage_needed(): - _connect_sectors(data, lesser_sectors[0], greater_sectors[1], is_sectors_flipped) - _connect_sectors(data, lesser_sectors[1], greater_sectors[1], is_sectors_flipped) - else: - var from := 0 if _is_extra_passage_flipped() else 1 - _connect_sectors(data, lesser_sectors[from], greater_sectors[1], is_sectors_flipped) + _fill_passages_for_unequal_pair_2_to_3( + data, lesser_sectors, greater_sectors, is_sectors_flipped + ) + + +func _fill_passages_for_unequal_pair_1_to_2_3( + data : AreaData, + lesser_sectors: Array[SectorData], + greater_sectors: Array[SectorData], + is_sectors_flipped: bool +) -> void: + var greater_size := greater_sectors.size() + for i in range(greater_size): + _connect_sectors(data, lesser_sectors[0], greater_sectors[i], is_sectors_flipped) + + +func _fill_passages_for_unequal_pair_2_to_3( + data : AreaData, + lesser_sectors: Array[SectorData], + greater_sectors: Array[SectorData], + is_sectors_flipped: bool +) -> void: + _connect_sectors(data, lesser_sectors[0], greater_sectors[0], is_sectors_flipped) + _connect_sectors(data, lesser_sectors[1], greater_sectors[2], is_sectors_flipped) + if _extra_passage_needed(): + _connect_sectors(data, lesser_sectors[0], greater_sectors[1], is_sectors_flipped) + _connect_sectors(data, lesser_sectors[1], greater_sectors[1], is_sectors_flipped) + else: + var from := 0 if _is_extra_passage_flipped() else 1 + _connect_sectors(data, lesser_sectors[from], greater_sectors[1], is_sectors_flipped) func _extra_passage_needed() -> bool: diff --git a/game/world/generators/sector_generator.gd b/game/world/generators/sector_generator.gd index 75b9621..eadd576 100644 --- a/game/world/generators/sector_generator.gd +++ b/game/world/generators/sector_generator.gd @@ -2,15 +2,41 @@ class_name SectorGenerator extends Node +const CHANSES_BY_SECTOR_TYPE : Dictionary[SectorData.SectorType, int] = { + SectorData.SectorType.EmptySector: 45, + SectorData.SectorType.ShopSector: 30, + SectorData.SectorType.RepairSector: 20, + SectorData.SectorType.DebrisSector: 5, +} + + var local_seed_rng : RandomNumberGenerator = RandomNumberGenerator.new() +var sector_type_rng : RandomNumberGenerator = RandomNumberGenerator.new() func generate(seed_value: int) -> SectorData: local_seed_rng.seed = seed_value + sector_type_rng.seed = local_seed_rng.randi() var data : SectorData = SectorData.new() data.seed_value = seed_value - + data.type = _get_sector_type() return data + + +func _get_sector_type() -> SectorData.SectorType: + var total_chance := 0 + for type in CHANSES_BY_SECTOR_TYPE: + total_chance += CHANSES_BY_SECTOR_TYPE[type] + + var threshold := sector_type_rng.randi_range(1, total_chance) + + var cumulative := 0 + for type in CHANSES_BY_SECTOR_TYPE: + cumulative += CHANSES_BY_SECTOR_TYPE[type] + if threshold <= cumulative: + return type + + return SectorData.SectorType.EmptySector diff --git a/game/world/generators/stage_generator.gd b/game/world/generators/stage_generator.gd index 92816fb..9da0fa9 100644 --- a/game/world/generators/stage_generator.gd +++ b/game/world/generators/stage_generator.gd @@ -2,6 +2,13 @@ class_name StageGenerator extends Node +enum StageType { + Start, + Inner, + Boss, +} + + const CHANSES_BY_SECTOR_COUNT : Dictionary[int, int] = { 1: 25, 2: 60, @@ -17,7 +24,7 @@ var sector_count_rng : RandomNumberGenerator = RandomNumberGenerator.new() @onready var sector_generator : SectorGenerator = $SectorGenerator -func generate(seed_value: int, is_endpoint: bool = false) -> StageData: +func generate(seed_value: int, type: StageType = StageType.Inner) -> StageData: local_seed_rng.seed = seed_value sector_seed_rng.seed = local_seed_rng.randi() sector_count_rng.seed = local_seed_rng.randi() @@ -25,17 +32,22 @@ func generate(seed_value: int, is_endpoint: bool = false) -> StageData: var data : StageData = StageData.new() data.seed_value = seed_value - _fill_sectors(data, is_endpoint) + _fill_sectors(data, type) return data -func _fill_sectors(data : StageData, is_endpoint: bool = false) -> void: - var sector_count := 1 if is_endpoint else _get_sector_count() +func _fill_sectors(data : StageData, type: StageType = StageType.Inner) -> void: + var sector_count := _get_sector_count() if type == StageType.Inner else 1 for i in sector_count: var seed_value := sector_seed_rng.randi() var sector := sector_generator.generate(seed_value) data.sectors.append(sector) + match type: + StageType.Start: + sector.type = SectorData.SectorType.StartSector + StageType.Boss: + sector.type = SectorData.SectorType.BossSector func _get_sector_count() -> int: