Commit 28cb810e authored by Emery Tanghanwaye's avatar Emery Tanghanwaye
Browse files

waterGame: initial work

parent dad8a11a
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)
// {
//
// }
}
using Godot;
using System;
public class WButton : Button
{
//
// static properties of each button
private readonly float BasePrice;
private readonly float CashPerSecond;
private readonly string UnitName;
private readonly bool IsBad;
private Game Game;
// more dynamic properties of each button
private int NumUnits = 0;
private float CurrentPrice = 0f;
public int GetNumUnits()
{
return NumUnits;
}
public float Purchase(float money)
{
float moneyLeft = 0f;
if (money >= CurrentPrice)
{
moneyLeft = (money - CurrentPrice);
NumUnits += 1;
CurrentPrice += (CurrentPrice * 0.5f);
}
else
{
moneyLeft = -1;
}
return moneyLeft;
}
public override void _Ready()
{
Game = GetTree().GetRoot().GetNode<Game>("Game");
Connect("button_up", this, nameof(OnButtonRelease));
CurrentPrice = BasePrice;
}
public override void _PhysicsProcess(float delta)
{
Text = $"Buy a {UnitName} (Cost: {CurrentPrice:C2}, makes {CashPerSecond:C2}/s)";
}
public void OnButtonRelease()
{
float money = Purchase(Game.Money);
if (money != -1f)
{
Game.Money = money;
Game.ProfitRate += CashPerSecond;
if (IsBad)
{
Game.IncreaseBadPoints();
}
}
}
public WButton() : this("Default", 1f, 1f, false) { }
public WButton(string unitName, float basePrice, float cashPerSecond, bool isBad) : base()
{
this.UnitName = unitName;
this.BasePrice = basePrice;
this.CashPerSecond = cashPerSecond;
this.IsBad = isBad;
}
}
\ No newline at end of file
[gd_scene load_steps=2 format=2]
[ext_resource path="res://WellButton.cs" type="Script" id=1]
[node name="WellButton" type="Button"]
margin_left = 90.0
margin_top = 183.0
margin_right = 316.0
margin_bottom = 282.0
text = "Buy Well ($0)"
script = ExtResource( 1 )
using Godot;
using System;
using System.Collections.Generic;
public class Game : Node2D
{
// private constants for calculating the money the player has
private float _Money = 0f;
private float _ProfitRate = 1f;
// Labels for different text labels in the game
private Label MoneyLabel;
private Label WellLabel;
private Label ProfitLabel;
// List of all the buttons in the game
private List<WButton> Buttons = new List<WButton>();
// References to the different buttons within the game
private Control GUI;
// 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 = value;
}
}
// Basic property for the value added to money every second
public float ProfitRate
{
get
{
return _ProfitRate;
}
set
{
_ProfitRate = value;
}
}
public void IncreaseBadPoints() { BadPoints++; }
private void CreateButtons()
{
WButton wellButton = new WButton("Well", 10, 1, false);
GUI.AddChild(wellButton);
Buttons.Add(wellButton);
wellButton.SetPosition(new Vector2(90f, 180f));
wellButton.SetSize(new Vector2(220f, 100f));
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));
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));
}
public override void _Ready()
{
// Pull in our required labels
MoneyLabel = GetNode<Label>("GUI/MoneyLabel");
WellLabel = GetNode<Label>("GUI/WellLabel");
ProfitLabel = GetNode<Label>("GUI/ProfitLabel");
// Pull in GUI reference
GUI = GetNode<Control>("GUI");
CreateButtons();
}
public override void _PhysicsProcess(float delta)
{
Money += ProfitRate * delta;
MoneyLabel.Text = $"{Money:C2}";
ProfitLabel.Text = $"{ProfitRate:C2} per second";
WellLabel.Text = $"Wells: {Buttons.ToArray()[0].GetNumUnits()}";
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}
[gd_scene format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Game.cs" type="Script" id=1]
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
[node name="GUI" type="Control" parent="."]
margin_right = 40.0
margin_bottom = 40.0
[node name="MoneyLabel" type="Label" parent="GUI"]
margin_left = 19.2844
margin_top = 44.0787
margin_right = 59.2844
margin_bottom = 58.0787
text = "$0"
[node name="WellLabel" type="Label" parent="GUI"]
margin_left = 22.2763
margin_top = 64.8037
margin_right = 62.2763
margin_bottom = 78.8037
text = "Wells: 0"
[node name="ProfitLabel" type="Label" parent="GUI"]
margin_left = 25.9466
margin_top = 82.4185
margin_right = 65.9466
margin_bottom = 96.4185
using System.Reflection;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("WaterGame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputPath>.mono/temp/bin/$(Configuration)</OutputPath>
<RootNamespace>WaterGame</RootNamespace>
<AssemblyName>WaterGame</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<BaseIntermediateOutputPath>.mono/temp/obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Tools|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TOOLS;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="GodotSharp">
<HintPath>$(ProjectDir)/.mono/assemblies/GodotSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GodotSharpEditor" Condition=" '$(Configuration)' == 'Tools' ">
<HintPath>$(ProjectDir)/.mono/assemblies/GodotSharpEditor.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="**/*.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaterGame", "WaterGame.csproj", "{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Tools|Any CPU = Tools|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}.Release|Any CPU.Build.0 = Release|Any CPU
{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}.Tools|Any CPU.ActiveCfg = Tools|Any CPU
{0959EDBF-1B7E-4FC3-B633-4D0010FA5ED4}.Tools|Any CPU.Build.0 = Tools|Any CPU
EndGlobalSection
EndGlobal
......@@ -16,8 +16,13 @@ _global_script_class_icons={
[application]
config/name="WaterGame"
run/main_scene="res://Game.tscn"
config/icon="res://icon.png"
[mono]
project/auto_update_project=false
[rendering]
environment/default_environment="res://default_env.tres"
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