-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cs
More file actions
341 lines (277 loc) · 9.96 KB
/
Copy pathGame.cs
File metadata and controls
341 lines (277 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
using Godot;
using System;
using System.Collections.Generic;
public class Game : Node2D
{
// initial amount of money player has
private float _Money = 0f;
// the amount of money player earns per second
private float _ProfitRate = 1f;
// the player's current level of progression
private int CurrentStage = 1;
// the threshold needed to progress to the next stage
private int NextStageRequirement = 1000;
// sprite for the game background
private AnimatedSprite Background;
private Sprite FailScreen;
// Labels for different text labels in the game
private Label MoneyLabel;
private Label ProfitLabel;
private Label StageLabel;
private Label GoalLabel;
private Label TargetRateLabel;
// Reference to the GUI node to add buttons and labels to
private Control ButtonHolder;
// reference to button group for UI navigation
private ButtonGroup ButtGroup;
// points counting how many bad choices the player has made
private int BadPoints = 0;
// Basic property for money
public float Money
{
get
{
return _Money;
}
set
{
if (value < 0)
{
_Money = 0;
}
else
{
_Money = value;
}
}
}
// Basic property for the profit rate added to money every second
public float ProfitRate
{
get
{
return _ProfitRate;
}
set
{
_ProfitRate = value;
}
}
// increases bad points whenever called by a bad button
public void IncreaseBadPoints() { BadPoints++; }
// the base x values buttons can be created on
private float[] ButtXVals = {90f, 500f, 910f};
// the y values buttons can be created on
private float[] ButtYVals = {200f, 330f, 460f};
// current index of our button creation function for the x
private int XIndex = 0;
// current index of our button creation function for the y
private int YIndex = 0;
// generates each button, its label, and give it a spot in the gamespace.
// currently, can only support up to 9 spots per stage due to the hard coded nature of the positions.
private void CreateButton(string buttName, float baseCost, float cashPerSec, bool isBad)
{
if (YIndex > 2)
{
YIndex = 0;
XIndex++;
}
WButton button = new WButton(buttName, baseCost, cashPerSec, isBad);
ButtonHolder.AddChild(button);
float xPos = ButtXVals[XIndex] + (1280f * (CurrentStage - 1f));
button.SetPosition(new Vector2(xPos, ButtYVals[YIndex]));
button.SetSize(new Vector2(220f, 100f));
WLabel label = new WLabel(button);
ButtonHolder.AddChild(label);
YIndex++;
}
// creates all the buttons for stage 1
private void CreateFirstStageButtons()
{
CreateButton("Wells", 10f, 1f, false);
CreateButton("Eco-Friendly Filtration", 25f, 2f, false);
CreateButton("Cheap Filtration", 15f, 5f, true);
}
// creates all the buttons for stage 2
private void CreateSecondStageButtons()
{
CreateButton("UV Filtration", 100f, 20f, false);
CreateButton("Vapor Filtration", 75f, 25f, true);
CreateButton("Tap Water", 200f, 40f, false);
CreateButton("Plastic Bottles", 250f, 30f, true);
}
// creates all the buttons for stage 3
private void CreateThirdStageButtons()
{
CreateButton("Clean Landfills", 1500f, 300f, false);
CreateButton("Collect Rain Water", 1200f, 200f, false);
CreateButton("Cheap Plastic Bottles", 450f, 200f, true);
CreateButton("3rd World Plants", 1000f, 400f, true);
// presents the first stage where the players may see different choices based on their previous choices
if (BadPoints >= 10)
{
CreateButton("Florescent Lights", 500f, 250f, true);
CreateButton("Gas Powered Pumps", 700f, 350f, true);
}
else
{
CreateButton("Solar-Powered Pumps", 700f, 200f, false);
CreateButton("Local Water Plants", 1200f, 250f, false);
}
}
// creates all the buttons for stage 4
private void CreateFourthStageButtons()
{
CreateButton("Styrofoam Bottles", 9000f, 3000f, true);
CreateButton("Hydro-Electric Power", 14000f, 2500f, false);
// if player continues to be bad, they get into the lose condition of the game: ruining the planet
if (BadPoints >= 20)
{
CreateButton("Mega Plants", 10000f, 7000f, true);
CreateButton("Cheap Piping", 8000f, 4800f, true);
CreateButton("De-Regulation Lobbying", 11000f, 10000f, true);
CreateButton("Glacier Melting", 11000f, 20000f, true);
}
else
{
CreateButton("Tighter Quality Control", 13000f, 4000f, false);
CreateButton("Wind Powered Plants", 12000f, 4500f, false);
CreateButton("Electric Transport", 11000f, 3000f, false);
CreateButton("Sanitation Plants", 1000f, 2800f, false);
}
}
// creates all the buttons for stage 5
private void CreateFifthStageButtons()
{
CreateButton("Plant Trees", 1000f, 15000f, false);
CreateButton("Clean Landfills", 5000f, 20000f, false);
CreateButton("Renewable Bottles", 5000f, 1200f, false);
CreateButton("Hydroelectric Energy", 250000f, 300000f, false);
CreateButton("Clean Oceans", 5000f, 1000f, false);
CreateButton("Recycle Plastics", 100000f, 50000f, false);
}
// function for handing the move between stages
private void IncreaseStage()
{
// increments our stage number variable
CurrentStage++;
// resets indexes for x + y position
YIndex = 0;
XIndex = 0;
// enables the next button in the button group, moves us to the next stage and changes the name
if (CurrentStage == 2)
{
Background.Frame = 1;
ButtGroup.EnableNextButton();
CreateSecondStageButtons();
NextStageRequirement = 20000;
StageLabel.Text = "Stage: River";
ProfitRate += 10f;
}
// same as before, but with a possible split if the player makes bad choices
if (CurrentStage == 3)
{
ButtGroup.EnableNextButton();
CreateThirdStageButtons();
NextStageRequirement = 250000;
ProfitRate += 200;
if (BadPoints >= 10)
{
Background.Frame = 2;
StageLabel.Text = "Stage: Ocean";
}
else
{
Background.Frame = 3;
StageLabel.Text = "Stage: Spring Water";
}
}
// same as stage 3
if (CurrentStage == 4)
{
ButtGroup.EnableNextButton();
CreateFourthStageButtons();
NextStageRequirement = 5000000;
ProfitRate += 5000;
if (BadPoints >= 20)
{
Background.Frame = 4;
StageLabel.Text = "Stage: Glacier";
}
else
{
Background.Frame = 5;
StageLabel.Text = "Stage: Dam";
}
}
// flips the profit if the player is bad, beginning the loss condition for bad players. activates end-game philanthropist content for good players
if (CurrentStage == 5)
{
if (BadPoints >= 20) {
ProfitRate = -(ProfitRate * 0.1f);
StageLabel.Text = "Stage 5: ???";
}
else
{
Background.Frame = 6;
ButtGroup.EnableNextButton();
CreateFifthStageButtons();
StageLabel.Text = "Stage 5: Philanthropy";
NextStageRequirement = Int32.MaxValue;
ProfitRate += 10000;
}
}
}
private void EndGameBad()
{
FailScreen.Visible = true;
}
public override void _Ready()
{
// pulls in background object
Background = GetNode<AnimatedSprite>("ScrollCamera/Camera2D/Background");
FailScreen = GetNode<Sprite>("GUI/CanvasLayer/FailScreen");
// Pulls in our labels
MoneyLabel = GetNode<Label>("GUI/CanvasLayer/MoneyLabel");
ProfitLabel = GetNode<Label>("GUI/CanvasLayer/ProfitLabel");
StageLabel = GetNode<Label>("GUI/CanvasLayer/StageLabel");
GoalLabel = GetNode<Label>("GUI/CanvasLayer/GoalLabel");
// Pull in GUI reference
ButtonHolder = GetNode<Control>("GUI/ButtonHolder");
// Get Button Group Reference
ButtGroup = GetNode<ButtonGroup>("ScrollCamera/CanvasLayer/ButtonGroup");
// enables the first button
ButtGroup.EnableNextButton();
// enables the first set of game buttons
CreateFirstStageButtons();
}
public override void _PhysicsProcess(float delta)
{
// increments the money value
Money += ProfitRate * delta;
// label text setting handling
MoneyLabel.Text = $"{Money:C2}";
ProfitLabel.Text = $"{ProfitRate:C2} per second";
// sets the goal to something mysterious if a bad player hits the loss condition
if ((CurrentStage == 5) && (BadPoints >= 20))
{
GoalLabel.Text = "Next Goal: ???";
ProfitRate = -ProfitRate;
}
else
{
// shows the next bar to reach for profit
GoalLabel.Text = $"Next Goal: {NextStageRequirement:C2}";
}
// increments the stage when the player reaches a certain threshold
if (Money > NextStageRequirement)
{
IncreaseStage();
}
// ends the game once the bad player loses all their money
if ((CurrentStage == 5) && (Money < 0))
{
EndGameBad();
}
}
}