initial game files

This commit is contained in:
Antti Hakkarainen 2023-02-05 23:36:27 +02:00
commit 24a05c557d
14 changed files with 319 additions and 0 deletions

69
scripts/Control.gd Normal file
View file

@ -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)

17
scripts/Globals.gd Normal file
View file

@ -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"

19
scripts/Main.gd Normal file
View file

@ -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

34
scripts/View.gd Normal file
View file

@ -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())