Game.cs 9.96 KB
Newer Older
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
1
2
3
4
5
6
using Godot;
using System;
using System.Collections.Generic;

public class Game : Node2D
{
7
    // initial amount of money player has
Emery Tanghanwaye's avatar
final    
Emery Tanghanwaye committed
8
    private float _Money = 0f;
9
    // the amount of money player earns per second
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
10
11
    private float _ProfitRate = 1f;

12
    // the player's current level of progression
13
    private int CurrentStage = 1;
14
    // the threshold needed to progress to the next stage
15
    private int NextStageRequirement = 1000;
16
17
18

    // sprite for the game background
    private AnimatedSprite Background;
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
19
    private Sprite FailScreen;
20

Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
21
22
23
    // Labels for different text labels in the game
    private Label MoneyLabel;
    private Label ProfitLabel;
24
    private Label StageLabel;
25
    private Label GoalLabel;
26
    private Label TargetRateLabel;
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
27

28
    // Reference to the GUI node to add buttons and labels to
29
    private Control ButtonHolder;
30
    // reference to button group for UI navigation
31
    private ButtonGroup ButtGroup;
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
32
33

    // points counting how many bad choices the player has made
34
    private int BadPoints = 0;
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
35
36
37
38
39
40
41
42
43
44

    // Basic property for money
    public float Money
    {
        get
        {
            return _Money;
        }
        set
        {
45
            if (value < 0)
46
            {
47
                _Money = 0;
48
49
50
51
52
            }
            else
            {
                _Money = value;
            }
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
53
54
55
        }
    }

56
    // Basic property for the profit rate added to money every second
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
57
58
59
60
61
62
63
64
65
66
67
68
    public float ProfitRate
    {
        get
        {
            return _ProfitRate;
        }
        set
        {
            _ProfitRate = value;
        }
    }

69
    // increases bad points whenever called by a bad button
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
70
71
    public void IncreaseBadPoints() { BadPoints++; }

72
    // the base x values buttons can be created on
73
    private float[] ButtXVals = {90f, 500f, 910f};
74
    // the y values buttons can be created on
75
    private float[] ButtYVals = {200f, 330f, 460f};
76
    // current index of our button creation function for the x
77
    private int XIndex = 0;
78
    // current index of our button creation function for the y
79
80
    private int YIndex = 0;

81
82
    // 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.
83
84
85
86
87
88
89
90
91
    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);
92
        ButtonHolder.AddChild(button);
93
94
95
96
97
98

        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);
99
        ButtonHolder.AddChild(label);
100
101
102
103

        YIndex++;
    }

104
    // creates all the buttons for stage 1
105
    private void CreateFirstStageButtons()
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
106
    {
107
108
109
110
111
112
113
        CreateButton("Wells", 10f, 1f, false);

        CreateButton("Eco-Friendly Filtration", 25f, 2f, false);

        CreateButton("Cheap Filtration", 15f, 5f, true);
    }

114
    // creates all the buttons for stage 2
115
116
117
118
119
120
121
122
    private void CreateSecondStageButtons()
    {
        CreateButton("UV Filtration", 100f, 20f, false);

        CreateButton("Vapor Filtration", 75f, 25f, true);

        CreateButton("Tap Water", 200f, 40f, false);

123
        CreateButton("Plastic Bottles", 250f, 30f, true);
124
125
    }

126
    // creates all the buttons for stage 3
127
128
    private void CreateThirdStageButtons()
    {
129
130
131
132
133
134
135
136
137
        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);


138
        // presents the first stage where the players may see different choices based on their previous choices
139
140
141
142
143
144
145
146
147
148
149
150
151
152
        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);
        }
    }

153
    // creates all the buttons for stage 4
154
155
156
157
158
159
    private void CreateFourthStageButtons()
    {
        CreateButton("Styrofoam Bottles", 9000f, 3000f, true);

        CreateButton("Hydro-Electric Power", 14000f, 2500f, false);

160
        // if player continues to be bad, they get into the lose condition of the game: ruining the planet
161
162
163
164
165
166
167
168
169
170
171
        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
172
        {
173
174
175
176
177
178
179
            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);
180
181
182
        }
    }

183
184

    // creates all the buttons for stage 5
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    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);
    }

200
    // function for handing the move between stages
