Compare commits
3 commits
d37c4ec858
...
b0b659acd4
Author | SHA1 | Date | |
---|---|---|---|
b0b659acd4 | |||
e1cdf38dfb | |||
6f56fffb59 |
32 changed files with 220 additions and 75 deletions
|
@ -1,7 +1,7 @@
|
|||
[gd_resource type="Resource" script_class="Constructible" load_steps=5 format=3 uid="uid://dj524jjal1f0n"]
|
||||
[gd_resource type="Resource" script_class="Prototype" load_steps=5 format=3 uid="uid://dj524jjal1f0n"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/constructible.gd" id="1_53h7j"]
|
||||
[ext_resource type="Texture2D" uid="uid://cbtre16ilxte0" path="res://sprites/atlasses/Popekko.png" id="1_x27pp"]
|
||||
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_53h7j"]
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_x27pp"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0h8dd82b3ox5" path="res://scenes/conveyor.tscn" id="2_hinjf"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"]
|
||||
|
|
15
generic/constructibles/dbg_assembler.tres
Normal file
15
generic/constructibles/dbg_assembler.tres
Normal file
|
@ -0,0 +1,15 @@
|
|||
[gd_resource type="Resource" script_class="Constructible" load_steps=5 format=3 uid="uid://yn1iesx30nfu"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_mqcr0"]
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_sh8t1"]
|
||||
[ext_resource type="PackedScene" uid="uid://dfatkxv6n55dw" path="res://scenes/debug_assembler.tscn" id="2_kf3x0"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_kf3x0"]
|
||||
atlas = ExtResource("1_sh8t1")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_mqcr0")
|
||||
scene = ExtResource("2_kf3x0")
|
||||
preview = SubResource("AtlasTexture_kf3x0")
|
||||
metadata/_custom_type_script = "uid://c80sp6f77l5ha"
|
|
@ -18,8 +18,8 @@ config/icon="res://icon.svg"
|
|||
[autoload]
|
||||
|
||||
GuiEventBus="*res://scripts/gui/gui_event_bus.gd"
|
||||
RuntimePlayerData="*res://scripts/runtime_player_data.gd"
|
||||
Registry="*res://scripts/registry.gd"
|
||||
RuntimePlayerData="*res://scripts/autoloads/runtime_player_data.gd"
|
||||
Registry="*res://scripts/autoloads/registry.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://u7thalwj5742"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://u7thalwj5742"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b7du4vul4bmpq" path="res://scenes/player_platform.tscn" id="1_4ia00"]
|
||||
[ext_resource type="Script" uid="uid://db37xmo8ygwhg" path="res://scripts/gui/construction_button.gd" id="2_27lod"]
|
||||
[ext_resource type="Resource" uid="uid://dj524jjal1f0n" path="res://generic/constructibles/conveyor.tres" id="3_2crwe"]
|
||||
[ext_resource type="Script" uid="uid://b4nkk0ndqcto" path="res://scripts/construction_placer.gd" id="4_i7yte"]
|
||||
[ext_resource type="Script" uid="uid://b4nkk0ndqcto" path="res://scripts/placement_manager.gd" id="4_i7yte"]
|
||||
[ext_resource type="PackedScene" uid="uid://bac552xgua68e" path="res://scenes/other_platform.tscn" id="5_mnxrb"]
|
||||
[ext_resource type="Resource" uid="uid://yn1iesx30nfu" path="res://generic/constructibles/dbg_assembler.tres" id="5_ymyc2"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_bq5r8"]
|
||||
length = 0.001
|
||||
|
@ -81,6 +82,24 @@ expand_icon = true
|
|||
script = ExtResource("2_27lod")
|
||||
constructible = ExtResource("3_2crwe")
|
||||
|
||||
[node name="AssemblerButton" type="Button" parent="GUI/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.008
|
||||
anchor_top = 0.086
|
||||
anchor_right = 0.1
|
||||
anchor_bottom = 0.88600004
|
||||
offset_left = 50.904
|
||||
offset_top = -0.01999998
|
||||
offset_right = 50.8
|
||||
offset_bottom = -0.020004272
|
||||
size_flags_horizontal = 3
|
||||
theme_type_variation = &"CRT"
|
||||
icon_alignment = 1
|
||||
expand_icon = true
|
||||
script = ExtResource("2_27lod")
|
||||
constructible = ExtResource("5_ymyc2")
|
||||
|
||||
[node name="Placer" type="Node2D" parent="."]
|
||||
script = ExtResource("4_i7yte")
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://b0h8dd82b3ox5"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cbtre16ilxte0" path="res://sprites/atlasses/Popekko.png" id="1_kqxj7"]
|
||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/construction.gd" id="1_y326v"]
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_kqxj7"]
|
||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_y326v"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"]
|
||||
atlas = ExtResource("1_kqxj7")
|
||||
|
|
16
scenes/debug_assembler.tscn
Normal file
16
scenes/debug_assembler.tscn
Normal file
|
@ -0,0 +1,16 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dfatkxv6n55dw"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_k5y3y"]
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="2_4befw"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xh4eg"]
|
||||
atlas = ExtResource("2_4befw")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[node name="DebugAssembler" type="Node2D"]
|
||||
script = ExtResource("1_k5y3y")
|
||||
dimensions = Rect2i(0, 0, 2, 2)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_xh4eg")
|
||||
offset = Vector2(8, 8)
|
|
@ -1,13 +1,20 @@
|
|||
[gd_scene load_steps=3 format=4 uid="uid://bac552xgua68e"]
|
||||
[gd_scene load_steps=4 format=4 uid="uid://bac552xgua68e"]
|
||||
|
||||
[ext_resource type="TileSet" uid="uid://bv75bu0af04vs" path="res://generic/platform.tres" id="1_fs1oy"]
|
||||
[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/build_zone.gd" id="2_bwire"]
|
||||
[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/placement_zone.gd" id="2_bwire"]
|
||||
[ext_resource type="Script" uid="uid://x5edy155eg0s" path="res://scripts/grid_controller.gd" id="3_qaudu"]
|
||||
|
||||
[node name="OtherPlatform" type="TileMapLayer"]
|
||||
tile_map_data = PackedByteArray("AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAEAAAAAAAIAAAAAAAEAAAAAAAMAAAAAAAEAAAAAAAQAAAAAAAEAAAABAAAAAAAAAAEAAAABAAEAAAAAAAEAAAABAAIAAAAAAAEAAAABAAMAAAAAAAAAAAABAAQAAAAAAAEAAAACAAAAAAAAAAAAAAACAAEAAAAAAAEAAAACAAIAAAAAAAEAAAACAAMAAAAAAAAAAAACAAQAAAAAAAAAAAD/////AAACAAEAAAD//wAAAAAEAAIAAAD//wEAAAAEAAIAAAD//wIAAAAEAAIAAAD//wMAAAAEAAIAAAD//wQAAAAEAAIAAAAAAP//AAABAAIAAAABAP//AAABAAIAAAACAP//AAABAAIAAAADAP//AAADAAEAAAD//wUAAAAEAAEAAAADAAUAAAAFAAEAAAAAAAUAAAAGAAEAAAABAAUAAAAGAAEAAAACAAUAAAAGAAEAAAADAAAAAAAFAAIAAAADAAEAAAAFAAIAAAADAAIAAAAFAAIAAAADAAMAAAAFAAIAAAADAAQAAAAFAAIAAAA=")
|
||||
tile_set = ExtResource("1_fs1oy")
|
||||
|
||||
[node name="BuildZone" type="Marker2D" parent="."]
|
||||
[node name="BuildZone" type="Marker2D" parent="." node_paths=PackedStringArray("grid_controller")]
|
||||
script = ExtResource("2_bwire")
|
||||
building_rect = Rect2(0, 0, 48, 80)
|
||||
grid_controller = NodePath("../EntityHolder")
|
||||
metadata/_custom_type_script = "uid://lw1ya3iu14uf"
|
||||
|
||||
[node name="EntityHolder" type="Node2D" parent="." node_paths=PackedStringArray("building_zone")]
|
||||
script = ExtResource("3_qaudu")
|
||||
building_zone = NodePath("../BuildZone")
|
||||
metadata/_custom_type_script = "uid://x5edy155eg0s"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
[gd_scene load_steps=4 format=4 uid="uid://b7du4vul4bmpq"]
|
||||
|
||||
[ext_resource type="TileSet" uid="uid://bv75bu0af04vs" path="res://generic/platform.tres" id="1_khkq2"]
|
||||
[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/build_zone.gd" id="2_wpmwa"]
|
||||
[ext_resource type="Script" uid="uid://x5edy155eg0s" path="res://scripts/entity_holder.gd" id="3_6hjoe"]
|
||||
[ext_resource type="Script" uid="uid://lw1ya3iu14uf" path="res://scripts/placement_zone.gd" id="2_wpmwa"]
|
||||
[ext_resource type="Script" uid="uid://x5edy155eg0s" path="res://scripts/grid_controller.gd" id="3_6hjoe"]
|
||||
|
||||
[node name="PlayerPlatform" type="Node2D"]
|
||||
|
||||
|
@ -10,9 +10,10 @@
|
|||
tile_map_data = PackedByteArray("AAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAEAAAADAAAAAAAAAAAAAAAEAAAAAAAAAAAA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AcAAAAAAAAAAAARAAAAAAABAAEAAAARAAEAAAABAAEAAAARAAIAAAABAAEAAAARAAMAAAABAAEAAAARAAQAAAABAAEAAAARAAUAAAABAAEAAAARAAYAAAABAAEAAAARAAcAAAABAAEAAAD//wAAAAABAAAAAAD//wEAAAABAAAAAAD//wIAAAABAAAAAAD//wMAAAABAAAAAAD//wQAAAABAAAAAAD//wUAAAABAAAAAAD//wYAAAABAAAAAAD//wcAAAABAAAAAAAAAP//AAAAAAIAAAABAP//AAAAAAIAAAACAP//AAAAAAIAAAADAP//AAAAAAIAAAAEAP//AAAAAAIAAAAFAP//AAAAAAIAAAAGAP//AAAAAAIAAAAHAP//AAAAAAIAAAAIAP//AAAAAAIAAAAJAP//AAAAAAIAAAAKAP//AAAAAAIAAAALAP//AAAAAAIAAAAMAP//AAAAAAIAAAANAP//AAAAAAIAAAAOAP//AAAAAAIAAAAPAP//AAAAAAIAAAAQAP//AAAAAAIAAAD/////AAACAAIAAAARAP//AAADAAIAAAD//wgAAAADAAAAAAARAAgAAAAEAAAAAAAQAAgAAAACAAAAAAAPAAgAAAACAAAAAAAOAAgAAAACAAAAAAANAAgAAAACAAAAAAAMAAgAAAACAAAAAAALAAgAAAACAAAAAAAKAAgAAAACAAAAAAAJAAgAAAACAAAAAAAIAAgAAAACAAAAAAAHAAgAAAACAAAAAAAGAAgAAAACAAAAAAAFAAgAAAACAAAAAAAEAAgAAAACAAAAAAADAAgAAAACAAAAAAACAAgAAAACAAAAAAABAAgAAAACAAAAAAAAAAgAAAACAAAAAAA=")
|
||||
tile_set = ExtResource("1_khkq2")
|
||||
|
||||
[node name="BuildRect" type="Marker2D" parent="."]
|
||||
[node name="BuildRect" type="Marker2D" parent="." node_paths=PackedStringArray("grid_controller")]
|
||||
script = ExtResource("2_wpmwa")
|
||||
building_rect = Rect2(0, 0, 272, 128)
|
||||
grid_controller = NodePath("../EntityHolder")
|
||||
|
||||
[node name="EntityHolder" type="Node2D" parent="." node_paths=PackedStringArray("building_zone")]
|
||||
script = ExtResource("3_6hjoe")
|
||||
|
|
2
scripts/autoloads/registry.gd
Normal file
2
scripts/autoloads/registry.gd
Normal file
|
@ -0,0 +1,2 @@
|
|||
## Global class for runtime
|
||||
extends Node
|
|
@ -1,9 +1,12 @@
|
|||
## Global class for player in-game data
|
||||
|
||||
extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
get_tree().scene_changed.connect(cleanup_runtime_cache)
|
||||
|
||||
## Method to cleanup all data that will be nulled
|
||||
func cleanup_runtime_cache():
|
||||
build_zones.clear()
|
||||
|
||||
var build_zones : Array[BuildZone]
|
||||
var build_zones : Array[PlacementZone]
|
|
@ -1,6 +0,0 @@
|
|||
extends Resource
|
||||
|
||||
class_name Constructible
|
||||
|
||||
@export var scene : PackedScene
|
||||
@export var preview : Texture2D
|
|
@ -1,6 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Construction
|
||||
|
||||
func get_relative(dv : Vector2) -> Construction:
|
||||
return get_parent().get_at(global_position+dv)
|
|
@ -1,22 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name EntityHolder
|
||||
|
||||
const GRID_SIZE : Vector2 = Vector2(16,16)
|
||||
|
||||
@export var building_zone : BuildZone
|
||||
var constructions : Array[Construction]
|
||||
|
||||
func _ready() -> void:
|
||||
constructions.resize(building_zone.get_capacity())
|
||||
|
||||
func add_construction(construction : Construction) -> bool:
|
||||
if constructions[building_zone.indexify_global_point(construction.global_position)]:
|
||||
return false
|
||||
construction.reparent(self)
|
||||
construction.global_position = building_zone.get_placement_position(construction.global_position)
|
||||
constructions[building_zone.indexify_global_point(construction.global_position)] = construction
|
||||
return true
|
||||
|
||||
func get_at(point : Vector2):
|
||||
return constructions[building_zone.indexify_global_point(point)]
|
6
scripts/globals.gd
Normal file
6
scripts/globals.gd
Normal file
|
@ -0,0 +1,6 @@
|
|||
@abstract
|
||||
extends Object
|
||||
|
||||
class_name Globals
|
||||
|
||||
const GRID_SIZE : Vector2 = Vector2(16,16)
|
1
scripts/globals.gd.uid
Normal file
1
scripts/globals.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bnmjkc8vfd7mo
|
42
scripts/grid_controller.gd
Normal file
42
scripts/grid_controller.gd
Normal file
|
@ -0,0 +1,42 @@
|
|||
extends Node2D
|
||||
|
||||
# TODO: Make able to hold multiple placement zones, supporting uniform forms
|
||||
|
||||
## Class that contains all structures of platform
|
||||
|
||||
class_name GridController
|
||||
|
||||
|
||||
## Building zone controller uses for checks and capacity
|
||||
@export var building_zone : PlacementZone
|
||||
|
||||
## Internal structure storage
|
||||
var structures : Array[Structure]
|
||||
|
||||
func _ready() -> void:
|
||||
structures.resize(building_zone.get_capacity())
|
||||
|
||||
## Tries to add structure to its internal storage [br]
|
||||
## Returns false if has colliding structures
|
||||
func add_structure(structure : Structure) -> bool:
|
||||
var structure_dp = structure.get_dimension_points()
|
||||
for point in structure_dp:
|
||||
if structures[building_zone.indexify_global_point(structure.global_position + point)]:
|
||||
return false
|
||||
structure.reparent(self)
|
||||
structure.global_position = building_zone.get_placement_position(structure.global_position)
|
||||
|
||||
for point in structure_dp:
|
||||
structures[building_zone.indexify_global_point(structure.global_position + point)] = structure
|
||||
return true
|
||||
|
||||
## Returns structure at point. [br]
|
||||
## Returns null if no structure is at point
|
||||
func get_at(point : Vector2) -> Structure:
|
||||
var index = building_zone.indexify_global_point(point)
|
||||
if index == -1:
|
||||
return null
|
||||
return structures[index]
|
||||
|
||||
func is_point_occupied(point : Vector2) -> bool:
|
||||
return get_at(point) != null
|
|
@ -1,6 +1,6 @@
|
|||
extends Button
|
||||
|
||||
@export var constructible : Constructible
|
||||
@export var constructible : Prototype
|
||||
|
||||
func _ready() -> void:
|
||||
icon = constructible.preview
|
||||
|
|
|
@ -2,5 +2,5 @@ extends Node
|
|||
|
||||
@warning_ignore_start("unused_signal")
|
||||
|
||||
signal construction_selected(constructible : Constructible)
|
||||
signal construction_placed(constructible : Constructible)
|
||||
signal construction_selected(constructible : Prototype)
|
||||
signal construction_placed(constructible : Prototype)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extends Node2D
|
||||
|
||||
var held_construction : Construction
|
||||
## Currently held structure
|
||||
var held_construction : Structure
|
||||
|
||||
func _ready() -> void:
|
||||
GuiEventBus.construction_selected.connect(on_construction_selected)
|
||||
|
@ -13,13 +14,13 @@ func _input(event: InputEvent) -> void:
|
|||
if zone == null:
|
||||
held_construction.queue_free()
|
||||
else:
|
||||
if zone.get_parent().get_node("EntityHolder").add_construction(held_construction):
|
||||
if held_construction.try_place(zone):
|
||||
held_construction = null
|
||||
|
||||
if event.is_action_pressed("plc_cancel"):
|
||||
held_construction.queue_free()
|
||||
|
||||
func on_construction_selected(constructible : Constructible):
|
||||
func on_construction_selected(constructible : Prototype):
|
||||
if held_construction:
|
||||
held_construction.queue_free()
|
||||
held_construction = constructible.scene.instantiate()
|
||||
|
@ -27,16 +28,17 @@ func on_construction_selected(constructible : Constructible):
|
|||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if held_construction != null:
|
||||
var mouse_pos = get_global_mouse_position()
|
||||
var zone = try_get_zone(mouse_pos)
|
||||
if zone:
|
||||
global_position = zone.get_placement_position(mouse_pos)
|
||||
else:
|
||||
global_position = mouse_pos
|
||||
if held_construction == null:
|
||||
return
|
||||
var mouse_pos = get_global_mouse_position()
|
||||
var zone = try_get_zone(mouse_pos)
|
||||
if zone and held_construction.can_be_placed(zone):
|
||||
global_position = zone.get_placement_position(mouse_pos)
|
||||
else:
|
||||
global_position = mouse_pos
|
||||
|
||||
func try_get_zone(point : Vector2) -> BuildZone:
|
||||
for zone in Registry.build_zones:
|
||||
func try_get_zone(point : Vector2) -> PlacementZone:
|
||||
for zone in RuntimePlayerData.build_zones:
|
||||
if zone.is_global_point_in_zone(point):
|
||||
return zone
|
||||
return null
|
|
@ -4,9 +4,7 @@
|
|||
## Class that helps to manage construction sites
|
||||
extends Marker2D
|
||||
|
||||
class_name BuildZone
|
||||
|
||||
const GRID_SIZE : Vector2 = Vector2(16,16)
|
||||
class_name PlacementZone
|
||||
|
||||
## Rect that used for bounds check and conversions
|
||||
@export var building_rect : Rect2:
|
||||
|
@ -17,9 +15,11 @@ const GRID_SIZE : Vector2 = Vector2(16,16)
|
|||
get:
|
||||
return building_rect
|
||||
|
||||
@export var grid_controller : GridController
|
||||
|
||||
func _ready() -> void:
|
||||
if not Engine.is_editor_hint():
|
||||
Registry.build_zones.append(self)
|
||||
RuntimePlayerData.build_zones.append(self)
|
||||
|
||||
func _draw() -> void:
|
||||
if Engine.is_editor_hint() and EditorInterface.get_inspector().get_edited_object() == self:
|
||||
|
@ -37,7 +37,7 @@ func is_global_point_in_zone(point: Vector2) -> bool:
|
|||
func indexify_point(point : Vector2) -> int:
|
||||
if is_point_in_zone(point) == false:
|
||||
return -1
|
||||
return int(point.x) / int(GRID_SIZE.x) + int(building_rect.size.x/GRID_SIZE.x)*(int(point.y) / int(GRID_SIZE.y))
|
||||
return int(point.x) / int(Globals.GRID_SIZE.x) + int(building_rect.size.x/Globals.GRID_SIZE.x)*(int(point.y) / int(Globals.GRID_SIZE.y))
|
||||
|
||||
## Returns index of point (global coordinates) to be used in array
|
||||
func indexify_global_point(point : Vector2) -> int:
|
||||
|
@ -45,7 +45,7 @@ func indexify_global_point(point : Vector2) -> int:
|
|||
|
||||
## Inverses indexification of point, returning snapped position
|
||||
func inverse_index(index: int) -> Vector2:
|
||||
return to_global(Vector2(index%int(building_rect.size.x/GRID_SIZE.x)*GRID_SIZE.x,index / int(building_rect.size.x/GRID_SIZE.x) * GRID_SIZE.y))
|
||||
return to_global(Vector2(index%int(building_rect.size.x/Globals.GRID_SIZE.x)*Globals.GRID_SIZE.x,index / int(building_rect.size.x/Globals.GRID_SIZE.x) * Globals.GRID_SIZE.y))
|
||||
|
||||
## Returns snapped position of point (global coordinates).
|
||||
## Equivalent of [code]
|
||||
|
@ -54,8 +54,8 @@ func inverse_index(index: int) -> Vector2:
|
|||
func get_placement_position(point : Vector2) -> Vector2:
|
||||
if is_global_point_in_zone(point) == false:
|
||||
return Vector2.ZERO
|
||||
return to_global((to_local(point) / GRID_SIZE).floor()*GRID_SIZE + GRID_SIZE/2.0)
|
||||
return to_global((to_local(point) / Globals.GRID_SIZE).floor()*Globals.GRID_SIZE + Globals.GRID_SIZE/2.0)
|
||||
|
||||
## Returns capacity of building zone to be used in the array
|
||||
func get_capacity() -> int:
|
||||
return int(building_rect.size.x/GRID_SIZE.x)*int(building_rect.size.y/GRID_SIZE.y)
|
||||
return int(building_rect.size.x/Globals.GRID_SIZE.x)*int(building_rect.size.y/Globals.GRID_SIZE.y)
|
11
scripts/prototype.gd
Normal file
11
scripts/prototype.gd
Normal file
|
@ -0,0 +1,11 @@
|
|||
extends Resource
|
||||
|
||||
## Player instantiatable resource
|
||||
|
||||
class_name Prototype
|
||||
|
||||
## Scene to instantiate
|
||||
@export var scene : PackedScene
|
||||
|
||||
## UI Preview
|
||||
@export var preview : Texture2D
|
|
@ -1 +0,0 @@
|
|||
extends Node
|
55
scripts/structure.gd
Normal file
55
scripts/structure.gd
Normal file
|
@ -0,0 +1,55 @@
|
|||
@tool
|
||||
extends Node2D
|
||||
|
||||
## Game object that interact with other structures in its grid space
|
||||
class_name Structure
|
||||
|
||||
## Dimensions of structure in grid tiles
|
||||
@export var dimensions : Rect2i = Rect2i(0,0,1,1):
|
||||
set(value):
|
||||
dimensions = value
|
||||
if Engine.is_editor_hint():
|
||||
queue_redraw()
|
||||
get:
|
||||
return dimensions
|
||||
|
||||
## Debug draw of points
|
||||
func _draw() -> void:
|
||||
if Engine.is_editor_hint():
|
||||
for x in range(dimensions.size.x):
|
||||
for y in range(dimensions.size.y):
|
||||
draw_circle((dimensions.position+Vector2i(x,y)) * Vector2i(Globals.GRID_SIZE),2,Color.AQUA)
|
||||
|
||||
## Get structure at tile coordinates relative to this structure [br]
|
||||
## dv : Vector2 - get position in tiles [br]
|
||||
func get_relative(dv : Vector2) -> Structure:
|
||||
return get_parent().get_at(global_position+dv*Globals.GRID_SIZE)
|
||||
|
||||
## Check structure is in zone and does not collide with any other structures [br]
|
||||
## Returns true if structure is in zone and does not collide with any other structure [br]
|
||||
## Returns false if structure is not in zone or does not collide with any other structure
|
||||
func can_be_placed(zone : PlacementZone) -> bool:
|
||||
for dp in get_dimension_points():
|
||||
var point = global_position + dp
|
||||
if zone.is_global_point_in_zone(point) == false:
|
||||
return false
|
||||
if zone.grid_controller.is_point_occupied(point):
|
||||
return false
|
||||
return true
|
||||
|
||||
## Tries to place structure in zone's grid controller
|
||||
## Returns false if structure is not in zone or collides with any structure
|
||||
func try_place(zone : PlacementZone) -> bool:
|
||||
if can_be_placed(zone) == false:
|
||||
return false
|
||||
|
||||
return zone.grid_controller.add_structure(self)
|
||||
|
||||
## Returns array of integer points in dimensions
|
||||
func get_dimension_points() -> Array[Vector2]:
|
||||
var result : Array[Vector2] = []
|
||||
result.resize(dimensions.size.x*dimensions.size.y)
|
||||
for x in range(dimensions.size.x):
|
||||
for y in range(dimensions.size.y):
|
||||
result[x + y * dimensions.size.x] = (Vector2(x,y)*Globals.GRID_SIZE + Vector2(dimensions.position))
|
||||
return result
|
Binary file not shown.
Before Width: | Height: | Size: 948 B After Width: | Height: | Size: 1.1 KiB |
|
@ -2,7 +2,7 @@
|
|||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cbtre16ilxte0"
|
||||
uid="uid://dinyjq8853usn"
|
||||
path="res://.godot/imported/Popekko.png-5c34a5f2a8c85fcf59453310fa6553d9.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue