summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmario/gamestate.lua62
-rwxr-xr-xmario/hud.lua4
-rw-r--r--mario/init.lua27
-rw-r--r--mario/sounds/mario-coin.ogg (renamed from mario/sounds/mario_coin.ogg)bin4814 -> 4814 bytes
-rw-r--r--mario/turtle.lua42
-rwxr-xr-xpacmine/gamestate.lua2
6 files changed, 86 insertions, 51 deletions
diff --git a/mario/gamestate.lua b/mario/gamestate.lua
index bd23d5c..2572a99 100755
--- a/mario/gamestate.lua
+++ b/mario/gamestate.lua
@@ -20,7 +20,7 @@ function mario.game_start(pos, player, gamedef)
-- make sure any previous game with the same id has ended
local gamestate = mario.games[id]
if gamestate then
- minetest.chat_send_player(name, "A game is already in progress for player " .. gamestate.player_name)
+ minetest.chat_send_player(player_name, "A game is already in progress for player " .. gamestate.player_name)
return
end
@@ -31,8 +31,10 @@ 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.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})),
+
+ turtle1_start = vector.add(pos, (gamedef.turtle1_start or {x=3,y=12,z=1})),
+ turtle2_start = vector.add(pos, (gamedef.turtle1_start or {x=30,y=12,z=1})),
+
coin_total = gamedef.coin_total or 84,
speed = gamedef.speed or 2,
lives = gamedef.lives or 3,
@@ -51,6 +53,9 @@ function mario.game_start(pos, player, gamedef)
local schem = gamedef
minetest.place_schematic({x=pos.x-1,y=pos.y-2,z=pos.z-2},gamedef.schematic,0, "air", true)
+ -- initialize player
+ player:set_physics_override(1,1,0.3,true,false)
+
-- Set start positions
mario.game_reset(id, player)
mario.update_hud(id, player)
@@ -76,6 +81,8 @@ function mario.game_end(id)
minetest.chat_send_player(gamestate.player_name, "You made it to the highscores! Your Ranking: " .. ranking)
end
end
+ -- Restore normal physics
+ player:set_physics_override(1,1,1,true,false)
-- Clear the data
mario.games[id] = nil
mario.players[id] = nil
@@ -84,6 +91,7 @@ end
-- Resets the game to the start positions
function mario.game_reset(id, player)
local gamestate = mario.games[id]
+ if not gamestate then return end
minetest.log("action", "resetting game " .. id)
-- Save the time when the game was last resetted (to solve timing issues)
@@ -99,26 +107,33 @@ function mario.game_reset(id, player)
-- 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({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:turtle1")
- turtle:get_luaentity().gameid = id
+ local turtle = minetest.add_entity(gamestate.turtle1_start, "mario:turtle1")
+ turtle = turtle:get_luaentity()
+ turtle.gameid = id
+ turtle.direction = {x=1,y=0,z=0}
end
end)
minetest.after(2, function()
if mario.games[id] and last_reset == mario.games[id].last_reset then
- local turtle = minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:turtle1")
- turtle:get_luaentity().gameid = id
+ local turtle = minetest.add_entity(gamestate.turtle2_start, "mario:turtle2")
+ turtle = turtle:get_luaentity()
+ turtle.gameid = id
+ turtle.direction = {x=1,y=0,z=0}
end
end)
minetest.after(45, function()
if mario.games[id] and last_reset == mario.games[id].last_reset then
- local turtle = minetest.add_entity({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:turtle1")
- turtle:get_luaentity().gameid = id
+ local turtle = minetest.add_entity(gamestate.turtle1_start, "mario:turtle3")
+ turtle = turtle:get_luaentity()
+ turtle.gameid = id
+ turtle.direction = {x=-1,y=0,z=0}
end
end)
minetest.after(45, function()
if mario.games[id] and last_reset == mario.games[id].last_reset then
- local turtle = minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:turtle1")
- turtle:get_luaentity().gameid = id
+ local turtle = minetest.add_entity(gamestate.turtle2_start, "mario:turtle4"):get_luaentity()
+ turtle.gameid = id
+ turtle.direction = {x=-1,y=0,z=0}
end
end)
end
@@ -203,6 +218,27 @@ function mario.on_player_got_mushroom(player, points)
minetest.sound_play("mario-bonus", {pos = pos, max_hear_distance = 6})
end
+-- The player died!
+function mario.on_player_death(id, player)
+ local gamestate = mario.games[id]
+ if not gamestate then return end
+
+ gamestate.lives = gamestate.lives - 1
+ if gamestate.lives < 1 then
+ minetest.chat_send_player(gamestate.player_name,"Game Over")
+ mario.game_end(id)
+ minetest.sound_play("mario-game-over", {max_hear_distance = 20, object=player})
+ elseif gamestate.lives == 1 then
+ minetest.chat_send_player(gamestate.player_name,"This is your last life")
+ mario.game_reset(id, player)
+ minetest.sound_play("mario-continue", {max_hear_distance = 10, object=player})
+ else
+ minetest.chat_send_player(gamestate.player_name,"You have ".. gamestate.lives .." lives left")
+ mario.game_reset(id, player)
+ minetest.sound_play("mario-continue", {max_hear_distance = 10, object=player})
+ end
+end
+
-- Get the game that the given player is playing
function mario.get_game_by_player(player_name)
for _,gamestate in pairs(mario.games) do
@@ -220,8 +256,8 @@ end
local function on_player_gamestep(player, gameid)
local player_pos = player:getpos()
local positions = {
- {x=0.5,y=0.5,z=0.5},
- {x=-0.5,y=0.5,z=-0.5},
+ {x=0.5,y=0.5,z=0.25},
+ {x=-0.5,y=0.5,z=-0.25},
}
for _,pos in pairs(positions) do
pos = vector.add(player_pos, pos)
diff --git a/mario/hud.lua b/mario/hud.lua
index 8da1d4d..d9bf346 100755
--- a/mario/hud.lua
+++ b/mario/hud.lua
@@ -15,7 +15,7 @@ function mario.update_hud(id, player)
local hudtext = "Score " .. game.score
.. "\nLevel " .. game.level
.. "\nLives " .. game.lives
- .. "\ncoins " .. coins_left
+ .. "\nCoins " .. coins_left
local hud = hud_table[game.player_name]
if not hud then
@@ -24,7 +24,7 @@ function mario.update_hud(id, player)
position = {x = 0, y = 1},
offset = {x=100, y = -100},
scale = {x = 100, y = 100},
- number = 0xfff227, --color
+ number = 0xff2227, --color
text = hudtext
})
hud_table[game.player_name] = hud
diff --git a/mario/init.lua b/mario/init.lua
index 426e354..7f60785 100644
--- a/mario/init.lua
+++ b/mario/init.lua
@@ -22,23 +22,10 @@ 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)
- 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")
- -- 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}
-
- minetest.sound_play("mario-game-start", {pos = pos,max_hear_distance = 40,gain = 10.0,})
+ })
end,
})
minetest.register_node("mario:placer2",{
@@ -59,6 +46,7 @@ minetest.register_node("mario:placer2",{
minetest.place_schematic({x=pos.x-1,y=pos.y-1,z=pos.z-2},schem,0, "air", true)
end,
})
+
minetest.register_node("mario:exit",{
description = "Exit",
tiles = {
@@ -73,8 +61,13 @@ minetest.register_node("mario:exit",{
paramtype = "light",
groups = {cracky = 3},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- player:setpos({x=pos.x-5,y=pos.y+0.1,z=pos.z-3})
- print(name)
- player:set_physics_override(1,1,1,true,false)
+ local game = mario.get_game_by_player(player:get_player_name())
+ mario.game_end(game.id)
end,
})
+
+-- Register with the myhighscore mod
+myhighscore.register_game("mario:classic_board", {
+ description = "Mario",
+ icon = "mario_border.png^mario_m.png",
+})
diff --git a/mario/sounds/mario_coin.ogg b/mario/sounds/mario-coin.ogg
index aa789b0..aa789b0 100644
--- a/mario/sounds/mario_coin.ogg
+++ b/mario/sounds/mario-coin.ogg
Binary files differ
diff --git a/mario/turtle.lua b/mario/turtle.lua
index b513d5c..546123f 100644
--- a/mario/turtle.lua
+++ b/mario/turtle.lua
@@ -47,30 +47,19 @@ for i in ipairs(turtles) do
if self.timer < 1 then return end
self.timer = 0
- local velocity = self.object:getvelocity()
-
- -- if our velocity is close to zero, turn around (we are in collision)
- if math.abs(velocity.x) < 0.25 then
- self.direction.x = -self.direction.x
- if(self.direction.x == 0) then
- self.direction.x = 1
- end
- end
- self:update_velocity()
- end,
---[[
-- Do we have game state? if not just die
local gamestate = mario.games[self.gameid]
if not gamestate then
- minetest.log("action", "Removing pacman ghost without game assigned")
+ minetest.log("action", "Removing turtle without game assigned")
self.object:remove()
return
end
+
-- Make sure we are in the right state by keeping track of the reset time
-- if the reset time changed it's likely the game got resetted while the entity wasn't loaded
if self.last_reset then
if self.last_reset ~= gamestate.last_reset then
- minetest.log("action", "Removing pacman ghost remaining after reset ")
+ minetest.log("action", "Removing turtle remaining after reset ")
self.object:remove()
end
else
@@ -83,6 +72,24 @@ for i in ipairs(turtles) do
end
local player = self.target
+ -- find distance to the player
+ local dist = vector.distance(self.object:getpos(), player:getpos())
+ if dist < 1 then
+ mario.on_player_death(self.gameid, player)
+ end
+
+ local velocity = self.object:getvelocity()
+
+ -- if our velocity is close to zero, turn around (we are in collision)
+ if math.abs(velocity.x) < 0.25 then
+ self.direction.x = -self.direction.x
+ if(self.direction.x == 0) then
+ self.direction.x = 1
+ end
+ end
+ self:update_velocity()
+ end,
+--[[
-- If there's no player just stop
if not player then
self.set_velocity(self, 0)
@@ -132,18 +139,18 @@ for i in ipairs(turtles) do
end
end
end,
+ --]]
-- This function should return the saved state of the entity in a string
get_staticdata = function(self)
return (self.gameid or "") .. ";" .. (self.last_reset or "")
end,
---]]
+
-- This function should load the saved state of the entity from a string
on_activate = function(self, staticdata)
self:update_velocity()
self.object:setacceleration(self.acceleration)
- --self.object:set_armor_groups({immortal=1})
- --[[
+ self.object:set_armor_groups({immortal=1})
if staticdata and staticdata ~= "" then
local data = string.split(staticdata, ";")
if #data == 2 then
@@ -151,7 +158,6 @@ for i in ipairs(turtles) do
self.last_reset = tonumber(data[2])
end
end
- --]]
end
})
end
diff --git a/pacmine/gamestate.lua b/pacmine/gamestate.lua
index 3955e7c..3b948f7 100755
--- a/pacmine/gamestate.lua
+++ b/pacmine/gamestate.lua
@@ -23,7 +23,7 @@ function pacmine.game_start(pos, player, gamedef)
-- make sure any previous game with the same id has ended
local gamestate = pacmine.games[id]
if gamestate then
- minetest.chat_send_player(name, "A game is already in progress for player " .. gamestate.player_name)
+ minetest.chat_send_player(player_name, "A game is already in progress for player " .. gamestate.player_name)
return
end