This commit is contained in:
Victor Turgeon 2023-06-11 17:43:09 -04:00
commit 71e524876f
3 changed files with 278 additions and 279 deletions

View File

@ -18,7 +18,7 @@ public partial class the_end : Control
private void Tick() { private void Tick() {
if (_tock == 0) if (_tock == 0)
_lbl.Set("visible", true); _lbl.Set("visible", true);
if (_tock == 4) { if (_tock == 3) {
var scene = GD.Load<PackedScene>("res://menu/start_game_menu.tscn"); var scene = GD.Load<PackedScene>("res://menu/start_game_menu.tscn");
var instance = scene.Instantiate(); var instance = scene.Instantiate();
GetNode<Node>("/root/").AddChild(instance); GetNode<Node>("/root/").AddChild(instance);

View File

@ -1,10 +1,10 @@
[gd_scene load_steps=10 format=3 uid="uid://4tym1auav4yv"] [gd_scene load_steps=10 format=3 uid="uid://4tym1auav4yv"]
[ext_resource type="Script" path="res://menu/start_game_menu.cs" id="1_0k2xm"] [ext_resource type="Script" path="res://menu/start_game_menu.cs" id="1_0k2xm"]
[ext_resource type="Texture2D" uid="uid://bd7j1ug5gs26w" path="res://images/mushroom_cloud001.webp" id="2_aky60"] [ext_resource type="Texture2D" uid="uid://b44vs2lwgnh37" path="res://images/mushroom_cloud001.webp" id="2_aky60"]
[ext_resource type="AudioStream" uid="uid://co52ygvp3wcra" path="res://music/I Feel Grunge (Slow).wav" id="2_yw57x"] [ext_resource type="AudioStream" uid="uid://ckg5eypyrhidg" path="res://music/I Feel Grunge (Slow).wav" id="2_yw57x"]
[ext_resource type="AudioStream" uid="uid://ds7ec1n3pytnr" path="res://audio/btn.wav" id="4_fx2mk"] [ext_resource type="AudioStream" uid="uid://c8dcqkmytnyay" path="res://audio/btn.wav" id="4_fx2mk"]
[ext_resource type="AudioStream" uid="uid://cg78xtngxrjlg" path="res://audio/dot.wav" id="5_y8gc7"] [ext_resource type="AudioStream" uid="uid://dja6tipmq1m8l" path="res://audio/dot.wav" id="5_y8gc7"]
[sub_resource type="LabelSettings" id="LabelSettings_n38oc"] [sub_resource type="LabelSettings" id="LabelSettings_n38oc"]
font_size = 290 font_size = 290

View File

@ -3,325 +3,324 @@ using System;
public partial class player : Camera3D public partial class player : Camera3D
{ {
private const string _path = "/root/player/"; private const string _path = "/root/player/";
[Export] [Export]
private Label _con; private Label _con;
[Export] [Export]
private Label _mousePosLabel; private Label _mousePosLabel;
[Export] [Export]
private Label _cursorPosLabel; private Label _cursorPosLabel;
[Export] [Export]
private RayCast3D _cursor; private RayCast3D _cursor;
[Export] [Export]
private Node3D _cursorPoint; private Node3D _cursorPoint;
private bool _mUp, _mDown, _mLeft, _mRight, _wIn, _wOut; private bool _mUp, _mDown, _mLeft, _mRight, _wIn, _wOut;
private enum buildingType private enum buildingType
{ {
kash, kash,
pr, pr,
nuke nuke
} }
[Export] [Export]
private PackedScene _kash_building; private PackedScene _kash_building;
[Export] [Export]
private PackedScene _pr_building; private PackedScene _pr_building;
[Export] [Export]
private PackedScene _nuke_building; private PackedScene _nuke_building;
[Export] [Export]
private TextureProgressBar _nuke, _pr, _kash; private TextureProgressBar _nuke, _pr, _kash;
[Export] [Export]
private Label _chatter, _timer, _pr_count, _nuke_count, _kash_count; private Label _chatter, _timer, _pr_count, _nuke_count, _kash_count;
[Export] [Export]
private AudioStreamPlayer _sndChtr, _sndBtn; private AudioStreamPlayer _sndChtr, _sndBtn;
[Export] [Export]
private Timer _tmrChtr, _tmrCashGen; private Timer _tmrChtr, _tmrCashGen;
[Export] [Export]
private Button _btnEnd, _btnNukes, _btnPR, _btnKashCow; private Button _btnEnd, _btnNukes, _btnPR, _btnKashCow;
private float Nukes { get => (float)_nuke.Value; set => _nuke.Value = value; } private float Nukes { get => (float)_nuke.Value; set => _nuke.Value = value; }
private float PR { get => (float)_pr.Value; set => _pr.Value = value; } private float PR { get => (float)_pr.Value; set => _pr.Value = value; }
private float Kash { get => (float)_kash.Value; set => _kash.Value = value; } private float Kash { get => (float)_kash.Value; set => _kash.Value = value; }
private int KashFlow { get; set; } = 1; private int KashFlow { get; set; } = 1;
private int GameTime { get; set; } = 60; private int GameTime { get; set; } = 60;
private string Chatter private string Chatter
{ {
get => _chatter.Get("text").ToString(); set get => _chatter.Get("text").ToString(); set
{ {
if (value != "") if (value != "")
_sndChtr.Play(); _sndChtr.Play();
_chatter.Set("text", value); _chatter.Set("text", value);
_tmrChtr.Start(); _tmrChtr.Start();
} }
} }
public base_building CurrentBuilding { get; set; } public base_building CurrentBuilding { get; set; }
public override void _Ready() public override void _Ready()
{ {
_tmrChtr.Start(); _tmrChtr.Start();
_tmrChtr.Timeout += () => Chatter = ""; _tmrChtr.Timeout += () => Chatter = "";
_tmrCashGen.Timeout += MakeMoney; _tmrCashGen.Timeout += MakeMoney;
_btnEnd.Pressed += () => _sndBtn.Play(); _btnEnd.Pressed += () => _sndBtn.Play();
_btnNukes.Pressed += () => HandleBtnNuke(); _btnNukes.Pressed += () => HandleBtnNuke();
_btnPR.Pressed += () => HandleBtnPR(); _btnPR.Pressed += () => HandleBtnPR();
_btnKashCow.Pressed += () => HandleBtnKash(); _btnKashCow.Pressed += () => HandleBtnKash();
Chatter = "The enemy is stockpiling weapons of mass destruction."; Chatter = "The enemy is stockpiling weapons of mass destruction.";
SetBarLabels(); SetBarLabels();
} }
private void UnHandBuilding() private void UnHandBuilding()
{ {
if (CurrentBuilding != null) if (CurrentBuilding != null)
{ {
GetParent().RemoveChild(CurrentBuilding); GetParent().RemoveChild(CurrentBuilding);
CurrentBuilding.QueueFree(); CurrentBuilding.QueueFree();
CurrentBuilding = null; CurrentBuilding = null;
game_manager.CurrentState = game_manager.State.Play; game_manager.CurrentState = game_manager.State.Play;
} }
} }
private void InstantiateBuilding(buildingType type) private void InstantiateBuilding(buildingType type)
{ {
PackedScene toInstantiate = null; PackedScene toInstantiate = null;
UnHandBuilding(); UnHandBuilding();
switch (type) switch (type)
{ {
case buildingType.kash: case buildingType.kash:
toInstantiate = _kash_building; toInstantiate = _kash_building;
break; break;
case buildingType.pr: case buildingType.pr:
toInstantiate = _pr_building; toInstantiate = _pr_building;
break; break;
case buildingType.nuke: case buildingType.nuke:
toInstantiate = _nuke_building; toInstantiate = _nuke_building;
break; break;
default: default:
toInstantiate = _kash_building; toInstantiate = _kash_building;
break; break;
} }
CurrentBuilding = toInstantiate.Instantiate<base_building>(); CurrentBuilding = toInstantiate.Instantiate<base_building>();
this.GetParent().CallDeferred("add_child", CurrentBuilding); this.GetParent().CallDeferred("add_child", CurrentBuilding);
game_manager.CurrentState = game_manager.State.Building; game_manager.CurrentState = game_manager.State.Building;
} }
private void HandleBtnNuke() private void HandleBtnNuke()
{ {
_sndBtn.Play(); _sndBtn.Play();
InstantiateBuilding(buildingType.nuke); InstantiateBuilding(buildingType.nuke);
} }
private void HandleBtnPR() private void HandleBtnPR()
{ {
_sndBtn.Play(); _sndBtn.Play();
InstantiateBuilding(buildingType.pr); InstantiateBuilding(buildingType.pr);
} }
private void HandleBtnKash() private void HandleBtnKash()
{ {
_sndBtn.Play(); _sndBtn.Play();
InstantiateBuilding(buildingType.kash); InstantiateBuilding(buildingType.kash);
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {
Vector3 rot = this.Rotation; Vector3 rot = this.Rotation;
bool zin = true, zout = true; bool zin = true, zout = true;
if (Input.IsActionPressed("CamNorth")) if (Input.IsActionPressed("CamNorth"))
_mUp = true; _mUp = true;
if (Input.IsActionPressed("CamSouth")) if (Input.IsActionPressed("CamSouth"))
_mDown = true; _mDown = true;
if (Input.IsActionPressed("CamEast")) if (Input.IsActionPressed("CamEast"))
_mRight = true; _mRight = true;
if (Input.IsActionPressed("CamWest")) if (Input.IsActionPressed("CamWest"))
_mLeft = true; _mLeft = true;
this.Rotation -= rot; this.Rotation -= rot;
if (this.Position.Y < 5) if (this.Position.Y < 5)
zin = false; zin = false;
else if (this.Position.Y > 45) else if (this.Position.Y > 45)
zout = false; zout = false;
if (_mLeft && this.Position.X > -30) if (_mLeft && this.Position.X > -30)
this.Translate(new Vector3((float)-delta * 10, 0, 0)); this.Translate(new Vector3((float)-delta * 10, 0, 0));
if (_mRight && this.Position.X < 30) if (_mRight && this.Position.X < 30)
this.Translate(new Vector3((float)delta * 10, 0, 0)); this.Translate(new Vector3((float)delta * 10, 0, 0));
if (_mUp && this.Position.Z > -25) if (_mUp && this.Position.Z > -25)
this.Translate(new Vector3(0, 0, (float)-delta * 10)); this.Translate(new Vector3(0, 0, (float)-delta * 10));
if (_mDown && this.Position.Z < 25) if (_mDown && this.Position.Z < 25)
this.Translate(new Vector3(0, 0, (float)delta * 10)); this.Translate(new Vector3(0, 0, (float)delta * 10));
this.Rotation += rot; this.Rotation += rot;
if (_wIn && zin) if (_wIn && zin)
this.Translate(new Vector3(0, 0, (float)-delta * 10)); this.Translate(new Vector3(0, 0, (float)-delta * 10));
if (_wOut && zout) if (_wOut && zout)
this.Translate(new Vector3(0, 0, (float)delta * 10)); this.Translate(new Vector3(0, 0, (float)delta * 10));
_con.Set("text", this.Position); _con.Set("text", this.Position);
if (_cursor != null && _cursorPoint != null) if (_cursor != null && _cursorPoint != null)
{ {
//Get the collision with map and change its X and Z value to always be in the center of a tile //Get the collision with map and change its X and Z value to always be in the center of a tile
Vector3I collisionVector = (Vector3I)_cursor.GetCollisionPoint(); Vector3I collisionVector = (Vector3I)_cursor.GetCollisionPoint();
_cursorPosLabel.Text = "Virtual Cursor Postion" + collisionVector.ToString(); _cursorPosLabel.Text = "Virtual Cursor Postion" + collisionVector.ToString();
_cursorPoint.GlobalPosition = new Vector3(collisionVector.X - collisionVector.X % 2, 1.1f, collisionVector.Z - collisionVector.Z % 2); _cursorPoint.GlobalPosition = new Vector3(collisionVector.X - collisionVector.X % 2, 1.1f, collisionVector.Z - collisionVector.Z % 2);
if (game_manager.CurrentState == game_manager.State.Building) if (game_manager.CurrentState == game_manager.State.Building)
HandleBuilding(); HandleBuilding();
} }
} }
public override void _Input(InputEvent @event) public override void _Input(InputEvent @event)
{ {
_mLeft = _mRight = _mUp = _mDown = _wIn = _wOut = false; _mLeft = _mRight = _mUp = _mDown = _wIn = _wOut = false;
if (@event is InputEventMouseMotion mouse) if (@event is InputEventMouseMotion mouse)
{ {
Vector2 vec = mouse.Position; Vector2 vec = mouse.Position;
if (vec.X < 5) if (vec.X < 5)
_mLeft = true; _mLeft = true;
else if (vec.X > 1915) else if (vec.X > 1915)
_mRight = true; _mRight = true;
if (vec.Y < 20) if (vec.Y < 20)
_mUp = true; _mUp = true;
else if (vec.Y > 1060) else if (vec.Y > 1060)
_mDown = true; _mDown = true;
_mousePosLabel.Text = "Mouse position: " + vec.ToString(); _mousePosLabel.Text = "Mouse position: " + vec.ToString();
_cursor.Position = new Vector3( _cursor.Position = new Vector3(
(vec.X - GetViewport().GetVisibleRect().Size.X / 2) * this.Position.Y / 1000, (vec.X - GetViewport().GetVisibleRect().Size.X / 2) * this.Position.Y / 1000,
-((vec.Y - GetViewport().GetVisibleRect().Size.Y / 2) * this.Position.Y / 1000) -((vec.Y - GetViewport().GetVisibleRect().Size.Y / 2) * this.Position.Y / 1000)
, 0 , 0
); );
} }
else if (@event is InputEventMouseButton mousebtn) else if (@event is InputEventMouseButton mousebtn)
{ {
if (mousebtn.ButtonIndex == MouseButton.WheelUp) if (mousebtn.ButtonIndex == MouseButton.WheelUp)
_wIn = true; _wIn = true;
else if (mousebtn.ButtonIndex == MouseButton.WheelDown) else if (mousebtn.ButtonIndex == MouseButton.WheelDown)
_wOut = true; _wOut = true;
} }
} }
private void CheckGame() private void CheckGame() {
{ if (PR <= 0)
bool gameover = false; End("res://endings/revolution.tscn");
else if (Nukes >= 100)
{
_btnEnd.Disabled = false;
_btnEnd.Pressed += () => { _sndBtn.Play(); End("res://endings/mad.tscn"); };
Chatter = "You can destroy your enemy, you have the nuclear capacity.";
}
if (GameTime < 0)
if (Nukes >= 100)
End("res://endings/coldwar.tscn");
else if (Nukes == 0)
End("res://endings/peace.tscn");
else End("res://endings/gotnuked.tscn");
}
if (PR <= 0) public void BuildBuilding(int price, int pr, int nukes, int kashFlow = 0)
gameover = true; {
else if (Nukes >= 100) if (price > Kash)
{ {
_btnEnd.Disabled = false; Chatter = "Not enough money.";
_btnEnd.Pressed += () => { _sndBtn.Play(); Nuke(); }; CheckGame();
} return;
if (GameTime <= 0) }
gameover = true;
if (gameover) Nukes += nukes;
Chatter = "Game Over."; PR += pr;
} Kash -= price;
KashFlow += kashFlow;
public void BuildBuilding(int price, int pr, int nukes, int kashFlow = 0) base_building tempBuilding = (base_building)CurrentBuilding.Duplicate();
{ GetParent().CallDeferred("add_child", tempBuilding);
if (price > Kash)
{
Chatter = "Not enough money.";
CheckGame();
return;
}
Nukes += nukes; game_manager.CurrentState = game_manager.State.Play;
PR += pr;
Kash -= price;
KashFlow += kashFlow;
base_building tempBuilding = (base_building)CurrentBuilding.Duplicate(); SetBarLabels();
GetParent().CallDeferred("add_child", tempBuilding); CheckGame();
}
game_manager.CurrentState = game_manager.State.Play; private void MakeMoney()
{
Kash += KashFlow;
GameTime--;
_timer.Set("text", GameTime.ToString());
SetBarLabels(); SetBarLabels();
CheckGame(); CheckGame();
} }
private void MakeMoney() private void SetBarLabels()
{ {
Kash += KashFlow; _kash_count.Text = $"{Kash}M$({KashFlow}M$/s)";
GameTime--; _nuke_count.Text = $"{Nukes} Megatons";
_timer.Set("text", GameTime.ToString()); _pr_count.Text = $"{PR}(%) Approval";
}
SetBarLabels();
CheckGame();
}
private void SetBarLabels()
{
_kash_count.Text = $"{Kash}M$({KashFlow}M$/s)";
_nuke_count.Text = $"{Nukes} Megatons";
_pr_count.Text = $"{PR}(%) Approval";
}
public void HandleBuilding() public void HandleBuilding()
{ {
if (CurrentBuilding != null) if (CurrentBuilding != null)
{ {
CurrentBuilding.GlobalPosition = _cursorPoint.GlobalPosition; CurrentBuilding.GlobalPosition = _cursorPoint.GlobalPosition;
if (Input.IsActionJustPressed("rotate")) if (Input.IsActionJustPressed("rotate"))
{ {
CurrentBuilding.RotateY(Mathf.DegToRad(90)); CurrentBuilding.RotateY(Mathf.DegToRad(90));
} }
if (Input.IsActionJustPressed("cancel")) if (Input.IsActionJustPressed("cancel"))
{ {
UnHandBuilding(); UnHandBuilding();
} }
if (Input.IsActionJustPressed("build")) if (Input.IsActionJustPressed("build"))
{ {
if (CurrentBuilding.IsPlaceable) if (CurrentBuilding.IsPlaceable)
{ {
switch (CurrentBuilding.DisplayName) switch (CurrentBuilding.DisplayName)
{ {
case "Radio Tower": case "Radio Tower":
propaganda_building radio = (propaganda_building)CurrentBuilding; propaganda_building radio = (propaganda_building)CurrentBuilding;
BuildBuilding(radio.KashCost, radio.Approval, 0); BuildBuilding(radio.KashCost, radio.Approval, 0);
break; break;
case "Nuke Silo": case "Nuke Silo":
arms_building silo = (arms_building)CurrentBuilding; arms_building silo = (arms_building)CurrentBuilding;
BuildBuilding(silo.KashCost, silo.Approval, silo.Megaton); BuildBuilding(silo.KashCost, silo.Approval, silo.Megaton);
break; break;
case "Factory": case "Factory":
kash_building factory = (kash_building)CurrentBuilding; kash_building factory = (kash_building)CurrentBuilding;
BuildBuilding(factory.KashCost, 0, 0, factory.KashGenPerSec); BuildBuilding(factory.KashCost, 0, 0, factory.KashGenPerSec);
break; break;
default: default:
break; break;
} }
} }
} }
} }
} }
public void Nuke() public void End(string str)
{ {
var scene = GD.Load<PackedScene>("res://endings/mad.tscn"); var scene = GD.Load<PackedScene>(str);
var instance = scene.Instantiate(); var instance = scene.Instantiate();
GetNode<Node>("/root/").AddChild(instance); GetNode<Node>("/root/").AddChild(instance);
this.GetParent().QueueFree(); this.GetParent().QueueFree();
} }
} }