From a045ffc07cfa98ed01c2cdc4163dc2282e08188f Mon Sep 17 00:00:00 2001 From: Linus_Probert Date: Tue, 13 Feb 2018 09:50:52 +0100 Subject: [PATCH] Fixes missing lights in coridors and exit under candle Also some improvements to the in game menu handling. --- TODO.txt | 4 ++-- data/maproombuilder.lua | 19 ++++++++++++++----- src/main.c | 34 ++++++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/TODO.txt b/TODO.txt index 4204a39..1f2b95c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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 diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index 5164ec2..16dae90 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -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 diff --git a/src/main.c b/src/main.c index 62911ae..9fa58d2 100644 --- a/src/main.c +++ b/src/main.c @@ -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);