summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Carmona Varo <ferkiwi@gmail.com>2015-10-27 00:58:36 +0100
committerFernando Carmona Varo <ferkiwi@gmail.com>2015-10-27 00:58:36 +0100
commit087713746ba1b8cac4ce5142fa136d3bde56cca6 (patch)
tree1c5e1a4e60362325fd85ae660505f36ce602fa34
parent551b77b9dc7da84299c39f333314eaa36e699981 (diff)
Added turtle movement
-rw-r--r--mario/init.lua13
-rw-r--r--mario/turtle.lua59
2 files changed, 49 insertions, 23 deletions
diff --git a/mario/init.lua b/mario/init.lua
index 51b1b64..c435bf7 100644
--- a/mario/init.lua
+++ b/mario/init.lua
@@ -1,8 +1,11 @@
+mario = {}
dofile(minetest.get_modpath("mario").."/pipes.lua")
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")
+
minetest.register_node("mario:placer",{
description = "Reset",
@@ -23,8 +26,14 @@ minetest.register_node("mario:placer",{
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)
- minetest.add_entity({x=pos.x+3,y=pos.y+12,z=pos.z+1}, "mario:1")
- minetest.add_entity({x=pos.x+30,y=pos.y+12,z=pos.z+1}, "mario:1")
+
+ -- 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",{
diff --git a/mario/turtle.lua b/mario/turtle.lua
index d7d0967..b10e1e3 100644
--- a/mario/turtle.lua
+++ b/mario/turtle.lua
@@ -3,10 +3,10 @@ local ghosts_death_delay = 5
local turtles = {
- {"1","Ferk"},
- {"2","Don"},
- {"3","Max"},
- {"4","Nathan"},
+ {"turtle1","Ferk"},
+ {"turtle2","Don"},
+ {"turtle3","Max"},
+ {"turtle4","Nathan"},
}
for i in ipairs(turtles) do
local itm = turtles[i][1]
@@ -27,26 +27,40 @@ for i in ipairs(turtles) do
"mario_turtle.png",
},
- velocity = {x=math.random(-1,1), y=0, z=math.random(-1,1)},
- collisionbox = {-0.25, -1.0, -0.25, 0.25, 0.48, 0.25},
+ collisionbox = {-0.25, -0.5, -0.25, 0.25, 0.4, 0.25},
is_visible = true,
automatic_rotate = true,
automatic_face_movement_dir = -90, -- set yaw direction in degrees, false to disable
makes_footstep_sound = false,
+ direction = {x=1, y=0, z=0},
+ acceleration = {x=0, y=-10, z=0},
+ speed = 3,
- set_velocity = function(self, v)
- if not v then v = 0 end
- local yaw = self.object:getyaw()
- self.object:setvelocity({x=math.sin(yaw) * -v, y=self.object:getvelocity().y, z=math.cos(yaw) * v})
+ update_velocity = function(self)
+ local velocity = vector.multiply(self.direction, self.speed)
+ self.object:setvelocity(velocity)
end,
+
on_step = function(self, dtime)
-- every 1 second
self.timer = (self.timer or 0) + dtime
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 = pacmine.games[self.gameid]
+ local gamestate = mario.games[self.gameid]
if not gamestate then
minetest.log("action", "Removing pacman ghost without game assigned")
self.object:remove()
@@ -90,25 +104,25 @@ for i in ipairs(turtles) do
-- 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("pacmine_eatghost", {pos = boardcenter,max_hear_distance = 6, object=player, loop=false})
- player:get_inventory():add_item('main', 'pacmine:cherrys')
+ 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
minetest.chat_send_player(gamestate.player_name,"Game Over")
- pacmine.game_end(self.gameid)
- minetest.sound_play("pacmine_death", {pos = boardcenter,max_hear_distance = 20, object=player, loop=false})
+ mario.game_end(self.gameid)
+ minetest.sound_play("mario_death", {pos = boardcenter,max_hear_distance = 20, object=player, loop=false})
elseif gamestate.lives == 1 then
minetest.chat_send_player(gamestate.player_name,"This is your last life")
- pacmine.game_reset(self.gameid, player)
+ mario.game_reset(self.gameid, player)
else
minetest.chat_send_player(gamestate.player_name,"You have ".. gamestate.lives .." lives left")
- pacmine.game_reset(self.gameid, player)
+ mario.game_reset(self.gameid, player)
end
end
- pacmine.update_hud(self.gameid, player)
+ mario.update_hud(self.gameid, player)
else
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
@@ -130,10 +144,13 @@ for i in ipairs(turtles) do
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.object:set_armor_groups({immortal=1})
+ self:update_velocity()
+ self.object:setacceleration(self.acceleration)
+ --self.object:set_armor_groups({immortal=1})
+ --[[
if staticdata and staticdata ~= "" then
local data = string.split(staticdata, ";")
if #data == 2 then
@@ -141,7 +158,7 @@ for i in ipairs(turtles) do
self.last_reset = tonumber(data[2])
end
end
---]]
+ --]]
end
})
end