Skip to content

Commit

Permalink
Updates to Godot 3.5.1 and implements a horrible radar
Browse files Browse the repository at this point in the history
  • Loading branch information
thoraxe committed Nov 11, 2022
1 parent 853e5f4 commit 2d2992b
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"searchNuGetOrgSymbolServer": true
},
"preLaunchTask": "build",
"executable": "/home/thoraxe/Godot/Godot_v3.4.4-stable_mono_x11_64/Godot_v3.4.4-stable_mono_x11.64",
"executable": "/opt/Godot/Godot_v3.5.1-stable_mono_x11_64/Godot_v3.5.1-stable_mono_x11.64",
// See which arguments are available here:
// https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html
"executableArguments": [
Expand All @@ -36,7 +36,7 @@
"request": "launch",
"mode": "executable",
"preLaunchTask": "build",
"executable": "/home/thoraxe/Godot/Godot_v3.4.4-stable_mono_x11_64/Godot_v3.4.4-stable_mono_x11.64",
"executable": "/opt/Godot/Godot_v3.5.1-stable_mono_x11_64/Godot_v3.5.1-stable_mono_x11.64",
"justMyCode": "false",
// See which arguments are available here:
// https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"godot_tools.editor_path": "/home/thoraxe/Godot/Godot_v3.4.4-stable_mono_x11_64/Godot_v3.4.4-stable_mono_x11.64"
"godot_tools.editor_path": "/opt/Godot/Godot_v3.5.1-stable_mono_x11_64/Godot_v3.5.1-stable_mono_x11.64"
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": [
{
"label": "build",
"command": "/home/thoraxe/Godot/Godot_v3.4.4-stable_mono_x11_64/Godot_v3.4.4-stable_mono_x11.64",
"command": "/opt/Godot/Godot_v3.5.1-stable_mono_x11_64/Godot_v3.5.1-stable_mono_x11.64",
"type": "process",
"args": [
"--build-solutions",
Expand Down
Binary file modified Assets/UIElements/HUD/HUD_radar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/UIElements/HUD/ship_blip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Assets/UIElements/HUD/ship_blip.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/ship_blip.png-21b05ac5c0188a19b9bf26882c1c07ed.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/UIElements/HUD/ship_blip.png"
dest_files=[ "res://.import/ship_blip.png-21b05ac5c0188a19b9bf26882c1c07ed.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
9 changes: 8 additions & 1 deletion Scenes/MainScenes/GUI.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://Assets/UIElements/HUD/HUD_speedometer.png" type="Texture" id=1]
[ext_resource path="res://Assets/Fonts/RedHatText-Regular.tres" type="DynamicFont" id=2]
[ext_resource path="res://Assets/UIElements/HUD/HUD_missile.png" type="Texture" id=3]
[ext_resource path="res://Assets/UIElements/HUD/HUD_missile_status_circle_indicator.png" type="Texture" id=4]
[ext_resource path="res://Assets/UIElements/HUD/HUD_radar.png" type="Texture" id=5]

[node name="GUI" type="CanvasLayer"]

Expand Down Expand Up @@ -41,3 +42,9 @@ margin_top = 122.0
margin_right = 252.0
margin_bottom = 218.0
texture = ExtResource( 4 )

[node name="Radar" type="TextureRect" parent="."]
visible = false
margin_right = 40.0
margin_bottom = 40.0
texture = ExtResource( 5 )
84 changes: 82 additions & 2 deletions Scenes/MainScenes/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ public class Game : Node
Texture missileReadyIndicatorReady;
Texture missileReadyIndicatorNotReady;
Texture missileReadyIndicatorDefault;
TextureRect gameRadar;
Texture shipBlip;

// radar update timer
int radarRefreshTime = 1; // 1000ms = 1sec
float radarRefreshTimer = 0;

// dictionary mapping for quicker access (might not need if GetNode<> is fast enough)
[Export]
Dictionary<String, PlayerShip> playerObjects = new Dictionary<string, PlayerShip>();
Dictionary<String, SpaceMissile> missileObjects = new Dictionary<string, SpaceMissile>();
PlayerShip myShip = null;
Expand Down Expand Up @@ -69,6 +76,9 @@ public void initializeGameUI()
missileReadyIndicatorNotReady = ResourceLoader.Load<Texture>("res://Assets/UIElements/HUD/HUD_missile_status_circle_indicator_red.png");
missileReadyIndicatorReady = ResourceLoader.Load<Texture>("res://Assets/UIElements/HUD/HUD_missile_status_circle_indicator_green.png");

// load the ship blip texture
shipBlip = ResourceLoader.Load<Texture>("res://Assets/UIElements/HUD/ship_blip.png");

// TODO: should we be adding the GUI to the scene instead of displaying its elements?
// find the HUD to show its elements
gameUI = GetNode<CanvasLayer>("GUI");
Expand All @@ -79,6 +89,9 @@ public void initializeGameUI()
missileDisplay.Show();

missileReadyIndicator = gameUI.GetNode<TextureRect>("Missile/MissileReadyIndicator");

gameRadar = gameUI.GetNode<TextureRect>("Radar");
gameRadar.Show();
}

void updateGameUI()
Expand All @@ -93,6 +106,50 @@ void updateGameUI()
else missileReadyIndicator.Texture = missileReadyIndicatorReady;
}

void updateGameRadar()
{
// the radar circle is approximately 280x280 and its center is
// approximately 169,215 on the image

// delete all the radar blips
// TODO: the performance on this is probably terrible
deleteChildren(gameRadar);

// iterate over the player objects
foreach(KeyValuePair<String, PlayerShip> entry in playerObjects)
{
String player = entry.Key;
PlayerShip playerShip = entry.Value;

// don't draw ourselves
if (player == myUuid) return;

_serilogger.Verbose($"Game.cs: Player {player} is at position {playerShip.Position.x}:{playerShip.Position.y}");

float deltaX = myShip.Position.x - playerShip.Position.x;
float deltaY = myShip.Position.y - playerShip.Position.y;

_serilogger.Verbose($"Game.cs: Relative position to player is {deltaX}:{deltaY}");

// scale the relative position where 10,000 is the edge of the radar circle
float scaledX = (deltaX / 10000) * (280 / 2);
float scaledY = (deltaY / 10000) * (280 / 2);

// x and y are "upside down" for some reason
float finalX = (scaledX * -1) + 169;
float finalY = (scaledY * -1) + 215;

_serilogger.Verbose($"Game.cs: Scaled position to player is {scaledX}:{scaledY}");

// add a blip at the scaled location offset from the center
Sprite newBlip = new Sprite();
newBlip.Texture = shipBlip;
newBlip.Offset = new Vector2(finalX, finalY);

gameRadar.AddChild(newBlip);
}
}

public override void _Process(float delta)
{

Expand All @@ -113,6 +170,19 @@ public override void _Process(float delta)
if ((velocity.Length() > 0) || (shoot.Length() > 0)) ProcessInputEvent(velocity, shoot);

if (myShip != null) updateGameUI();

// https://gdscript.com/solutions/godot-timing-tutorial/
// check if we should update the debug UI, which itself should only be done if
// we are in a graphical mode
// TODO: only if in graphical debug mode
// TODO: should also probably use timer node
radarRefreshTimer += delta;
if (radarRefreshTimer >= radarRefreshTime)
{
radarRefreshTimer = 0;
_serilogger.Debug($"Game.cs: Updating radar");
updateGameRadar();
}
}
}

Expand Down Expand Up @@ -378,7 +448,7 @@ void ProcessInputEvent(Vector2 velocity, Vector2 shoot)
{
if (velocity.Length() > 0)
{
_serilogger.Debug("Game.cs: Got move command");
_serilogger.Verbose("Game.cs: Got move command");
cb.command_type = Command.CommandType.CommandTypeMove;
cb.InputX = (int)velocity.x;
cb.InputY = (int)velocity.y;
Expand All @@ -388,7 +458,7 @@ void ProcessInputEvent(Vector2 velocity, Vector2 shoot)
// only process a shoot command if we don't already have our own missile
if ( (shoot.Length() > 0) && (myShip.MyMissile == null) && (myShip.MissileReady) )
{
_serilogger.Debug("Game.cs: Got shoot command");
_serilogger.Verbose("Game.cs: Got shoot command");
cb.command_type = Command.CommandType.CommandTypeShoot;

// suggest a UUID for our new missile
Expand Down Expand Up @@ -417,4 +487,14 @@ public override void _Notification(int what)
QuitGame();
}
}

void deleteChildren(Node theNode)
{
foreach (Node n in theNode.GetChildren())
{
theNode.RemoveChild(n);
n.QueueFree();
}
}

}
5 changes: 3 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ config/icon="res://icon.png"

[display]

window/size/width=1280
window/size/height=1024
window/size/width=1920
window/size/height=1080

[global]

Expand Down Expand Up @@ -65,6 +65,7 @@ zoom_out={

[mono]

project/assembly_name="srt-godot-client"
export/include_scripts_content=true

[physics]
Expand Down

0 comments on commit 2d2992b

Please sign in to comment.