summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Carmona Varo <ferkiwi@gmail.com>2015-11-08 14:06:09 +0100
committerFernando Carmona Varo <ferkiwi@gmail.com>2015-11-08 14:06:09 +0100
commitc9a814a173e70746b8756ca39bd1fdc694610e8a (patch)
tree697d53f17ee865cf030d1887a59c15a511ee8c77
parente57a87c26466b430557f853975fbc2d0e9f17765 (diff)
Added green mushroom to mario, it'll spawn when there are only 10 coins left
-rw-r--r--mario/blocks.lua13
-rwxr-xr-xmario/gamestate.lua18
2 files changed, 17 insertions, 14 deletions
diff --git a/mario/blocks.lua b/mario/blocks.lua
index 4c493d4..66829e2 100644
--- a/mario/blocks.lua
+++ b/mario/blocks.lua
@@ -87,8 +87,8 @@ minetest.register_node("mario:mushroom",{
walkable = false,
groups = {cracky = 3},
node_box = nbox,
- on_destruct = function(pos)
- minetest.sound_play("mario-bonus", {pos = pos,max_hear_distance = 40,gain = 10.0,})
+ on_timer = function(pos, dtime)
+ minetest.remove_node(pos)
end,
on_player_collision = function(pos, player, gameid)
minetest.remove_node(pos)
@@ -111,11 +111,16 @@ minetest.register_node("mario:mushroom_green",{
walkable = false,
groups = {cracky = 3},
node_box = nbox,
- on_destruct = function(pos)
- minetest.sound_play("mario-1-up", {pos = pos,max_hear_distance = 40,gain = 10.0,})
+ on_timer = function(pos, dtime)
+ minetest.remove_node(pos)
end,
on_player_collision = function(pos, player, gameid)
minetest.remove_node(pos)
+ minetest.sound_play("mario-1-up", {pos = pos,max_hear_distance = 6,gain = 10.0,})
+ local gamestate = mario.games[gameid]
+ if gamestate then
+ gamestate.lives = gamestate.lives + 1
+ end
mario.on_player_got_mushroom(player, 15)
end
})
diff --git a/mario/gamestate.lua b/mario/gamestate.lua
index c4c664b..a2bfb89 100755
--- a/mario/gamestate.lua
+++ b/mario/gamestate.lua
@@ -153,19 +153,15 @@ function mario.remove_turtles(id)
end
-- Add a mushroom to the game board
-function mario.add_mushroom(id)
+function mario.add_mushroom(id, mushroomtype, offset)
local gamestate = mario.games[id]
if not gamestate then return end
local node = {}
- -- Different mushroom will be used depending on the level
- --if gamestate.level == 1 then
- node.name = "mario:mushroom"
- --end
- local pos = vector.add(gamestate.player_start,{x=0,y=12,z=0})
+ node.name = mushroomtype or "mario:mushroom"
+ local pos = vector.add(gamestate.player_start, offset or {x=0,y=12,z=0})
minetest.set_node(pos, node)
- print(node.param2)
-- Set the timer for the mushroom to disappear
- minetest.get_node_timer(pos):start(60)
+ minetest.get_node_timer(pos):start(120)
end
-- A player got a coin, update the state
@@ -180,7 +176,9 @@ function mario.on_player_got_coin(player)
minetest.sound_play("mario-coin", {object = player, max_hear_distance = 6})
if gamestate.coin_count == 10 then
- mario.add_mushroom(gamestate.id)
+ mario.add_mushroom(gamestate.id, "mario:mushroom", {x=0,y=12,z=0})
+ elseif gamestate.coin_count == gamestate.coin_total - 10 then
+ mario.add_mushroom(gamestate.id, "mario:mushroom_green", {x=0,y=-1,z=0})
elseif gamestate.coin_count >= gamestate.coin_total then
minetest.chat_send_player(name, "You cleared the board!")
@@ -215,7 +213,7 @@ function mario.on_player_got_mushroom(player, points)
if not gamestate then return end
gamestate.score = gamestate.score + points
minetest.chat_send_player(name, points .. " bonus points!")
- minetest.sound_play("mario-bonus", {pos = pos, max_hear_distance = 6})
+ minetest.sound_play("mario-bonus", {object = player, max_hear_distance = 6})
end
-- The player died!