Commit 78a2f218 authored by Emery Tanghanwaye's avatar Emery Tanghanwaye
Browse files

waterGame: add documentation

parent a9597df2
using Godot;
using System;
public class Button : Godot.Button
{
// Declare member variables here. Examples:
// private int a = 2;
// private string b = "text";
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}
......@@ -3,14 +3,21 @@ using System;
public class ButtonGroup : Control
{
// creates array of positions for the pages
private Vector2[] PageLocations = new Vector2[5];
// reference to the camera
private Camera2D Cam;
// list of buttons for page movement
private Button[] Buttons = new Button[5];
// tween node for fancy movement between pages
private Tween CamTween;
// variable keeping track of our current page
private int CurrentPage = 0;
// variable keeping track of which buttons we've enabled
private int ButtsEnabled = 0;
// function which enables the next buttons
public void EnableNextButton()
{
Buttons[ButtsEnabled++].Visible = true;
......@@ -18,9 +25,11 @@ public class ButtonGroup : Control
public override void _Ready()
{
// creates references to camera and tween nodes
Cam = GetNode<Camera2D>("../../Camera2D");
CamTween = GetNode<Tween>("Tween");
// generates all the buttons
for (int i = 0; i < 5; i++)
{
Button button = new Button();
......@@ -31,6 +40,7 @@ public class ButtonGroup : Control
this.AddChild(button);
Buttons[i] = button;
// does the math for the different page locations
Vector2 pageLocation = Cam.Offset;
pageLocation.x = (Cam.Offset.x + (1280 * i));
PageLocations[i] = pageLocation;
......@@ -39,13 +49,16 @@ public class ButtonGroup : Control
public override void _PhysicsProcess(float delta)
{
// checks every button to see if its pressed
for (int i = 0; i < 5; i++)
{
// if a button is pressed, and we're not already on it's page, continue
if (Buttons[i].IsPressed() && (CurrentPage != i))
{
Vector2 originalPos = Cam.Offset;
CurrentPage = i;
// this is greek to me still, but this interpolates the original pos and the intended pos to create a smooth slide effect
CamTween.InterpolateProperty(Cam, "offset", originalPos, PageLocations[i], 0.25f, Tween.TransitionType.Linear, Tween.EaseType.InOut);
CamTween.Start();
......
......@@ -4,11 +4,14 @@ using System.Collections.Generic;
public class Game : Node2D
{
// private constants for calculating the money the player has
private float _Money = 1000000f;
// 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;
// Labels for different text labels in the game
......@@ -17,11 +20,9 @@ public class Game : Node2D
private Label StageLabel;
private Label GoalLabel;
// List of all the buttons in the game
private List<WButton> Stage2Buttons = new List<WButton>();
// References to the different nodes within the game
// Reference to the GUI node to add buttons and labels to
private Control GUI;
// reference to button group for UI navigation
private ButtonGroup ButtGroup;
// points counting how many bad choices the player has made
......@@ -41,7 +42,7 @@ public class Game : Node2D
}
}
// Basic property for the value added to money every second
// Basic property for the profit rate added to money every second
public float ProfitRate
{
get
......@@ -54,13 +55,20 @@ public class Game : Node2D
}
}
// 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)
......@@ -82,7 +90,7 @@ public class Game : Node2D
YIndex++;
}
// creates all the buttons for stage 1
private void CreateFirstStageButtons()
{
CreateButton("Wells", 10f, 1f, false);
......@@ -92,6 +100,7 @@ public class Game : Node2D
CreateButton("Cheap Filtration", 15f, 5f, true);
}
// creates all the buttons for stage 2
private void CreateSecondStageButtons()
{
CreateButton("UV Filtration", 100f, 20f, false);
......@@ -103,6 +112,7 @@ public class Game : Node2D
CreateButton("Plastic Bottles", 250f, 30f, true);
}
// creates all the buttons for stage 3
private void CreateThirdStageButtons()
{
CreateButton("Clean Landfills", 1500f, 300f, false);
......@@ -114,6 +124,7 @@ public class Game : Node2D
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);
......@@ -128,12 +139,14 @@ public class Game : Node2D
}
}
// 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);
......@@ -156,6 +169,8 @@ public class Game : Node2D
}
}
// creates all the buttons for stage 5
private void CreateFifthStageButtons()
{
CreateButton("Plant Trees", 1000f, 15000f, false);
......@@ -171,13 +186,17 @@ public class Game : Node2D
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)
{
ButtGroup.EnableNextButton();
......@@ -187,6 +206,7 @@ public class Game : Node2D
ProfitRate += 10f;
}
// same as before, but with a possible split if the player makes bad choices
if (CurrentStage == 3)
{
ButtGroup.EnableNextButton();
......@@ -203,10 +223,11 @@ public class Game : Node2D
}
}
// same as stage 3
if (CurrentStage == 4)
{
ButtGroup.EnableNextButton();
CreateThirdStageButtons();
CreateFourthStageButtons();
NextStageRequirement = 1000000;
ProfitRate += 5000;
if (BadPoints >= 20)
......@@ -219,6 +240,7 @@ public class Game : Node2D
}
}
// 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) {
......@@ -242,7 +264,7 @@ public class Game : Node2D
public override void _Ready()
{
// Pull in our required labels
// Pulls in our labels
MoneyLabel = GetNode<Label>("GUI/CanvasLayer/MoneyLabel");
ProfitLabel = GetNode<Label>("GUI/CanvasLayer/ProfitLabel");
StageLabel = GetNode<Label>("GUI/CanvasLayer/StageLabel");
......@@ -254,30 +276,40 @@ public class Game : Node2D
// 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: ???";
}
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))
{
EndGame();
......
......@@ -3,19 +3,23 @@ using System;
public class WButton : Button
{
//
// static properties of each button
// the initial price of the button
private readonly float BasePrice;
// the amount of money the item will give you per sec
private readonly float CashPerSecond;
// name of the item
private readonly string _UnitName;
// whether or not the item has an adverse effect on the environment
private readonly bool IsBad;
// reference to game
private Game Game;
// more dynamic properties of each button
// amount of the item purchased
private int _NumUnits = 0;
// the current price of the item purchased
private float CurrentPrice = 0f;
// basic property for units
public int NumUnits
{
get
......@@ -24,6 +28,7 @@ public class WButton : Button
}
}
// basic property for the name
public string UnitName
{
get
......@@ -32,12 +37,15 @@ public class WButton : Button
}
}
// method for handling the removal of money from the player's wallet
public float Purchase(float money)
{
float moneyLeft = 0f;
// checks if the player can buy it
if (money >= CurrentPrice)
{
// if we can, buy it, increase the price, and have the player make more money as well
moneyLeft = (money - CurrentPrice);
_NumUnits += 1;
......@@ -45,6 +53,7 @@ public class WButton : Button
}
else
{
// if the player doesn't have the money, return a value the code will recognize as incorrect
moneyLeft = -1;
}
......@@ -53,25 +62,34 @@ public class WButton : Button
public override void _Ready()
{
// ties our game reference to the actual node
Game = GetTree().GetRoot().GetNode<Game>("Game");
// ties the button release event to the OnButtonRelease method
Connect("button_up", this, nameof(OnButtonRelease));
// sets our current price to the base price initially
CurrentPrice = BasePrice;
}
public override void _PhysicsProcess(float delta)
{
// sets our text to the name, cost, and how much it makes the player
Text = $"{UnitName} (Cost: {CurrentPrice:C2}, makes {CashPerSecond:C2}/s)";
}
public void OnButtonRelease()
{
// calls our purchase method
float money = Purchase(Game.Money);
// if we don't have the money, the method returns -1, so stop if this is the case
if (money != -1f)
{
// sets the games amount of money to the new amount
Game.Money = money;
// increases the players profit amount
Game.ProfitRate += CashPerSecond;
// gives the player more bad points if this item isn't good
if (IsBad)
{
Game.IncreaseBadPoints();
......@@ -79,8 +97,10 @@ public class WButton : Button
}
}
// default constructor for the wbutton, as i am unsure on whether or not the editor expects an empty constructor
public WButton() : this("Default", 1f, 1f, false) { }
// basic constructor
public WButton(string unitName, float basePrice, float cashPerSecond, bool isBad) : base()
{
this._UnitName = unitName;
......
......@@ -3,15 +3,19 @@ using System;
public class WLabel : Label
{
// holds a reference to a button
private readonly WButton WButton;
public override void _PhysicsProcess(float delta)
{
// sets our text to the amount of units purchased
Text = $"{WButton.UnitName}: {WButton.NumUnits}";
}
// no argument constructor, just in case the editor expects this
public WLabel() : this(null) { }
// basic constructor for this custom label
public WLabel(WButton wbutton) : base()
{
this.WButton = wbutton;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment