Commit fe380217 authored by Emery Tanghanwaye's avatar Emery Tanghanwaye
Browse files

waterGame: add stage 5 for good path, and better transitioning

parent d55be889
using Godot;
using System;
public class ButtonGroup : Control
{
private Vector2[] PageLocations = new Vector2[5];
private Camera2D Cam;
private Button[] Buttons = new Button[5];
private Tween CamTween;
private int CurrentPage = 0;
private int ButtsEnabled = 0;
public void EnableNextButton()
{
Buttons[ButtsEnabled++].Visible = true;
}
public override void _Ready()
{
Cam = GetNode<Camera2D>("../../Camera2D");
CamTween = GetNode<Tween>("Tween");
for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Visible = false;
button.SetSize(new Vector2(25f, 25f));
button.SetPosition(new Vector2((280f * i), 0));
button.Text = (i + 1).ToString();
this.AddChild(button);
Buttons[i] = button;
Vector2 pageLocation = Cam.Offset;
pageLocation.x = (Cam.Offset.x + (1280 * i));
PageLocations[i] = pageLocation;
}
}
public override void _PhysicsProcess(float delta)
{
for (int i = 0; i < 5; i++)
{
if (Buttons[i].IsPressed() && (CurrentPage != i))
{
Vector2 originalPos = Cam.Offset;
CurrentPage = i;
CamTween.InterpolateProperty(Cam, "offset", originalPos, PageLocations[i], 0.25f, Tween.TransitionType.Linear, Tween.EaseType.InOut);
CamTween.Start();
}
}
}
}
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
......@@ -22,7 +22,7 @@ public class Game : Node2D
// References to the different nodes within the game
private Control GUI;
private ScrollCamera ScrollCamera;
private ButtonGroup ButtGroup;
// points counting how many bad choices the player has made
private int BadPoints = 0;
......@@ -156,6 +156,21 @@ public class Game : Node2D
}
}
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);
}
private void IncreaseStage()
{
CurrentStage++;
......@@ -165,16 +180,16 @@ public class Game : Node2D
if (CurrentStage == 2)
{
ButtGroup.EnableNextButton();
CreateSecondStageButtons();
NextStageRequirement = 20000;
StageLabel.Text = "Stage: River";
ProfitRate += 10f;
ScrollCamera.ScrollBarVisibility = true;
ScrollCamera.ExtendToNextStage();
}
if (CurrentStage == 3)
{
ButtGroup.EnableNextButton();
CreateThirdStageButtons();
NextStageRequirement = 250000;
ProfitRate += 200;
......@@ -186,11 +201,11 @@ public class Game : Node2D
{
StageLabel.Text = "Stage: Spring Water";
}
ScrollCamera.ExtendToNextStage();
}
if (CurrentStage == 4)
{
ButtGroup.EnableNextButton();
CreateThirdStageButtons();
NextStageRequirement = 1000000;
ProfitRate += 5000;
......@@ -202,7 +217,6 @@ public class Game : Node2D
{
StageLabel.Text = "Stage: Dam";
}
ScrollCamera.ExtendToNextStage();
}
if (CurrentStage == 5)
......@@ -210,6 +224,14 @@ public class Game : Node2D
if (BadPoints >= 20) {
ProfitRate = -ProfitRate;
}
else
{
ButtGroup.EnableNextButton();
CreateFifthStageButtons();
StageLabel.Text = "Stage 5: Philanthropy";
NextStageRequirement = Int32.MaxValue;
ProfitRate += 10000;
}
}
}
......@@ -229,8 +251,10 @@ public class Game : Node2D
// Pull in GUI reference
GUI = GetNode<Control>("GUI");
// Pull in Camera
ScrollCamera = GetNode<ScrollCamera>("ScrollCamera");
// Get Button Group Reference
ButtGroup = GetNode<ButtonGroup>("ScrollCamera/CanvasLayer/ButtonGroup");
ButtGroup.EnableNextButton();
CreateFirstStageButtons();
}
......
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Game.cs" type="Script" id=1]
[ext_resource path="res://ScrollCamera.cs" type="Script" id=2]
[ext_resource path="res://ButtonGroup.cs" type="Script" id=2]
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
......@@ -11,7 +11,6 @@ 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="ScrollCamera"]
offset = Vector2( 580, -300 )
......@@ -19,13 +18,14 @@ current = true
[node name="CanvasLayer" type="CanvasLayer" parent="ScrollCamera"]
[node name="HScrollBar" type="HScrollBar" parent="ScrollCamera/CanvasLayer"]
visible = false
[node name="ButtonGroup" type="Control" parent="ScrollCamera/CanvasLayer"]
margin_left = 60.0
margin_top = 660.0
margin_right = 1220.0
margin_bottom = 690.0
max_value = 0.0
margin_right = 100.0
margin_bottom = 700.0
script = ExtResource( 2 )
[node name="Tween" type="Tween" parent="ScrollCamera/CanvasLayer/ButtonGroup"]
[node name="GUI" type="Control" parent="."]
......
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