Compare commits

..

1 Commits

Author SHA1 Message Date
CoDeayant
115d34d656 Добавил кнопки и интерфейс 2024-12-08 16:30:25 +05:00
29 changed files with 388 additions and 688 deletions

19
TimerforVariable.tscn Normal file
View File

@ -0,0 +1,19 @@
[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")

View File

@ -1,3 +0,0 @@
extends Button
# Called when the node enters the

View File

@ -1,32 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://ceju5kxboqm1r"]
[ext_resource type="Script" path="res://UI/construct.gd" id="1_g0ew0"]
[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="Construct" type="Button" parent="."]
layout_mode = 0
offset_right = 8.0
offset_bottom = 8.0
text = "Конструкция"
script = ExtResource("1_g0ew0")
[node name="Destroy" type="Button" parent="."]
layout_mode = 0
offset_top = 40.0
offset_right = 92.0
offset_bottom = 71.0
text = "Демонтаж"
[node name="Road" type="Button" parent="."]
layout_mode = 0
offset_top = 80.0
offset_right = 66.0
offset_bottom = 111.0
text = "Дорога"

BIN
assets/Heart.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

34
assets/Heart.png.import Normal file
View File

@ -0,0 +1,34 @@
[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

BIN
assets/Iconary.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

34
assets/Iconary.png.import Normal file
View File

@ -0,0 +1,34 @@
[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

BIN
assets/Sprite-0001.aseprite Normal file

Binary file not shown.

BIN
assets/coridors.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

43
buttons.tscn Normal file
View File

@ -0,0 +1,43 @@
[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 = "Строить"

5
demolish.gd Normal file
View File

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

12
energylabel.gd Normal file
View File

@ -0,0 +1,12 @@
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,146 +0,0 @@
[preset.0]
name="Windows Desktop"
platform="Windows Desktop"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../export/windows/game.exe"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2
[preset.0.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=0
binary_format/embed_pck=false
texture_format/s3tc_bptc=true
texture_format/etc2_astc=false
binary_format/architecture="x86_64"
codesign/enable=false
codesign/timestamp=true
codesign/timestamp_server_url=""
codesign/digest_algorithm=1
codesign/description=""
codesign/custom_options=PackedStringArray()
application/modify_resources=false
application/icon=""
application/console_wrapper_icon=""
application/icon_interpolation=4
application/file_version=""
application/product_version=""
application/company_name=""
application/product_name=""
application/file_description=""
application/copyright=""
application/trademarks=""
application/export_angle=0
application/export_d3d12=0
application/d3d12_agility_sdk_multiarch=true
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
Start-ScheduledTask -TaskName godot_remote_debug
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
Remove-Item -Recurse -Force '{temp_dir}'"
[preset.1]
name="Web"
platform="Web"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../export/web/game.html"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2
[preset.1.options]
custom_template/debug=""
custom_template/release=""
variant/extensions_support=false
variant/thread_support=false
vram_texture_compression/for_desktop=true
vram_texture_compression/for_mobile=false
html/export_icon=true
html/custom_html_shell=""
html/head_include=""
html/canvas_resize_policy=2
html/focus_canvas_on_start=true
html/experimental_virtual_keyboard=false
progressive_web_app/enabled=false
progressive_web_app/ensure_cross_origin_isolation_headers=true
progressive_web_app/offline_page=""
progressive_web_app/display=1
progressive_web_app/orientation=0
progressive_web_app/icon_144x144=""
progressive_web_app/icon_180x180=""
progressive_web_app/icon_512x512=""
progressive_web_app/background_color=Color(0, 0, 0, 1)
[preset.2]
name="Linux"
platform="Linux"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../export/linux/game.x86_64"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2
[preset.2.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/s3tc_bptc=true
texture_format/etc2_astc=false
binary_format/architecture="x86_64"
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="#!/usr/bin/env bash
export DISPLAY=:0
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
\"{temp_dir}/{exe_name}\" {cmd_args}"
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
rm -rf \"{temp_dir}\""

14
label.gd Normal file
View File

@ -0,0 +1,14 @@
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 Normal file
View File

@ -0,0 +1,14 @@
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()

40
menu.tscn Normal file
View File

@ -0,0 +1,40 @@
[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"]

View File

@ -1,56 +0,0 @@
class_name NPC
extends Node2D
var id_path: Array[Vector2i]
var target: Vector2i
var speed: float = 1
var oxygen: float = 100
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)
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, speed)
if global_position.x < target_pos.x: $Sprite2D.flip_h = true
elif global_position.x > target_pos.x: $Sprite2D.flip_h = false
if global_position == target_pos:
id_path.pop_front()
set_target(target)
if $"../../TileMap".check_indoors(global_position/16):
set_spacesuit(false)
else:
set_spacesuit(true)
func set_spacesuit(suit: bool) -> void:
$Sprite2D.set_spacesuit(suit)
if suit: speed = 0.2
else: speed = 1
func set_target(pos: Vector2i):
var new_id_path = $"../../TileMap".astar_grid.get_id_path(
$"../../TileMap/ground".local_to_map(global_position+$"../../TileMap/ground".global_position),
target
).slice(1)
if not new_id_path.is_empty():
id_path = new_id_path
target = pos
else:
id_path = []
target = pos

View File

@ -1,21 +0,0 @@
[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"]
resource_local_to_scene = true
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_filter = 1
texture = SubResource("AtlasTexture_2v0ml")
centered = false
script = ExtResource("2_jtl2q")

View File

@ -1,27 +0,0 @@
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

4
options_menu.gd Normal file
View File

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

34
options_menu.tscn Normal file
View File

@ -0,0 +1,34 @@
[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"]

1
play.gd Normal file
View File

@ -0,0 +1 @@
extends Button

View File

@ -11,17 +11,16 @@ config_version=5
[application] [application]
config/name="TestProject" config/name="TestProject"
run/main_scene="res://world/world.tscn" run/main_scene="res://menu.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility") config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://assets/icon.svg" config/icon="res://assets/icon.svg"
[display] [display]
window/size/viewport_width=640 window/size/viewport_width=1024
window/size/viewport_height=480 window/size/viewport_height=1024
window/size/mode=2
window/stretch/mode="canvas_items" window/stretch/mode="canvas_items"
window/stretch/aspect="keep_height" window/stretch/aspect="keep_width"
[dotnet] [dotnet]
@ -48,34 +47,10 @@ right_mouse={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(277, 13),"global_position":Vector2(286, 59),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(277, 13),"global_position":Vector2(286, 59),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
] ]
} }
zoom_in={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":61,"unicode":61,"location":0,"echo":false,"script":null)
]
}
zoom_out={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":45,"unicode":45,"location":0,"echo":false,"script":null)
]
}
1={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null)
]
}
2={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
]
}
3={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
]
}
[rendering] [rendering]
textures/canvas_textures/default_texture_filter=0 textures/canvas_textures/default_texture_filter=0
renderer/rendering_method="gl_compatibility" renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility"
textures/main_scene="res://world.tscn"

