Incomplete monster key fixes

This commit is contained in:
Linus Probert 2019-03-19 21:54:58 +01:00
parent 59a1e81c6e
commit 18987e2c2a
9 changed files with 73 additions and 27 deletions

View File

@ -214,16 +214,16 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
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 },
door_top_silverlock = { t_door0, t_door1, 32, 0, true, false, false, false, 1 },
door_left_silverlock = { t_door0, t_door1, 48, 0, true, false, false, false, 1 },
door_top_goldlock = { t_door0, t_door1, 64, 0, true, false, false, false, 2 },
door_left_goldlock = { t_door0, t_door1, 80, 0, true, false, false, false, 2 },
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 },
gate_top_silverlock = { t_door0, t_door1, 32, 32, true, false, false, false, 1 },
gate_left_silverlock = { t_door0, t_door1, 48, 32, true, false, false, false, 1 },
gate_top_goldlock = { t_door0, t_door1, 64, 32, true, false, false, false, 2 },
gate_left_goldlock = { t_door0, t_door1, 80, 32, true, false, false, false, 2 },
}
lights = {
@ -351,6 +351,10 @@ function draw_layout_to_room(room, matrix, roomx, roomy)
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] == "S" then
room.doors[i][j] = getDoor(matrix, i, j, doors.door_top_silverlock, doors.door_left_silverlock)
elseif matrix[i][j] == "G" then
room.doors[i][j] = getDoor(matrix, i, j, doors.door_top_goldlock, doors.door_left_goldlock)
elseif matrix[i][j] == "g" then
room.doors[i][j] = getDoor(matrix, i, j, doors.gate_top_nolock, doors.gate_left_nolock)
end

View File

@ -1,12 +1,12 @@
++++++++++++++++
++++++++++++++++
++"#####d####"++
++"#####G####"++
++#-c--c--c--#++
++#----------#++
++#-c--c--c--#++
++d----------d++
++G----------S++
++#-c--c--c--#++
++#----------#++
++"#####d####"++
++"#####S####"++
++++++++++++++++
++++++++++++++++

View File

@ -132,6 +132,7 @@ local function generate_path ()
room.type = "shop"
shopAdded = true
end
room.type = "locked"
roomCount = roomCount + 1
room_builder.build_room(room, i-1, j-1)
if room.type ~= "shop" then

View File

@ -121,7 +121,8 @@ local function repack(data)
isCollider = data[5] or false,
isLightSource = data[6] or false,
isLevelExit = data[7] or false,
isLethal = data[8] or false
isLethal = data[8] or false,
lockType = data[9] or 0
}
end
@ -509,6 +510,8 @@ function module.build_room(room, roomx, roomy)
build_coridoor_room(room)
elseif room.type == "shop" then
build_shop_room(room, roomx, roomy)
elseif room.type == "locked" then
build_locked_room(room, roomx, roomy)
else
build_normal_room(room)
--build_locked_room(room, roomx, roomy)

View File

