-
Notifications
You must be signed in to change notification settings - Fork 0
/
hud.gd
58 lines (48 loc) · 1.3 KB
/
hud.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
extends CanvasLayer
var hud = {}
var tank_hud = null
var global = null
var pause = false
func _ready():
tank_hud = preload("res://tank_hud.xml")
global = get_node("/root/global")
for player in global.players:
add_hudtank(player, global.colors[player] )
set_process_input(true)
func _input(ev):
if ev.is_pressed():
if ev.is_action("ui_cancel"):
if global.status == global.GAMEOVER:
get_scene().set_pause(false)
global.goto_scene("res://title.xml")
elif ev.is_action("pause") and global.status == global.PLAYING:
pause = !pause
if pause:
get_scene().set_pause(true)
get_node("pause").show()
else:
get_scene().set_pause(false)
get_node("pause").hide()
func add_hudtank(hudid, color):
var ti = tank_hud.instance()
ti.hudid = hudid
ti.set_color(color)
get_node("HBoxContainer").add_child(ti)
hud[hudid] = ti
func set_lives(hudid, lives):
hud[hudid].set_lives(lives)
if lives == 0:
check_victory()
func check_victory():
var alive = 0
var winner = ""
for player in hud:
if hud[player].lives > 0:
alive += 1
winner = hud[player]
if alive == 1:
get_node("victory").add_child(winner.get_node("tank/tank").duplicate())
get_node("victory").set_text(" wins!")
get_node("victory/anim").play("victory")
global.status = global.GAMEOVER
get_scene().set_pause(true)