Commit 2ec819bf authored by Emery Tanghanwaye's avatar Emery Tanghanwaye
Browse files

waterGame: improve button code

parent cb5b7538
......@@ -8,15 +8,20 @@ public class Game : Node2D
private float _Money = 0f;
private float _ProfitRate = 1f;
private int CurrentStage = 1;
private int NextStageRequirement = 1000;
// Labels for different text labels in the game
private Label MoneyLabel;
private Label ProfitLabel;
private Label StageLabel;
// List of all the buttons in the game
private List<WButton> Buttons = new List<WButton>();
private List<WButton> Stage2Buttons = new List<WButton>();
// References to the different buttons within the game
// References to the different nodes within the game
private Control GUI;
private ScrollCamera ScrollCamera;
// points counting how many bad choices the player has made
private int BadPoints = 0;
......@@ -50,34 +55,87 @@ public class Game : Node2D
public void IncreaseBadPoints() { BadPoints++; }
private float[] ButtXVals = {90f, 500f, 910f};
private float[] ButtYVals = {200f, 330f, 460f};
private int XIndex = 0;
private int YIndex = 0;
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);
GUI.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);
GUI.AddChild(label);
YIndex++;
}
private void CreateFirstStageButtons()
{
WButton wellButton = new WButton("Wells", 10, 1, false);
GUI.AddChild(wellButton);
Buttons.Add(wellButton);
wellButton.SetPosition(new Vector2(90f, 180f));
wellButton.SetSize(new Vector2(220f, 100f));
WLabel wellLabel = new WLabel(wellButton);
GUI.AddChild(wellLabel);
WButton ecoFiltButton = new WButton("Eco-Friendly Filtration", 25, 2, false);
GUI.AddChild(ecoFiltButton);
Buttons.Add(ecoFiltButton);
ecoFiltButton.SetPosition(new Vector2(90f, 370f));
ecoFiltButton.SetSize(new Vector2(220f, 100f));
WLabel ecoFiltLabel = new WLabel(ecoFiltButton);
GUI.AddChild(ecoFiltLabel);
WButton cheapFiltButton = new WButton("Cheap Filtration", 15, 5, true);
GUI.AddChild(cheapFiltButton);
Buttons.Add(cheapFiltButton);
cheapFiltButton.SetPosition(new Vector2(500f, 370f));
cheapFiltButton.SetSize(new Vector2(220f, 100f));
WLabel cheapFiltLabel = new WLabel(cheapFiltButton);
GUI.AddChild(cheapFiltLabel);
CreateButton("Wells", 10f, 1f, false);
CreateButton("Eco-Friendly Filtration", 25f, 2f, false);
CreateButton("Cheap Filtration", 15f, 5f, true);
}
private void CreateSecondStageButtons()
{
CreateButton("UV Filtration", 100f, 20f, false);
CreateButton("Vapor Filtration", 75f, 25f, true);
CreateButton("Tap Water", 200f, 40f, false);
CreateButton("Bottled Water", 250f, 30f, true);
}
private void CreateThirdStageButtons()
{
if (BadPoints >= 5)
{
//CreateButton("");
}
}
private void IncreaseStage()
{
CurrentStage++;
YIndex = 0;
XIndex = 0;
if (CurrentStage == 2)
{
CreateSecondStageButtons();
NextStageRequirement = 10000;
StageLabel.Text = "Stage: River";
ProfitRate += 10f;
ScrollCamera.ScrollBarVisibility = true;
}
if (CurrentStage == 3)
{
if (BadPoints >= 5)
{
StageLabel.Text = "Stage: Ocean";
}
else
{
StageLabel.Text = "Stage: Spring Water";
}
}
}
public override void _Ready()
......@@ -85,10 +143,14 @@ public class Game : Node2D
// Pull in our required labels
MoneyLabel = GetNode<Label>("GUI/CanvasLayer/MoneyLabel");
ProfitLabel = GetNode<Label>("GUI/CanvasLayer/ProfitLabel");
StageLabel = GetNode<Label>("GUI/CanvasLayer/StageLabel");
// Pull in GUI reference
GUI = GetNode<Control>("GUI");
// Pull in Camera
ScrollCamera = GetNode<ScrollCamera>("ScrollCamera");
CreateFirstStageButtons();
}
......@@ -97,11 +159,10 @@ public class Game : Node2D
Money += ProfitRate * delta;
MoneyLabel.Text = $"{Money:C2}";
ProfitLabel.Text = $"{ProfitRate:C2} per second";
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
if (Money > NextStageRequirement)
{
IncreaseStage();
}
}
}
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Game.cs" type="Script" id=1]
[ext_resource path="res://Camera.cs" type="Script" id=2]
[ext_resource path="res://ScrollCamera.cs" type="Script" id=2]
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
[node name="Camera" type="Control" parent="."]
[node name="ScrollCamera" type="Control" parent="."]
margin_left = 60.0
margin_top = 660.0
margin_right = 100.0
margin_bottom = 700.0
script = ExtResource( 2 )
[node name="Camera2D" type="Camera2D" parent="Camera"]
[node name="Camera2D" type="Camera2D" parent="ScrollCamera"]
offset = Vector2( 580, -300 )
current = true
[node name="CanvasLayer" type="CanvasLayer" parent="Camera"]
[node name="CanvasLayer" type="CanvasLayer" parent="ScrollCamera"]
[node name="HScrollBar" type="HScrollBar" parent="Camera/CanvasLayer"]
[node name="HScrollBar" type="HScrollBar" parent="ScrollCamera/CanvasLayer"]
visible = false
margin_left = 60.0
margin_top = 660.0
margin_right = 1220.0
margin_bottom = 690.0
max_value = 1000.0
max_value = 1280.0
[node name="GUI" type="Control" parent="."]
margin_right = 40.0
margin_bottom = 40.0
[node name="CanvasLayer" type="CanvasLayer" parent="GUI"]
[node name="ProfitLabel" type="Label" parent="GUI/CanvasLayer"]
margin_left = 25.9466
margin_top = 82.4186
margin_right = 65.9466
margin_bottom = 96.4186
margin_left = 60.0
margin_top = 30.0
margin_right = 171.0
margin_bottom = 44.0
text = "$0.00 per second"
[node name="MoneyLabel" type="Label" parent="GUI/CanvasLayer"]
margin_left = 19.2844
margin_top = 44.0787
margin_right = 59.2844
margin_bottom = 58.0787
margin_left = 60.0
margin_top = 45.0
margin_right = 76.0
margin_bottom = 59.0
text = "$0"
[node name="StageLabel" type="Label" parent="GUI/CanvasLayer"]
margin_left = 60.0
margin_top = 60.0
margin_right = 121.0
margin_bottom = 74.0
text = "Stage: Well"
using Godot;
using System;
public class Camera : Control
public class ScrollCamera : Control
{
private Camera2D Cam;
private HScrollBar ScrlBar;
private Vector2 OriginalPos;
public bool ScrollBarVisibility
{
set
{
ScrlBar.Visible = value;
}
}
public void ExtendToNextStage()
{
ScrlBar.MaxValue += 1280;
}
public override void _Ready()
{
Cam = GetNode<Camera2D>("Camera2D");
......
......@@ -17,5 +17,7 @@ public class WLabel : Label
this.WButton = wbutton;
Vector2 LabelPos = new Vector2(WButton.GetPosition().x, (WButton.GetPosition().y + WButton.GetSize().y + 2f));
this.SetPosition(LabelPos);
this.SetSize(new Vector2(0f, 14f));
}
}
\ No newline at end of file
......@@ -23,7 +23,8 @@ config/icon="res://icon.png"
window/size/width=1280
window/size/height=720
window/stretch/mode="viewport"
window/stretch/mode="2d"
window/stretch/aspect="keep"
[mono]
......
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