@ -456,6 +456,9 @@ map_open_door(MapTile *tile, Player *player)
{
if (tile->lockType == LOCK_NONE || tile->lockType & player->equipment.keys) {
// Open the door
if (tile->lockType != LOCK_NONE)
gui_log("You unlocked a door!");
mixer_play_effect(DOOR_OPEN);
tile->sprite->texture_index = 1;
tile->collider = false;

View File

@ -182,6 +182,7 @@ extract_tile_data(lua_State *L,
int tile_x, tile_y;
int t_index0, t_index1, tile_clip_x, tile_clip_y;
bool collider, lightsource, levelExit, lethal;
int lockType;
map = luaL_checkmap(L, 1);
tile_x = (int) luaL_checkinteger(L, 2);
@ -200,18 +201,20 @@ extract_tile_data(lua_State *L,
lua_getfield(L, 4, "isLightSource");
lua_getfield(L, 4, "isLevelExit");
lua_getfield(L, 4, "isLethal");
lua_getfield(L, 4, "lockType");
t_index0 = (int) luaL_checkinteger(L, -8);
t_index1 = (int) luaL_checkinteger(L, -7);
tile_clip_x = (int) luaL_checkinteger(L, -6);
tile_clip_y = (int) luaL_checkinteger(L, -5);
collider = lua_toboolean(L, -4);
lightsource = lua_toboolean(L, -3);
levelExit = lua_toboolean(L, -2);
lethal = lua_toboolean(L, -1);
t_index0 = (int) luaL_checkinteger(L, -9);
t_index1 = (int) luaL_checkinteger(L, -8);
tile_clip_x = (int) luaL_checkinteger(L, -7);
tile_clip_y = (int) luaL_checkinteger(L, -6);
collider = lua_toboolean(L, -5);
lightsource = lua_toboolean(L, -4);
levelExit = lua_toboolean(L, -3);
lethal = lua_toboolean(L, -2);
lockType = (int) luaL_checkinteger(L, -1);
// Clear the stack
lua_pop(L, 8);
lua_pop(L, 9);
Position tilePos = (Position) { tile_x, tile_y };
SDL_Rect clip = (SDL_Rect) { tile_clip_x, tile_clip_y, 16, 16 };
@ -227,6 +230,7 @@ extract_tile_data(lua_State *L,
tile->lightsource = lightsource;
tile->levelExit = levelExit;
tile->lethal = lethal;
tile->lockType = lockType;
f_add_tile(map, &tilePos, tile);
}
@ -386,6 +390,24 @@ l_add_chest(lua_State *L)
return 0;
}
static int
l_add_key_to_random_monster(lua_State *L)
{
Map *map = luaL_checkmap(L, 0);
int keytype = (int) luaL_checkinteger(L, 1);
unsigned int max = linkedlist_size(&map->monsters);
unsigned int index = bh_map_rand(max - 1);
Monster *m = linkedlist_get(&map->monsters, index);
if (!m)
return 0;
m->items.keyType = keytype;
return 0;
}
static int
l_add_monster(lua_State *L)
{

View File

@ -266,6 +266,7 @@ monster_create(void)
m->state.forceCount = 0;
m->boss = false;
m->bloodlust = false;
m->items.keyType = LOCK_NONE;
monster_set_behaviour(m, NORMAL);
return m;
@ -704,6 +705,12 @@ monster_drop_loot(Monster *monster, Map *map, Player *player)
linkedlist_append(&map->items, treasure);
}
if (monster->items.keyType != LOCK_NONE) {
Item *key = item_builder_build_key(monster->items.keyType);
key->sprite->pos = monsterTilePos;
linkedlist_append(&map->items, key);
}
if (monster->stats.lvl > 2 && get_random(29) == 0) {
Artifact *a = artifact_create_random(player, 1);
a->sprite->pos = monsterTilePos;

View File

@ -27,6 +27,7 @@
#include "linkedlist.h"
struct UpdateData;
enum DoorLockType;
typedef enum {
PACIFIST,
@ -63,6 +64,10 @@ typedef struct MonsterStateIndicator {
int displayCount;
} MonsterStateIndicator;
typedef struct MonsterItems {
enum DoorLockType keyType;
} MonsterItems;
typedef struct Monster {
char *label;
char *lclabel;
@ -71,6 +76,7 @@ typedef struct Monster {
State state;
MonsterStateIndicator stateIndicator;
MonsterBehaviour behaviour;
MonsterItems items;
unsigned int steps;
bool boss;
bool bloodlust;

View File

@ -239,14 +239,14 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
gamecontroller_rumble(0.30f, 100);
if (space->monster) {
on_monster_collision(player, space->monster, matrix, direction);
} else if (space->door) {
// Open the door
mixer_play_effect(DOOR_OPEN);
space->door->sprite->texture_index = 1;
space->door->collider = false;
} else if (space->door && map_open_door(space->door, player)) {
// Door opened, pass
} else {
mixer_play_effect(BONK);
camera_shake(direction, 100);
if (space->door)
gui_log("Ouch! That door seems to be locked");
else
gui_log("Ouch! There is something in the way");
}
return true;