summaryrefslogtreecommitdiff
path: root/pacmine
diff options
context:
space:
mode:
authorFernando Carmona Varo <ferkiwi@gmail.com>2015-11-07 10:27:05 +0100
committerFernando Carmona Varo <ferkiwi@gmail.com>2015-11-07 10:27:05 +0100
commitaeaca5d7494efe55767c997181a5c071c4800c43 (patch)
tree8ea473837f6efed03c5c5ec63639b0e3042272fe /pacmine
parent234cac868e1baf2089ef255d0751a7e288725db5 (diff)
Some refactoring for the on_player_collision
Diffstat (limited to 'pacmine')
-rw-r--r--pacmine/fruit.lua16
-rwxr-xr-xpacmine/gamestate.lua22
-rw-r--r--pacmine/init.lua8
3 files changed, 22 insertions, 24 deletions
diff --git a/pacmine/fruit.lua b/pacmine/fruit.lua
index 4c21ccc..3100312 100644
--- a/pacmine/fruit.lua
+++ b/pacmine/fruit.lua
@@ -6,17 +6,17 @@ local sbox = {
type = "fixed",
fixed = {{0, 0, 0, 0, 0, 0}}
}
-
+
local pelletitems = {
- {"cherrys", "Cherrys","2"},
- {"apple", "Apple","3"},
- {"orange", "Orange","4"},
- {"strawberry", "Strawberry","2"},
+ {"cherrys", "Cherrys","100"},
+ {"strawberry", "Strawberry","300"},
+ {"orange", "Orange","500"},
+ {"apple", "Apple","700"},
}
for i in ipairs (pelletitems) do
local itm = pelletitems[i][1]
local desc = pelletitems[i][2]
- local hlth = pelletitems[i][3]
+ local points = pelletitems[i][3]
minetest.register_node("pacmine:"..itm,{
description = desc,
@@ -34,6 +34,10 @@ minetest.register_node("pacmine:"..itm,{
collision_box = cbox,
on_timer = function(pos, dtime)
minetest.remove_node(pos)
+ end,
+ on_player_collision = function(pos, player, gameid)
+ minetest.remove_node(pos)
+ pacmine.on_player_got_fruit(player, points)
end
})
end
diff --git a/pacmine/gamestate.lua b/pacmine/gamestate.lua
index 3b948f7..f028e65 100755
--- a/pacmine/gamestate.lua
+++ b/pacmine/gamestate.lua
@@ -262,24 +262,10 @@ local function on_player_gamestep(player, gameid)
for _,pos in pairs(positions) do
pos = vector.add(player_pos, pos)
local node = minetest.get_node(pos)
- if node.name == "pacmine:pellet_1" then
- minetest.remove_node(pos)
- pacmine.on_player_got_pellet(player)
- elseif node.name == "pacmine:pellet_2" then
- minetest.remove_node(pos)
- pacmine.on_player_got_power_pellet(player)
- elseif node.name == "pacmine:cherrys" then
- minetest.remove_node(pos)
- pacmine.on_player_got_fruit(player, 100)
- elseif node.name == "pacmine:strawberry" then
- minetest.remove_node(pos)
- pacmine.on_player_got_fruit(player, 300)
- elseif node.name == "pacmine:orange" then
- minetest.remove_node(pos)
- pacmine.on_player_got_fruit(player, 500)
- elseif node.name == "pacmine:apple" then
- minetest.remove_node(pos)
- pacmine.on_player_got_fruit(player, 700)
+ local nodedef = minetest.registered_nodes[node.name]
+
+ if nodedef and nodedef.on_player_collision then
+ nodedef.on_player_collision(pos, player, gameid)
end
end
end
diff --git a/pacmine/init.lua b/pacmine/init.lua
index 53fbb53..5e8823b 100644
--- a/pacmine/init.lua
+++ b/pacmine/init.lua
@@ -35,6 +35,10 @@ minetest.register_node("pacmine:pellet_1", {
{0, 0, 0, 0, 0, 0},
}
},
+ on_player_collision = function(pos, player, gameid)
+ minetest.remove_node(pos)
+ pacmine.on_player_got_pellet(player)
+ end
})
--Power Pellets. Need to make these do something
@@ -68,6 +72,10 @@ minetest.register_node("pacmine:pellet_2", {
{0, 0, 0, 0, 0, 0},
}
},
+ on_player_collision = function(pos, player, gameid)
+ minetest.remove_node(pos)
+ pacmine.on_player_got_power_pellet(player)
+ end
})
--The placer block for pacmine