diff --git a/assets/scifi_tilesheet@2.png b/assets/scifi_tilesheet@2.png index c1073a4..4772739 100644 Binary files a/assets/scifi_tilesheet@2.png and b/assets/scifi_tilesheet@2.png differ diff --git a/data/buildings/corruptor.tres b/data/buildings/corruptor.tres new file mode 100644 index 0000000..71ace03 --- /dev/null +++ b/data/buildings/corruptor.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="Building" load_steps=2 format=3 uid="uid://bgwoy0uh2cpvu"] + +[ext_resource type="Script" path="res://scripts/building.gd" id="1_ssts7"] + +[resource] +script = ExtResource("1_ssts7") +atlas_texture_region = Vector2i(0, 0) +name = "" +description = "" +cost = {} diff --git a/data/buildings/hub.tres b/data/buildings/hub.tres new file mode 100644 index 0000000..eb1907a --- /dev/null +++ b/data/buildings/hub.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" script_class="Building" load_steps=5 format=3 uid="uid://c6vv3hyn5sd7o"] + +[ext_resource type="Script" path="res://scripts/expansion_patterns/expansion_square_pattern.gd" id="1_attvt"] +[ext_resource type="Script" path="res://scripts/building.gd" id="1_ssd30"] +[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon_resource.tres" id="2_d8jrj"] + +[sub_resource type="Resource" id="Resource_nqpn0"] +script = ExtResource("1_attvt") + +[resource] +script = ExtResource("1_ssd30") +corruption_pattern = SubResource("Resource_nqpn0") +atlas_texture_region = Vector2i(17, 7) +name = "Hub" +description = "Main cheap base that corrupts a square" +cost = { +ExtResource("2_d8jrj"): 50 +} diff --git a/data/scifi_tileset.tres b/data/scifi_tileset.tres index 575130c..51eb108 100644 --- a/data/scifi_tileset.tres +++ b/data/scifi_tileset.tres @@ -176,7 +176,19 @@ texture_region_size = Vector2i(128, 128) 10:7/0/terrains_peering_bit/top_side = 0 10:7/0/terrains_peering_bit/top_right_corner = 0 11:7/0 = 0 +11:7/0/terrain_set = 0 +11:7/0/terrain = 0 +11:7/0/terrains_peering_bit/right_side = 0 +11:7/0/terrains_peering_bit/left_side = 0 +11:7/0/terrains_peering_bit/top_left_corner = 0 +11:7/0/terrains_peering_bit/top_side = 0 12:7/0 = 0 +12:7/0/terrain_set = 0 +12:7/0/terrain = 0 +12:7/0/terrains_peering_bit/right_side = 0 +12:7/0/terrains_peering_bit/left_side = 0 +12:7/0/terrains_peering_bit/top_side = 0 +12:7/0/terrains_peering_bit/top_right_corner = 0 13:7/0 = 0 14:7/0 = 0 15:7/0 = 0 @@ -185,7 +197,17 @@ texture_region_size = Vector2i(128, 128) 0:8/0 = 0 1:8/0 = 0 2:8/0 = 0 +2:8/0/terrain_set = 0 +2:8/0/terrain = 0 +2:8/0/terrains_peering_bit/right_side = 0 +2:8/0/terrains_peering_bit/bottom_side = 0 +2:8/0/terrains_peering_bit/top_side = 0 3:8/0 = 0 +3:8/0/terrain_set = 0 +3:8/0/terrain = 0 +3:8/0/terrains_peering_bit/bottom_side = 0 +3:8/0/terrains_peering_bit/left_side = 0 +3:8/0/terrains_peering_bit/top_side = 0 4:8/0 = 0 4:8/0/terrain_set = 0 4:8/0/terrain = 0 @@ -244,7 +266,19 @@ texture_region_size = Vector2i(128, 128) 10:8/0/terrains_peering_bit/top_side = 0 10:8/0/terrains_peering_bit/top_right_corner = 0 11:8/0 = 0 +11:8/0/terrain_set = 0 +11:8/0/terrain = 0 +11:8/0/terrains_peering_bit/bottom_side = 0 +11:8/0/terrains_peering_bit/left_side = 0 +11:8/0/terrains_peering_bit/top_left_corner = 0 +11:8/0/terrains_peering_bit/top_side = 0 12:8/0 = 0 +12:8/0/terrain_set = 0 +12:8/0/terrain = 0 +12:8/0/terrains_peering_bit/bottom_side = 0 +12:8/0/terrains_peering_bit/bottom_left_corner = 0 +12:8/0/terrains_peering_bit/left_side = 0 +12:8/0/terrains_peering_bit/top_side = 0 13:8/0 = 0 14:8/0 = 0 15:8/0 = 0 @@ -253,7 +287,17 @@ texture_region_size = Vector2i(128, 128) 0:9/0 = 0 1:9/0 = 0 2:9/0 = 0 +2:9/0/terrain_set = 0 +2:9/0/terrain = 0 +2:9/0/terrains_peering_bit/right_side = 0 +2:9/0/terrains_peering_bit/left_side = 0 +2:9/0/terrains_peering_bit/top_side = 0 3:9/0 = 0 +3:9/0/terrain_set = 0 +3:9/0/terrain = 0 +3:9/0/terrains_peering_bit/right_side = 0 +3:9/0/terrains_peering_bit/bottom_side = 0 +3:9/0/terrains_peering_bit/left_side = 0 4:9/0 = 0 4:9/0/terrain_set = 0 4:9/0/terrain = 0 @@ -308,7 +352,19 @@ texture_region_size = Vector2i(128, 128) 10:9/0/terrains_peering_bit/top_side = 0 10:9/0/terrains_peering_bit/top_right_corner = 0 11:9/0 = 0 +11:9/0/terrain_set = 0 +11:9/0/terrain = 0 +11:9/0/terrains_peering_bit/right_side = 0 +11:9/0/terrains_peering_bit/bottom_right_corner = 0 +11:9/0/terrains_peering_bit/bottom_side = 0 +11:9/0/terrains_peering_bit/top_side = 0 12:9/0 = 0 +12:9/0/terrain_set = 0 +12:9/0/terrain = 0 +12:9/0/terrains_peering_bit/right_side = 0 +12:9/0/terrains_peering_bit/bottom_side = 0 +12:9/0/terrains_peering_bit/top_side = 0 +12:9/0/terrains_peering_bit/top_right_corner = 0 13:9/0 = 0 14:9/0 = 0 15:9/0 = 0 @@ -338,7 +394,19 @@ texture_region_size = Vector2i(128, 128) 9:10/0 = 0 10:10/0 = 0 11:10/0 = 0 +11:10/0/terrain_set = 0 +11:10/0/terrain = 0 +11:10/0/terrains_peering_bit/right_side = 0 +11:10/0/terrains_peering_bit/bottom_side = 0 +11:10/0/terrains_peering_bit/bottom_left_corner = 0 +11:10/0/terrains_peering_bit/left_side = 0 12:10/0 = 0 +12:10/0/terrain_set = 0 +12:10/0/terrain = 0 +12:10/0/terrains_peering_bit/right_side = 0 +12:10/0/terrains_peering_bit/bottom_right_corner = 0 +12:10/0/terrains_peering_bit/bottom_side = 0 +12:10/0/terrains_peering_bit/left_side = 0 13:10/0 = 0 14:10/0 = 0 15:10/0 = 0 diff --git a/scene/world.tscn b/scene/world.tscn index 7aa0d39..d9c3879 100644 --- a/scene/world.tscn +++ b/scene/world.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://m0us5xqa3gnk"] +[gd_scene load_steps=13 format=3 uid="uid://m0us5xqa3gnk"] [ext_resource type="Script" path="res://scripts/world.gd" id="1_yf6q1"] [ext_resource type="Resource" uid="uid://dr00rd4f42jqe" path="res://data/game_resources/gem_resource.tres" id="2_rn4a2"] @@ -7,8 +7,21 @@ [ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon_resource.tres" id="3_pq6ic"] [ext_resource type="Script" path="res://scripts/building_manager.gd" id="4_61js3"] [ext_resource type="Script" path="res://scripts/resource_manager.gd" id="5_k5643"] +[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="5_qhth7"] [ext_resource type="Script" path="res://scripts/gui.gd" id="6_yuatk"] +[sub_resource type="AtlasTexture" id="AtlasTexture_rchmc"] +atlas = ExtResource("5_qhth7") +region = Rect2(1920, 896, 128, 128) + +[sub_resource type="AtlasTexture" id="AtlasTexture_4w4ox"] +atlas = ExtResource("5_qhth7") +region = Rect2(2048, 896, 128, 128) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2smg6"] +atlas = ExtResource("5_qhth7") +region = Rect2(2176, 896, 128, 128) + [node name="world" type="Node2D"] script = ExtResource("1_yf6q1") game_resources = Array[Resource("res://scripts/game_resource.gd")]([ExtResource("2_rn4a2"), ExtResource("3_pq6ic")]) @@ -63,18 +76,82 @@ offset_left = -128.0 offset_bottom = 128.0 grow_horizontal = 0 -[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/GUI/ResourceContainer"] +[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/GUI/ResourceContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 4 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 4 +theme_override_constants/margin_bottom = 4 + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/GUI/ResourceContainer/MarginContainer"] layout_mode = 2 -[node name="ResourcesLabel" type="Label" parent="CanvasLayer/GUI/ResourceContainer/VBoxContainer"] +[node name="ResourcesLabel" type="Label" parent="CanvasLayer/GUI/ResourceContainer/MarginContainer/VBoxContainer"] layout_mode = 2 size_flags_stretch_ratio = 2.0 text = "Resources:" horizontal_alignment = 1 -[node name="GridContainer" type="GridContainer" parent="CanvasLayer/GUI/ResourceContainer/VBoxContainer"] +[node name="GridContainer" type="GridContainer" parent="CanvasLayer/GUI/ResourceContainer/MarginContainer/VBoxContainer"] layout_mode = 2 columns = 2 +[node name="BottomBar" type="PanelContainer" parent="CanvasLayer/GUI"] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/GUI/BottomBar"] +custom_minimum_size = Vector2(0, 128) +layout_mode = 2 + +[node name="BuildContainer" type="GridContainer" parent="CanvasLayer/GUI/BottomBar/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +columns = 2 + +[node name="TextureButton" type="TextureButton" parent="CanvasLayer/GUI/BottomBar/HBoxContainer/BuildContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +texture_normal = SubResource("AtlasTexture_rchmc") +ignore_texture_size = true +stretch_mode = 5 + +[node name="TextureButton2" type="TextureButton" parent="CanvasLayer/GUI/BottomBar/HBoxContainer/BuildContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +texture_normal = SubResource("AtlasTexture_4w4ox") +ignore_texture_size = true +stretch_mode = 5 + +[node name="TextureButton3" type="TextureButton" parent="CanvasLayer/GUI/BottomBar/HBoxContainer/BuildContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +texture_normal = SubResource("AtlasTexture_2smg6") +ignore_texture_size = true +stretch_mode = 5 + +[node name="DetailsPanel" type="PanelContainer" parent="CanvasLayer/GUI/BottomBar/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 3.0 + +[node name="Label" type="Label" parent="CanvasLayer/GUI/BottomBar/HBoxContainer/DetailsPanel"] +layout_mode = 2 +text = "Item details here: +other info here too" + +[node name="Spacer" type="Control" parent="CanvasLayer/GUI/BottomBar/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 2.0 + [connection signal="changed_resource" from="ResourceManager" to="CanvasLayer/GUI" method="_on_resource_manager_changed_resource"] [connection signal="timeout" from="ResourceManager/Timer" to="ResourceManager" method="_on_timer_timeout"] diff --git a/scripts/Base.gd b/scripts/Base.gd index 232afbf..62c340b 100644 --- a/scripts/Base.gd +++ b/scripts/Base.gd @@ -1,25 +1,25 @@ extends Node2D class_name Base -@export var corruption_pattern: ExpansionBase +@export var building_data: Building @export var world: World @onready var expand_timer: Timer = $ExpandTimer var grid_loc: Vector2i - +#Vector2i(17,7) var corruption_tiles: Array[Vector2i] = [] func _ready() -> void: grid_loc = world.grid_location(position) - world.change_location_data(grid_loc, Constants.TilemapLayers.BUILDINGS, Vector2i(17,7)) + world.change_location_data(grid_loc, Constants.TilemapLayers.BUILDINGS, building_data.atlas_texture_region) corruption_tiles.append(grid_loc) world.corrupt_location(grid_loc) + building_data.corruption_pattern.expansion_finished.connect(on_corruption_finished) func _on_expand_timer_timeout() -> void: - var corrupt_tile: Vector2i = corruption_pattern.expand_next_tile() + grid_loc - if corrupt_tile: - corruption_tiles.append(corrupt_tile) - world.corrupt_location(corrupt_tile) + var corrupt_tile: Vector2i = building_data.corruption_pattern.expand_next_tile() + grid_loc + corruption_tiles.append(corrupt_tile) + world.corrupt_location(corrupt_tile) func on_corruption_finished() -> void: expand_timer.stop() diff --git a/scripts/building.gd b/scripts/building.gd new file mode 100644 index 0000000..28c3b77 --- /dev/null +++ b/scripts/building.gd @@ -0,0 +1,8 @@ +class_name Building +extends Resource + +@export var corruption_pattern: ExpansionBase +@export var atlas_texture_region: Vector2i +@export var name: String +@export var description: String +@export var cost: Dictionary diff --git a/scripts/building_manager.gd b/scripts/building_manager.gd index 9fd6035..7bfe73f 100644 --- a/scripts/building_manager.gd +++ b/scripts/building_manager.gd @@ -2,13 +2,13 @@ extends Node2D @onready var world: World = $".." var base = preload("res://scene/base.tscn") +var building = preload("res://data/buildings/hub.tres") func _unhandled_input(event): if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT: var build: Base = base.instantiate() build.position = get_global_mouse_position() build.world = world - build.corruption_pattern = ExpansionSquarePattern.new() - build.corruption_pattern.expansion_finished.connect(build.on_corruption_finished) + build.building_data = building.duplicate(true) add_child(build) #world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2)) diff --git a/scripts/expansion_patterns/expansion_random_pattern_large.gd b/scripts/expansion_patterns/expansion_random_pattern_large.gd new file mode 100644 index 0000000..7333b25 --- /dev/null +++ b/scripts/expansion_patterns/expansion_random_pattern_large.gd @@ -0,0 +1,18 @@ +class_name ExpansionRandomPatternLarge extends ExpansionBase + +const EXPANSION_DISTANCE: int = 8 + +var expansion_tiles: Array[Vector2i] = [] + +func expand_next_tile() -> Vector2i: + if expansion_tiles.is_empty(): + for i in range(EXPANSION_DISTANCE, 0, -1): + expansion_tiles.append(Vector2i(0, i)) + expansion_tiles.append(Vector2i(0, -i)) + expansion_tiles.append(Vector2i(i, 0)) + expansion_tiles.append(Vector2i(-i, 0)) + for ran in range(1, EXPANSION_DISTANCE): + pass + if expansion_tiles.size() == 1: + expansion_finished.emit() + return expansion_tiles.pop_back() diff --git a/scripts/expansion_patterns/expansion_square_pattern.gd b/scripts/expansion_patterns/expansion_square_pattern.gd index c08f0e1..e40d3cf 100644 --- a/scripts/expansion_patterns/expansion_square_pattern.gd +++ b/scripts/expansion_patterns/expansion_square_pattern.gd @@ -15,5 +15,4 @@ func expand_next_tile() -> Vector2i: expansion_tiles.append(Vector2i(x, y)) if expansion_stage == EXPANSION_STAGES and expansion_tiles.size() == 1: expansion_finished.emit() - return expansion_tiles.pop_at(randi_range(0, expansion_tiles.size() - 1))