From 9fc6dc36feac4888ee10a8ee9aeb4fffc2f6e80a Mon Sep 17 00:00:00 2001 From: Fernando Carmona Varo Date: Thu, 22 Oct 2015 20:58:05 +0200 Subject: improved pellet detection --- gamestate.lua | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'gamestate.lua') diff --git a/gamestate.lua b/gamestate.lua index 2368eae..149c0d3 100755 --- a/gamestate.lua +++ b/gamestate.lua @@ -204,24 +204,26 @@ end -- Called every 0.5 seconds for each player that is currently playing pacman local function on_player_gamestep(player, gameid) local player_pos = player:getpos() - local pos = { - x = math.floor(player_pos.x + 0.5), - y = math.floor(player_pos.y + 0.5), - z = math.floor(player_pos.z + 0.5), + local positions = { + {x=0.5,y=0.5,z=0.5}, + {x=-0.5,y=0.5,z=-0.5}, } - local node = minetest.get_node(pos) - if node.name == "mypacman:pellet_1" then - minetest.remove_node(pos) - mypacman.on_player_got_pellet(player) - elseif node.name == "mypacman:pellet_2" then - minetest.remove_node(pos) - mypacman.on_player_got_power_pellet(player) - - minetest.sound_play("mypacman_eatfruit", { - pos = pos, - max_hear_distance = 100, - gain = 10.0, - }) + for _,pos in pairs(positions) do + pos = vector.add(player_pos, pos) + local node = minetest.get_node(pos) + if node.name == "mypacman:pellet_1" then + minetest.remove_node(pos) + mypacman.on_player_got_pellet(player) + elseif node.name == "mypacman:pellet_2" then + minetest.remove_node(pos) + mypacman.on_player_got_power_pellet(player) + + minetest.sound_play("mypacman_eatfruit", { + pos = pos, + max_hear_distance = 100, + gain = 10.0, + }) + end end end -- cgit v1.2.3