11
settings.gd Normal file
View File

@ -0,0 +1,11 @@
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

View File

@ -1,4 +1,3 @@
class_name MyTileMap
extends Node2D extends Node2D
enum StructType { enum StructType {
@ -72,7 +71,6 @@ enum struct_fields {
var layers: Array[TileMapLayer] var layers: Array[TileMapLayer]
var layers_dict: Dictionary var layers_dict: Dictionary
var astar_grid: AStarGrid2D
func _list_childrens(node: Node2D): func _list_childrens(node: Node2D):
for child in node.get_children(): for child in node.get_children():
@ -86,18 +84,6 @@ func _list_childrens(node: Node2D):
func _ready() -> void: func _ready() -> void:
layers = [] layers = []
_list_childrens(self) _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: func get_maxZ(tile_pos: Vector2i) -> int:
var max_z: int = -1024 var max_z: int = -1024
@ -119,12 +105,10 @@ func place_road(pos: Vector2i) -> bool:
if get_maxZ(pos) >= layer.z_index: if get_maxZ(pos) >= layer.z_index:
return false return false
layer.set_cells_terrain_connect([pos], 0, 2, true) layer.set_cells_terrain_connect([pos], 0, 2, true)
update_astar_tile(pos)
return true return true
func erase_road(pos: Vector2i) -> bool: func erase_road(pos: Vector2i) -> bool:
var layer: TileMapLayer = layers_dict["roads"] var layer: TileMapLayer = layers_dict["roads"]
layer.erase_cell(pos) layer.erase_cell(pos)
update_astar_tile(pos)
return true return true
func place_way(pos1: Vector2i, pos2: Vector2i) -> bool: func place_way(pos1: Vector2i, pos2: Vector2i) -> bool:
@ -164,6 +148,19 @@ func place_way(pos1: Vector2i, pos2: Vector2i) -> bool:
place_struct(Vector2i(pos1.x, y), StructType.V_WAY) place_struct(Vector2i(pos1.x, y), StructType.V_WAY)
return true 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): func destroy_building(pos: Vector2i, only_ways: bool = false):
for layer in layers: for layer in layers:
var tiledata: TileData = layer.get_cell_tile_data(pos) var tiledata: TileData = layer.get_cell_tile_data(pos)
@ -186,20 +183,6 @@ func destroy_building(pos: Vector2i, only_ways: bool = false):
remove_struct(pos) remove_struct(pos)
return 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: func place_struct(pos: Vector2i, type: StructType) -> bool:
if not structs.has(type): if not structs.has(type):
return false return false
@ -223,30 +206,4 @@ func place_struct(pos: Vector2i, type: StructType) -> bool:
var offset = Vector2i(x, y) var offset = Vector2i(x, y)
var tile_pos = pos+offset-half_size var tile_pos = pos+offset-half_size
layer.set_cell(tile_pos, source_id, Vector2i(x,y)+pos_atlas) layer.set_cell(tile_pos, source_id, Vector2i(x,y)+pos_atlas)
update_astar_tile(tile_pos)
return true 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))
func check_indoors(pos: Vector2i) -> bool:
var layer = get_toplayer(pos)
var tiledata: TileData = layer.get_cell_tile_data(pos)
if tiledata != null: return tiledata.get_custom_data("indoors")
else: return false

View File

@ -1,14 +1,23 @@
class_name World
extends Node2D extends Node2D
const tile_size: int = 16
# Переменная для хранения ссылки на TileMap # Переменная для хранения ссылки на TileMap
@onready var ground: TileMapLayer = $TileMap/ground @onready var ground: TileMapLayer = $TileMap/ground
@onready var tileMap: Node2D = $TileMap @onready var tileMap: Node2D = $TileMap
const SELECTION_SCENE = preload("res://UI/selection/selection.tscn") const SELECTION_SCENE = preload("res://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_instrument: instruments
var selected_tile: Vector2i var selected_tile: Vector2i
var selected_tile2: Vector2i var selected_tile2: Vector2i
@ -20,7 +29,6 @@ var lmb: bool
var rmb: bool var rmb: bool
func _ready(): func _ready():
Engine.physics_ticks_per_second = 60
selection = SELECTION_SCENE.instantiate() selection = SELECTION_SCENE.instantiate()
selection2 = SELECTION_SCENE.instantiate() selection2 = SELECTION_SCENE.instantiate()
add_child(selection) add_child(selection)
@ -51,7 +59,6 @@ func _physics_process(delta: float) -> void:
if(selected_tile==selected_tile2): if(selected_tile==selected_tile2):
selected_tile2 = Vector2i(-128,-128) selected_tile2 = Vector2i(-128,-128)
selected2 = false selected2 = false
print(tileMap.is_walkable(selected_tile))
if Input.is_action_just_released("right_mouse") and rmb: 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)) selected_tile2 = select_tile(ground.local_to_map(get_global_mouse_position()-tileMap.global_position))
if(selected_tile!=selected_tile2): selected2 = true if(selected_tile!=selected_tile2): selected2 = true
@ -61,6 +68,10 @@ func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"): if Input.is_action_just_pressed("ui_cancel"):
change_instrument(instruments.NULL) change_instrument(instruments.NULL)
if Input.is_action_just_pressed("ui_right"):
change_instrument(selected_instrument+1)
if Input.is_action_just_pressed("ui_left"):
change_instrument(selected_instrument-1)
match selected_instrument: match selected_instrument:
instruments.NULL: instruments.NULL:
@ -103,21 +114,5 @@ func change_instrument(new: instruments):
lmb = false lmb = false
rmb = false rmb = false
func _process(delta: float) -> void: func _input(event):
if Input.is_action_pressed("ui_right"): pass
$Camera2D.translate(Vector2.RIGHT*320*delta/$Camera2D.zoom)
if Input.is_action_pressed("ui_left"):
$Camera2D.translate(Vector2.LEFT*320*delta/$Camera2D.zoom)
if Input.is_action_pressed("ui_up"):
$Camera2D.translate(Vector2.UP*320*delta/$Camera2D.zoom)
if Input.is_action_pressed("ui_down"):
$Camera2D.translate(Vector2.DOWN*320*delta/$Camera2D.zoom)
if Input.is_action_just_pressed("zoom_in"):
$Camera2D.zoom+=Vector2.ONE*0.25
if Input.is_action_just_pressed("zoom_out"):
$Camera2D.zoom-=Vector2.ONE*0.25
if Input.is_action_just_pressed("1"): change_instrument(instruments.CONSTRUCT)
if Input.is_action_just_pressed("2"): change_instrument(instruments.DESTROY)
if Input.is_action_just_pressed("3"): change_instrument(instruments.BUILD_ROAD)

File diff suppressed because one or more lines are too long

View File

@ -1,32 +0,0 @@
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):
npc.set_target(target)
# 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