From cea7c99c3d95e330ee59f7089a8221094464fca0 Mon Sep 17 00:00:00 2001 From: Victor Turgeon Date: Sun, 11 Jun 2023 11:12:28 -0400 Subject: [PATCH] minor cursor changes --- player/player.cs | 271 ++++++++++++++++++++++++----------------------- 1 file changed, 137 insertions(+), 134 deletions(-) diff --git a/player/player.cs b/player/player.cs index ccb9c75..e3e17be 100644 --- a/player/player.cs +++ b/player/player.cs @@ -3,159 +3,162 @@ using System; public partial class player : Camera3D { - 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; + private const string _path = "/root/player/"; - [Export] - private PackedScene _test_building; + [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 TextureProgressBar _nuke, _pr, _kash; - - [Export] - private Label _chatter; - - [Export] - private AudioStreamPlayer _sndChtr, _sndBtn; - - [Export] - private Timer _tmrChtr; - - private float Nuke { 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 string Chatter { get => _chatter.Get("text").ToString(); set { - if (!(bool)_tmrChtr.Get("is_stopped") && value != "") - _sndChtr.Play(); - _chatter.Set("text", value); - _tmrChtr.Start(); - } - } + [Export] + private PackedScene _test_building; - public Node3D CurrentBuilding { get; set; } + [Export] + private TextureProgressBar _nuke, _pr, _kash; - public override void _Ready() - { - //for debugging TODO: Remove - game_manager.CurrentState = game_manager.State.Building; - if (_test_building != null) - { - CurrentBuilding = _test_building.Instantiate(); - GD.Print(CurrentBuilding); + [Export] + private Label _chatter; - GetTree().Root.CallDeferred("add_child", CurrentBuilding); - } - _tmrChtr.Start(); - _tmrChtr.Timeout += () => Chatter = ""; - } + [Export] + private AudioStreamPlayer _sndChtr, _sndBtn; - public override void _Process(double delta) - { - Vector3 rot = this.Rotation; - bool zin = true, zout = true; + [Export] + private Timer _tmrChtr; - if (Input.IsActionPressed("CamNorth")) - _mUp = true; - if (Input.IsActionPressed("CamSouth")) - _mDown = true; - if (Input.IsActionPressed("CamEast")) - _mRight = true; - if (Input.IsActionPressed("CamWest")) - _mLeft = true; + private float Nuke { 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; } - 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; + private string Chatter + { + get => _chatter.Get("text").ToString(); set + { + if (!(bool)_tmrChtr.Get("is_stopped") && value != "") + _sndChtr.Play(); + _chatter.Set("text", value); + _tmrChtr.Start(); + } + } - if (_wIn && zin) - this.Translate(new Vector3(0, 0, (float)-delta * 10)); - if (_wOut && zout) - this.Translate(new Vector3(0, 0, (float)delta * 10)); + public Node3D CurrentBuilding { get; set; } - _con.Set("text", this.Position); + public override void _Ready() + { + //for debugging TODO: Remove + game_manager.CurrentState = game_manager.State.Building; + if (_test_building != null) + { + CurrentBuilding = _test_building.Instantiate(); + GD.Print(CurrentBuilding); + + GetTree().Root.CallDeferred("add_child", CurrentBuilding); + } + _tmrChtr.Start(); + _tmrChtr.Timeout += () => Chatter = ""; + } + + public override void _Process(double delta) + { + Vector3 rot = this.Rotation; + bool zin = true, zout = true; + + if (Input.IsActionPressed("CamNorth")) + _mUp = true; + if (Input.IsActionPressed("CamSouth")) + _mDown = true; + if (Input.IsActionPressed("CamEast")) + _mRight = true; + if (Input.IsActionPressed("CamWest")) + _mLeft = 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 (_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, collisionVector.Y + 0.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 / 700, - -((vec.Y - GetViewport().GetVisibleRect().Size.Y / 2) * this.Position.Y / 700) - , 0 - ); - } - else if (@event is InputEventMouseButton mousebtn) - { - if (mousebtn.ButtonIndex == MouseButton.WheelUp) - _wIn = true; - else if (mousebtn.ButtonIndex == MouseButton.WheelDown) - _wOut = true; - } + _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; + } - } + } - public void HandleBuilding() - { - if (CurrentBuilding != null) - { - CurrentBuilding.GlobalPosition = _cursorPoint.GlobalPosition; + public void HandleBuilding() + { + if (CurrentBuilding != null) + { + CurrentBuilding.GlobalPosition = _cursorPoint.GlobalPosition; - if (Input.IsActionJustPressed("build")) - { - Node3D tempBuilding = (Node3D)CurrentBuilding.Duplicate(); - GetTree().Root.CallDeferred("add_child", tempBuilding); - } - } - } + if (Input.IsActionJustPressed("build")) + { + Node3D tempBuilding = (Node3D)CurrentBuilding.Duplicate(); + GetTree().Root.CallDeferred("add_child", tempBuilding); + } + } + } }