Skip to content
Snippets Groups Projects
Commit bb7322f8 authored by dg's avatar dg
Browse files

door opens !!!

rooms generator (like Bone module levels)


git-svn-id: http://svn.net-core.org/repos/t-engine4@20 51575b47-30f0-44d4-a5cc-537603b46e54
parent 1932005d
No related branches found
No related tags found
No related merge requests found
......@@ -18,16 +18,18 @@ function _M:init(t)
self.uid = next_uid
__uids[self.uid] = self
self.image = t.image or nil
self.display = t.display or '.'
self.color_r = t.color_r or 0
self.color_g = t.color_g or 0
self.color_b = t.color_b or 0
self.color_br = t.color_br or -1
self.color_bg = t.color_bg or -1
self.color_bb = t.color_bb or -1
self.block_sight = t.block_sight
self.block_move = t.block_move
for k, e in pairs(t) do self[k] = e end
self.image = self.image or nil
self.display = self.display or '.'
self.color_r = self.color_r or 0
self.color_g = self.color_g or 0
self.color_b = self.color_b or 0
self.color_br = self.color_br or -1
self.color_bg = self.color_bg or -1
self.color_bb = self.color_bb or -1
self.block_sight = self.block_sight or false
self.block_move = self.block_move or false
next_uid = next_uid + 1
end
......
require "engine.class"
local Map = require "engine.Map"
require "engine.Generator"
module(..., package.seeall, class.inherit(engine.Generator))
function _M:init(map, grid_list, data)
engine.Generator.init(self, map)
self.floor = grid_list[data.floor]
self.wall = grid_list[data.wall]
self.up = grid_list[data.up]
self.down = grid_list[data.down]
end
function _M:generate()
for i = 0, self.map.w - 1 do for j = 0, self.map.h - 1 do
self.map(i, j, Map.TERRAIN, self.wall)
end end
-- Always starts at 1, 1
self.map(1, 1, Map.TERRAIN, self.up)
return 1, 1
end
require "engine.class"
local Map = require "engine.Map"
require "engine.Generator"
--- Generator that makes a map
module(..., package.seeall, class.inherit(engine.Generator))
function _M:init(map, grid_list, data)
engine.Generator.init(self, map)
self.floor = grid_list[data.floor]
self.wall = grid_list[data.wall]
self.door = grid_list[data.door]
self.up = grid_list[data.up]
self.down = grid_list[data.down]
end
function _M:doRooms(room, no, tab)
if room.w * room.h >= 60 and room.w >= 5 and room.h >= 5 and not room.no_touch and no > 0 then
local sy, sx = rng.range(3, room.h - 2), rng.range(3, room.w - 2)
local axis = rng.percent(50)
if room.w < (room.h * 3) then axis = true else axis = false end
if axis then
for z = 0, room.w - 1 do
self.map(room.x + z, room.y + sy, Map.TERRAIN, self.wall)
end
self:doRooms({ y=room.y, x=room.x, h=sy, w=room.w}, no-1," "..tab)
self:doRooms({ y=room.y + sy + 1, x=room.x, h=room.h - sy - 1, w=room.w}, no-1," "..tab)
else
for z = 0, room.h - 1 do
self.map(room.x + sx, room.y + z, Map.TERRAIN, self.wall)
end
self:doRooms({ y=room.y, x=room.x, h=room.h, w=sx}, no-1," "..tab)
self:doRooms({ y=room.y, x=room.x + sx + 1, h=room.h, w=room.w - sx - 1}, no-1," "..tab)
end
self.map(room.x + sx, room.y + sy, Map.TERRAIN, self.door)
end
end
function _M:generate()
for i = 0, self.map.w - 1 do for j = 0, self.map.h - 1 do
if j == 0 or j == self.map.h - 1 or i == 0 or i == self.map.w - 1 then
self.map(i, j, Map.TERRAIN, self.wall)
else
self.map(i, j, Map.TERRAIN, self.floor)
end
end end
self:doRooms({ x=1, y=1, h=self.map.h - 2, w=self.map.w - 2 }, 10, "#")
-- Always starts at 1, 1
self.map(1, 1, Map.TERRAIN, self.up)
return 1, 1
end
......@@ -4,7 +4,6 @@ require "engine.Actor"
module(..., package.seeall, class.inherit(engine.Actor))
function _M:init(t)
t.block_move = _M.bumped
self.level = 1
self.life = 100
self.mana = 100
......@@ -27,7 +26,7 @@ function _M:move(x, y, force)
return moved
end
function _M:bumped(x, y, e)
function _M:block_move(x, y, e)
-- Dont bump yourself!
if e and e ~= self then
game.log("%s attacks %s.", tostring(e.name), tostring(self.name))
......
......@@ -20,7 +20,7 @@ end
function _M:run()
self:setupCommands()
Zone:setup{npc_class="mod.class.NPC", grid_class="engine.Grid", object_class="engine.Entity"}
Zone:setup{npc_class="mod.class.NPC", grid_class="mod.class.Grid", object_class="engine.Entity"}
Map:setViewPort(self.w, math.floor(self.h * 0.80), 16, 16)
self.zone = Zone.new("ancient_ruins")
......
require "engine.class"
require "engine.Grid"
module(..., package.seeall, class.inherit(engine.Grid))
function _M:init(t)
engine.Grid.init(self, t)
end
function _M:block_move(x, y, e)
-- Open doors
if self.door_opened then
game.level.map(x, y, engine.Map.TERRAIN, game.zone.grid_list.DOOR_OPEN)
return true
end
return false
end
......@@ -22,5 +22,20 @@ return {
block_move = true,
block_sight = true,
},
{
define_as = "DOOR",
name = "door",
display = '+', color_r=238, color_g=154, color_b=77,
block_sight = true,
door_opened = "DOOR_OPEN",
},
{
define_as = "DOOR_OPEN",
name = "open door",
display = "'", color_r=238, color_g=154, color_b=77,
block_move = false,
block_sight = false,
door_closed = "DOOR",
},
}
return {
name = "ancient ruins",
max_level = 5,
width = 26, height = 5,
width = 50, height = 30,
all_remembered = true,
all_lited = true,
generator = {
map = {
class= "engine.generator.map.Empty",
class= "engine.generator.map.Rooms",
floor = "FLOOR",
wall = "WALL",
up = "UP",
down = "DOWN",
door = "DOOR",
},
actor = {
class = "engine.generator.actor.Random",
nb_npc = {6, 6},
nb_npc = {10, 20},
},
}
}
......@@ -422,7 +422,15 @@ static int rng_range(lua_State *L)
static int rng_call(lua_State *L)
{
int x = luaL_checknumber(L, 1);
lua_pushnumber(L, rand_div(x));
if (lua_isnumber(L, 2))
{
int y = luaL_checknumber(L, 2);
lua_pushnumber(L, x + rand_div(1 + y - x));
}
else
{
lua_pushnumber(L, rand_div(x));
}
return 1;
}
......@@ -443,6 +451,13 @@ static int rng_chance(lua_State *L)
return 1;
}
static int rng_percent(lua_State *L)
{
int x = luaL_checknumber(L, 1);
lua_pushboolean(L, rand_div(100) < x);
return 1;
}
static const struct luaL_reg rnglib[] =
{
{"__call", rng_call},
......@@ -450,6 +465,7 @@ static const struct luaL_reg rnglib[] =
{"dice", rng_dice},
{"seed", rng_seed},
{"chance", rng_chance},
{"percent", rng_percent},
{NULL, NULL},
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment