From 3308bddc6cd338411cda3a62c603a13a743ab6ca Mon Sep 17 00:00:00 2001 From: Anthony Foxclaw <35226681+tonytins@users.noreply.github.com> Date: Sun, 12 Apr 2020 20:06:52 -0400 Subject: [PATCH] Added income frequency - Added years and quarters to the interface - Created timer that increments the number of quarters in a year until it reaches four. After four, the quarter resets and the year increments. - Renamed TowerData to GameData --- project/assets/office.tscn | 4 --- project/project.godot | 4 +-- project/src/autoload/gamedata.gd | 8 ++++++ project/src/autoload/twrdata.gd | 16 ----------- project/src/gpanel.gd | 7 ----- project/src/gui.gd | 10 ++++--- project/src/gui.tscn | 46 +++++++++++++++++++++++++++----- project/src/newgame.gd | 2 +- project/src/room.gd | 34 ++++++++++++++++------- project/src/titlescreen.tscn | 15 ++--------- project/src/world.gd | 12 +++++++++ project/src/world.tscn | 9 ++++++- 12 files changed, 104 insertions(+), 63 deletions(-) create mode 100644 project/src/autoload/gamedata.gd delete mode 100644 project/src/autoload/twrdata.gd delete mode 100644 project/src/gpanel.gd create mode 100644 project/src/world.gd diff --git a/project/assets/office.tscn b/project/assets/office.tscn index 54d2315..9f65900 100644 --- a/project/assets/office.tscn +++ b/project/assets/office.tscn @@ -9,7 +9,3 @@ room_income = 500 room_expense = 350 room_capacity = 1 is_rentable = true - -[node name="Rent" type="Timer" parent="."] -wait_time = 5.0 -[connection signal="timeout" from="Rent" to="." method="_on_Rent_timeout"] diff --git a/project/project.godot b/project/project.godot index 6433bbe..b8399db 100644 --- a/project/project.godot +++ b/project/project.godot @@ -21,11 +21,11 @@ config/icon="res://icon.png" [autoload] -TowerData="*res://src/autoload/twrdata.gd" +GameData="*res://src/autoload/gamedata.gd" [display] -window/stretch/mode="viewport" +window/stretch/mode="2d" window/stretch/aspect="keep" [rendering] diff --git a/project/src/autoload/gamedata.gd b/project/src/autoload/gamedata.gd new file mode 100644 index 0000000..66a6d54 --- /dev/null +++ b/project/src/autoload/gamedata.gd @@ -0,0 +1,8 @@ +extends Node + +var tower_name: String +var budget: int = 2000000 +var year: int = 1 +var prev_quarter: int +var quarter: int = 1 +enum GameSpeed { SLOW, MEDIUM, FAST } diff --git a/project/src/autoload/twrdata.gd b/project/src/autoload/twrdata.gd deleted file mode 100644 index dd7ff95..0000000 --- a/project/src/autoload/twrdata.gd +++ /dev/null @@ -1,16 +0,0 @@ -extends Node - -var tower_name: String - -var budget: int -var prev_budget: int - -func starting_budget(lev: int): - - if lev == 3: - budget = 5000 - elif lev == 2: - budget = 10000 - # Default to easy mode - else: - budget = 20000 diff --git a/project/src/gpanel.gd b/project/src/gpanel.gd deleted file mode 100644 index 519b07f..0000000 --- a/project/src/gpanel.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends Panel - -func _ready(): - $TwrMenus/TwrNameLbl.text = TowerData.tower_name - -func _process(delta): - $TwrMenus/MoneyLbl.text = str(TowerData.budget) diff --git a/project/src/gui.gd b/project/src/gui.gd index 05163b1..34a3ef2 100644 --- a/project/src/gui.gd +++ b/project/src/gui.gd @@ -2,12 +2,16 @@ extends Control func _ready(): + $GPanel/GameStatus/MoneyLbl.text = str(GameData.budget) + $GPanel/GameStatus/YearNumLbl.text = str(GameData.year) + $GPanel/GameStatus/QuaterNumLbl.text = str(GameData.quarter) + $GPanel/GameMenus/NameLbl.text = GameData.tower_name $WelcomeDlg.show() - $GPanel/GameMenus/NameLbl.text = TowerData.tower_name func _process(delta): - # $GPanel/GameStatus/MoneyLbl.text = str(TowerData.budget) - pass + $GPanel/GameStatus/MoneyLbl.text = str(GameData.budget) + $GPanel/GameStatus/YearNumLbl.text = str(GameData.year) + $GPanel/GameStatus/QuaterNumLbl.text = str(GameData.quarter) func _on_WelcomeDlg_confirmed(): $WelcomeDlg.hide() diff --git a/project/src/gui.tscn b/project/src/gui.tscn index 6b9f392..0e2020b 100644 --- a/project/src/gui.tscn +++ b/project/src/gui.tscn @@ -30,20 +30,20 @@ __meta__ = { [node name="NameLbl" type="Label" parent="GPanel/GameMenus"] margin_top = 3.0 -margin_right = 80.0 +margin_right = 9.0 margin_bottom = 17.0 -text = "Tower Name" +text = "#" [node name="GameSpeed" type="MenuButton" parent="GPanel/GameMenus"] -margin_left = 84.0 -margin_right = 177.0 +margin_left = 13.0 +margin_right = 106.0 margin_bottom = 20.0 text = "Game Speed" items = [ "Slow", null, 0, false, false, 0, 0, null, "", false, "Medium", null, 0, false, false, 1, 0, null, "", false, "Fast", null, 0, false, false, 2, 0, null, "", false ] [node name="Disasters" type="MenuButton" parent="GPanel/GameMenus"] -margin_left = 181.0 -margin_right = 253.0 +margin_left = 110.0 +margin_right = 182.0 margin_bottom = 20.0 text = "Disasters" @@ -61,6 +61,39 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="YearLbl" type="Label" parent="GPanel/GameStatus"] +margin_left = 193.0 +margin_top = 3.0 +margin_right = 200.0 +margin_bottom = 17.0 +text = "Y" + +[node name="YearNumLbl" type="Label" parent="GPanel/GameStatus"] +margin_left = 204.0 +margin_top = 3.0 +margin_right = 212.0 +margin_bottom = 17.0 +text = "1" + +[node name="QuaterLbl" type="Label" parent="GPanel/GameStatus"] +margin_left = 216.0 +margin_top = 3.0 +margin_right = 227.0 +margin_bottom = 17.0 +text = "Q" + +[node name="QuaterNumLbl" type="Label" parent="GPanel/GameStatus"] +margin_left = 231.0 +margin_top = 3.0 +margin_right = 239.0 +margin_bottom = 17.0 +text = "1" + +[node name="VSeparator" type="VSeparator" parent="GPanel/GameStatus"] +margin_left = 243.0 +margin_right = 247.0 +margin_bottom = 20.0 + [node name="CurrencyLbl" type="Label" parent="GPanel/GameStatus"] margin_left = 251.0 margin_top = 3.0 @@ -84,6 +117,7 @@ margin_bottom = 583.202 text = "Debug" [node name="WelcomeDlg" type="AcceptDialog" parent="."] +pause_mode = 2 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 diff --git a/project/src/newgame.gd b/project/src/newgame.gd index 7458f71..9ec52b2 100644 --- a/project/src/newgame.gd +++ b/project/src/newgame.gd @@ -2,6 +2,6 @@ extends Control func _on_CreateBtn_pressed(): var tower_name = $TwrNameEdit.text - TowerData.tower_name = tower_name + GameData.tower_name = tower_name get_tree().change_scene("res://src/world.tscn") diff --git a/project/src/room.gd b/project/src/room.gd index 7b98e43..eea4d1d 100644 --- a/project/src/room.gd +++ b/project/src/room.gd @@ -1,19 +1,31 @@ extends Node2D -export var room_cost: int +enum IncomeFrequency { ONE_TIME, QUARTERLY, DAILY } + +export var room_cost: int = 10000 export var room_income: int export var room_expense: int export var room_capacity: int export var is_rentable: bool +export(IncomeFrequency) var income_frequency = IncomeFrequency.DAILY +var rent: Timer var is_vacant: bool var num_of_tenants: int var is_full: bool func _ready(): + + match income_frequency: + # TODO: how long should a day be? + IncomeFrequency.DAILY: + rent.wait_time = 1 + IncomeFrequency.QUARTERLY: + rent.wait_time = 5 + # Once placed in-world, it'll substract from your budget - if TowerData.budget >= room_cost: - TowerData.budget = -room_cost + if GameData.budget >= room_cost: + GameData.budget = -room_cost func _process(delta): @@ -22,12 +34,14 @@ func _process(delta): if num_of_tenants >= room_capacity: is_vacant = false num_of_tenants += 1 - $Rent.start() + rent.start() else: - $Rent.stop() + rent.stop() -func _on_Rent_timeout(): - # On timeout, pay the player and restart timer - if room_income != 0: - TowerData.budget = room_income - $Rent.start() + match income_frequency: + IncomeFrequency.DAILY: + # On timeout, pay the player and restart timer + GameData.budget = room_income + rent.start() + IncomeFrequency.ONE_TIME: + GameData.budget = room_income diff --git a/project/src/titlescreen.tscn b/project/src/titlescreen.tscn index 33bfbca..2aa2a8b 100644 --- a/project/src/titlescreen.tscn +++ b/project/src/titlescreen.tscn @@ -29,22 +29,11 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="BudgetMenu" type="MenuButton" parent="."] -margin_left = 339.0 -margin_top = 294.0 -margin_right = 628.0 -margin_bottom = 314.0 -text = "Starting Budget" -items = [ "20000", null, 0, false, false, 0, 0, null, "", false, "10000", null, 0, false, false, 1, 0, null, "", false, "500", null, 0, false, false, 2, 0, null, "", false ] -__meta__ = { -"_edit_use_anchors_": false -} - [node name="CreateBtn" type="Button" parent="."] margin_left = 339.0 -margin_top = 319.0 +margin_top = 291.0 margin_right = 628.0 -margin_bottom = 339.0 +margin_bottom = 311.0 text = "Create" __meta__ = { "_edit_use_anchors_": false diff --git a/project/src/world.gd b/project/src/world.gd new file mode 100644 index 0000000..b3becf0 --- /dev/null +++ b/project/src/world.gd @@ -0,0 +1,12 @@ +extends Node + +func _on_Quarters_timeout(): + + if GameData.prev_quarter == 4: + GameData.quarter = 1 + GameData.year += 1 + else: + GameData.quarter += 1 + + GameData.prev_quarter = GameData.quarter + $Quarters.start() diff --git a/project/src/world.tscn b/project/src/world.tscn index 22dcdc0..b9a8d49 100644 --- a/project/src/world.tscn +++ b/project/src/world.tscn @@ -1,7 +1,14 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] +[ext_resource path="res://src/world.gd" type="Script" id=1] [ext_resource path="res://src/gui.tscn" type="PackedScene" id=2] [node name="World" type="Node"] +script = ExtResource( 1 ) [node name="GUI" parent="." instance=ExtResource( 2 )] + +[node name="Quarters" type="Timer" parent="."] +wait_time = 5.0 +autostart = true +[connection signal="timeout" from="Quarters" to="." method="_on_Quarters_timeout"]