From cabd5d8817efaab1d156c4f4e3c17772ea348e61 Mon Sep 17 00:00:00 2001 From: Anthony Wilcox <35226681+tonytins@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:24:25 -0500 Subject: [PATCH] Budget script New bank script that serves for handling the budget, taxes, and starting funds. --- src/gui.tscn | 37 +++++++++++++++++++++++++++++++++++++ src/project.godot | 14 ++++++++++++++ src/scripts/bank.gd | 23 +++++++++++++++++++++++ src/{ => scripts}/world.gd | 14 ++++++++++++-- src/world.tscn | 9 ++++++--- 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/gui.tscn create mode 100644 src/scripts/bank.gd rename src/{ => scripts}/world.gd (79%) diff --git a/src/gui.tscn b/src/gui.tscn new file mode 100644 index 0000000..d72301d --- /dev/null +++ b/src/gui.tscn @@ -0,0 +1,37 @@ +[gd_scene format=2] + +[node name="GUI" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="GPanel" type="Panel" parent="."] +anchor_right = 1.0 +margin_bottom = 23.0 + +[node name="HBox" type="HBoxContainer" parent="GPanel"] +anchor_right = 1.0 +margin_top = 2.0 +margin_bottom = 22.0 +alignment = 2 + +[node name="CurrencyLbl" type="Label" parent="GPanel/HBox"] +margin_left = 1003.0 +margin_top = 3.0 +margin_right = 1011.0 +margin_bottom = 17.0 +text = "$" + +[node name="MoneyLbl" type="Label" parent="GPanel/HBox"] +margin_left = 1015.0 +margin_top = 3.0 +margin_right = 1024.0 +margin_bottom = 17.0 +text = "#" + +[node name="DebugBtn" type="Button" parent="GPanel"] +visible = false +margin_left = 932.754 +margin_top = 563.202 +margin_right = 985.754 +margin_bottom = 583.202 +text = "Debug" diff --git a/src/project.godot b/src/project.godot index f7e4246..5fdcaf2 100644 --- a/src/project.godot +++ b/src/project.godot @@ -19,11 +19,25 @@ config/name="City Limits" run/main_scene="res://world.tscn" config/icon="res://icon.png" +[autoload] + +bank="*res://scripts/bank.gd" + [display] window/stretch/mode="2d" window/stretch/aspect="keep" +[input] + +ui_cheats={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777238,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":67,"unicode":0,"echo":false,"script":null) + ] +} + [rendering] environment/default_environment="res://default_env.tres" diff --git a/src/scripts/bank.gd b/src/scripts/bank.gd new file mode 100644 index 0000000..293650d --- /dev/null +++ b/src/scripts/bank.gd @@ -0,0 +1,23 @@ +extends Node + +var budget: int +var prev_budget: int + +var res_tax: int +var comm_tax: int +var indust_tax: int + +var fire_tax: int +var police_tax: int +var power_tax: int + +func starting_budget(lev: int): + + if lev == 1: + budget = 20000 + elif lev == 2: + budget = 10000 + elif lev == 3: + budget = 5000 + else: + budget = NAN \ No newline at end of file diff --git a/src/world.gd b/src/scripts/world.gd similarity index 79% rename from src/world.gd rename to src/scripts/world.gd index 2df7f31..2d3db7b 100644 --- a/src/world.gd +++ b/src/scripts/world.gd @@ -1,10 +1,20 @@ -extends Node2D +extends Node -var noise : OpenSimplexNoise +var noise: OpenSimplexNoise var map_size = Vector2(80, 60) var terrian_cap = 0.3 +func _process(delta): + + $GUI/GPanel/HBox/MoneyLbl.text = str(bank.budget) + +func _input(event): + pass + func _ready(): + + bank.starting_budget(1) + randomize() noise = OpenSimplexNoise.new() noise.seed = randi() diff --git a/src/world.tscn b/src/world.tscn index ccfd199..4b323c1 100644 --- a/src/world.tscn +++ b/src/world.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] -[ext_resource path="res://world.gd" type="Script" id=1] +[ext_resource path="res://scripts/world.gd" type="Script" id=1] [ext_resource path="res://graphics/water.tres" type="TileSet" id=2] [ext_resource path="res://graphics/terrian.tres" type="TileSet" id=3] +[ext_resource path="res://gui.tscn" type="PackedScene" id=4] -[node name="Node2D" type="Node2D"] +[node name="Node2D" type="Node"] script = ExtResource( 1 ) [node name="Water" type="TileMap" parent="."] @@ -16,3 +17,5 @@ format = 1 tile_set = ExtResource( 3 ) cell_size = Vector2( 16, 16 ) format = 1 + +[node name="GUI" parent="." instance=ExtResource( 4 )]