-
Notifications
You must be signed in to change notification settings - Fork 1
/
Radar.gd
36 lines (31 loc) · 1.02 KB
/
Radar.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
extends Container
var radar_pointer_resource = load('res://ui/RadarPointer.tscn')
var camera
var blips = {}
func _ready():
camera = $'/root/Game/Camera'
Enemies.connect('add_enemy', self, '_on_add_enemy')
Enemies.connect('remove_enemy', self, '_on_remove_enemy')
func _on_add_enemy(enemy):
var blip = radar_pointer_resource.instance()
add_child(blip)
blips[enemy] = blip
func _on_remove_enemy(enemy):
if blips.has(enemy):
blips[enemy].queue_free()
blips.erase(enemy)
func _process(delta):
rect_size = OS.window_size
rect_position = Vector2(0, 0)
var centerOfScreen = OS.window_size/2
var radar_mid = rect_size/2
for enemy in blips:
if !weakref(enemy).get_ref():
continue
var blip = blips[enemy]
var relative_pos = enemy.position - camera.position - centerOfScreen
if relative_pos.length() <= min(rect_size.x/2, rect_size.y/2): blip.visible = false
else: blip.visible = true
relative_pos = relative_pos.normalized()*radar_mid
blip.position = radar_mid + relative_pos
blip.rotation = relative_pos.angle()