diff --git a/scenes/Main.tscn b/scenes/Main.tscn index b628a79..9c56aed 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -10,7 +10,7 @@ [ext_resource type="Script" path="res://source/game/MapBackground.gd" id="7_nh2ol"] [ext_resource type="Script" path="res://source/infolayer/InfoLayer.gd" id="9_dg6uy"] [ext_resource type="Script" path="res://source/uilayer/UILayer.gd" id="10_l2a8p"] -[ext_resource type="Script" path="res://source/EntityPlacer.gd" id="11_rf6kr"] +[ext_resource type="Script" path="res://source/uilayer/EntityPlacer.gd" id="11_gtqb3"] [ext_resource type="Script" path="res://source/uilayer/Control.gd" id="12_vhsyq"] [ext_resource type="Script" path="res://source/uilayer/Minimap.gd" id="13_80u53"] [ext_resource type="Script" path="res://source/uilayer/CameraMarker.gd" id="14_rvt3n"] @@ -60,7 +60,7 @@ layout_mode = 3 anchors_preset = 0 offset_right = 40.0 offset_bottom = 40.0 -script = ExtResource("11_rf6kr") +script = ExtResource("11_gtqb3") [node name="Control" type="Control" parent="EventBus/UILayer"] layout_mode = 3 diff --git a/source/EventBus.gd b/source/EventBus.gd index 81a42d1..c852b9d 100644 --- a/source/EventBus.gd +++ b/source/EventBus.gd @@ -155,6 +155,7 @@ func start_new_game(): var node_infolayer:InfoLayer node_infolayer = find_child("InfoLayer") + node_infolayer.set_draw_mode(0) node_infolayer.set_visible(true) # set camera to center of the map diff --git a/source/Globals.gd b/source/Globals.gd index accc4bf..51863e1 100644 --- a/source/Globals.gd +++ b/source/Globals.gd @@ -38,35 +38,6 @@ const ART_PATH:String = "res://art/" const SCRIPT_PATH:String = "res://scripts" -################################### -# MINIMAP SETTINGS # -################################### - -var minimap_colors:Dictionary = { - Globals.TILE_WATER : Color8(42, 31, 255), - Globals.TILE_TERRAIN: Color8(148, 113, 71), - Globals.TILE_FOREST : Color8(0,123,19), - "default": Color8(255,0,255), -} - - -################################### -# CHUNK AND TERRAIN SETTINGS # -################################### - -# world map chunk size -const CHUNK_SIZE:Vector2i = Vector2i(32,32) - -# tilemap tile types -enum {TILE_WATER, TILE_TERRAIN, TILE_FOREST, TILE_BOG} - -# parcel owner types -enum {PARCEL_CITY, PARCEL_STATE, PARCEL_PRIVATE} - -# tilemap layers -enum {LAYER_TERRAIN, LAYER_BUILDINGS} -const TILESET_TERRAIN:TileSet = preload("res://scenes/Chunk.tres") - ################################### # CAMERA SETTINGS # ################################### @@ -86,41 +57,6 @@ const CAMERA_ZOOM_DURATION: float = 0.1 const CAMERA_PAN_MULTI:float = 2.0 -################################### -# UI ELEMENT SETTINGS # -################################### - -# NODE NAMES -const WORLD_NODE:String = "World" -const DEBUGINFO_NODE:String = "DebugInfo" -const CONSTRUCTION_PANEL_NODE:String = "ConstructionPanel" - -const GUI_BUILD_BUTTON_SIZE_X: int = 50 -const GUI_BUILD_BUTTON_SIZE_Y: int = 50 -const GUI_BUILD_BUTTON_SIZE: Vector2i = Vector2i(GUI_BUILD_BUTTON_SIZE_X,GUI_BUILD_BUTTON_SIZE_Y) - -# maybe should use int for these instead for faster matching? -# ^ yes TODO switch to enum -const TYPE_RESIDENTIAL:String = "residential" -const TYPE_COMMERCIAL:String = "commercial" -const TYPE_INDUSTRIAL:String = "industrial" -const TYPE_SERVICES:String = "services" -const TYPE_SOCIAL:String = "social" -const TYPE_POWERPLANT:String = "powerplant" -const TYPE_ROADS:String = "roads" -const TYPE_DEMOLISH:String = "demolish" - -# Main menu buttons -enum { - MAINMENU_NEW_GAME, - MAINMENU_LOAD_GAME, - MAINMENU_RESUME_GAME, - MAINMENU_OPTIONS, - MAINMENU_CREDITS, - MAINMENU_QUIT_GAME, - } - - ################################### # WORLD GENERATION SETTINGS # ################################### @@ -139,6 +75,23 @@ const MAP_MAX_WIDTH:int = 4096 const TILE_SIZE_X:int = 16 const TILE_SIZE_Y:int = 16 +const INFOLAYER_PARCEL_BORDER:Color = Color8(200,25,25,220) +const INFOLAYER_PARCEL_FILL:Color = Color8(128,128,128,220) + +# parcel info is saved to a struct +class Parcel: + var start:Vector2i + var size:Vector2i + var owner:int + var value:float + +# parcel size +const PARCEL_WIDTH:int = 16 +const PARCEL_HEIGHT:int = 64 + +var STARTING_AREA_WIDTH_IN_PARCELS:int = 5 +var STARTING_AREA_HEIGHT_IN_PARCELS:int = 2 + # tile dict to tilemap var td = { TILE_WATER: { @@ -188,7 +141,100 @@ var td = { "key": [Vector2i(0,0)] } } + + +################################### +# CHUNK AND TERRAIN SETTINGS # +################################### + +# world map chunk size +const CHUNK_SIZE:Vector2i = Vector2i(32,32) + +# tilemap tile types +enum {TILE_WATER, TILE_TERRAIN, TILE_FOREST, TILE_BOG} + +# parcel owner types +enum {PARCEL_CITY, PARCEL_STATE, PARCEL_PRIVATE} + +# tilemap layers +enum {LAYER_TERRAIN, LAYER_BUILDINGS} +const TILESET_TERRAIN:TileSet = preload("res://scenes/Chunk.tres") + + +################################### +# MAIN MENU SETTINGS # +################################### + + +################################### +# INFOLAYER SETTINGS # +################################### + +enum { + INFOLAYER_PARCELS, + INFOLAYER_LAND_VALUE, + INFOLAYER_ZONETYPES, + INFOLAYER_TRAFFIC, + INFOLAYER_NOISE, + INFOLAYER_POLLUTION, + INFOLAYER_GARBAGE, + INFOLAYER_HAPPINESS, + INFOLAYER_EDUCATION, + INFOLAYER_CRIME, + INFOLAYER_FIRE, + INFOLAYER_HEAT, + INFOLAYER_WATER, + INFOLAYER_SNOW, + INFOLAYER_DISTRICTS, + } + + +################################### +# UI ELEMENT SETTINGS # +################################### + +# NODE NAMES +const WORLD_NODE:String = "World" +const DEBUGINFO_NODE:String = "DebugInfo" +const CONSTRUCTION_PANEL_NODE:String = "ConstructionPanel" + +const GUI_BUILD_BUTTON_SIZE_X: int = 50 +const GUI_BUILD_BUTTON_SIZE_Y: int = 50 +const GUI_BUILD_BUTTON_SIZE: Vector2i = Vector2i(GUI_BUILD_BUTTON_SIZE_X,GUI_BUILD_BUTTON_SIZE_Y) + +# maybe should use int for these instead for faster matching? +# ^ yes TODO switch to enum +const TYPE_RESIDENTIAL:String = "residential" +const TYPE_COMMERCIAL:String = "commercial" +const TYPE_INDUSTRIAL:String = "industrial" +const TYPE_SERVICES:String = "services" +const TYPE_SOCIAL:String = "social" +const TYPE_POWERPLANT:String = "powerplant" +const TYPE_ROADS:String = "roads" +const TYPE_DEMOLISH:String = "demolish" + +# Main menu buttons +enum { + MAINMENU_NEW_GAME, + MAINMENU_LOAD_GAME, + MAINMENU_RESUME_GAME, + MAINMENU_OPTIONS, + MAINMENU_CREDITS, + MAINMENU_QUIT_GAME, + } + +################################### +# MINIMAP SETTINGS # +################################### + +var minimap_colors:Dictionary = { + Globals.TILE_WATER : Color8(42, 31, 255), + Globals.TILE_TERRAIN: Color8(148, 113, 71), + Globals.TILE_FOREST : Color8(0,123,19), + "default": Color8(255,0,255), +} + ################################### # GAME ERORR MESSAGES # diff --git a/source/WorldGenerator.gd b/source/WorldGenerator.gd index b299626..ab1c1c7 100644 --- a/source/WorldGenerator.gd +++ b/source/WorldGenerator.gd @@ -93,19 +93,26 @@ func generate_biomes() -> void: Globals.map_terrain_data[y][x] = Globals.TILE_FOREST # can add other tresholds here for other biomes -# TODO move to globals later -var parcel_width = 16 -var parcel_height = 64 # forests are not generated yet so can just compare water and terrain func is_filled_with_water(coords:Vector2i) -> bool: var terrain_tile_count:int = 0 - for y in range(coords.y, coords.y + parcel_height): - for x in range(coords.x, coords.x + parcel_width): +# 0*64, 0*64 +64-1 = 0-63 +# 1*64, 1*64 +63 = 64-127 +# 2*64, 2*64 +63 = 128-191 +# 3*64, 3*64 +63 = 192-255 + for y in range( + coords.y*Globals.PARCEL_HEIGHT, + coords.y*Globals.PARCEL_HEIGHT + Globals.PARCEL_HEIGHT-1 + ): + for x in range( + coords.x*Globals.PARCEL_WIDTH, + coords.x*Globals.PARCEL_WIDTH + Globals.PARCEL_WIDTH-1 + ): if Globals.map_terrain_data[y][x] == Globals.TILE_TERRAIN: terrain_tile_count += 1 - + # parcel is ok if it has at least one land if terrain_tile_count > 0: return false @@ -115,24 +122,38 @@ func generate_parcels() -> void: # divide the land area Cadastres / Parcels # TODO better solution, this is something my skills were able to handle at proto stage # should replace with a real/better algo when I am skilled enough to do it - Globals.map_parcel_data.resize(Globals.map_size / parcel_height) + Globals.map_parcel_data.resize(Globals.map_size / Globals.PARCEL_HEIGHT) - for y in Globals.map_size / parcel_height: - Globals.map_parcel_data[y].resize(Globals.map_size / parcel_width) - for x in Globals.map_size / parcel_width: + for y in Globals.map_size / Globals.PARCEL_HEIGHT: + Globals.map_parcel_data[y].resize(Globals.map_size / Globals.PARCEL_WIDTH) + for x in Globals.map_size / Globals.PARCEL_WIDTH: # ignore parcels full fo water - if !is_filled_with_water(Vector2i(y,x)): - # 0 = top left corner, 1 = bottom right corner, 2 = owner - Globals.map_parcel_data[y][x] = [ - Vector2i(y * parcel_height, x * parcel_width), - Vector2i(y * parcel_height + parcel_height, x * parcel_width + parcel_width), - Globals.PARCEL_STATE - ] + if !is_filled_with_water(Vector2i(x,y)): + Globals.map_parcel_data[y][x] = Globals.Parcel.new() + Globals.map_parcel_data[y][x].start = Vector2i( + y * Globals.PARCEL_HEIGHT, + x * Globals.PARCEL_WIDTH, + ) + Globals.map_parcel_data[y][x].size = Vector2i( + Globals.PARCEL_WIDTH, + Globals.PARCEL_HEIGHT, + ) + Globals.map_parcel_data[y][x].owner = Globals.PARCEL_STATE - #for row in Globals.map_parcel_data: -# print(row) - #for col in row: - # print(Globals.map_parcel_data[row][col]) + + # not used, but could be used later + var total_parcels = Globals.map_size/Globals.PARCEL_WIDTH * Globals.map_size / Globals.PARCEL_HEIGHT + give_starting_parcels_for_city(total_parcels) + +func give_starting_parcels_for_city(_amount:int) -> void: + # gives a x*y parcel initial starting area for the player + var p_x = Globals.map_size/Globals.PARCEL_WIDTH/2 + var p_y = Globals.map_size/Globals.PARCEL_HEIGHT/2 + + for y in range(0, Globals.STARTING_AREA_HEIGHT_IN_PARCELS): + for x in range(0, Globals.STARTING_AREA_WIDTH_IN_PARCELS): + if Globals.map_parcel_data[p_y-y][p_x-x] != null: + Globals.map_parcel_data[p_y-y][p_x-x].owner = Globals.PARCEL_CITY func generate_world(filename) -> bool: diff --git a/source/camera/Camera.gd b/source/camera/Camera.gd index 3e3089a..8c1650c 100644 --- a/source/camera/Camera.gd +++ b/source/camera/Camera.gd @@ -89,11 +89,11 @@ func camera_pan_position(value) -> void: func camera_zoom_in() -> void: - set_camera_zoom_level(Globals.CAMERA_ZOOM_LEVEL - Globals.CAMERA_ZOOM_FACTOR) + set_camera_zoom_level(Globals.CAMERA_ZOOM_LEVEL + Globals.CAMERA_ZOOM_FACTOR) func camera_zoom_out() -> void: - set_camera_zoom_level(Globals.CAMERA_ZOOM_LEVEL + Globals.CAMERA_ZOOM_DURATION) + set_camera_zoom_level(Globals.CAMERA_ZOOM_LEVEL - Globals.CAMERA_ZOOM_DURATION) func camera_reset_rotation() -> void: diff --git a/source/infolayer/InfoLayer.gd b/source/infolayer/InfoLayer.gd index 687f157..dc94566 100644 --- a/source/infolayer/InfoLayer.gd +++ b/source/infolayer/InfoLayer.gd @@ -1,6 +1,8 @@ class_name InfoLayer extends Node2D +var draw_mode:int = -1 + # displays various info layers of the game # Called when the node enters the scene tree for the first time. @@ -11,13 +13,63 @@ func _ready(): func _draw(): - for y in 16: - for x in 64: - draw_rect(Rect2(x*16*16, y*64*16, 16*16, 64*16), Color8(200,25,25,220), false, 4.0) + # pass == not implemented (yet) + match draw_mode: + Globals.INFOLAYER_PARCELS: + draw_parcels() + Globals.INFOLAYER_LAND_VALUE:pass + Globals.INFOLAYER_ZONETYPES:pass + Globals.INFOLAYER_TRAFFIC:pass + Globals.INFOLAYER_NOISE:pass + Globals.INFOLAYER_POLLUTION:pass + Globals.INFOLAYER_GARBAGE:pass + Globals.INFOLAYER_HAPPINESS:pass + Globals.INFOLAYER_EDUCATION:pass + Globals.INFOLAYER_CRIME:pass + Globals.INFOLAYER_FIRE:pass + Globals.INFOLAYER_HEAT:pass + Globals.INFOLAYER_WATER:pass + Globals.INFOLAYER_SNOW:pass + Globals.INFOLAYER_DISTRICTS:pass + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): self.position = Vector2(0,0) +func draw_parcels() -> void: + for y in Globals.map_size/64: + for x in Globals.map_size/16: + if Globals.map_parcel_data[y][x] != null: + var p = Globals.map_parcel_data[y][x] + + # draw solid rect for non-city ownned parcels + if Globals.map_parcel_data[y][x].owner != Globals.PARCEL_CITY: + # Rect2 = start x, start y, width, height + draw_rect(Rect2( + p.start.y*Globals.TILE_SIZE_Y, + p.start.x*Globals.TILE_SIZE_X, + p.size.x*Globals.TILE_SIZE_X, + p.size.y*Globals.TILE_SIZE_Y), + Globals.INFOLAYER_PARCEL_FILL, true) + # draw borders for every parcel + draw_rect(Rect2( + p.start.y*Globals.TILE_SIZE_Y, + p.start.x*Globals.TILE_SIZE_X, + p.size.x*Globals.TILE_SIZE_X, + p.size.y*Globals.TILE_SIZE_Y), + Globals.INFOLAYER_PARCEL_BORDER, false, 4.0) + + +func get_draw_mode() -> int: + return self.draw_mode + + +func set_draw_mode(mode:int) -> void: + self.draw_mode = mode + if self.draw_mode >= 0: + queue_redraw() + + diff --git a/source/uilayer/Control.gd b/source/uilayer/Control.gd index d6fe94b..db8f04e 100644 --- a/source/uilayer/Control.gd +++ b/source/uilayer/Control.gd @@ -90,6 +90,7 @@ func create_buttons(): func update_debug_info_func(): debug_info.set_text( + "FPS " + str(Engine.get_frames_per_second()) + "\n" + "Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" + "Chunks: " + str(self.amount_of_chunks) + "\n" + "Chunk del: " + str(self.size_of_chunk_removal_queue)