201
202
    private void IncreaseStage()
    {
203
        // increments our stage number variable
204
205
        CurrentStage++;

206
        // resets indexes for x + y position
207
208
209
        YIndex = 0;
        XIndex = 0;

210
        // enables the next button in the button group, moves us to the next stage and changes the name
211
212
        if (CurrentStage == 2)
        {
213
            Background.Frame = 1;
214
            ButtGroup.EnableNextButton();
215
            CreateSecondStageButtons();
216
            NextStageRequirement = 20000;
217
218
219
            StageLabel.Text = "Stage: River";
            ProfitRate += 10f;
        }
220

221
        // same as before, but with a possible split if the player makes bad choices
222
223
        if (CurrentStage == 3)
        {
224
            ButtGroup.EnableNextButton();
225
226
227
228
            CreateThirdStageButtons();
            NextStageRequirement = 250000;
            ProfitRate += 200;
            if (BadPoints >= 10)
229
            {
230
                Background.Frame = 2;
231
232
233
234
                StageLabel.Text = "Stage: Ocean";
            }
            else
            {
235
                Background.Frame = 3;
236
237
                StageLabel.Text = "Stage: Spring Water";
            }
238
239
        }

240
        // same as stage 3
241
242
        if (CurrentStage == 4)
        {
243
            ButtGroup.EnableNextButton();
244
            CreateFourthStageButtons();
245
            NextStageRequirement = 5000000;
246
247
248
            ProfitRate += 5000;
            if (BadPoints >= 20)
            {
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
249
                Background.Frame = 4;
250
251
252
253
                StageLabel.Text = "Stage: Glacier";
            }
            else
            {
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
254
                Background.Frame = 5;
255
256
                StageLabel.Text = "Stage: Dam";
            }
257
        }
258

259
        // flips the profit if the player is bad, beginning the loss condition for bad players. activates end-game philanthropist content for good players
260
261
262
        if (CurrentStage == 5)
        {
            if (BadPoints >= 20) {
263
264
                ProfitRate = -(ProfitRate * 0.1f);
                StageLabel.Text = "Stage 5: ???";
265
            }
266
267
            else
            {
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
268
                Background.Frame = 6;
269
270
271
272
273
274
                ButtGroup.EnableNextButton();
                CreateFifthStageButtons();
                StageLabel.Text = "Stage 5: Philanthropy";
                NextStageRequirement = Int32.MaxValue;
                ProfitRate += 10000;
            }
275
276
277
        }
    }

278
279
    private void EndGameBad()
    {
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
280
        FailScreen.Visible = true;
281
282
    }

Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
283
284
    public override void _Ready()
    {
285
        // pulls in background object
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
286
        Background = GetNode<AnimatedSprite>("ScrollCamera/Camera2D/Background");
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
287
        FailScreen = GetNode<Sprite>("GUI/CanvasLayer/FailScreen");
288
        
289
        // Pulls in our labels
290
291
        MoneyLabel = GetNode<Label>("GUI/CanvasLayer/MoneyLabel");
        ProfitLabel = GetNode<Label>("GUI/CanvasLayer/ProfitLabel");
292
        StageLabel = GetNode<Label>("GUI/CanvasLayer/StageLabel");
293
        GoalLabel = GetNode<Label>("GUI/CanvasLayer/GoalLabel");
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
294
295

        // Pull in GUI reference
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
296
        ButtonHolder = GetNode<Control>("GUI/ButtonHolder");
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
297

298
299
300
        // Get Button Group Reference
        ButtGroup = GetNode<ButtonGroup>("ScrollCamera/CanvasLayer/ButtonGroup");

301
        // enables the first button
302
        ButtGroup.EnableNextButton();
303

304
        // enables the first set of game buttons
305
        CreateFirstStageButtons();
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
306
307
308
309
    }

    public override void _PhysicsProcess(float delta)
    {
310
        // increments the money value
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
311
        Money += ProfitRate * delta;
312
313

        // label text setting handling
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
314
315
        MoneyLabel.Text = $"{Money:C2}";
        ProfitLabel.Text = $"{ProfitRate:C2} per second";
316
317

        // sets the goal to something mysterious if a bad player hits the loss condition
318
319
320
        if ((CurrentStage == 5) && (BadPoints >= 20))
        {
            GoalLabel.Text = "Next Goal: ???";
321
            ProfitRate = -ProfitRate;
322
323
324
        }
        else
        {
325
            // shows the next bar to reach for profit
326
327
            GoalLabel.Text = $"Next Goal: {NextStageRequirement:C2}";
        }
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
328

329
        // increments the stage when the player reaches a certain threshold
330
331
332
333
        if (Money > NextStageRequirement)
        {
            IncreaseStage();
        }
334

335
        // ends the game once the bad player loses all their money
336
337
        if ((CurrentStage == 5) && (Money < 0))
        {
338
            EndGameBad();
339
        }
340
    }
Emery Tanghanwaye's avatar
Emery Tanghanwaye committed
341
}