Completes #31 Adds chests to game

This commit is contained in:
Linus Probert 2018-08-10 20:09:56 +02:00
parent 1c7631cf52
commit 62d1bbd49d
11 changed files with 92 additions and 18 deletions

View File

@ -264,6 +264,7 @@ if (NOT DEBUG_BUILD)
"menumapgen.lua"
"monstergen.lua"
"trapgen.lua"
"chestgen.lua"
"pitlayouts.dat"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
)

Binary file not shown.

63
data/chestgen.lua Normal file
View File

@ -0,0 +1,63 @@
local room_builder = require "maproombuilder"
local module = {}
local random = math.random
local textures = {
"Items/Chest0.png",
"Items/Chest1.png"
}
local chests = {}
for i=0,1 do
table.insert(chests, {
textures[1],
textures[2],
0,
i * 16
});
table.insert(chests, {
textures[1],
textures[2],
16,
i * 16
});
end
local function repack(data)
return {
texturePath1 = data[1],
texturePath2 = data[2],
clipX = data[3],
clipY = data[4]
}
end
function module.add_chests_to_room(room)
if room.type == "coridoor" then
return
end
local count = random(3) - 1
local i = 0
while i < count do
local rx = random(13) + 1
local ry = random(9) + 1
if room_builder.is_tile_avilable(room, rx, ry) then
room.chests[rx][ry] = chests[random(#chests)]
i = i + 1
end
end
end
function module.load_chests(map, chests)
for i=0,15 do
for j=0,11 do
chest = chests[i][j]
if chest then
add_chest(map, i, j, CURRENT_LEVEL, repack(chest))
end
end
end
end
return module

View File

@ -1,6 +1,7 @@
local room_builder = require "maproombuilder"
local monster_gen = require "monstergen"
local trap_gen = require "trapgen"
local chest_gen = require "chestgen"
-- Setting up some functions
local time = os.time
@ -117,6 +118,7 @@ local function generate_path ()
room_builder.build_room(room)
monster_gen.add_monsters_to_room(room, i-1, j-1)
trap_gen.add_traps_to_room(room, i-1, j-1)
chest_gen.add_chests_to_room(room, i-1, j-1)
end
end
end
@ -141,6 +143,7 @@ for i=1,10 do
room_builder.load_room(map, room)
monster_gen.load_monsters(map, room.monsters)
trap_gen.load_traps(map, room.traps)
chest_gen.load_chests(map, room.chests)
end
end
end

View File

@ -131,7 +131,7 @@ local function repack(data)
end
local function add_random_decor_to_room(room)
local decor_count = random(10) - 1
local decor_count = random(8)
for i=1,decor_count do
x = random(11) + 1
y = random(8) + 1
@ -452,6 +452,16 @@ function module.add_full_lighting(room)
room.decor[11][9] = lightDecor.candle2
end
function module.is_tile_avilable(room, rx, ry)
return not room.chests[rx][ry]
and not room.traps[rx][ry]
and not room.monsters[rx][ry]
and not room.decor[rx][ry]
and (room.tiles[rx][ry]
and not room.tiles[rx][ry][5]
and not room.tiles[rx][ry][8])
end
function module.create_empty_room()
room = {
exits = {},
@ -466,6 +476,7 @@ function module.create_empty_room()
arg = nil
},
monsters = {},
chests = {},
traps = {}
}
for i=0,15 do
@ -473,11 +484,13 @@ function module.create_empty_room()
room.decor[i] = {}
room.monsters[i] = {}
room.traps[i] = {}
room.chests[i] = {}
for j=0,11 do
room.tiles[i][j] = nil
room.decor[i][j] = nil
room.monsters[i][j] = nil
room.traps[i][j] = nil
room.chests[i][j] = nil
end
end
return room

View File

@ -1,3 +1,4 @@
local room_builder = require "maproombuilder"
local module = {}
local random = math.random
@ -250,13 +251,7 @@ function module.add_monsters_to_room(room, roomx, roomy)
while i < count do
local rx = random(13) + 1
local ry = random(9) + 1
if not room.decor[rx][ry]
and not room.monsters[rx][ry]
and (room.tiles[rx][ry]
and not room.tiles[rx][ry][5]
and not room.tiles[rx][ry][8])
then
if room_builder.is_tile_avilable(room, rx, ry) then
local x = (roomx * 512) + rx * 32
local y = (roomy * 384) + ry * 32
room.monsters[rx][ry] = {

View File

@ -1,3 +1,4 @@
local room_builder = require "maproombuilder"
local module = {}
local random = math.random
@ -34,13 +35,7 @@ function module.add_traps_to_room(room)
while i < count do
local rx = random(13) + 1
local ry = random(9) + 1
if not room.decor[rx][ry]
and not room.monsters[rx][ry]
and (room.tiles[rx][ry]
and not room.tiles[rx][ry][5]
and not room.tiles[rx][ry][8])
then
if room_builder.is_tile_avilable(room, rx, ry) then
room.traps[rx][ry] = traps[random(#traps)]
i = i + 1
end

View File

@ -19,6 +19,7 @@
#include <stdlib.h>
#include "item.h"
#include "util.h"
#include "mixer.h"
Item *
item_create(void)
@ -59,6 +60,7 @@ item_collected(Item *item, Player *player)
if (!item->openable) {
item->collected = true;
} else {
mixer_play_effect(CHEST_OPEN);
item->opened = true;
item->sprite->texture_index = 1;
}

View File

@ -330,15 +330,15 @@ l_add_chest(lua_State *L)
cr->x * MAP_ROOM_WIDTH * TILE_DIMENSION + x * TILE_DIMENSION,
cr->y * MAP_ROOM_HEIGHT * TILE_DIMENSION + y * TILE_DIMENSION
};
if (get_random(2) == 0)
lua_pop(L, 4);
if (get_random(1) == 0)
linkedlist_append(&chest->items, item_builder_build_item(level, TREASURE));
if (get_random(4) == 0)
linkedlist_append(&chest->items, item_builder_build_item(level, HEALTH));
if (get_random(4) == 0)
linkedlist_append(&chest->items, item_builder_build_item(level, DAGGER));
lua_pop(L, 4);
linkedlist_append(&map->items, chest);
return 0;

View File

@ -83,6 +83,7 @@ load_effects(void)
effects[FALL1] = load_effect("Sounds/FX/fall1.wav");
effects[SLAM] = load_effect("Sounds/FX/slam.wav");
effects[MAGIC_PICKUP] = load_effect("Sounds/FX/magic_pickup.wav");
effects[CHEST_OPEN] = load_effect("Sounds/FX/chest_open.wav");
}
void

View File

@ -59,6 +59,7 @@ typedef enum Fx_t {
DAGGER_PICKUP,
SLAM,
MAGIC_PICKUP,
CHEST_OPEN,
LAST_EFFECT
} Fx;