diff options
Diffstat (limited to 'mario')
-rw-r--r-- | mario/blocks.lua | 12 | ||||
-rwxr-xr-x | mario/gamestate.lua | 16 | ||||
-rw-r--r-- | mario/portal.lua | 21 |
3 files changed, 24 insertions, 25 deletions
diff --git a/mario/blocks.lua b/mario/blocks.lua index f44f61f..4c493d4 100644 --- a/mario/blocks.lua +++ b/mario/blocks.lua @@ -52,6 +52,10 @@ minetest.register_node("mario:coin", { on_destruct = function(pos) minetest.sound_play("mario-coin", {pos = pos,max_hear_distance = 40,gain = 10.0,}) end, + on_player_collision = function(pos, player, gameid) + minetest.remove_node(pos) + mario.on_player_got_coin(player) + end }) local nbox = { @@ -86,6 +90,10 @@ minetest.register_node("mario:mushroom",{ on_destruct = function(pos) minetest.sound_play("mario-bonus", {pos = pos,max_hear_distance = 40,gain = 10.0,}) end, + on_player_collision = function(pos, player, gameid) + minetest.remove_node(pos) + mario.on_player_got_mushroom(player, 15) + end }) minetest.register_node("mario:mushroom_green",{ @@ -106,4 +114,8 @@ minetest.register_node("mario:mushroom_green",{ on_destruct = function(pos) minetest.sound_play("mario-1-up", {pos = pos,max_hear_distance = 40,gain = 10.0,}) end, + on_player_collision = function(pos, player, gameid) + minetest.remove_node(pos) + mario.on_player_got_mushroom(player, 15) + end }) diff --git a/mario/gamestate.lua b/mario/gamestate.lua index 1ccf4a7..c4c664b 100755 --- a/mario/gamestate.lua +++ b/mario/gamestate.lua @@ -262,18 +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 == "mario:coin" then - minetest.remove_node(pos) - mario.on_player_got_coin(player) - elseif node.name == "mario:mushroom" then - minetest.remove_node(pos) - mario.on_player_got_mushroom(player, 15) - elseif node.name == "mario:portal_right" then - player_pos.x = player_pos.x -31 - player:setpos(player_pos) - elseif node.name == "mario:portal_left" then - player_pos.x = player_pos.x +31 - player:setpos(player_pos) + 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/mario/portal.lua b/mario/portal.lua index eb04b93..1ff31ee 100644 --- a/mario/portal.lua +++ b/mario/portal.lua @@ -9,6 +9,9 @@ minetest.register_node("mario:portal", { walkable = false, is_ground_content = false, groups = {cracky = 2,not_in_creative_inventory=1}, + on_player_collision = function(pos, player, gameid) + player:setpos({x=pos.x,y=pos.y+12,z=pos.z}) + end }) minetest.register_node("mario:portal_left", { description = "Portal Left", @@ -20,6 +23,9 @@ minetest.register_node("mario:portal_left", { --walkable = false, is_ground_content = false, groups = {cracky = 2,not_in_creative_inventory=0}, + on_player_collision = function(pos, player, gameid) + player:setpos(vector.add(pos,{x=31, y=0, z=0})) + end }) minetest.register_node("mario:portal_right", { description = "Portal Right", @@ -31,18 +37,7 @@ minetest.register_node("mario:portal_right", { --walkable = false, is_ground_content = false, groups = {cracky = 2,not_in_creative_inventory=0}, -}) -minetest.register_abm({ - nodenames = {"mario:portal"}, - interval = 0.5, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local objs = minetest.env:get_objects_inside_radius(pos, 1) - for k, player in pairs(objs) do - if player:get_player_name() then - - player:setpos({x=pos.x,y=pos.y+12,z=pos.z}) - end - end + on_player_collision = function(pos, player, gameid) + player:setpos(vector.add(pos,{x=-31, y=0, z=0})) end }) |