summaryrefslogtreecommitdiff
path: root/gamestate.lua
diff options
context:
space:
mode:
authorFernando Carmona Varo <ferkiwi@gmail.com>2015-10-22 20:58:05 +0200
committerFernando Carmona Varo <ferkiwi@gmail.com>2015-10-22 20:58:05 +0200
commit9fc6dc36feac4888ee10a8ee9aeb4fffc2f6e80a (patch)
treedce2078f1f924ef83f0bce3566166e3d63c56bbb /gamestate.lua
parent1a89f9a8e8e2dd95a1dccb70c10892b604ab434c (diff)
improved pellet detection
Diffstat (limited to 'gamestate.lua')
-rwxr-xr-xgamestate.lua36
1 files changed, 19 insertions, 17 deletions
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