Completes crumbling rooms.

This commit is contained in:
Linus Probert 2018-10-15 22:19:23 +02:00
parent 6e6f28dd8e
commit feed0e29fa
9 changed files with 32 additions and 18 deletions

View File

@ -222,28 +222,28 @@ local function add_pits_to_room(room)
return true
end
local function add_tiles_to_room (room)
local function add_tiles_to_room (room, singletile)
for i=0,15 do
for j=0,11 do
if (i >= 1 and i <= 14 and j >= 1 and j <= 10) then
if (i == 1 and j == 1) then
room.tiles[i][j] = floor.topleft
room.tiles[i][j] = singletile and floor.single or floor.topleft
elseif (i == 14 and j == 1) then
room.tiles[i][j] = floor.topright
room.tiles[i][j] = singletile and floor.single or floor.topright
elseif (i == 1 and j == 10) then
room.tiles[i][j] = floor.bottomleft
room.tiles[i][j] = singletile and floor.single or floor.bottomleft
elseif (i == 14 and j == 10) then
room.tiles[i][j] = floor.bottomright
room.tiles[i][j] = singletile and floor.single or floor.bottomright
elseif (i == 1) then
room.tiles[i][j] = floor.left
room.tiles[i][j] = singletile and floor.single or floor.left
elseif (i == 14) then
room.tiles[i][j] = floor.right
room.tiles[i][j] = singletile and floor.single or floor.right
elseif (j == 1) then
room.tiles[i][j] = floor.top
room.tiles[i][j] = singletile and floor.single or floor.top
elseif (j == 10) then
room.tiles[i][j] = floor.bottom
room.tiles[i][j] = singletile and floor.single or floor.bottom
else
room.tiles[i][j] = floor.center
room.tiles[i][j] = singletile and floor.single or floor.center
end
end
end
@ -422,17 +422,22 @@ local function add_level_exit(room)
end
local function build_normal_room(room)
add_tiles_to_room(room)
local crumbling = CURRENT_LEVEL > 3 and random(8) == 1
add_tiles_to_room(room, crumbling)
add_random_decor_to_room(room)
add_walls_to_room(room)
add_exits_to_room(room)
local pitsAdded = add_pits_to_room(room)
local pitsAdded = crumbling or add_pits_to_room(room)
if room.goal then
add_level_exit(room)
end
if CURRENT_LEVEL > 5 and random(8) == 1 then
if crumbling then
room.modifier.type = "CRUMBLING"
room.modifier.arg = ""
elseif CURRENT_LEVEL > 3 and random(8) == 1 then
room.modifier.type = "FIRE"
room.modifier.arg = ""
elseif ((not pitsAdded and CURRENT_LEVEL > 1) or CURRENT_LEVEL > 3) and random(8) == 1 then
@ -546,6 +551,7 @@ function module.load_textures(map)
floor.singlebottom = { t_floor, -1, xo + 48, yo + 32, false }
floor.singleleft = { t_floor, -1, xo + 64, yo + 16, false }
floor.singleright = { t_floor, -1, xo + 96, yo + 16, false }
floor.single = { t_floor, -1, xo + 80, yo + 0, false }
local pit_yo = (random(5) + random(3)) * (16 * 2)
pits.topleft = { t_pit0, t_pit1, 0, pit_yo, false, false, false, true }

View File

@ -291,6 +291,7 @@ map_update(UpdateData *data)
Room *room = map->rooms[roomPos.x][roomPos.y];
for (size_t i=0; i < MAP_ROOM_WIDTH; ++i) {
for (size_t j=0; j < MAP_ROOM_HEIGHT; ++j) {
if (room->tiles[i][j])
sprite_update(room->tiles[i][j]->sprite, data);
}
}

View File

@ -119,6 +119,9 @@ l_map_set_current_room_modifier(lua_State *L)
} else if (strcmp(modifier, "FIRE") == 0) {
Room *room = map->rooms[map->currentRoom.x][map->currentRoom.y];
room->modifier.type = RMOD_TYPE_FIRE;
} else if (strcmp(modifier, "CRUMBLING") == 0) {
Room *room = map->rooms[map->currentRoom.x][map->currentRoom.y];
room->modifier.type = RMOD_TYPE_CRUMBLING;
} else {
luaL_error(L, "Unknown room modifier: %s", modifier);
return 1;

View File

@ -29,7 +29,7 @@ typedef enum RoomModifierType_e {
RMOD_TYPE_NONE,
RMOD_TYPE_WINDY,
RMOD_TYPE_FIRE,
RMOD_TYPE_FALLING_TILES
RMOD_TYPE_CRUMBLING
} RoomModifierType;
typedef struct WindData {

View File

@ -104,12 +104,14 @@ menu_create_character_selector(void (*onCharacterSelect)(const char *))
s1->clip = CLIP16(0, 48);
s1->dim = DIM(64, 64);
s1->pos = POS(xoffset - 32, 256);
s1->fixed = true;
Sprite *s2 = sprite_create();
sprite_set_texture(s2, texturecache_add(spriteSheets[i]), 0);
s2->clip = CLIP16(0, 0);
s2->dim = DIM(64, 64);
s2->pos = POS(xoffset - 32, 256);
s2->fixed = true;
menu_item_add(menu, s1, s2, (void (*)(void *)) onCharacterSelect);
MenuItem *item = linkedlist_get(&menu->items, (Uint32) i);

View File

@ -586,7 +586,7 @@ monster_update(Monster *m, UpdateData *data)
sprite_update(m->sprite, data);
if (m->sprite->hidden == SPRITE_STATE_FALLING && m->sprite->hidden) {
if (m->sprite->state == SPRITE_STATE_PLUMMETED) {
m->stats.hp = 0;
player_monster_kill_check(data->player, m);
return;

View File

@ -294,7 +294,8 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction)
if (!has_collided(player, matrix, direction)) {
action_spent(player);
RoomSpace *lastSpace = &matrix->spaces[lastPos.x][lastPos.y];
if (lastPos.x > 1 &&
if (matrix->modifier->type == RMOD_TYPE_CRUMBLING &&
lastPos.x > 1 &&
lastPos.y > 1 &&
lastPos.x < 14 &&
lastPos.y < 10 &&

View File

@ -138,7 +138,7 @@ sprite_update(Sprite *s, UpdateData *data)
}
if (s->dim.width < 4) {
s->hidden = true;
s->state = SPRITE_STATE_DEFAULT;
s->state = SPRITE_STATE_PLUMMETED;
}
}
}

View File

@ -31,6 +31,7 @@ typedef struct UpdateData UpdateData;
typedef enum SpriteState {
SPRITE_STATE_FALLING,
SPRITE_STATE_PLUMMETED,
SPRITE_STATE_DEFAULT
} SpriteState;