diff --git a/AMQPserver.cs b/AMQPserver.cs index ee83a3e..5bd439b 100644 --- a/AMQPserver.cs +++ b/AMQPserver.cs @@ -7,7 +7,7 @@ using ProtoBuf; using redhatgamedev.srt.v1; -public class AMQPserver : Node +public partial class AMQPserver : Node { public Serilog.Core.Logger _serilogger; diff --git a/Assets/Fonts/RedHatDisplay-Bold.ttf.import b/Assets/Fonts/RedHatDisplay-Bold.ttf.import new file mode 100644 index 0000000..76fb01c --- /dev/null +++ b/Assets/Fonts/RedHatDisplay-Bold.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://ddlj3n66imcl8" +path="res://.godot/imported/RedHatDisplay-Bold.ttf-e1dcbec6b90d2c43121204c0d1c08eca.fontdata" + +[deps] + +source_file="res://Assets/Fonts/RedHatDisplay-Bold.ttf" +dest_files=["res://.godot/imported/RedHatDisplay-Bold.ttf-e1dcbec6b90d2c43121204c0d1c08eca.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/Assets/Fonts/RedHatText-Italic.ttf.import b/Assets/Fonts/RedHatText-Italic.ttf.import new file mode 100644 index 0000000..0df7536 --- /dev/null +++ b/Assets/Fonts/RedHatText-Italic.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://bjs422uhj0nlv" +path="res://.godot/imported/RedHatText-Italic.ttf-5442a7b92e90f81dfa98b0f90cbbf3fd.fontdata" + +[deps] + +source_file="res://Assets/Fonts/RedHatText-Italic.ttf" +dest_files=["res://.godot/imported/RedHatText-Italic.ttf-5442a7b92e90f81dfa98b0f90cbbf3fd.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/Assets/Fonts/RedHatText-Regular.ttf.import b/Assets/Fonts/RedHatText-Regular.ttf.import new file mode 100644 index 0000000..1e2c7de --- /dev/null +++ b/Assets/Fonts/RedHatText-Regular.ttf.import @@ -0,0 +1,33 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://c4x2m5t0ax0nk" +path="res://.godot/imported/RedHatText-Regular.ttf-26d51c6f384dae5a588f82cd577f5d85.fontdata" + +[deps] + +source_file="res://Assets/Fonts/RedHatText-Regular.ttf" +dest_files=["res://.godot/imported/RedHatText-Regular.ttf-26d51c6f384dae5a588f82cd577f5d85.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/CSLogger.cs b/CSLogger.cs index 8117a6c..f76495e 100644 --- a/CSLogger.cs +++ b/CSLogger.cs @@ -2,7 +2,7 @@ using Godot; using System; -public class CSLogger : Node +public partial class CSLogger : Node { Node gdlogger; diff --git a/Player.tscn b/Player.tscn index c2f6c4c..a96285e 100644 --- a/Player.tscn +++ b/Player.tscn @@ -1,95 +1,71 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=4 format=3 uid="uid://vmssqp0t7y7w"] -[ext_resource path="res://images/ship.png" type="Texture" id=1] -[ext_resource path="res://PlayerShip.cs" type="Script" id=2] +[ext_resource type="Texture2D" uid="uid://dttvdirodvjq7" path="res://images/ship.png" id="1"] +[ext_resource type="Script" path="res://PlayerShip.cs" id="2"] -[sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 39.5, 41.5 ) +[sub_resource type="RectangleShape2D" id="1"] +size = Vector2(39.5, 41.5) [node name="ShipThings" type="Area2D"] [node name="ClickBox" type="CollisionShape2D" parent="."] -position = Vector2( -0.5, 6.5 ) -shape = SubResource( 1 ) +position = Vector2(-0.5, 6.5) +shape = SubResource("1") [node name="Stat" type="Node2D" parent="."] [node name="IDLabel" type="Label" parent="Stat"] -margin_left = -35.0 -margin_top = 28.0 -margin_right = 35.0 -margin_bottom = 42.0 +offset_left = -35.0 +offset_top = 28.0 +offset_right = 35.0 +offset_bottom = 42.0 grow_horizontal = 2 text = "UUIDUUID" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} [node name="LinearVelocity" type="Label" parent="Stat"] -margin_left = -33.0 -margin_top = 41.0 -margin_right = 33.0 -margin_bottom = 55.0 +offset_left = -33.0 +offset_top = 41.0 +offset_right = 33.0 +offset_bottom = 55.0 text = "LinVel" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} [node name="AngularVelocity" type="Label" parent="Stat"] -margin_left = -33.0 -margin_top = 53.0 -margin_right = 33.0 -margin_bottom = 67.0 +offset_left = -33.0 +offset_top = 53.0 +offset_right = 33.0 +offset_bottom = 67.0 text = "AngVel" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} [node name="HitPoints" type="Label" parent="Stat"] -margin_left = -33.0 -margin_top = 68.0 -margin_right = 33.0 -margin_bottom = 82.0 +offset_left = -33.0 +offset_top = 68.0 +offset_right = 33.0 +offset_bottom = 82.0 text = "HP" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} [node name="Position" type="Label" parent="Stat"] -margin_left = -33.0 -margin_top = 81.0 -margin_right = 33.0 -margin_bottom = 95.0 +offset_left = -33.0 +offset_top = 81.0 +offset_right = 33.0 +offset_bottom = 95.0 text = "Position" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} [node name="Hex" type="Label" parent="Stat"] -margin_left = -33.0 -margin_top = 93.0 -margin_right = 33.0 -margin_bottom = 107.0 +offset_left = -33.0 +offset_top = 93.0 +offset_right = 33.0 +offset_bottom = 107.0 text = "MyHex" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} -[node name="PlayerShip" type="KinematicBody2D" parent="."] -script = ExtResource( 2 ) +[node name="PlayerShip" type="CharacterBody2D" parent="."] +script = ExtResource("2") -[node name="Sprite" type="Sprite" parent="PlayerShip"] -scale = Vector2( 0.25, 0.25 ) -texture = ExtResource( 1 ) +[node name="Sprite2D" type="Sprite2D" parent="PlayerShip"] +scale = Vector2(0.25, 0.25) +texture = ExtResource("1") [node name="ShipHitBox" type="CollisionPolygon2D" parent="PlayerShip"] -polygon = PoolVector2Array( -5, -31, 5, -31, 11, -10, 16, 5, 26, 10, 29, 28, -17, 28, -28, 28, -28, 15, -25, 10, -16, 4 ) +polygon = PackedVector2Array(-5, -31, 5, -31, 11, -10, 16, 5, 26, 10, 29, 28, -17, 28, -28, 28, -28, 15, -25, 10, -16, 4) [node name="RemoteTransform2D" type="RemoteTransform2D" parent="PlayerShip"] remote_path = NodePath("../../Stat") diff --git a/PlayerShip.cs b/PlayerShip.cs index f903b1a..28de11d 100644 --- a/PlayerShip.cs +++ b/PlayerShip.cs @@ -1,29 +1,31 @@ using Godot; using System; using System.Collections; +using System.Collections.Concurrent; +using System.Collections.Generic; using redhatgamedev.srt.v1; -public class PlayerShip : KinematicBody2D +public partial class PlayerShip : CharacterBody2D { public Serilog.Core.Logger _serilogger; - public float Thrust = 1f; // effective acceleration + public double Thrust = 1f; // effective acceleration - public float MaxSpeed = 5; + public double MaxSpeed = 5; - public float StopThreshold = 10f; + public double StopThreshold = 10f; - public float GoThreshold = 90f; + public double GoThreshold = 90f; - public float CurrentVelocity = 0; + public double CurrentVelocity = 0; - public float RotationThrust = 1.5f; + public double RotationThrust = 1.5f; - public float CurrentRotation = 0; + public double CurrentRotation = 0; public int HitPoints = 100; - public Queue MovementQueue = new Queue(); + public ConcurrentQueue MovementQueue = new ConcurrentQueue(); public String uuid; @@ -41,16 +43,18 @@ public class PlayerShip : KinematicBody2D // relevant when two players are very close to one another and // prevents missile spamming float MissileReloadTime = 2; - float MissileReloadCountdown; + double MissileReloadCountdown; bool MissileReady = true; public int MissileDamage = 25; Node2D shipThing = null; + CollisionShape2D clickBox = null; + Layout theLayout; - PackedScene MissileScene = (PackedScene)ResourceLoader.Load("res://SpaceMissile.tscn"); + PackedScene MissilePackedScene = (PackedScene)ResourceLoader.Load("res://SpaceMissile.tscn"); bool QueuedForRemoval = false; // used when this player is about to be removed from play @@ -65,7 +69,7 @@ public class PlayerShip : KinematicBody2D // used by the debug UI to show which player has the camera focus public bool isFocused = false; - Sprite shipSprite; + Sprite2D shipSprite; public GameEvent.GameObject CreatePlayerGameObjectBuffer() { @@ -76,14 +80,14 @@ public GameEvent.GameObject CreatePlayerGameObjectBuffer() gameObject.Uuid = uuid; // TODO: only send if changed? - gameObject.PositionX = (int)GlobalPosition.x; - gameObject.PositionY = (int)GlobalPosition.y; + gameObject.PositionX = (int)GlobalPosition.X; + gameObject.PositionY = (int)GlobalPosition.Y; // TODO: only send if changed? gameObject.Angle = RotationDegrees; // need to send the velocity because that's how the client shows the speedometer - gameObject.AbsoluteVelocity = CurrentVelocity; + gameObject.AbsoluteVelocity = (float)CurrentVelocity; // TODO: only send this if it's a change from previous? gameObject.HitPoints = HitPoints; @@ -114,7 +118,8 @@ public void FireMissile(string missileUUID = null) return; } - MyMissile = (SpaceMissile)MissileScene.Instance(); + Node missileNode = MissilePackedScene.Instantiate(); + MyMissile = (SpaceMissile)missileNode; // TODO: need to check for UUID collision _serilogger.Debug($"PlayerShip.cs: Supplied UUID is {missileUUID}"); @@ -169,11 +174,13 @@ public override void _Ready() Node2D shipThing = (Node2D)GetParent(); Label playerIDLabel = (Label)shipThing.GetNode("Stat/IDLabel"); + clickBox = shipThing.GetNode("ClickBox"); + // TODO: deal with really long UUIDs playerIDLabel.Text = uuid; myCamera = GetNode("Camera2D"); - shipSprite = GetNode("Sprite"); + shipSprite = GetNode("Sprite2D"); // TODO: we are doing instant rotation so probably should rename this angularVelocityLabel = (Label)shipThing.GetNode("Stat/AngularVelocity"); @@ -205,7 +212,7 @@ void RemovePlayer() MyServer.PlayerRemoveQueue.Enqueue(uuid); } - void CheckMissileReload(float delta) + void CheckMissileReload(double delta) { // nothing to check if we are already reloaded if (MissileReady == true) { return; } @@ -224,7 +231,7 @@ public void UpdateFocused() else shipSprite.Modulate = new Color(1,1,1,1); } - public override void _Process(float delta) + public override void _Process(double delta) { if (QueuedForRemoval) return; @@ -232,33 +239,36 @@ public override void _Process(float delta) if (shipThing == null) shipThing = (Node2D)GetParent(); // figure out the hex from the pixel position - FractionalHex theHex = theLayout.PixelToHex(new Point(GlobalPosition.x, GlobalPosition.y)); + FractionalHex theHex = theLayout.PixelToHex(new Point(GlobalPosition.X, GlobalPosition.Y)); hexLabel.Text = $"q: {theHex.HexRound().q}, r: {theHex.HexRound().r}, s: {theHex.HexRound().s}"; angularVelocityLabel.Text = $"Rot: {RotationDegrees}"; linearVelocityLabel.Text = $"Vel: {CurrentVelocity}"; hitPointsLabel.Text = $"HP: {HitPoints}"; - positionLabel.Text = $"X: {GlobalPosition.x} Y: {GlobalPosition.y}"; + positionLabel.Text = $"X: {GlobalPosition.X} Y: {GlobalPosition.Y}"; + + // reposition the click box to be located where the ship thing is + clickBox.Position = GlobalPosition; CheckMissileReload(delta); UpdateFocused(); } - public override void _PhysicsProcess(float delta) + public override void _PhysicsProcess(double delta) { if (shipThing == null) shipThing = (Node2D)GetParent(); // somewhat based on: https://kidscancode.org/godot_recipes/2d/topdown_movement/ // "rotate and move" / asteroids-style-ish - float rotation_dir = 0; // in case we need it + double rotation_dir = 0; // in case we need it _serilogger.Verbose($"{uuid}: handling physics"); - if (MovementQueue.Count > 0) + Vector2 thisMovement = Vector2.Zero; + if (MovementQueue.TryDequeue(out thisMovement)) { - Vector2 thisMovement = (Vector2)MovementQueue.Dequeue(); - _serilogger.Verbose($"UUID: {uuid} X: {thisMovement.x} Y: {thisMovement.y}"); + _serilogger.Verbose($"UUID: {uuid} X: {thisMovement.X} Y: {thisMovement.Y}"); - if (thisMovement.y > 0) + if (thisMovement.Y > 0) { CurrentVelocity = Mathf.Lerp(CurrentVelocity, MaxSpeed, Thrust * delta); @@ -266,7 +276,7 @@ public override void _PhysicsProcess(float delta) if (CurrentVelocity > MaxSpeed * (GoThreshold/100)) { CurrentVelocity = MaxSpeed; } } - if (thisMovement.y < 0) + if (thisMovement.Y < 0) { CurrentVelocity = Mathf.Lerp(CurrentVelocity, 0, Thrust * delta); @@ -275,17 +285,17 @@ public override void _PhysicsProcess(float delta) if (CurrentVelocity < MaxSpeed * (StopThreshold/100)) { CurrentVelocity = 0; } } - if (thisMovement.x != 0) + if (thisMovement.X != 0) { - rotation_dir = thisMovement.x; + rotation_dir = thisMovement.X; } _serilogger.Verbose($"UUID: {uuid} Velocity: {CurrentVelocity}"); - } - Vector2 velocity = -(Transform.y * CurrentVelocity); - _serilogger.Verbose($"UUID: {uuid} Vector X: {velocity.x} Y: {velocity.y} "); - Rotation += rotation_dir * RotationThrust * delta; + + Vector2 velocity = -(Transform.Y * (float)CurrentVelocity); + _serilogger.Verbose($"UUID: {uuid} Vector X: {velocity.X} Y: {velocity.Y} "); + Rotation += (float)(rotation_dir * RotationThrust * delta); // TODO: implement collision mechanics MoveAndCollide(velocity); diff --git a/Sector.cs b/Sector.cs index bb0ae3b..14ca064 100644 --- a/Sector.cs +++ b/Sector.cs @@ -1,14 +1,14 @@ using Godot; using System; -public class Sector : Node2D +public partial class Sector : Node2D { public string SectorLabel = "x,x"; // Called when the node enters the scene tree for the first time. public override void _Ready() { - GetNode