From 611fc24518c435aac82b28b8a1ea0e832930325f Mon Sep 17 00:00:00 2001 From: Fernando Carmona Varo Date: Fri, 23 Oct 2015 19:24:49 +0200 Subject: Some improvements to the HUD --- ghost.lua | 2 +- hud.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ init.lua | 2 +- scorehud.lua | 35 ----------------------------------- 4 files changed, 44 insertions(+), 37 deletions(-) create mode 100755 hud.lua delete mode 100755 scorehud.lua diff --git a/ghost.lua b/ghost.lua index 7b7eea5..1c9e47e 100644 --- a/ghost.lua +++ b/ghost.lua @@ -92,7 +92,6 @@ for i in ipairs(ghosts) do -- play sound and reward player minetest.sound_play("mypacman_eatghost", {pos = boardcenter,max_hear_distance = 6, object=player, loop=false}) player:get_inventory():add_item('main', 'mypacman:cherrys') - mypacman.update_hud(self.gameid, player) else -- Ghost catches the player! gamestate.lives = gamestate.lives - 1 @@ -110,6 +109,7 @@ for i in ipairs(ghosts) do mypacman.game_reset(self.gameid, player) end end + mypacman.update_hud(self.gameid, player) else local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} diff --git a/hud.lua b/hud.lua new file mode 100755 index 0000000..00f015d --- /dev/null +++ b/hud.lua @@ -0,0 +1,42 @@ + + +local hud_table = {} + +function mypacman.update_hud(id, player) + local game = mypacman.games[id] + player = player or minetest.get_player_by_name(game.player_name) + if not player then + return + elseif not game then + mypacman.remove_hud(player) + return + end + + local hudtext = "Score: " .. game.score + .. "\nLevel: " .. game.level + .. "\nLives: " .. game.lives + + 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 = 0x8888FF, --color + text = hudtext + }) + hud_table[game.player_name] = hud + else + player:hud_change(hud, "text", hudtext) + end +end + + +function mypacman.remove_hud(player, playername) + local name = playername or player:get_player_name() + local hud = hud_table[name] + if hud then + player:hud_remove(hud) + end +end diff --git a/init.lua b/init.lua index 8e7dbc7..69c0df7 100644 --- a/init.lua +++ b/init.lua @@ -8,7 +8,7 @@ dofile(minetest.get_modpath("mypacman").."/ghost.lua") dofile(minetest.get_modpath("mypacman").."/blocks.lua") dofile(minetest.get_modpath("mypacman").."/portals.lua") dofile(minetest.get_modpath("mypacman").."/gamestate.lua") -dofile(minetest.get_modpath("mypacman").."/scorehud.lua") +dofile(minetest.get_modpath("mypacman").."/hud.lua") --Yellow Pellets diff --git a/scorehud.lua b/scorehud.lua deleted file mode 100755 index dbdfd7f..0000000 --- a/scorehud.lua +++ /dev/null @@ -1,35 +0,0 @@ - - -local hud_table = {} - -function mypacman.update_hud(id, player) - local game = mypacman.games[id] - player = player or minetest.get_player_by_name(game.player_name) - if not player then - return - end - local hudtext = "Score: " .. game.score - local hud = hud_table[game.player_name] - if not hud then - hud = player:hud_add({ - hud_elem_type = "text", - position = {x = 1, y = 0}, - offset = {x=-400, y = 75}, - scale = {x = 100, y = 100}, - number = 0xFFFFFF, --color - text = hudtext - }) - hud_table[game.player_name] = hud - else - player:hud_change(hud, "text", hudtext) - end -end - - -function mypacman.remove_hud(player, playername) - local name = playername or player:get_player_name() - local hud = hud_table[name] - if hud then - player:hud_remove(hud) - end -end -- cgit v1.2.3