better labels

This commit is contained in:
Victor Turgeon 2023-06-11 15:55:47 -04:00
parent 72514d01c4
commit 49fe37d568
3 changed files with 287 additions and 222 deletions

View File

@ -1,10 +1,10 @@
[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="Texture2D" uid="uid://b44vs2lwgnh37" path="res://images/mushroom_cloud001.webp" id="2_aky60"]
[ext_resource type="AudioStream" uid="uid://ckg5eypyrhidg" path="res://music/I Feel Grunge (Slow).wav" id="2_yw57x"]
[ext_resource type="AudioStream" uid="uid://c8dcqkmytnyay" path="res://audio/btn.wav" id="4_fx2mk"]
[ext_resource type="AudioStream" uid="uid://dja6tipmq1m8l" path="res://audio/dot.wav" id="5_y8gc7"]
[ext_resource type="Texture2D" uid="uid://bd7j1ug5gs26w" 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://ds7ec1n3pytnr" path="res://audio/btn.wav" id="4_fx2mk"]
[ext_resource type="AudioStream" uid="uid://cg78xtngxrjlg" path="res://audio/dot.wav" id="5_y8gc7"]
[sub_resource type="LabelSettings" id="LabelSettings_n38oc"]
font_size = 290

View File

@ -3,224 +3,237 @@ using System;
public partial class player : Camera3D
{
private const string _path = "/root/player/";
private const string _path = "/root/player/";
[Export]
private Label _con;
[Export]
private Label _mousePosLabel;
[Export]
private Label _cursorPosLabel;
[Export]
private RayCast3D _cursor;
[Export]
private Node3D _cursorPoint;
private bool _mUp, _mDown, _mLeft, _mRight, _wIn, _wOut;
[Export]
private Label _con;
[Export]
private Label _mousePosLabel;
[Export]
private Label _cursorPosLabel;
[Export]
private RayCast3D _cursor;
[Export]
private Node3D _cursorPoint;
private bool _mUp, _mDown, _mLeft, _mRight, _wIn, _wOut;
[Export]
private PackedScene _test_building;
[Export]
private PackedScene _test_building;
[Export]
private TextureProgressBar _nuke, _pr, _kash;
[Export]
private TextureProgressBar _nuke, _pr, _kash;
[Export]
private Label _chatter, _timer;
[Export]
private Label _chatter, _timer, _pr_count, _nuke_count, _kash_count;
[Export]
private AudioStreamPlayer _sndChtr, _sndBtn;
[Export]
private AudioStreamPlayer _sndChtr, _sndBtn;
[Export]
private Timer _tmrChtr, _tmrCashGen;
[Export]
private Button _btnEnd, _btnNukes, _btnPR, _btnKashCow;
[Export]
private Timer _tmrChtr, _tmrCashGen;
private float Nukes { get => (float)_nuke.Value; set => _nuke.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 int KashFlow { get; set; }
private int GameTime { get; set; } = 60;
private string Chatter
{
get => _chatter.Get("text").ToString(); set
{
if (value != "")
_sndChtr.Play();
_chatter.Set("text", value);
_tmrChtr.Start();
}
}
[Export]
private Button _btnEnd, _btnNukes, _btnPR, _btnKashCow;
private float Nukes { get => (float)_nuke.Value; set => _nuke.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 int KashFlow { get; set; } = 1;
private int GameTime { get; set; } = 60;
private string Chatter
{
get => _chatter.Get("text").ToString(); set
{
if (value != "")
_sndChtr.Play();
_chatter.Set("text", value);
_tmrChtr.Start();
}
}
public base_building CurrentBuilding { get; set; }
public base_building CurrentBuilding { get; set; }
public override void _Ready()
{
//for debugging TODO: Remove
game_manager.CurrentState = game_manager.State.Building;
if (_test_building != null)
{
CurrentBuilding = _test_building.Instantiate<base_building>();
GetTree().Root.CallDeferred("add_child", CurrentBuilding);
}
_tmrChtr.Start();
_tmrChtr.Timeout += () => Chatter = "";
_tmrCashGen.Timeout += MakeMoney;
_btnEnd.Pressed += () => _sndBtn.Play();
_btnNukes.Pressed += () => { _sndBtn.Play(); ChangeScore(30, -5, 10, 0);};
_btnPR.Pressed += () => { _sndBtn.Play(); ChangeScore(5, 10, 0, 0);};
_btnKashCow.Pressed += () => { _sndBtn.Play(); ChangeScore(6, 0, 0, 1);};
Chatter = "The enemy is stockpiling weapons of mass destruction.";
}
public override void _Ready()
{
//for debugging TODO: Remove
game_manager.CurrentState = game_manager.State.Building;
if (_test_building != null)
{
CurrentBuilding = _test_building.Instantiate<base_building>();
GetTree().Root.CallDeferred("add_child", CurrentBuilding);
}
_tmrChtr.Start();
_tmrChtr.Timeout += () => Chatter = "";
_tmrCashGen.Timeout += MakeMoney;
_btnEnd.Pressed += () => _sndBtn.Play();
_btnNukes.Pressed += () => { _sndBtn.Play(); ChangeScore(30, -5, 10, 0); };
_btnPR.Pressed += () => { _sndBtn.Play(); ChangeScore(5, 10, 0, 0); };
_btnKashCow.Pressed += () => { _sndBtn.Play(); ChangeScore(6, 0, 0, 1); };
Chatter = "The enemy is stockpiling weapons of mass destruction.";
public override void _Process(double delta)
{
Vector3 rot = this.Rotation;
bool zin = true, zout = true;
SetBarLabels();
}
if (Input.IsActionPressed("CamNorth"))
_mUp = true;
if (Input.IsActionPressed("CamSouth"))
_mDown = true;
if (Input.IsActionPressed("CamEast"))
_mRight = true;
if (Input.IsActionPressed("CamWest"))
_mLeft = true;
public override void _Process(double delta)
{
Vector3 rot = this.Rotation;
bool zin = true, zout = true;
this.Rotation -= rot;
if (this.Position.Y < 5)
zin = false;
else if (this.Position.Y > 45)
zout = false;
if (_mLeft && this.Position.X > -30)
this.Translate(new Vector3((float)-delta * 10, 0, 0));
if (_mRight && this.Position.X < 30)
this.Translate(new Vector3((float)delta * 10, 0, 0));
if (_mUp && this.Position.Z > -25)
this.Translate(new Vector3(0, 0, (float)-delta * 10));
if (_mDown && this.Position.Z < 25)
this.Translate(new Vector3(0, 0, (float)delta * 10));
this.Rotation += rot;
if (Input.IsActionPressed("CamNorth"))
_mUp = true;
if (Input.IsActionPressed("CamSouth"))
_mDown = true;
if (Input.IsActionPressed("CamEast"))
_mRight = true;
if (Input.IsActionPressed("CamWest"))
_mLeft = true;
if (_wIn && zin)
this.Translate(new Vector3(0, 0, (float)-delta * 10));
if (_wOut && zout)
this.Translate(new Vector3(0, 0, (float)delta * 10));
this.Rotation -= rot;
if (this.Position.Y < 5)
zin = false;
else if (this.Position.Y > 45)
zout = false;
if (_mLeft && this.Position.X > -30)
this.Translate(new Vector3((float)-delta * 10, 0, 0));
if (_mRight && this.Position.X < 30)
this.Translate(new Vector3((float)delta * 10, 0, 0));
if (_mUp && this.Position.Z > -25)
this.Translate(new Vector3(0, 0, (float)-delta * 10));
if (_mDown && this.Position.Z < 25)
this.Translate(new Vector3(0, 0, (float)delta * 10));
this.Rotation += rot;
_con.Set("text", this.Position);
if (_wIn && zin)
this.Translate(new Vector3(0, 0, (float)-delta * 10));
if (_wOut && zout)
this.Translate(new Vector3(0, 0, (float)delta * 10));
_con.Set("text", this.Position);
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
Vector3I collisionVector = (Vector3I)_cursor.GetCollisionPoint();
_cursorPosLabel.Text = "Virtual Cursor Postion" + collisionVector.ToString();
_cursorPoint.GlobalPosition = new Vector3(collisionVector.X - collisionVector.X % 2, 1.1f, collisionVector.Z - collisionVector.Z % 2);
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
Vector3I collisionVector = (Vector3I)_cursor.GetCollisionPoint();
_cursorPosLabel.Text = "Virtual Cursor Postion" + collisionVector.ToString();
_cursorPoint.GlobalPosition = new Vector3(collisionVector.X - collisionVector.X % 2, 1.1f, collisionVector.Z - collisionVector.Z % 2);
if (game_manager.CurrentState == game_manager.State.Building)
HandleBuilding();
}
}
if (game_manager.CurrentState == game_manager.State.Building)
HandleBuilding();
}
}
public override void _Input(InputEvent @event)
{
_mLeft = _mRight = _mUp = _mDown = _wIn = _wOut = false;
public override void _Input(InputEvent @event)
{
_mLeft = _mRight = _mUp = _mDown = _wIn = _wOut = false;
if (@event is InputEventMouseMotion mouse)
{
Vector2 vec = mouse.Position;
if (vec.X < 5)
_mLeft = true;
else if (vec.X > 1915)
_mRight = true;
if (vec.Y < 20)
_mUp = true;
else if (vec.Y > 1060)
_mDown = true;
if (@event is InputEventMouseMotion mouse)
{
Vector2 vec = mouse.Position;
if (vec.X < 5)
_mLeft = true;
else if (vec.X > 1915)
_mRight = true;
if (vec.Y < 20)
_mUp = true;
else if (vec.Y > 1060)
_mDown = true;
_mousePosLabel.Text = "Mouse position: " + vec.ToString();
_mousePosLabel.Text = "Mouse position: " + vec.ToString();
_cursor.Position = new Vector3(
(vec.X - GetViewport().GetVisibleRect().Size.X / 2) * this.Position.Y / 1000,
-((vec.Y - GetViewport().GetVisibleRect().Size.Y / 2) * this.Position.Y / 1000)
, 0
);
}
else if (@event is InputEventMouseButton mousebtn)
{
if (mousebtn.ButtonIndex == MouseButton.WheelUp)
_wIn = true;
else if (mousebtn.ButtonIndex == MouseButton.WheelDown)
_wOut = true;
}
}
private void CheckGame() {
bool gameover = false;
if (PR <= 0)
gameover = true;
else if (Kash <= 0)
gameover = true;
else if (Nukes >= 100)
_btnEnd.Pressed += () => { _sndBtn.Play(); Nuke();};
if (GameTime <= 0)
gameover = true;
if (gameover)
Chatter = "Game Over.";
}
public void ChangeScore(int price, int pr, int nukes, int isCashCow) {
if (price > Kash) {
Chatter = "Not enough money.";
CheckGame();
return;
}
if (isCashCow > 1)
isCashCow = 1;
else if (isCashCow < -1)
isCashCow = -1;
Nukes += nukes;
PR += pr;
Kash -= price;
KashFlow += isCashCow;
CheckGame();
}
private void MakeMoney() {
Kash += KashFlow * 2;
GameTime--;
_timer.Set("text", GameTime.ToString());
CheckGame();
}
_cursor.Position = new Vector3(
(vec.X - GetViewport().GetVisibleRect().Size.X / 2) * this.Position.Y / 1000,
-((vec.Y - GetViewport().GetVisibleRect().Size.Y / 2) * this.Position.Y / 1000)
, 0
);
}
else if (@event is InputEventMouseButton mousebtn)
{
if (mousebtn.ButtonIndex == MouseButton.WheelUp)
_wIn = true;
else if (mousebtn.ButtonIndex == MouseButton.WheelDown)
_wOut = true;
}
}
private void CheckGame()
{
bool gameover = false;
if (PR <= 0)
gameover = true;
else if (Nukes >= 100)
{
_btnEnd.Disabled = false;
_btnEnd.Pressed += () => { _sndBtn.Play(); Nuke(); };
}
if (GameTime <= 0)
gameover = true;
if (gameover)
Chatter = "Game Over.";
}
public void ChangeScore(int price, int pr, int nukes, int kashFlow = 0)
{
if (price > Kash)
{
Chatter = "Not enough money.";
CheckGame();
return;
}
Nukes += nukes;
PR += pr;
Kash -= price;
KashFlow += kashFlow;
SetBarLabels();
CheckGame();
}
private void MakeMoney()
{
Kash += KashFlow;
GameTime--;
_timer.Set("text", GameTime.ToString());
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()
{
if (CurrentBuilding != null)
{
CurrentBuilding.GlobalPosition = _cursorPoint.GlobalPosition;
public void HandleBuilding()
{
if (CurrentBuilding != null)
{
CurrentBuilding.GlobalPosition = _cursorPoint.GlobalPosition;
if (Input.IsActionJustPressed("rotate"))
{
CurrentBuilding.RotateY(Mathf.DegToRad(90));
}
if (Input.IsActionJustPressed("rotate"))
{
CurrentBuilding.RotateY(Mathf.DegToRad(90));
}
if (Input.IsActionJustPressed("build"))
{
if (CurrentBuilding.IsPlaceable)
{
base_building tempBuilding = (base_building)CurrentBuilding.Duplicate();
GetTree().Root.CallDeferred("add_child", tempBuilding);
}
}
}
}
public void Nuke() {}
if (Input.IsActionJustPressed("build"))
{
if (CurrentBuilding.IsPlaceable)
{
base_building tempBuilding = (base_building)CurrentBuilding.Duplicate();
GetTree().Root.CallDeferred("add_child", tempBuilding);
}
}
}
}
public void Nuke() { }
}

View File

@ -1,8 +1,8 @@
[gd_scene load_steps=23 format=3 uid="uid://b5gb5paiupum"]
[gd_scene load_steps=25 format=3 uid="uid://b5gb5paiupum"]
[ext_resource type="Script" path="res://player/player.cs" id="1_of2l4"]
[ext_resource type="AudioStream" uid="uid://dye3nhm41yk6r" path="res://audio/chatter.wav" id="2_sa1qd"]
[ext_resource type="AudioStream" uid="uid://c8dcqkmytnyay" path="res://audio/btn.wav" id="3_00x5l"]
[ext_resource type="AudioStream" uid="uid://07ben02qe8yc" path="res://audio/chatter.wav" id="2_sa1qd"]
[ext_resource type="AudioStream" uid="uid://ds7ec1n3pytnr" path="res://audio/btn.wav" id="3_00x5l"]
[sub_resource type="CameraAttributesPhysical" id="CameraAttributesPhysical_1ejpb"]
frustum_near = 0.032
@ -33,6 +33,9 @@ gradient = SubResource("Gradient_dxeak")
width = 24
height = 255
[sub_resource type="LabelSettings" id="LabelSettings_xdjlf"]
font_color = Color(0, 0, 0, 1)
[sub_resource type="Gradient" id="Gradient_tpani"]
colors = PackedColorArray(0.893472, 0.979245, 1, 1, 0.347927, 0.885716, 1, 1)
@ -65,17 +68,20 @@ gradient = SubResource("Gradient_od2su")
width = 24
height = 255
[sub_resource type="LabelSettings" id="LabelSettings_2lyli"]
font_color = Color(0, 0, 0, 1)
[sub_resource type="LabelSettings" id="LabelSettings_adeuk"]
font_size = 12
font_size = 15
[sub_resource type="LabelSettings" id="LabelSettings_kxike"]
font_size = 25
font_size = 64
outline_size = 7
outline_color = Color(0, 0, 0, 1)
[sub_resource type="SphereMesh" id="SphereMesh_mtv4x"]
[node name="player" type="Camera3D" node_paths=PackedStringArray("_con", "_mousePosLabel", "_cursorPosLabel", "_cursor", "_cursorPoint", "_nuke", "_pr", "_kash", "_chatter", "_timer", "_sndChtr", "_sndBtn", "_tmrChtr", "_tmrCashGen", "_btnEnd", "_btnNukes", "_btnPR", "_btnKashCow")]
[node name="player" type="Camera3D" node_paths=PackedStringArray("_con", "_mousePosLabel", "_cursorPosLabel", "_cursor", "_cursorPoint", "_nuke", "_pr", "_kash", "_chatter", "_timer", "_pr_count", "_nuke_count", "_kash_count", "_sndChtr", "_sndBtn", "_tmrChtr", "_tmrCashGen", "_btnEnd", "_btnNukes", "_btnPR", "_btnKashCow")]
attributes = SubResource("CameraAttributesPhysical_1ejpb")
script = ExtResource("1_of2l4")
_con = NodePath("HUD/Debug info/Label")
@ -88,6 +94,9 @@ _pr = NodePath("HUD/Buttons and info/PrBar")
_kash = NodePath("HUD/Buttons and info/KashBar")
_chatter = NodePath("HUD/lbl_Chatter")
_timer = NodePath("HUD/Time")
_pr_count = NodePath("HUD/Buttons and info/PrBar/PrCount")
_nuke_count = NodePath("HUD/Buttons and info/NukeBar/NukeCount")
_kash_count = NodePath("HUD/Buttons and info/KashBar/KashCount")
_sndChtr = NodePath("snd_Chatter")
_sndBtn = NodePath("snd_Button")
_tmrChtr = NodePath("tmr_Chatter")
@ -106,6 +115,7 @@ grow_horizontal = 2
grow_vertical = 2
[node name="Debug info" type="Control" parent="HUD"]
visible = false
layout_mode = 1
anchors_preset = 0
offset_left = 33.0
@ -168,6 +178,7 @@ offset_left = -132.0
offset_top = -132.0
grow_horizontal = 0
grow_vertical = 0
disabled = true
text = "Nuke Enemy"
icon = SubResource("GradientTexture2D_y5odr")
icon_alignment = 1
@ -185,7 +196,7 @@ offset_top = -132.0
offset_right = -133.0
grow_horizontal = 0
grow_vertical = 0
text = "BDE"
text = "Arms"
icon_alignment = 1
expand_icon = true
@ -241,6 +252,20 @@ fill_mode = 3
texture_under = SubResource("GradientTexture2D_2xkee")
texture_progress = SubResource("GradientTexture2D_d5w6a")
[node name="NukeCount" type="Label" parent="HUD/Buttons and info/NukeBar"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 24.0
offset_top = -125.5
offset_right = 43.0
offset_bottom = -99.5
grow_vertical = 2
rotation = 1.57079
text = "69"
label_settings = SubResource("LabelSettings_xdjlf")
[node name="PrBar" type="TextureProgressBar" parent="HUD/Buttons and info"]
layout_mode = 1
anchors_preset = 3
@ -262,6 +287,20 @@ fill_mode = 3
texture_under = SubResource("GradientTexture2D_7myfq")
texture_progress = SubResource("GradientTexture2D_kdame")
[node name="PrCount" type="Label" parent="HUD/Buttons and info/PrBar"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 24.0
offset_top = -125.5
offset_right = 43.0
offset_bottom = -99.5
grow_vertical = 2
rotation = 1.57079
text = "69"
label_settings = SubResource("LabelSettings_xdjlf")
[node name="KashBar" type="TextureProgressBar" parent="HUD/Buttons and info"]
layout_mode = 1
anchors_preset = 3
@ -269,9 +308,9 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -81.0
offset_left = -79.0
offset_top = -392.0
offset_right = -57.0
offset_right = -55.0
offset_bottom = -137.0
grow_horizontal = 0
grow_vertical = 0
@ -284,6 +323,20 @@ fill_mode = 3
texture_under = SubResource("GradientTexture2D_18k81")
texture_progress = SubResource("GradientTexture2D_nfg3s")
[node name="KashCount" type="Label" parent="HUD/Buttons and info/KashBar"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 24.0
offset_top = -125.5
offset_right = 47.0
offset_bottom = -99.5
grow_vertical = 2
rotation = 1.57079
text = "69 "
label_settings = SubResource("LabelSettings_xdjlf")
[node name="lbl_Nukes" type="Label" parent="HUD/Buttons and info"]
layout_mode = 1
anchors_preset = 3
@ -300,6 +353,7 @@ grow_vertical = 0
rotation = 1.5708
text = "ARMS
"
label_settings = SubResource("LabelSettings_2lyli")
horizontal_alignment = 1
vertical_alignment = 1
@ -318,6 +372,7 @@ grow_horizontal = 0
grow_vertical = 0
rotation = 1.5708
text = "PR"
label_settings = SubResource("LabelSettings_2lyli")
[node name="lbl_Kash" type="Label" parent="HUD/Buttons and info"]
layout_mode = 1
@ -334,6 +389,7 @@ grow_horizontal = 0
grow_vertical = 0
rotation = 1.5708
text = "KA$H"
label_settings = SubResource("LabelSettings_2lyli")
[node name="Desc" type="Label" parent="HUD"]
layout_mode = 1
@ -342,30 +398,26 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -535.0
offset_top = -194.0
offset_right = -134.0
offset_bottom = -134.0
offset_left = -556.0
offset_top = -210.0
offset_right = -132.0
offset_bottom = -135.0
grow_horizontal = 0
grow_vertical = 0
text = "Kash Flow: +2M$/sec. PR: +10%. Mtons: +10.
text = "Kash Flow: +1M$/sec. PR: +10%. Mtons: +10.
Cost: 6M$. Cost: 5M$. PR: -5%.
Cost: 30M$."
label_settings = SubResource("LabelSettings_adeuk")
[node name="Time" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -133.0
offset_top = -389.0
offset_right = -90.0
offset_bottom = -352.0
grow_horizontal = 0
grow_vertical = 0
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -37.0
offset_right = 37.0
offset_bottom = 91.0
grow_horizontal = 2
text = "60"
label_settings = SubResource("LabelSettings_kxike")