summaryrefslogtreecommitdiff
path: root/mario
diff options
context:
space:
mode:
Diffstat (limited to 'mario')
-rw-r--r--mario/init.lua7
-rw-r--r--mario/turtle.lua35
2 files changed, 32 insertions, 10 deletions
diff --git a/mario/init.lua b/mario/init.lua
index 2538dc1..c435bf7 100644
--- a/mario/init.lua
+++ b/mario/init.lua
@@ -26,8 +26,13 @@ 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)
+
+ -- 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+30,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,
})
diff --git a/mario/turtle.lua b/mario/turtle.lua
index 7010803..7896f2e 100644
--- a/mario/turtle.lua
+++ b/mario/turtle.lua
@@ -27,24 +27,38 @@ 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, -0.25, -0.25, 0.25, 0.25, 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 = mario.games[self.gameid]
if not gamestate then
@@ -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