diff options
| -rw-r--r-- | mario/blocks.lua | 2 | ||||
| -rwxr-xr-x | mario/gamestate.lua | 37 | ||||
| -rwxr-xr-x | mario/hud.lua | 44 | ||||
| -rw-r--r-- | mario/init.lua | 21 | ||||
| -rw-r--r-- | mario/turtle.lua | 15 | 
5 files changed, 76 insertions, 43 deletions
| diff --git a/mario/blocks.lua b/mario/blocks.lua index 7005de3..f44f61f 100644 --- a/mario/blocks.lua +++ b/mario/blocks.lua @@ -80,6 +80,7 @@ minetest.register_node("mario:mushroom",{  			},  	drawtype = "nodebox",  	paramtype = "light", +	walkable = false,  	groups = {cracky = 3},  	node_box = nbox,  	on_destruct = function(pos) @@ -99,6 +100,7 @@ minetest.register_node("mario:mushroom_green",{  			},  	drawtype = "nodebox",  	paramtype = "light", +	walkable = false,  	groups = {cracky = 3},  	node_box = nbox,  	on_destruct = function(pos) diff --git a/mario/gamestate.lua b/mario/gamestate.lua index c58b5e4..bd23d5c 100755 --- a/mario/gamestate.lua +++ b/mario/gamestate.lua @@ -31,8 +31,8 @@ function mario.game_start(pos, player, gamedef)  		player_name = player_name,  		pos = pos,  		player_start = vector.add(pos, (gamedef.player_start or {x=16,y=0,z=1})), -		turtle1_start = vector.add(pos, (gamedef.turtle_start or {x=3,y=0.5,z=12})), -		turtle2_start = vector.add(pos, (gamedef.turtle_start or {x=30,y=0.5,z=12})), +		turtle1_start = vector.add(pos, (gamedef.turtle1_start or {x=3,y=0.5,z=12})), +		turtle2_start = vector.add(pos, (gamedef.turtle2_start or {x=30,y=0.5,z=12})),  		coin_total =  gamedef.coin_total or 84,  		speed = gamedef.speed or 2,  		lives = gamedef.lives or 3, @@ -94,29 +94,30 @@ function mario.game_reset(id, player)  	-- Position the player  	local player = player or minetest.get_player_by_name(gamestate.player_name)  	player:setpos(gamestate.player_start) +	local pos = gamestate.pos  	-- Spawn the turtles and assign the game id to each turtle  	minetest.after(2, function()  		if mario.games[id] and last_reset == mario.games[id].last_reset then -			local turtle = minetest.add_entity(gamestate.turtle_start, "mario:turtle") +			local turtle = minetest.add_entity({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:turtle1")  			turtle:get_luaentity().gameid = id  		end  	end)  	minetest.after(2, function()  		if mario.games[id] and last_reset == mario.games[id].last_reset then -			local turtle = minetest.add_entity(gamestate.turtle_start, "mario:turtle2") +			local turtle = minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:turtle1")  			turtle:get_luaentity().gameid = id  		end  	end)  	minetest.after(45, function()  		if mario.games[id] and last_reset == mario.games[id].last_reset then -			local turtle = minetest.add_entity(gamestate.turtle_start, "mario:turtle3") +			local turtle = minetest.add_entity({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:turtle1")  			turtle:get_luaentity().gameid = id  		end  	end)  	minetest.after(45, function()  		if mario.games[id] and last_reset == mario.games[id].last_reset then -			local turtle = minetest.add_entity(gamestate.turtle_start, "mario:turtle4") +			local turtle = minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:turtle1")  			turtle:get_luaentity().gameid = id  		end  	end) @@ -142,9 +143,9 @@ function mario.add_mushroom(id)  	if not gamestate then return end  	local node = {}  	-- Different mushroom will be used depending on the level -	if gamestate.level == 1 then +	--if gamestate.level == 1 then  		node.name = "mario:mushroom" -	end +	--end  	local pos = vector.add(gamestate.player_start,{x=0,y=12,z=0})  	minetest.set_node(pos, node)  	print(node.param2) @@ -163,7 +164,7 @@ function mario.on_player_got_coin(player)  	mario.update_hud(gamestate.id, player)  	minetest.sound_play("mario-coin", {object = player, max_hear_distance = 6}) -	if gamestate.coin_count == 70 or gamestate.coin_count == 180 then +	if gamestate.coin_count == 10 then  		mario.add_mushroom(gamestate.id)  	elseif gamestate.coin_count >= gamestate.coin_total then  		minetest.chat_send_player(name, "You cleared the board!") @@ -225,24 +226,12 @@ 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_1" then +		if node.name == "mario:coin" then  			minetest.remove_node(pos)  			mario.on_player_got_coin(player) -		elseif node.name == "mario:coin_2" then -			minetest.remove_node(pos) -			mario.on_player_got_power_coin(player) -		elseif node.name == "mario:cherrys" then -			minetest.remove_node(pos) -			mario.on_player_got_mushroom(player, 100) -		elseif node.name == "mario:strawberry" then -			minetest.remove_node(pos) -			mario.on_player_got_mushroom(player, 300) -		elseif node.name == "mario:orange" then -			minetest.remove_node(pos) -			mario.on_player_got_mushroom(player, 500) -		elseif node.name == "mario:apple" then +		elseif node.name == "mario:mushroom" then  			minetest.remove_node(pos) -			mario.on_player_got_mushroom(player, 700) +			mario.on_player_got_mushroom(player, 15)  		end  	end  end diff --git a/mario/hud.lua b/mario/hud.lua new file mode 100755 index 0000000..8da1d4d --- /dev/null +++ b/mario/hud.lua @@ -0,0 +1,44 @@ + + +local hud_table = {} + +function mario.update_hud(id, player) +	local game = mario.games[id] +	player = player or minetest.get_player_by_name(game.player_name) +	if not player then +		return +	elseif not game then +		mario.remove_hud(player) +		return +	end +	local coins_left = game.coin_total - game.coin_count +	local hudtext = "Score      " .. game.score +		.. "\nLevel       " .. game.level +		.. "\nLives       " .. game.lives +		.. "\ncoins    " .. coins_left + +	local hud = hud_table[game.player_name] +	if not hud then +		hud = player:hud_add({ +			hud_elem_type = "text", +			position = {x = 0, y = 1}, +			offset = {x=100, y = -100}, +			scale = {x = 100, y = 100}, +			number = 0xfff227, --color +			text = hudtext +		}) +		hud_table[game.player_name] = hud +	else +		player:hud_change(hud, "text", hudtext) +	end +end + + +function mario.remove_hud(player, playername) +	local name = playername or player:get_player_name() +	local hud = hud_table[name] +	if hud then +		player:hud_remove(hud) +		hud_table[name] = nil +	end +end diff --git a/mario/init.lua b/mario/init.lua index c435bf7..426e354 100644 --- a/mario/init.lua +++ b/mario/init.lua @@ -5,6 +5,7 @@ dofile(minetest.get_modpath("mario").."/blocks.lua")  dofile(minetest.get_modpath("mario").."/portal.lua")  dofile(minetest.get_modpath("mario").."/turtle.lua")  dofile(minetest.get_modpath("mario").."/gamestate.lua") +dofile(minetest.get_modpath("mario").."/hud.lua")  minetest.register_node("mario:placer",{ @@ -21,17 +22,21 @@ minetest.register_node("mario:placer",{  	paramtype = "light",  	groups = {cracky = 3},  	on_rightclick = function(pos, node, player, itemstack, pointed_thing) -		local schem = minetest.get_modpath("mario").."/schems/mario.mts" -		minetest.place_schematic({x=pos.x-1,y=pos.y-2,z=pos.z-2},schem,0, "air", true) -		player:setpos({x=pos.x+16,y=pos.y+0.1,z=pos.z+1}) -		print(name) +		--local schem = minetest.get_modpath("mario").."/schems/mario.mts" +		--minetest.place_schematic({x=pos.x-1,y=pos.y-2,z=pos.z-2},schem,0, "air", true) +		--player:setpos({x=pos.x+16,y=pos.y+0.1,z=pos.z+1}) +		--print(name)  		player:set_physics_override(1,1,0.3,true,false) - +		 +		mario.game_start(pos, player, { +			schematic = minetest.get_modpath("mario").."/schems/mario.mts", +			scorename = "mario:classic_board", +			})  		-- Left Turtle -		minetest.add_entity({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:turtle1") +		--minetest.add_entity({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:turtle1")  		-- Right Turtle -		local turtler = minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:turtle1"):get_luaentity() -		turtler.direction = {x=-1,y=0,z=0} +		--local turtler = minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:turtle1"):get_luaentity() +		--turtler.direction = {x=-1,y=0,z=0}  		minetest.sound_play("mario-game-start", {pos = pos,max_hear_distance = 40,gain = 10.0,})  	end, diff --git a/mario/turtle.lua b/mario/turtle.lua index 7896f2e..b513d5c 100644 --- a/mario/turtle.lua +++ b/mario/turtle.lua @@ -97,16 +97,7 @@ for i in ipairs(turtles) do  			if distance < 1.5 then  				-- player touches ghost!! -				if gamestate.power_pellet then -					-- Player eats ghost! move it to spawn -					local ghost_spawn = vector.add(gamestate.pos, {x=13,y=0.5,z=19}) -					self.object:setpos(ghost_spawn) -					-- set the timer negative so it'll have to wait extra time -					self.timer = -ghosts_death_delay -					-- play sound and reward player -					minetest.sound_play("mario_eatghost", {pos = boardcenter,max_hear_distance = 6, object=player, loop=false}) -					player:get_inventory():add_item('main', 'mario:cherrys') -				else +  					-- Ghost catches the player!  					gamestate.lives = gamestate.lives - 1  					if gamestate.lives < 1 then @@ -121,8 +112,10 @@ for i in ipairs(turtles) do  						minetest.chat_send_player(gamestate.player_name,"You have ".. gamestate.lives .." lives left")  						mario.game_reset(self.gameid, player)  					end -				end +				--end  				mario.update_hud(self.gameid, player) +		 +  			else  				local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} | 
