Skip to content

Commit

Permalink
Change ships' minimap icon color when targeted
Browse files Browse the repository at this point in the history
Resolves #5.
  • Loading branch information
jspahrsummers committed Jun 28, 2024
1 parent c70aa20 commit e086ccd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
3 changes: 3 additions & 0 deletions game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ script = ExtResource("7_6citj")
hyperspace_controller = NodePath("../HyperspaceController")
free_when_destroyed = false

[node name="MinimapIcon" parent="Player" index="3"]
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, 0, 0, 0)

[node name="AudioListener3D" type="AudioListener3D" parent="Player"]
transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, 0, 0, 0)
current = true
Expand Down
5 changes: 5 additions & 0 deletions gui/minimap_target_override_mat.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://cyhh74uif4hp0"]

[resource]
shading_mode = 0
albedo_color = Color(1, 1, 0, 1)
7 changes: 3 additions & 4 deletions ships/corvette01/corvette01.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[gd_scene load_steps=13 format=3 uid="uid://cqxv07b8bwiev"]
[gd_scene load_steps=12 format=3 uid="uid://cqxv07b8bwiev"]

[ext_resource type="Script" path="res://ships/ship.gd" id="1_wioy5"]
[ext_resource type="ArrayMesh" uid="uid://40a23nnu1j37" path="res://ships/corvette01/corvette01_mesh.tres" id="1_yacfo"]
[ext_resource type="Resource" uid="uid://dc468i445pkgd" path="res://ships/corvette01/corvette01.tres" id="2_20tol"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster_bolt.tscn" id="2_gae27"]
[ext_resource type="PackedScene" uid="uid://cdyo800b83x5i" path="res://effects/explosions/explosion002.tscn" id="2_xcc1t"]
[ext_resource type="Material" uid="uid://dskoto6nul131" path="res://gui/target_overlay_mat.tres" id="4_it73y"]
[ext_resource type="AudioStream" uid="uid://5iqc5o8p02l5" path="res://ships/audio/THRUSTER LOW.wav" id="4_xrdjv"]
[ext_resource type="PackedScene" uid="uid://dbc2usdmy5wf3" path="res://effects/engine_glow/engine_glow.tscn" id="8_kgu6n"]

Expand All @@ -23,7 +22,7 @@ shading_mode = 0
material = SubResource("StandardMaterial3D_t5loa")
orientation = 1

[node name="Corvette" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance", "weapon_hardpoints", "engine_glow") groups=["ships"]]
[node name="Corvette" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance", "minimap_mesh_instance", "weapon_hardpoints", "engine_glow") groups=["ships"]]
transform = Transform3D(1, -3.48787e-16, 3.48787e-16, 3.48787e-16, 1, -3.48787e-16, -3.48787e-16, 3.48787e-16, 1, 0, 0, 0)
collision_mask = 2
axis_lock_linear_y = true
Expand All @@ -34,8 +33,8 @@ ship_def = ExtResource("2_20tol")
bullet = ExtResource("2_gae27")
explosion = ExtResource("2_xcc1t")
thruster_audio = NodePath("AudioStreamPlayer3D")
target_overlay_material = ExtResource("4_it73y")
mesh_instance = NodePath("MeshInstance3D")
minimap_mesh_instance = NodePath("MinimapIcon")
weapon_hardpoints = [NodePath("BlasterHardpoint")]
engine_glow = [NodePath("EngineGlowLeft"), NodePath("EngineGlowRight")]
engine_glow_tween_duration_sec = 0.3
Expand Down
7 changes: 3 additions & 4 deletions ships/frigate03/frigate03.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[gd_scene load_steps=15 format=3 uid="uid://bxggrqus7bst5"]
[gd_scene load_steps=14 format=3 uid="uid://bxggrqus7bst5"]

[ext_resource type="Script" path="res://ships/ship.gd" id="1_wioy5"]
[ext_resource type="PackedScene" uid="uid://b7tckdwyjwpso" path="res://weapons/blaster/blaster_bolt.tscn" id="2_gae27"]
[ext_resource type="Resource" uid="uid://dmd83o4ylhb0l" path="res://ships/frigate03/frigate03.tres" id="2_lg5km"]
[ext_resource type="PackedScene" uid="uid://cdyo800b83x5i" path="res://effects/explosions/explosion002.tscn" id="2_xcc1t"]
[ext_resource type="Material" uid="uid://dskoto6nul131" path="res://gui/target_overlay_mat.tres" id="4_it73y"]
[ext_resource type="AudioStream" uid="uid://5iqc5o8p02l5" path="res://ships/audio/THRUSTER LOW.wav" id="4_xrdjv"]
[ext_resource type="ArrayMesh" uid="uid://c2y60nf8m25ka" path="res://ships/frigate03/frigate03_mesh.tres" id="6_g7bx0"]
[ext_resource type="PackedScene" uid="uid://dbc2usdmy5wf3" path="res://effects/engine_glow/engine_glow.tscn" id="8_ibdmx"]
Expand Down Expand Up @@ -32,7 +31,7 @@ material = SubResource("ShaderMaterial_rurkt")
size = Vector2(1, 2)
orientation = 1

[node name="Frigate" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance", "weapon_hardpoints", "engine_glow") groups=["ships"]]
[node name="Frigate" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio", "mesh_instance", "minimap_mesh_instance", "weapon_hardpoints", "engine_glow") groups=["ships"]]
transform = Transform3D(1, -3.48787e-16, 3.48787e-16, 3.48787e-16, 1, -3.48787e-16, -3.48787e-16, 3.48787e-16, 1, 0, 0, 0)
collision_mask = 2
axis_lock_linear_y = true
Expand All @@ -43,8 +42,8 @@ ship_def = ExtResource("2_lg5km")
bullet = ExtResource("2_gae27")
explosion = ExtResource("2_xcc1t")
thruster_audio = NodePath("AudioStreamPlayer3D")
target_overlay_material = ExtResource("4_it73y")
mesh_instance = NodePath("MeshInstance3D")
minimap_mesh_instance = NodePath("MinimapIcon")
weapon_hardpoints = [NodePath("BlasterHardpoint")]
engine_glow = [NodePath("EngineGlow")]
engine_glow_tween_duration_sec = 0.6
Expand Down
19 changes: 15 additions & 4 deletions ships/ship.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ class_name Ship
## This audio stream should be a looping sound. Rather than restarting from the beginning each time the thruster is used, the audio stream is paused and resumed, and evenutally loops.
@export var thruster_audio: AudioStreamPlayer3D

## A material to overlay on this ship's mesh when it is targeted by the player.
@export var target_overlay_material: BaseMaterial3D

## This ship's mesh.
@export var mesh_instance: MeshInstance3D

## A material to overlay on this ship's mesh when it is targeted by the player.
@export var target_overlay_material: BaseMaterial3D = preload ("res://gui/target_overlay_mat.tres")

## This ship's minimap icon.
@export var minimap_mesh_instance: MeshInstance3D

## A material to override this ship's minimap icon when it is targeted by the player.
@export var minimap_target_override_material: BaseMaterial3D = preload ("res://gui/minimap_target_override_mat.tres")

## Whether the ship node should be removed from the scene tree and freed when it is destroyed.
##
## If false, the ship will instead be made invisible and stop participating in physics and collision calculations. This is mostly useful for the player's ship, which is often expected to exist (even if invisible) by other nodes.
Expand Down Expand Up @@ -235,7 +241,12 @@ func set_target(targeted_ship: Ship) -> void:

## Invoked when the player's target changes to or from this ship, to apply or remove the corresponding visual indicator.
func set_targeted_by_player(targeted: bool) -> void:
self.mesh_instance.material_overlay = self.target_overlay_material if targeted else null
if targeted:
self.mesh_instance.material_overlay = self.target_overlay_material
self.minimap_mesh_instance.material_override = self.minimap_target_override_material
else:
self.mesh_instance.material_overlay = null
self.minimap_mesh_instance.material_override = null

func _on_ship_destroyed(ship: Ship) -> void:
assert(ship == self.target, "Should only receive ship destruction notification from current target")
Expand Down

0 comments on commit e086ccd

Please sign in to comment.