Minimap
This commit is contained in:
parent
231ff2bb1d
commit
6c5350d47e
32 changed files with 114 additions and 186 deletions
27
scripts/Ship/minimap.gd
Normal file
27
scripts/Ship/minimap.gd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extends Control
|
||||
|
||||
@export var marker : PackedScene
|
||||
|
||||
@onready var ship: PlayerShip = $"../.."
|
||||
|
||||
var markers = []
|
||||
|
||||
#func _process(_delta):
|
||||
# $Sprite.self_modulate = ship.material.get_shader_parameter('color')
|
||||
|
||||
func _ready():
|
||||
get_tree().create_timer(0.05).timeout.connect(init_markers)
|
||||
|
||||
func init_markers():
|
||||
for ship in ship.star_system.ships:
|
||||
add_marker(ship, MinimapMarker.Type.Ship)
|
||||
for base in ship.star_system.bases:
|
||||
add_marker(base, MinimapMarker.Type.Base)
|
||||
|
||||
func add_marker(target : Node, type : MinimapMarker.Type):
|
||||
var marker_inst = marker.instantiate()
|
||||
markers.append(marker_inst)
|
||||
marker_inst.target = target
|
||||
marker_inst.type = type
|
||||
marker_inst.position = Vector2(120, 120)
|
||||
add_child(marker_inst)
|
||||
31
scripts/Ship/minimap_marker.gd
Normal file
31
scripts/Ship/minimap_marker.gd
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
extends Node2D
|
||||
|
||||
class_name MinimapMarker
|
||||
|
||||
@onready var marker = $MarkerSprite
|
||||
@onready var ship = $"../../.."
|
||||
|
||||
enum Type { Ship, Base, Loot, Quest }
|
||||
|
||||
var target : Node2D
|
||||
var type := Type.Ship
|
||||
|
||||
const TYPES_INDEXES = {
|
||||
Type.Ship: 0,
|
||||
Type.Base: 1,
|
||||
Type.Loot: 2,
|
||||
Type.Quest: 3
|
||||
}
|
||||
|
||||
func _ready():
|
||||
marker.frame = TYPES_INDEXES[type]
|
||||
|
||||
# Update marker angle and size
|
||||
func _process(_delta):
|
||||
if !is_instance_valid(target):
|
||||
queue_free()
|
||||
return
|
||||
rotation = ship.global_position.angle_to_point(target.global_position)
|
||||
var sp_scale = 2048 / clamp(ship.global_position.distance_to(target.global_position), 2048, 8192)
|
||||
marker.scale = Vector2(sp_scale, sp_scale)
|
||||
#modulate = target.material.get_shader_parameter("color")
|
||||
|
|
@ -19,6 +19,10 @@ var cargo = {}
|
|||
## Current quest
|
||||
var quest: Quest = null
|
||||
|
||||
func _ready():
|
||||
super._ready()
|
||||
star_system.ships.pop_back()
|
||||
|
||||
func destroy():
|
||||
super.destroy()
|
||||
if docking_base != null:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ signal destroyed
|
|||
var faction : Game.Faction
|
||||
|
||||
func _ready() -> void:
|
||||
star_system.ships.append(self)
|
||||
hull.global_position = global_position
|
||||
destroyed.connect(destroy_timeout)
|
||||
destroyed.connect(star_system.on_ship_destroyed.bind(self))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue