From 18987e2c2abda53143026f139c1cadded2a35a46 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 19 Mar 2019 21:54:58 +0100 Subject: [PATCH] Incomplete monster key fixes --- data/layoutparser.lua | 20 +++++++++++-------- data/lockedroomlayouts.dat | 6 +++--- data/mapgen.lua | 1 + data/maproombuilder.lua | 5 ++++- src/map.c | 3 +++ src/map_lua.c | 40 +++++++++++++++++++++++++++++--------- src/monster.c | 7 +++++++ src/monster.h | 6 ++++++ src/player.c | 12 ++++++------ 9 files changed, 73 insertions(+), 27 deletions(-) diff --git a/data/layoutparser.lua b/data/layoutparser.lua index c15540d..d10315c 100644 --- a/data/layoutparser.lua +++ b/data/layoutparser.lua @@ -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 diff --git a/data/lockedroomlayouts.dat b/data/lockedroomlayouts.dat index d084058..9b34415 100644 --- a/data/lockedroomlayouts.dat +++ b/data/lockedroomlayouts.dat @@ -1,12 +1,12 @@ ++++++++++++++++ ++++++++++++++++ -++"#####d####"++ +++"#####G####"++ ++#-c--c--c--#++ ++#----------#++ ++#-c--c--c--#++ -++d----------d++ +++G----------S++ ++#-c--c--c--#++ ++#----------#++ -++"#####d####"++ +++"#####S####"++ ++++++++++++++++ ++++++++++++++++ \ No newline at end of file diff --git a/data/mapgen.lua b/data/mapgen.lua index 4586110..525a65d 100644 --- a/data/mapgen.lua +++ b/data/mapgen.lua @@ -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 diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index 3e64f40..1be8df9 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -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) diff --git a/src/map.c b/src/map.c index dc76e9a..9d40813 100644 --- a/src/map.c +++ b/src/map.c @@ -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; diff --git a/src/map_lua.c b/src/map_lua.c index 3a88392..4eb8ad6 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -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) { diff --git a/src/monster.c b/src/monster.c index 1b7664d..eee036f 100644 --- a/src/monster.c +++ b/src/monster.c @@ -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; diff --git a/src/monster.h b/src/monster.h index 1e17ddd..9910f42 100644 --- a/src/monster.h +++ b/src/monster.h @@ -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; diff --git a/src/player.c b/src/player.c index c3f4d50..f7e67a2 100644 --- a/src/player.c +++ b/src/player.c @@ -239,15 +239,15 @@ 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); - gui_log("Ouch! There is something in the way"); + if (space->door) + gui_log("Ouch! That door seems to be locked"); + else + gui_log("Ouch! There is something in the way"); } return true; }