Adds doors and greater chance of walls

This commit is contained in:
Linus Probert 2019-03-14 19:11:25 +01:00
parent 184b42ff5a
commit e50d40fb1c
10 changed files with 114 additions and 15 deletions

Binary file not shown.

View File

@ -3,7 +3,9 @@ local pits = {}
local walls = {} local walls = {}
local fences = {} local fences = {}
local lights = {} local lights = {}
local doors = {}
local walldecor = {} local walldecor = {}
local chest
local function readLayoutFile(file) local function readLayoutFile(file)
local layoutfile = read_file(file) local layoutfile = read_file(file)
@ -139,6 +141,15 @@ local function setPitTile(room, matrix, i, j)
end end
end end
local function getDoor(matrix, i, j, topDoor, leftDoor)
local above, below, left, right, above_left, above_right, below_left, below_right = getTileStateFor(matrix, i, j, { "#", "\"", "/"});
if above and below then
return leftDoor
else
return topDoor
end
end
local module = {} local module = {}
function module.load_textures(map, wall_xoffset, wall_yoffset) function module.load_textures(map, wall_xoffset, wall_yoffset)
local t_pit0 = add_texture(map, "Objects/Pit0.png") local t_pit0 = add_texture(map, "Objects/Pit0.png")
@ -147,6 +158,8 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
local t_fence = add_texture(map, "Objects/Fence.png") local t_fence = add_texture(map, "Objects/Fence.png")
local t_decor0 = add_texture(map, "Objects/Decor0.png") local t_decor0 = add_texture(map, "Objects/Decor0.png")
local t_decor1 = add_texture(map, "Objects/Decor1.png") local t_decor1 = add_texture(map, "Objects/Decor1.png")
local t_door0 = add_texture(map, "Objects/Door0.png")
local t_door1 = add_texture(map, "Objects/Door1.png")
local yo = (random(5) + random(3)) * (16 * 2) local yo = (random(5) + random(3)) * (16 * 2)
pits = { pits = {
@ -198,11 +211,27 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
bottom_t = { t_fence, nil, 64, yo + 32, true }, bottom_t = { t_fence, nil, 64, yo + 32, true },
} }
doors = {
door_top_nolock = { t_door0, t_door1, 0, 0, true },
door_left_nolock = { t_door0, t_door1, 16, 0, true },
door_top_silverlock = { t_door0, t_door1, 32, 0, true },
door_left_silverlock = { t_door0, t_door1, 48, 0, true },
door_top_goldlock = { t_door0, t_door1, 64, 0, true },
door_left_goldlock = { t_door0, t_door1, 80, 0, true },
gate_top_nolock = { t_door0, t_door1, 0, 32, true },
gate_left_nolock = { t_door0, t_door1, 16, 32, true },
gate_top_silverlock = { t_door0, t_door1, 32, 32, true },
gate_left_silverlock = { t_door0, t_door1, 48, 32, true },
gate_top_goldlock = { t_door0, t_door1, 64, 32, true },
gate_left_goldlock = { t_door0, t_door1, 80, 32, true },
}
lights = { lights = {
candle0 = { t_decor0, t_decor1, 3 * 16, 8 * 16, true, true }, candle0 = { t_decor0, t_decor1, 3 * 16, 8 * 16, true, true },
candle1 = { t_decor0, t_decor1, 1 * 16, 8 * 16, true, true }, candle1 = { t_decor0, t_decor1, 1 * 16, 8 * 16, true, true },
candle2 = { t_decor0, t_decor1, 5 * 16, 8 * 16, true, false }, candle2 = { t_decor0, t_decor1, 5 * 16, 8 * 16, true, false },
} }
walldecor = { walldecor = {
topleft = { topleft = {
{ t_decor0, nil, 2 * 16, 2 * 16, false }, { t_decor0, nil, 2 * 16, 2 * 16, false },
@ -261,6 +290,8 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
{ t_decor0, nil, 5 * 16, 2 * 16, false }, { t_decor0, nil, 5 * 16, 2 * 16, false },
}, },
} }
chest = { "Items/Chest0.png", "Items/Chest1.png", 16, 0}
end end
function createJumbleLayout(matrix) function createJumbleLayout(matrix)
@ -299,12 +330,12 @@ function draw_layout_to_room(room, matrix, roomx, roomy)
if matrix[i][j] == "p" then if matrix[i][j] == "p" then
setPitTile(room, matrix, i, j); setPitTile(room, matrix, i, j);
elseif matrix[i][j] == "#" then elseif matrix[i][j] == "#" then
setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/", "d", "g"}, false)
elseif matrix[i][j] == "\"" then elseif matrix[i][j] == "\"" then
setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/", "d", "g"}, false)
room.decor[i][j] = lights.candle1 room.decor[i][j] = lights.candle1
elseif matrix[i][j] == "/" then elseif matrix[i][j] == "/" then
setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/", "d", "g"}, false)
if random(2) == 1 then if random(2) == 1 then
room.decor[i][j] = lights.candle1 room.decor[i][j] = lights.candle1
else else
@ -316,6 +347,12 @@ function draw_layout_to_room(room, matrix, roomx, roomy)
create_shop_artifact(map, (roomx*512) + i*32, (roomy * 384) + j*32) create_shop_artifact(map, (roomx*512) + i*32, (roomy * 384) + j*32)
elseif matrix[i][j] == "l" then elseif matrix[i][j] == "l" then
room.decor[i][j] = lights.candle0 room.decor[i][j] = lights.candle0
elseif matrix[i][j] == "c" then
room.chests[i][j] = chest
elseif matrix[i][j] == "d" then
room.doors[i][j] = getDoor(matrix, i, j, doors.door_top_nolock, doors.door_left_nolock)
elseif matrix[i][j] == "g" then
room.doors[i][j] = getDoor(matrix, i, j, doors.gate_top_nolock, doors.gate_left_nolock)
end end
end end
end end
@ -331,7 +368,7 @@ function pickALayout(matrix)
end end
function module.add_walls_to_room(room) function module.add_walls_to_room(room)
if random(3) ~= 1 then if random(2) == 1 then
return false return false
end end
@ -354,4 +391,10 @@ function module.add_shop_layout(room, roomx, roomy)
return true return true
end end
function module.add_locked_room_layout(room, roomx, roomy)
local matrix = readLayoutFile("lockedroomlayouts.dat")
draw_layout_to_room(room, matrix[random(#matrix)], roomx, roomy)
return true
end
return module return module

View File

@ -0,0 +1,12 @@
++++++++++++++++
++++++++++++++++
++"#####d####"++
++#-c--c--c--#++
++#----------#++
++#-c--c--c--#++
++d----------d++
++#-c--c--c--#++
++#----------#++
++"#####d####"++
++++++++++++++++
++++++++++++++++

View File

@ -398,6 +398,14 @@ local function build_shop_room(room, roomx, roomy)
return room return room
end end
local function build_locked_room(room, roomx, roomy)
add_tiles_to_room(room, false)
add_walls_to_room(room)
add_exits_to_room(room)
layoutparser.add_locked_room_layout(room, roomx, roomy)
return room
end
local function build_normal_room(room) local function build_normal_room(room)
local crumbling = (CURRENT_LEVEL > 3 or QUICK_MODE) and random(8) == 1 local crumbling = (CURRENT_LEVEL > 3 or QUICK_MODE) and random(8) == 1
local pitsAdded = false; local pitsAdded = false;
@ -503,6 +511,7 @@ function module.build_room(room, roomx, roomy)
build_shop_room(room, roomx, roomy) build_shop_room(room, roomx, roomy)
else else
build_normal_room(room) build_normal_room(room)
--build_locked_room(room, roomx, roomy)
end end
end end

View File

@ -14,9 +14,9 @@
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++#--#-#-#-#-#++ ++#--#-#-#-#-#++
++------------++ ++---c--------++
++/-#-#-#-#--/++ ++/-#-#-#-#--/++
++------------++ ++-------c----++
++/--#-#-#-#-/++ ++/--#-#-#-#-/++
++------------++ ++------------++
++--#-#-#-#---++ ++--#-#-#-#---++
@ -30,7 +30,7 @@
++#----------#++ ++#----------#++
++#-/#######-#++ ++#-/#######-#++
++--#------#-#++ ++--#------#-#++
++--#--------#++ ++--d--cc--d-#++
++#-/#######-#++ ++#-/#######-#++
++#----------#++ ++#----------#++
++############++ ++############++
@ -40,12 +40,12 @@
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++/#--------#/++ ++/#--------#/++
++##-ffffff-##++ ++##-ffffdf-##++
++---f--c-f---++
++---f----f---++ ++---f----f---++
++--------f---++ ++---f-c--f---++
++--------f---++
++---f----f---++ ++---f----f---++
++##-ffffff-##++ ++##-fdffff-##++
++/#--------#/++ ++/#--------#/++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
@ -53,12 +53,38 @@
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++/#ffffffff#/++ ++/#ffffffff#/++
++##--------##++ ++#----------#++
++------------++
++---######---++ ++---######---++
++---d----#---++
++---#-cc-d---++
++---######---++ ++---######---++
++------------++ ++#----------#++
++##--------##++
++/#ffffffff#/++ ++/#ffffffff#/++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++++++++++++++++
++++++++++++++++
++/##########/++
++d-----d----d++
++#c----#---c#++
++############++
++#----#-----#++
++#-c--d--c--#++
++d----#-----d++
++/##########/++
++++++++++++++++
++++++++++++++++
++++++++++++++++
++++++++++++++++
++/####-#####/++
++#--c#-#c---#++
++d---#-#----d++
++#####-######++
++------------++
++#####-######++
++d--c#-#c---d++
++/####-#####/++
++++++++++++++++
++++++++++++++++

View File

@ -149,6 +149,7 @@ map_add_door(Map *map, Position *tile_pos, MapTile *tile)
Room *room = map->rooms[cr->x][cr->y]; Room *room = map->rooms[cr->x][cr->y];
switch_tile(map, tile_pos, tile, &room->doors[tile_pos->x][tile_pos->y]); switch_tile(map, tile_pos, tile, &room->doors[tile_pos->x][tile_pos->y]);
tile->door = true; tile->door = true;
tile->sprite->texture_index = 0;
tile->sprite->animate = false; tile->sprite->animate = false;
} }

View File

@ -271,12 +271,14 @@ l_add_tile(lua_State *L)
return 0; return 0;
} }
static int
l_add_wall(lua_State *L) l_add_wall(lua_State *L)
{ {
extract_tile_data(L, &map_add_wall); extract_tile_data(L, &map_add_wall);
return 0; return 0;
} }
static int
l_add_door(lua_State *L) l_add_door(lua_State *L)
{ {
extract_tile_data(L, &map_add_door); extract_tile_data(L, &map_add_door);

View File

@ -88,6 +88,7 @@ load_effects(void)
effects[FADE_IN] = load_effect("Sounds/FX/fade_in.wav"); effects[FADE_IN] = load_effect("Sounds/FX/fade_in.wav");
effects[FADE_OUT] = load_effect("Sounds/FX/fade_out.wav"); effects[FADE_OUT] = load_effect("Sounds/FX/fade_out.wav");
effects[BURST] = load_effect("Sounds/FX/burst.wav"); effects[BURST] = load_effect("Sounds/FX/burst.wav");
effects[DOOR_OPEN] = load_effect("Sounds/FX/door_open.wav");
} }
void void

View File

@ -64,6 +64,7 @@ typedef enum Fx_t {
FADE_IN, FADE_IN,
FADE_OUT, FADE_OUT,
BURST, BURST,
DOOR_OPEN,
LAST_EFFECT LAST_EFFECT
} Fx; } Fx;

View File

@ -239,6 +239,10 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
gamecontroller_rumble(0.30f, 100); gamecontroller_rumble(0.30f, 100);
if (space->monster) { if (space->monster) {
on_monster_collision(player, space->monster, matrix, direction); on_monster_collision(player, space->monster, matrix, direction);
} else if (space->door) {
mixer_play_effect(DOOR_OPEN);
space->door->sprite->texture_index = 1;
space->door->collider = false;
} else { } else {
mixer_play_effect(BONK); mixer_play_effect(BONK);
camera_shake(direction, 100); camera_shake(direction, 100);