summaryrefslogtreecommitdiff
path: root/pacmine/hud.lua
blob: 1598a2b450c1cc5d28b1f800633db26f24f1add8 (plain)
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


local hud_table = {}

function pacmine.update_hud(id, player)
	local game = pacmine.games[id]
	player = player or minetest.get_player_by_name(game.player_name)
	if not player then
		return
	elseif not game then
		pacmine.remove_hud(player)
		return
	end
	local pellets_left = 252 - game.pellet_count
	local hudtext = "Score      " .. game.score
		.. "\nLevel       " .. game.level
		.. "\nLives       " .. game.lives
		.. "\nPellets    " .. pellets_left

	local hud = hud_table[game.player_name]
	if not hud then
		hud = player:hud_add({
			hud_elem_type = "text",
			position = {x = 0, y = 1},
			offset = {x=100, y = -100},
			scale = {x = 100, y = 100},
			number = 0xfff227, --color
			text = hudtext
		})
		hud_table[game.player_name] = hud
	else
		player:hud_change(hud, "text", hudtext)
	end
end


function pacmine.remove_hud(player, playername)
	local name = playername or player:get_player_name()
	local hud = hud_table[name]
	if hud then
		player:hud_remove(hud)
		hud_table[name] = nil
	end
end