2024-09-09 17:46:51 +00:00
|
|
|
extends TileMap
|
|
|
|
|
2024-09-10 01:34:30 +00:00
|
|
|
var GridSize = 33
|
2024-09-09 17:46:51 +00:00
|
|
|
var Dic = {}
|
2024-09-09 17:55:23 +00:00
|
|
|
var Building_Mode: bool = false
|
2024-09-09 17:46:51 +00:00
|
|
|
|
2024-09-10 01:34:30 +00:00
|
|
|
func generate_percentage(percentages: Array):
|
|
|
|
var array_length = 0
|
|
|
|
for percentage in percentages.size():
|
|
|
|
if percentages[percentage] < 0:
|
|
|
|
percentages[percentage] = 0
|
|
|
|
array_length += percentages[percentage]
|
|
|
|
|
|
|
|
var arr: Array
|
|
|
|
arr.resize(array_length)
|
|
|
|
var sum = 0
|
|
|
|
for percentage in percentages.size():
|
|
|
|
for num in percentages[percentage]:
|
|
|
|
arr[num + sum] = percentage
|
|
|
|
sum += percentages[percentage]
|
|
|
|
return arr[randi()%array_length] + 1
|
|
|
|
|
|
|
|
func abs(num: int):
|
|
|
|
if num < 0:
|
|
|
|
num = -num
|
|
|
|
return num
|
|
|
|
|
2024-09-09 17:46:51 +00:00
|
|
|
func _ready():
|
|
|
|
for x in GridSize:
|
|
|
|
for y in GridSize:
|
2024-09-10 01:34:30 +00:00
|
|
|
var layer_number: int
|
|
|
|
var x_value: int = abs(GridSize/2 - x)
|
|
|
|
var y_value: int = abs(GridSize/2 - y)
|
|
|
|
var max_value: int = maxi(x_value, y_value)
|
|
|
|
match max_value:
|
|
|
|
16,15:
|
|
|
|
layer_number = 1
|
|
|
|
14:
|
|
|
|
layer_number = generate_percentage([3,1])
|
|
|
|
13:
|
|
|
|
layer_number = generate_percentage([2,1])
|
|
|
|
12:
|
|
|
|
layer_number = generate_percentage([1,1])
|
|
|
|
11:
|
|
|
|
layer_number = generate_percentage([1,2,1])
|
|
|
|
10:
|
|
|
|
layer_number = generate_percentage([0,3,2])
|
|
|
|
9:
|
|
|
|
layer_number = generate_percentage([0,1,1])
|
|
|
|
8:
|
|
|
|
layer_number = generate_percentage([0,1,2,1])
|
|
|
|
7:
|
|
|
|
layer_number = generate_percentage([0,0,3,2])
|
|
|
|
6:
|
|
|
|
layer_number = generate_percentage([0,0,1,1])
|
|
|
|
5:
|
|
|
|
layer_number = generate_percentage([0,0,1,2,1])
|
|
|
|
4:
|
|
|
|
layer_number = generate_percentage([0,0,0,3,2])
|
|
|
|
3:
|
|
|
|
layer_number = generate_percentage([0,0,0,1,1])
|
|
|
|
2:
|
|
|
|
layer_number = generate_percentage([0,0,0,1,2])
|
|
|
|
1,0:
|
|
|
|
layer_number = 5
|
|
|
|
print("x- ",x," y- ",y," layer- ",layer_number)
|
|
|
|
for layer in layer_number:
|
2024-09-12 02:40:54 +00:00
|
|
|
set_cell(layer, Vector2(x, y), 2, Vector2i(1, 1), 0)
|
2024-09-09 17:46:51 +00:00
|
|
|
Dic[str(Vector2(x,y))] = {
|
2024-09-10 01:34:30 +00:00
|
|
|
"Layer": layer_number,
|
2024-09-09 17:46:51 +00:00
|
|
|
"Placed": false
|
|
|
|
}
|
2024-09-10 01:34:30 +00:00
|
|
|
|
2024-09-09 17:46:51 +00:00
|
|
|
func _process(delta):
|
2024-09-09 17:55:23 +00:00
|
|
|
if Building_Mode:
|
|
|
|
var tile = local_to_map(get_global_mouse_position())
|
|
|
|
|
|
|
|
for x in GridSize:
|
|
|
|
for y in GridSize:
|
|
|
|
if !Dic[str(Vector2(x,y))].get("Placed"):
|
2024-09-10 01:34:30 +00:00
|
|
|
erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y))
|
2024-09-09 17:55:23 +00:00
|
|
|
|
|
|
|
if Dic.has(str(tile)):
|
2024-09-10 01:34:30 +00:00
|
|
|
set_cell(Dic[str(tile)].get("Layer"), tile, 1, Vector2i(0,0), 0)
|
2024-09-09 17:55:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_mouse_handler_clicked():
|
2024-09-09 18:19:38 +00:00
|
|
|
if Building_Mode:
|
|
|
|
var tile = local_to_map(get_global_mouse_position())
|
|
|
|
Dic[str(tile)]["Placed"] = true
|
2024-09-09 17:55:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_mouse_handler_rclicked():
|
2024-09-09 18:19:38 +00:00
|
|
|
Building_Mode = !Building_Mode
|
|
|
|
for x in GridSize:
|
|
|
|
for y in GridSize:
|
|
|
|
if !Dic[str(Vector2(x,y))].get("Placed"):
|
2024-09-10 01:34:30 +00:00
|
|
|
erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y))
|