Fixes missing lights in coridors and exit under candle

Also some improvements to the in game menu handling.
This commit is contained in:
Linus_Probert 2018-02-13 09:50:52 +01:00
parent dcafbbc6ac
commit a045ffc07c
3 changed files with 40 additions and 17 deletions

View File

@ -26,10 +26,10 @@ x Statistics
x More stuff to count
x Particle engine for blood splatter (keep it light!!!)
x Prevent level exit from spawning on occupied spot
o Menus
x Menus
x Main menu
x In game menu
- Player death (graphic or text?)
- Player death (GAME_OVER state) (graphic or text?)
- Sound?
- Make things less difficult and more interesting
- Interesting items

View File

@ -125,6 +125,12 @@ local function check_add_decoration(map, x, y, data)
add_decoration(map, x, y, repack(data))
end
local function check_add_tile(map, x, y, data)
if tile_occupied(map, x, y) then return false end
add_tile(map, x, y, repack(data))
return true
end
local function add_random_decor_to_room()
local decor_count = random(4) - 1
for i=1,decor_count do
@ -222,9 +228,12 @@ local function add_exit(map, direction)
end
local function add_level_exit(map)
x = random(14)
y = random(10)
add_tile(map, x, y, repack(special.level_exit));
success = false
while not success do
x = random(14)
y = random(10)
success = check_add_tile(map, x, y, special.level_exit);
end
end
local function build_vert_center_coridoor(map, offset)
@ -235,10 +244,10 @@ local function build_vert_center_coridoor(map, offset)
add_tile(map, 9, offset+j, repack(wall.vertical));
end
if random(2) == 1 then
check_add_decoration(map, 6, offset + 2, lightDecor.candle1)
add_decoration(map, 6, offset + 2, repack(lightDecor.candle1))
end
if random(2) == 1 then
check_add_decoration(map, 9, offset + 2, lightDecor.candle1)
add_decoration(map, 9, offset + 2, repack(lightDecor.candle1))
end
end

View File

@ -158,6 +158,7 @@ static void
startGame(void *unused)
{
UNUSED(unused);
cLevel = 1;
gGameState = PLAYING;
resetGame();
}
@ -228,9 +229,6 @@ initInGameMenu(void)
{ "QUIT", exitGame },
};
if (inGameMenu)
menu_destroy(inGameMenu);
createMenu(&inGameMenu, menu_items, 3);
}
@ -260,12 +258,12 @@ resetGame(void)
mainMenu = NULL;
}
initInGameMenu();
if (!inGameMenu)
initInGameMenu();
if (gMap)
map_destroy(gMap);
cLevel = 1;
info("Building new map");
gMap = map_lua_generator_run(cLevel, gRenderer);
gPlayer->sprite->pos = (Position) {
@ -296,8 +294,20 @@ loadMedia(void)
gPlayer = player_create(WARRIOR, gRenderer);
}
static
bool handle_events(void)
static bool
handle_main_events(SDL_Event *event)
{
if (gGameState == PLAYING || gGameState == IN_GAME_MENU) {
if (keyboard_press(SDLK_ESCAPE, event)) {
toggleInGameMenu(NULL);
return true;
}
}
return false;
}
static bool
handle_events(void)
{
static SDL_Event event;
bool quit = false;
@ -305,9 +315,13 @@ bool handle_events(void)
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
quit = true;
} else if (keyboard_press(SDLK_ESCAPE, &event)) {
toggleInGameMenu(NULL);
} else if (gGameState == PLAYING) {
continue;
}
if (handle_main_events(&event))
continue;
if (gGameState == PLAYING) {
gPlayer->handle_event(gPlayer,
gRoomMatrix,
&event);