4 Commits

25 changed files with 396 additions and 377 deletions

View File

@@ -1,19 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://c4i2x2n7xckcw"]
[ext_resource type="Script" path="res://label.gd" id="1_a6v74"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
text = "
"
script = ExtResource("1_a6v74")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 668 B

View File

@@ -1,34 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://brldhixjky0yu"
path="res://.godot/imported/Heart.png-30a5ad9a510a2f0aa8e7d98f371b9c70.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/Heart.png"
dest_files=["res://.godot/imported/Heart.png-30a5ad9a510a2f0aa8e7d98f371b9c70.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 662 B

View File

@@ -1,34 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c3ddbx3lnur65"
path="res://.godot/imported/Iconary.png-bab435acf0bd8e9d2f447ff1d2b59e76.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/Iconary.png"
dest_files=["res://.godot/imported/Iconary.png-bab435acf0bd8e9d2f447ff1d2b59e76.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -1,43 +0,0 @@
[gd_scene format=3 uid="uid://xodvne8kl7ek"]
[node name="Buttons" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="NULL" type="Button" parent="."]
z_index = 1025
offset_left = 932.0
offset_right = 1024.0
offset_bottom = 31.0
text = "Убрать
"
[node name="Demolish" type="Button" parent="."]
z_index = 1025
offset_left = 932.0
offset_top = 38.0
offset_right = 1024.0
offset_bottom = 69.0
text = "Демонтаж
"
[node name="Construct" type="Button" parent="."]
z_index = 1025
offset_left = 911.0
offset_top = 75.0
offset_right = 1024.0
offset_bottom = 106.0
text = "Конструкция
"
[node name="Build" type="Button" parent="."]
z_index = 1025
offset_left = 932.0
offset_top = 113.0
offset_right = 1024.0
offset_bottom = 144.0
text = "Строить"

View File

@@ -1,5 +0,0 @@
extends Button
# Called when the node enters the scene tree for the first time.
func _ready() -> void:

View File

@@ -1,12 +0,0 @@
extends Label
var energyLvl : float = 100.0
var time = 0.0
func addTIme(delta: float) -> void:
$Timer.new()
func _on_timer_timeout() -> void:
if (time == 0.0):
energyLvl -= 1.0

View File

@@ -1,14 +0,0 @@
extends Label
var max_energy = 100
var count_time = 0
var str_max_energy
func _process(delta: float) -> void:
$Label.text = max_energy
count_time += delta
if (count_time >= 60):
count_time = 0
if max_energy > 0:
max_energy -= 1
$Label.text = max_energy

14
menu.gd
View File

@@ -1,14 +0,0 @@
extends Control
func _on_play_pressed() -> void:
get_tree().change_scene_to_file("res://world.tscn")
func _on_settings_pressed() -> void:
get_tree().change_scene_to_file("res://options_menu.tscn")
func _on_quit_game_pressed() -> void:
get_tree().quit()

View File

@@ -1,40 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://dp6pttsbfm0f1"]
[ext_resource type="Script" path="res://menu.gd" id="1_a0bq7"]
[node name="menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_a0bq7")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="Play" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Play"
[node name="Settings" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Options"
[node name="Quit Game" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Quit game"
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(43, 55)
zoom = Vector2(2, 2)
[connection signal="pressed" from="MarginContainer/VBoxContainer/Play" to="." method="_on_play_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/Settings" to="." method="_on_settings_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/Quit Game" to="." method="_on_quit_game_pressed"]

30
npc/npc.gd Normal file
View File

@@ -0,0 +1,30 @@
class_name NPC
extends Node2D
var id_path: Array[Vector2i]
func is_walking() -> bool:
return not id_path.is_empty()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
randomize()
$Sprite2D.set_nation(randi()%$Sprite2D.Nations.max)
set_spacesuit(false)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
if id_path.is_empty(): return
var target_pos = Vector2(id_path.front()*World.tile_size)
global_position = global_position.move_toward(target_pos, 1)
if global_position == target_pos:
id_path.pop_front()
func set_spacesuit(suit: bool) -> void:
$Sprite2D.set_spacesuit(suit)

19
npc/npc.tscn Normal file
View File

@@ -0,0 +1,19 @@
[gd_scene load_steps=5 format=3 uid="uid://cxueg5xm4buqk"]
[ext_resource type="Script" path="res://npc/npc.gd" id="1_m82ir"]
[ext_resource type="Texture2D" uid="uid://bhpnk3olpquth" path="res://assets/moonnauts.png" id="1_vgeae"]
[ext_resource type="Script" path="res://npc/sprite_2d.gd" id="2_jtl2q"]
[sub_resource type="AtlasTexture" id="AtlasTexture_2v0ml"]
atlas = ExtResource("1_vgeae")
region = Rect2(0, 0, 16, 16)
[node name="npc" type="Node2D"]
z_index = 32
z_as_relative = false
script = ExtResource("1_m82ir")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = SubResource("AtlasTexture_2v0ml")
centered = false
script = ExtResource("2_jtl2q")

27
npc/sprite_2d.gd Normal file
View File

@@ -0,0 +1,27 @@
extends Sprite2D
enum Nations {
ru = 0,
arab = 1,
chi = 2,
max,
}
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func set_spacesuit(suit: bool) -> void:
var atlas: AtlasTexture = texture
if suit: atlas.region.position.y = 0
else: atlas.region.position.y = 16
func set_nation(nation: Nations) -> void:
var atlas: AtlasTexture = texture
atlas.region.position.x = 16*nation

View File

@@ -1,4 +0,0 @@
extends Control
func _on_back_to_menu_pressed() -> void:
get_tree().change_scene_to_file('res://menu.tscn')

View File

@@ -1,34 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://bnqopjqlq8iim"]
[ext_resource type="Script" path="res://options_menu.gd" id="1_tywj4"]
[node name="options_menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_tywj4")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="MasterVolume" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Master Volume"
[node name="back to menu" type="Button" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Back to menu"
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(62, 35)
zoom = Vector2(2, 2)
[connection signal="pressed" from="MarginContainer/VBoxContainer/back to menu" to="." method="_on_back_to_menu_pressed"]

View File

@@ -1 +0,0 @@
extends Button

View File

@@ -11,7 +11,7 @@ config_version=5
[application]
config/name="TestProject"
run/main_scene="res://menu.tscn"
run/main_scene="res://world/world.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://assets/icon.svg"
@@ -53,4 +53,3 @@ right_mouse={
textures/canvas_textures/default_texture_filter=0
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
textures/main_scene="res://world.tscn"

View File

@@ -1,11 +0,0 @@
extends Button
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

38
world/npcs.gd Normal file
View File

@@ -0,0 +1,38 @@
extends Node2D
const NPC_SCENE = preload("res://npc/npc.tscn")
var npcs: Array[NPC]
func add_npc(pos: Vector2i):
var npc: NPC = NPC_SCENE.instantiate()
npc.translate(pos*World.tile_size)
npcs.append(npc)
add_child(npc)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
randomize()
add_npc(Vector2i(11, 8))
add_npc(Vector2i(9, 9))
add_npc(Vector2i(12, 11))
func set_npc_target(npc: NPC, target: Vector2i):
var id_path = $"../TileMap".astar_grid.get_id_path(
$"../TileMap/ground".local_to_map(npc.global_position+$"../TileMap/ground".global_position),
target
).slice(1)
if not id_path.is_empty():
npc.id_path = id_path
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
for npc in npcs:
if not npc.is_walking():
set_npc_target(npc, Vector2i(randi()%64,randi()%64))
pass

View File

@@ -1,3 +1,4 @@
class_name MyTileMap
extends Node2D
enum StructType {
@@ -71,6 +72,7 @@ enum struct_fields {
var layers: Array[TileMapLayer]
var layers_dict: Dictionary
var astar_grid: AStarGrid2D
func _list_childrens(node: Node2D):
for child in node.get_children():
@@ -84,6 +86,18 @@ func _list_childrens(node: Node2D):
func _ready() -> void:
layers = []
_list_childrens(self)
astar_grid = AStarGrid2D.new()
astar_grid.region = layers_dict["ground"].get_used_rect()
astar_grid.cell_size = Vector2i(16, 16)
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
astar_grid.update()
for x in $ground.get_used_rect().size.x:
for y in $ground.get_used_rect().size.y:
var tile_pos = Vector2i(x,y)
update_astar_tile(tile_pos)
func get_maxZ(tile_pos: Vector2i) -> int:
var max_z: int = -1024
@@ -105,10 +119,12 @@ func place_road(pos: Vector2i) -> bool:
if get_maxZ(pos) >= layer.z_index:
return false
layer.set_cells_terrain_connect([pos], 0, 2, true)
update_astar_tile(pos)
return true
func erase_road(pos: Vector2i) -> bool:
var layer: TileMapLayer = layers_dict["roads"]
layer.erase_cell(pos)
update_astar_tile(pos)
return true
func place_way(pos1: Vector2i, pos2: Vector2i) -> bool:
@@ -148,19 +164,6 @@ func place_way(pos1: Vector2i, pos2: Vector2i) -> bool:
place_struct(Vector2i(pos1.x, y), StructType.V_WAY)
return true
func remove_struct(pos: Vector2i):
for layer in layers:
var tiledata: TileData = layer.get_cell_tile_data(pos)
if tiledata != null and tiledata.get_custom_data("is_center"):
var struct_size = tiledata.get_custom_data("struct_size")
var half_size = Vector2i(struct_size.x / 2, struct_size.y / 2)
for x in range(struct_size.x):
for y in range(struct_size.y):
var offset = Vector2i(x, y)
var tile_pos = pos+offset-half_size
layer.erase_cell(tile_pos)
return
func destroy_building(pos: Vector2i, only_ways: bool = false):
for layer in layers:
var tiledata: TileData = layer.get_cell_tile_data(pos)
@@ -183,6 +186,20 @@ func destroy_building(pos: Vector2i, only_ways: bool = false):
remove_struct(pos)
return
func remove_struct(pos: Vector2i):
for layer in layers:
var tiledata: TileData = layer.get_cell_tile_data(pos)
if tiledata != null and tiledata.get_custom_data("is_center"):
var struct_size = tiledata.get_custom_data("struct_size")
var half_size = Vector2i(struct_size.x / 2, struct_size.y / 2)
for x in range(struct_size.x):
for y in range(struct_size.y):
var offset = Vector2i(x, y)
var tile_pos = pos+offset-half_size
layer.erase_cell(tile_pos)
update_astar_tile(tile_pos)
return
func place_struct(pos: Vector2i, type: StructType) -> bool:
if not structs.has(type):
return false
@@ -206,4 +223,24 @@ func place_struct(pos: Vector2i, type: StructType) -> bool:
var offset = Vector2i(x, y)
var tile_pos = pos+offset-half_size
layer.set_cell(tile_pos, source_id, Vector2i(x,y)+pos_atlas)
update_astar_tile(tile_pos)
return true
func is_walkable(pos: Vector2i) -> bool:
var state: bool = true
for layer in layers:
var tiledata: TileData = layer.get_cell_tile_data(pos)
if tiledata != null and not tiledata.get_custom_data("walkable"):
state = false
break
return state
func weight(pos: Vector2i) -> int:
var layer = get_toplayer(pos)
var tiledata: TileData = layer.get_cell_tile_data(pos)
if tiledata != null: return tiledata.get_custom_data("astar_weight")
else: return 5
func update_astar_tile(pos: Vector2i):
astar_grid.set_point_solid(pos, not is_walkable(pos))
astar_grid.set_point_weight_scale(pos, weight(pos))

View File

@@ -1,23 +1,14 @@
class_name World
extends Node2D
const tile_size: int = 16
# Переменная для хранения ссылки на TileMap
@onready var ground: TileMapLayer = $TileMap/ground
@onready var tileMap: Node2D = $TileMap
const SELECTION_SCENE = preload("res://selection.tscn")
const SELECTION_SCENE = preload("res://UI/selection/selection.tscn")
func _on_null_pressed() -> void:
change_instrument(instruments.NULL)
func _on_demolish_pressed() -> void:
change_instrument(instruments.DESTROY)
func _on_construct_pressed() -> void:
change_instrument(instruments.CONSTRUCT)
func _on_build_pressed() -> void:
change_instrument(instruments.BUILD_ROAD)
var selected_instrument: instruments
var selected_tile: Vector2i
var selected_tile2: Vector2i
@@ -59,6 +50,7 @@ func _physics_process(delta: float) -> void:
if(selected_tile==selected_tile2):
selected_tile2 = Vector2i(-128,-128)
selected2 = false
print(tileMap.is_walkable(selected_tile))
if Input.is_action_just_released("right_mouse") and rmb:
selected_tile2 = select_tile(ground.local_to_map(get_global_mouse_position()-tileMap.global_position))
if(selected_tile!=selected_tile2): selected2 = true

File diff suppressed because one or more lines are too long