commit 24a05c557dc50318989cc311d012d00b4e0c729b Author: Antti Hakkarainen Date: Sun Feb 5 23:36:27 2023 +0200 initial game files diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4709183 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/art/buildings/building_grid.png b/art/buildings/building_grid.png new file mode 100644 index 0000000..b619524 Binary files /dev/null and b/art/buildings/building_grid.png differ diff --git a/art/buildings/building_grid.png.import b/art/buildings/building_grid.png.import new file mode 100644 index 0000000..3378691 --- /dev/null +++ b/art/buildings/building_grid.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dabmo11wkiwm3" +path="res://.godot/imported/building_grid.png-27ba2469cfdf76b27d7100fd4fe14939.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/buildings/building_grid.png" +dest_files=["res://.godot/imported/building_grid.png-27ba2469cfdf76b27d7100fd4fe14939.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 diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..adc26df --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..105a3cb --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cxn2fno1j7vf5" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..8d533e7 --- /dev/null +++ b/project.godot @@ -0,0 +1,20 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="ACSIM" +run/main_scene="res://scenes/Main.tscn" +config/features=PackedStringArray("4.0", "Forward Plus") +config/icon="res://icon.svg" + +[autoload] + +Globals="*res://scripts/Globals.gd" diff --git a/scenes/Building.gd b/scenes/Building.gd new file mode 100644 index 0000000..451f669 --- /dev/null +++ b/scenes/Building.gd @@ -0,0 +1,4 @@ +extends Node2D + +func _process(delta): + position = get_viewport().get_mouse_position() diff --git a/scenes/Building.tscn b/scenes/Building.tscn new file mode 100644 index 0000000..50162ac --- /dev/null +++ b/scenes/Building.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=3 uid="uid://sqvd1ev6ubp"] + +[ext_resource type="Script" path="res://scenes/Building.gd" id="1_uqlnt"] +[ext_resource type="Texture2D" uid="uid://dabmo11wkiwm3" path="res://art/buildings/building_grid.png" id="1_yd1tr"] + +[node name="Building" type="Node2D"] +script = ExtResource("1_uqlnt") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_yd1tr") diff --git a/scenes/Main.tscn b/scenes/Main.tscn new file mode 100644 index 0000000..e2ad638 --- /dev/null +++ b/scenes/Main.tscn @@ -0,0 +1,70 @@ +[gd_scene load_steps=4 format=3 uid="uid://ciperl36hv26g"] + +[ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"] +[ext_resource type="Script" path="res://scripts/View.gd" id="2_rg0qh"] +[ext_resource type="Script" path="res://scripts/Control.gd" id="3_1t1c8"] + +[node name="Main" type="Node"] +script = ExtResource("1_ysxum") + +[node name="View" type="Node2D" parent="."] +script = ExtResource("2_rg0qh") + +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchor_right = 0.193 +anchor_bottom = 0.299 +offset_left = 265.0 +offset_top = 243.0 +offset_right = 82.664 +offset_bottom = 89.248 +script = ExtResource("3_1t1c8") + +[node name="ConstructionPanel" type="Panel" parent="Control"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="button_residental" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[node name="button_commercial" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[node name="button_industrial" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[node name="button_roads" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[node name="button_demolish" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[node name="button_services" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[node name="button_social" type="Button" parent="Control/ConstructionPanel"] +layout_mode = 0 +offset_right = 8.0 +offset_bottom = 8.0 + +[connection signal="button_pressed" from="Control" to="View" method="_on_control_button_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_residental" to="Control" method="_on_button_residental_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_commercial" to="Control" method="_on_button_commercial_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_industrial" to="Control" method="_on_button_industrial_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_roads" to="Control" method="_on_button_roads_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_demolish" to="Control" method="_on_button_demolish_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_services" to="Control" method="_on_button_services_pressed"] +[connection signal="pressed" from="Control/ConstructionPanel/button_social" to="Control" method="_on_button_social_pressed"] diff --git a/scripts/Control.gd b/scripts/Control.gd new file mode 100644 index 0000000..7d78732 --- /dev/null +++ b/scripts/Control.gd @@ -0,0 +1,69 @@ +extends Control + +# var view = get_node("../View") + +signal button_pressed(button_name) + +var BUTTON_SIZE = Vector2i(50,50) + +# name, position +var buttons = { + "button_residental": [Vector2(0,0), "R"], + "button_commercial": [Vector2(50,0), "C"], + "button_industrial": [Vector2(100,00), "I"], + "button_roads": [Vector2(0,50), "Rd"], + "button_demolish": [Vector2(50,50), "Dm"], + "button_services": [Vector2(100,50), "Sv"], + "button_social": [Vector2(150,50), "So"], +} + +# Called when the node enters the scene tree for the first time. +func _ready(): + adjust_construction_panel() + $ConstructionPanel.set_size(Vector2(500, 120)) + create_buttons() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta): + pass + +func adjust_construction_panel(): + $ConstructionPanel.set_size(Vector2i(500, 120)) + $ConstructionPanel.set_position(Vector2i(0, -200)) + +# defines construction toolbar buttons +func create_buttons(): + for button in buttons: + var values = buttons[button] + var node_path = get_node("ConstructionPanel/" + str(button)) + + if(!node_path): + push_error("Error: Button '" + button + "' not found when trying to set it's properties in Control.gd!") + + node_path.set_size(BUTTON_SIZE) + node_path.set_position(values[0]) + node_path.set_anchor(SIDE_TOP, anchor_top) + node_path.set_text(values[1]) + node_path.show() + +# sends signals which View catches and places selected type of buildings +func _on_button_residental_pressed(): + emit_signal("button_pressed", Globals.TYPE_RESIDENTIAL) + +func _on_button_commercial_pressed(): + emit_signal("button_pressed", Globals.TYPE_COMMERCIAL) + +func _on_button_industrial_pressed(): + emit_signal("button_pressed", Globals.TYPE_INDUSTRIAL) + +func _on_button_roads_pressed(): + emit_signal("button_pressed", Globals.TYPE_ROADS) + +func _on_button_demolish_pressed(): + emit_signal("button_pressed", Globals.TYPE_DEMOLISH) + +func _on_button_services_pressed(): + emit_signal("button_pressed", Globals.TYPE_SERVICES) + +func _on_button_social_pressed(): + emit_signal("button_pressed", Globals.TYPE_SOCIAL) diff --git a/scripts/Globals.gd b/scripts/Globals.gd new file mode 100644 index 0000000..9065ed8 --- /dev/null +++ b/scripts/Globals.gd @@ -0,0 +1,17 @@ +extends Node + +const SCENE_PATH:String = "res://scenes/" +const ART_PATH:String = "res://art/" +const SCRIPT_PATH:String = "res://scripts" + +const DEFAULT_X_RES:int = 1920 +const DEFAULT_Y_RES:int = 1080 + +const TYPE_RESIDENTIAL = "residential" +const TYPE_COMMERCIAL = "commercial" +const TYPE_INDUSTRIAL = "industrial" +const TYPE_SERVICES = "services" +const TYPE_SOCIAL = "social" +const TYPE_POWERPLANT = "powerplant" +const TYPE_ROADS = "roads" +const TYPE_DEMOLISH = "demolish" diff --git a/scripts/Main.gd b/scripts/Main.gd new file mode 100644 index 0000000..3fa9006 --- /dev/null +++ b/scripts/Main.gd @@ -0,0 +1,19 @@ +# - "Cube Clicker 2000" where you click a spot and a cube appears there. +# - Then add different shapes or colors of cubes. +# - Then clamp their positions to be on a grid. +# - Then make it so that when you add yellow cubes, yellow desire meter goes down and green meter goes up. +# - Then click a bunch of grey cubes in a row and have them automatically flatten out into flat grey cubes (roads). +# - Then click and drag to draw the lines of grey cubes. +# - etc. + +extends Node + +# Called when the node enters the scene tree for the first time. +func _ready(): + DisplayServer.window_set_size( + Vector2i(Globals.DEFAULT_X_RES, Globals.DEFAULT_Y_RES) + ) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta): + pass diff --git a/scripts/View.gd b/scripts/View.gd new file mode 100644 index 0000000..00844a9 --- /dev/null +++ b/scripts/View.gd @@ -0,0 +1,34 @@ +extends Node2D + +var gui +var building + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(_delta): + pass + + +func _on_control_button_pressed(button_name): + # create new building, in Building node it is attached to mouse cursor + var scene = load(Globals.SCENE_PATH + "Building.tscn") + building = scene.instantiate() + add_child(building) + + #for _i in self.get_children(): + # print(_i) + + # stop processing the sprite (fix it in place). no idea if it is a good idea yet.. + + + # print(button_name + " button pressed in Control! :-0") + +func _input(event): + # places the building on cursor. a bad way! + if Input.is_anything_pressed() and building != null: + building.set_process(false) + building = null + # print(event.as_text())