Merge branch 'dev' - Restart Option added
This commit is contained in:
commit
c8e02c208e
@ -3,6 +3,7 @@
|
||||
// global configuration macros
|
||||
#define MAX_MAP_SIZE 20
|
||||
#define MAX_MAP_FIELDS (MAX_MAP_SIZE*MAX_MAP_SIZE)
|
||||
#define CYCLE_DURATIONS_MS 400
|
||||
|
||||
// logging settings
|
||||
//#define DEBUG_OUTPUT_ENABLED
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "config.h"
|
||||
|
||||
#define MAX_PRINTED_SCORES 10
|
||||
#define MAX_PRINTED_SCORES 13
|
||||
|
||||
extern int recordsInFile;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
config_t config = {
|
||||
.windowSize = 800,
|
||||
.blockSizePx = 800/10, //default map is 10x10 blocks
|
||||
.cycleDurationMs = 400,
|
||||
.cycleDurationMs = CYCLE_DURATIONS_MS,
|
||||
.difficulty = 1,
|
||||
.snakeDefaultLength = 2,
|
||||
.leaderboardFilename = "player_scores.bin",
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "menu.h"
|
||||
#include "snake.h"
|
||||
#include "map.h"
|
||||
#include "files.h"
|
||||
|
||||
|
||||
|
||||
@ -22,7 +23,12 @@ void handleInput_runningState(SDL_Event event)
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_q: // q: quit
|
||||
game.gameState = EXIT;
|
||||
//game.gameState = EXIT;
|
||||
game.gameState = MENU;
|
||||
activeMenu = LEADERBOARD;
|
||||
savePlayerScore(config.leaderboardFilename);
|
||||
readTopScores(config.leaderboardFilename);
|
||||
//showLeaderboard();
|
||||
break;
|
||||
|
||||
case SDLK_p: // p: pause
|
||||
|
33
src/menu.c
33
src/menu.c
@ -82,11 +82,16 @@ void showLeaderboard()
|
||||
//play audio file, wait until playback is finished
|
||||
//note: when displaying actual leaderboard, the second parameter should be 'false' to not block the program
|
||||
|
||||
renderLeaderboard();
|
||||
time_t now = GET_TIME_MS();
|
||||
|
||||
// is used to make ENTER blink
|
||||
if(now > (ttlStorage.lastTimeStep + ttlStorage.cycleDuration))
|
||||
{
|
||||
ttlStorage.showEnter = !ttlStorage.showEnter;
|
||||
renderLeaderboard();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void showPauseScreen()
|
||||
@ -145,7 +150,7 @@ void menuHandleInput(SDL_Event event){
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_q: // q: quit
|
||||
game.gameState = EXIT;
|
||||
// game.gameState = EXIT;
|
||||
break;
|
||||
|
||||
case SDLK_RETURN: // Enter key
|
||||
@ -235,8 +240,10 @@ void menuHandleInput(SDL_Event event){
|
||||
}
|
||||
|
||||
// initialize game
|
||||
LOGI("Schwierigkeitslevel: %d\n", ttlStorage.userDifficultyLevel);
|
||||
config.difficulty = ttlStorage.userDifficultyLevel;
|
||||
config.cycleDurationMs = config.cycleDurationMs / sqrt(config.difficulty);
|
||||
config.cycleDurationMs = CYCLE_DURATIONS_MS / sqrt(config.difficulty);
|
||||
|
||||
gameInit();
|
||||
|
||||
break;
|
||||
@ -265,7 +272,7 @@ void menuHandleInput(SDL_Event event){
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_q: // q: quit
|
||||
game.gameState = EXIT;
|
||||
// game.gameState = EXIT;
|
||||
break;
|
||||
|
||||
case SDLK_RETURN: // go return to settings
|
||||
@ -283,8 +290,18 @@ void menuHandleInput(SDL_Event event){
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_q: // q: quit
|
||||
case SDLK_RETURN:
|
||||
game.gameState = EXIT;
|
||||
// game.gameState = EXIT;
|
||||
break;
|
||||
|
||||
case SDLK_RETURN: // go to first page
|
||||
game.gameState = MENU;
|
||||
activeMenu = START;
|
||||
ttlStorage.lastTimeStep = 0;
|
||||
ttlStorage.inputStatus = 0;
|
||||
ttlStorage.userDifficultyLevel = 0;
|
||||
ttlStorage.userSelectedMap = 0;
|
||||
game.mapIsLoaded = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
28
src/render.c
28
src/render.c
@ -459,7 +459,11 @@ void renderInfoScreen()
|
||||
void renderLeaderboard()
|
||||
{
|
||||
|
||||
char* menuDescription[] ={"LEADERBOARD"};
|
||||
char* textLines[] ={
|
||||
"LEADERBOARD",
|
||||
"-- ENTER --"
|
||||
};
|
||||
|
||||
char* columnDescriptions[NUM_COLUMNS] =
|
||||
{
|
||||
"Score",
|
||||
@ -468,6 +472,7 @@ void renderLeaderboard()
|
||||
"Map"
|
||||
};
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(game.renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(game.renderer);
|
||||
|
||||
@ -477,8 +482,7 @@ void renderLeaderboard()
|
||||
|
||||
|
||||
// rendering 'LEADERBOARD'
|
||||
|
||||
ttlStorage.textSurface = TTF_RenderText_Solid(ttlStorage.ptrFont_30, menuDescription[0], ttlStorage.textColour[5]);
|
||||
ttlStorage.textSurface = TTF_RenderText_Solid(ttlStorage.ptrFont_30, textLines[0], ttlStorage.textColour[5]);
|
||||
ttlStorage.textTexture = SDL_CreateTextureFromSurface(game.renderer, ttlStorage.textSurface);
|
||||
|
||||
SDL_QueryTexture(ttlStorage.textTexture, NULL, NULL, &textWidth, &textHeight);
|
||||
@ -490,6 +494,23 @@ void renderLeaderboard()
|
||||
SDL_DestroyTexture(ttlStorage.textTexture);
|
||||
|
||||
|
||||
// rendering and print '-- ENTER --' every second cycle
|
||||
if(ttlStorage.showEnter)
|
||||
{
|
||||
ttlStorage.textSurface = TTF_RenderText_Solid(ttlStorage.ptrFont_30, textLines[1], ttlStorage.textColour[5]);
|
||||
ttlStorage.textTexture = SDL_CreateTextureFromSurface(game.renderer, ttlStorage.textSurface);
|
||||
|
||||
ttlStorage.textPrintPosition = (config.windowSize / 1.5); // print position for ENTER
|
||||
SDL_QueryTexture(ttlStorage.textTexture, NULL, NULL, &textWidth, &textHeight);
|
||||
|
||||
SDL_Rect dstRect = { (config.windowSize - textWidth) / 2, ttlStorage.textPrintPosition, textWidth, textHeight };;
|
||||
SDL_RenderCopy(game.renderer, ttlStorage.textTexture, NULL, &dstRect);
|
||||
|
||||
SDL_FreeSurface(ttlStorage.textSurface);
|
||||
SDL_DestroyTexture(ttlStorage.textTexture);
|
||||
}
|
||||
|
||||
|
||||
// rendering columns description
|
||||
for (int i = 0; i < NUM_COLUMNS; ++i) {
|
||||
ttlStorage.textSurface = TTF_RenderText_Solid(ttlStorage.ptrFont_30, columnDescriptions[i], ttlStorage.textColour[5]);
|
||||
@ -565,6 +586,7 @@ void renderLeaderboard()
|
||||
SDL_DestroyTexture(numberTexture2);
|
||||
}
|
||||
SDL_RenderPresent(game.renderer);
|
||||
ttlStorage.lastTimeStep = GET_TIME_MS();
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user