diff --git a/src/dawn/display/frame.c b/src/dawn/display/frame.c index 75d0339e..7a1f0429 100644 --- a/src/dawn/display/frame.c +++ b/src/dawn/display/frame.c @@ -25,7 +25,23 @@ void frameUpdate() { if(map == NULL) return; // Draw the map area. - frameMapDraw(); + if(GAME.state == GAME_STATE_PAUSED) { + framePausedDraw(); + } else { + frameMapDraw(); + } +} + +void framePausedDraw() { + char_t *test = "Paused"; + uint16_t x = (FRAME_WIDTH - strlen(test)) / 2; + uint16_t y = (FRAME_HEIGHT - FRAME_BOTTOM_UI_HEIGHT) / 2; + uint16_t j; + for(uint16_t i = 0; i < strlen(test); i++) { + j = (y * FRAME_WIDTH) + x + i; + FRAME_BUFFER[j] = test[i]; + FRAME_COLOR[j] = COLOR_WHITE; + } } void frameUIReset() { diff --git a/src/dawn/display/frame.h b/src/dawn/display/frame.h index ca100eb2..54c43189 100644 --- a/src/dawn/display/frame.h +++ b/src/dawn/display/frame.h @@ -32,6 +32,11 @@ void frameInit(); */ void frameUpdate(); +/** + * Draws the paused screen. + */ +void framePausedDraw(); + /** * Resets the UI area of the frame. */ diff --git a/src/dawn/game.c b/src/dawn/game.c index 0f282219..21aed3a6 100644 --- a/src/dawn/game.c +++ b/src/dawn/game.c @@ -31,15 +31,24 @@ uint8_t gameUpdate(const float_t delta) { timeUpdate(delta); inputUpdate(); - textboxUpdate(); + switch(GAME.state) { + case GAME_STATE_RUNNING: + textboxUpdate(); + if(GAME.currentMap) mapUpdate(GAME.currentMap); + if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_PAUSED; + break; + + case GAME_STATE_PAUSED: + if(inputWasPressed(INPUT_BIND_PAUSE)) GAME.state = GAME_STATE_RUNNING; + break; - if(GAME.currentMap) { - mapUpdate(GAME.currentMap); + default: + assertUnreachable("Invalid game state."); } displayUpdate(); - if(inputIsDown(INPUT_BIND_CANCEL)) return GAME_UPDATE_RESULT_EXIT; + if(GAME.shouldExit) return GAME_UPDATE_RESULT_EXIT; return GAME_UPDATE_RESULT_CONTINUE; } diff --git a/src/dawn/game.h b/src/dawn/game.h index 44ca640e..9db5912f 100644 --- a/src/dawn/game.h +++ b/src/dawn/game.h @@ -17,6 +17,7 @@ typedef struct { map_t *currentMap; uint8_t state; + bool_t shouldExit; } game_t; extern game_t GAME; diff --git a/src/dawn/input.h b/src/dawn/input.h index 69b350f3..516f2b53 100644 --- a/src/dawn/input.h +++ b/src/dawn/input.h @@ -17,8 +17,9 @@ typedef bool_t inputstate_t; #define INPUT_BIND_RIGHT 0x03 #define INPUT_BIND_ACCEPT 0x04 #define INPUT_BIND_CANCEL 0x05 +#define INPUT_BIND_PAUSE 0x06 -#define INPUT_BIND_COUNT (INPUT_BIND_CANCEL + 1) +#define INPUT_BIND_COUNT (INPUT_BIND_PAUSE + 1) typedef struct { inputstate_t currentState[INPUT_BIND_COUNT]; diff --git a/src/dawn/rpg/entity/player.c b/src/dawn/rpg/entity/player.c index 5e87f9f3..75fae9bb 100644 --- a/src/dawn/rpg/entity/player.c +++ b/src/dawn/rpg/entity/player.c @@ -12,6 +12,7 @@ #include "input.h" #include "assert/assert.h" #include "ui/textbox.h" +#include "game.h" void playerInit(entity_t *entity) { assertTrue(entity->type == ENTITY_TYPE_PLAYER, "Entity is not a player."); diff --git a/src/dawnglfw/dawnglfw.c b/src/dawnglfw/dawnglfw.c index 861c84d3..26d49abe 100644 --- a/src/dawnglfw/dawnglfw.c +++ b/src/dawnglfw/dawnglfw.c @@ -84,7 +84,8 @@ int32_t dawnGlfwStart() { dawnGlfwInputBind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER); dawnGlfwInputBind(INPUT_BIND_ACCEPT, GLFW_KEY_SPACE); dawnGlfwInputBind(INPUT_BIND_ACCEPT, GLFW_KEY_E); - dawnGlfwInputBind(INPUT_BIND_CANCEL, GLFW_KEY_ESCAPE); + dawnGlfwInputBind(INPUT_BIND_PAUSE, GLFW_KEY_ESCAPE); + dawnGlfwInputBind(INPUT_BIND_PAUSE, GLFW_KEY_P); dawnGlfwInputBind(INPUT_BIND_CANCEL, GLFW_KEY_Q); dawnGlfwInputBind(INPUT_BIND_CANCEL, GLFW_KEY_BACKSPACE);