Completes #31 Adds chests to game
This commit is contained in:
parent
1c7631cf52
commit
62d1bbd49d
|
@ -264,6 +264,7 @@ if (NOT DEBUG_BUILD)
|
||||||
"menumapgen.lua"
|
"menumapgen.lua"
|
||||||
"monstergen.lua"
|
"monstergen.lua"
|
||||||
"trapgen.lua"
|
"trapgen.lua"
|
||||||
|
"chestgen.lua"
|
||||||
"pitlayouts.dat"
|
"pitlayouts.dat"
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
|
||||||
)
|
)
|
||||||
|
|
Binary file not shown.
|
@ -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
|
|
@ -1,6 +1,7 @@
|
||||||
local room_builder = require "maproombuilder"
|
local room_builder = require "maproombuilder"
|
||||||
local monster_gen = require "monstergen"
|
local monster_gen = require "monstergen"
|
||||||
local trap_gen = require "trapgen"
|
local trap_gen = require "trapgen"
|
||||||
|
local chest_gen = require "chestgen"
|
||||||
|
|
||||||
-- Setting up some functions
|
-- Setting up some functions
|
||||||
local time = os.time
|
local time = os.time
|
||||||
|
@ -117,6 +118,7 @@ local function generate_path ()
|
||||||
room_builder.build_room(room)
|
room_builder.build_room(room)
|
||||||
monster_gen.add_monsters_to_room(room, i-1, j-1)
|
monster_gen.add_monsters_to_room(room, i-1, j-1)
|
||||||
trap_gen.add_traps_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
|
end
|
||||||
end
|
end
|
||||||
|
@ -141,6 +143,7 @@ for i=1,10 do
|
||||||
room_builder.load_room(map, room)
|
room_builder.load_room(map, room)
|
||||||
monster_gen.load_monsters(map, room.monsters)
|
monster_gen.load_monsters(map, room.monsters)
|
||||||
trap_gen.load_traps(map, room.traps)
|
trap_gen.load_traps(map, room.traps)
|
||||||
|
chest_gen.load_chests(map, room.chests)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -131,7 +131,7 @@ local function repack(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_random_decor_to_room(room)
|
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
|
for i=1,decor_count do
|
||||||
x = random(11) + 1
|
x = random(11) + 1
|
||||||
y = random(8) + 1
|
y = random(8) + 1
|
||||||
|
@ -452,6 +452,16 @@ function module.add_full_lighting(room)
|
||||||
room.decor[11][9] = lightDecor.candle2
|
room.decor[11][9] = lightDecor.candle2
|
||||||
end
|
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()
|
function module.create_empty_room()
|
||||||
room = {
|
room = {
|
||||||
exits = {},
|
exits = {},
|
||||||
|
@ -466,6 +476,7 @@ function module.create_empty_room()
|
||||||
arg = nil
|
arg = nil
|
||||||
},
|
},
|
||||||
monsters = {},
|
monsters = {},
|
||||||
|
chests = {},
|
||||||
traps = {}
|
traps = {}
|
||||||
}
|
}
|
||||||
for i=0,15 do
|
for i=0,15 do
|
||||||
|
@ -473,11 +484,13 @@ function module.create_empty_room()
|
||||||
room.decor[i] = {}
|
room.decor[i] = {}
|
||||||
room.monsters[i] = {}
|
room.monsters[i] = {}
|
||||||
room.traps[i] = {}
|
room.traps[i] = {}
|
||||||
|
room.chests[i] = {}
|
||||||
for j=0,11 do
|
for j=0,11 do
|
||||||
room.tiles[i][j] = nil
|
room.tiles[i][j] = nil
|
||||||
room.decor[i][j] = nil
|
room.decor[i][j] = nil
|
||||||
room.monsters[i][j] = nil
|
room.monsters[i][j] = nil
|
||||||
room.traps[i][j] = nil
|
room.traps[i][j] = nil
|
||||||
|
room.chests[i][j] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return room
|
return room
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
local room_builder = require "maproombuilder"
|
||||||
local module = {}
|
local module = {}
|
||||||
local random = math.random
|
local random = math.random
|
||||||
|
|
||||||
|
@ -250,13 +251,7 @@ function module.add_monsters_to_room(room, roomx, roomy)
|
||||||
while i < count do
|
while i < count do
|
||||||
local rx = random(13) + 1
|
local rx = random(13) + 1
|
||||||
local ry = random(9) + 1
|
local ry = random(9) + 1
|
||||||
if not room.decor[rx][ry]
|
if room_builder.is_tile_avilable(room, rx, ry) then
|
||||||
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
|
|
||||||
|
|
||||||
local x = (roomx * 512) + rx * 32
|
local x = (roomx * 512) + rx * 32
|
||||||
local y = (roomy * 384) + ry * 32
|
local y = (roomy * 384) + ry * 32
|
||||||
room.monsters[rx][ry] = {
|
room.monsters[rx][ry] = {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
local room_builder = require "maproombuilder"
|
||||||
local module = {}
|
local module = {}
|
||||||
local random = math.random
|
local random = math.random
|
||||||
|
|
||||||
|
@ -34,13 +35,7 @@ function module.add_traps_to_room(room)
|
||||||
while i < count do
|
while i < count do
|
||||||
local rx = random(13) + 1
|
local rx = random(13) + 1
|
||||||
local ry = random(9) + 1
|
local ry = random(9) + 1
|
||||||
if not room.decor[rx][ry]
|
if room_builder.is_tile_avilable(room, rx, ry) then
|
||||||
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
|
|
||||||
|
|
||||||
room.traps[rx][ry] = traps[random(#traps)]
|
room.traps[rx][ry] = traps[random(#traps)]
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "mixer.h"
|
||||||
|
|
||||||
Item *
|
Item *
|
||||||
item_create(void)
|
item_create(void)
|
||||||
|
@ -59,6 +60,7 @@ item_collected(Item *item, Player *player)
|
||||||
if (!item->openable) {
|
if (!item->openable) {
|
||||||
item->collected = true;
|
item->collected = true;
|
||||||
} else {
|
} else {
|
||||||
|
mixer_play_effect(CHEST_OPEN);
|
||||||
item->opened = true;
|
item->opened = true;
|
||||||
item->sprite->texture_index = 1;
|
item->sprite->texture_index = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,15 +330,15 @@ l_add_chest(lua_State *L)
|
||||||
cr->x * MAP_ROOM_WIDTH * TILE_DIMENSION + x * TILE_DIMENSION,
|
cr->x * MAP_ROOM_WIDTH * TILE_DIMENSION + x * TILE_DIMENSION,
|
||||||
cr->y * MAP_ROOM_HEIGHT * TILE_DIMENSION + y * 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));
|
linkedlist_append(&chest->items, item_builder_build_item(level, TREASURE));
|
||||||
if (get_random(4) == 0)
|
if (get_random(4) == 0)
|
||||||
linkedlist_append(&chest->items, item_builder_build_item(level, HEALTH));
|
linkedlist_append(&chest->items, item_builder_build_item(level, HEALTH));
|
||||||
if (get_random(4) == 0)
|
if (get_random(4) == 0)
|
||||||
linkedlist_append(&chest->items, item_builder_build_item(level, DAGGER));
|
linkedlist_append(&chest->items, item_builder_build_item(level, DAGGER));
|
||||||
|
|
||||||
lua_pop(L, 4);
|
|
||||||
|
|
||||||
linkedlist_append(&map->items, chest);
|
linkedlist_append(&map->items, chest);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -83,6 +83,7 @@ load_effects(void)
|
||||||
effects[FALL1] = load_effect("Sounds/FX/fall1.wav");
|
effects[FALL1] = load_effect("Sounds/FX/fall1.wav");
|
||||||
effects[SLAM] = load_effect("Sounds/FX/slam.wav");
|
effects[SLAM] = load_effect("Sounds/FX/slam.wav");
|
||||||
effects[MAGIC_PICKUP] = load_effect("Sounds/FX/magic_pickup.wav");
|
effects[MAGIC_PICKUP] = load_effect("Sounds/FX/magic_pickup.wav");
|
||||||
|
effects[CHEST_OPEN] = load_effect("Sounds/FX/chest_open.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -59,6 +59,7 @@ typedef enum Fx_t {
|
||||||
DAGGER_PICKUP,
|
DAGGER_PICKUP,
|
||||||
SLAM,
|
SLAM,
|
||||||
MAGIC_PICKUP,
|
MAGIC_PICKUP,
|
||||||
|
CHEST_OPEN,
|
||||||
LAST_EFFECT
|
LAST_EFFECT
|
||||||
} Fx;
|
} Fx;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue