Skip to content

Commit

Permalink
Fixed issue with stats resetting on continue / start
Browse files Browse the repository at this point in the history
  • Loading branch information
levidsmith committed Jan 7, 2020
1 parent 6775fe5 commit 6ddc4d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
21 changes: 14 additions & 7 deletions screen_game.c
Expand Up @@ -117,6 +117,15 @@ void start_screen_game() {
clear_list(&listPowerup);
clear_list(&listExplosion);

if (!iGameContinue) {
timeStartGame = SDL_GetTicks();
timeElapsed = 0;
iCurrentLevel = 0;

}



if (ship == NULL) {
ship = malloc(sizeof(struct Ship));
}
Expand Down Expand Up @@ -157,11 +166,6 @@ void start_screen_game() {
// printf("Initialize time\n");
// time(&timeStartGame);
// }
if (!iGameContinue) {
timeStartGame = SDL_GetTicks();
timeElapsed = 0;

}

timeCurrent = SDL_GetTicks();
timePrevious = SDL_GetTicks();
Expand Down Expand Up @@ -968,6 +972,7 @@ void handleInput_screen_game(int iType, int iKey) {

if (iWorldComplete) {
if (fKeyPressDelay <= 0) {
iCurrentWorld = -1;
iCurrentLevel = 0;
setCurrentScreen(2);
}
Expand All @@ -980,8 +985,10 @@ void handleInput_screen_game(int iType, int iKey) {

}
} else if (iKey == SDLK_q || iKey == SDLK_ESCAPE) {
iTitleMenuChoice = 1;
setCurrentScreen(0);
if (fKeyPressDelay <= 0 && !iGameOver && !iWorldComplete) {
iTitleMenuChoice = 1;
setCurrentScreen(0);
}
} else if (iKey == SDLK_m) {
Mix_VolumeMusic(0);
} else if (iKey == SDLK_TAB) {
Expand Down
9 changes: 8 additions & 1 deletion screen_title.c
Expand Up @@ -31,6 +31,8 @@ extern Mix_Music *musicTitle;
int iBackgroundOffsetTitle;
SDL_Rect posTitle;
int iTitleMenuChoice = 0;
extern int iResetStats;
extern int iCurrentWorld;
int iGameContinue;
int iCanContinue = FALSE;

Expand Down Expand Up @@ -127,10 +129,15 @@ void handleInput_screen_title(int iType, int iKey) {
if (iKey == SDLK_SPACE) {
if (iTitleMenuChoice == 0) {
iGameContinue = FALSE;
iResetStats = TRUE;
setCurrentScreen(2);
} else if (iTitleMenuChoice == 1) {
iGameContinue = TRUE;
setCurrentScreen(1);
if (iCurrentWorld == -1) {
setCurrentScreen(2);
} else {
setCurrentScreen(1);
}
} else if (iTitleMenuChoice == 2) {
quit();
}
Expand Down
9 changes: 9 additions & 0 deletions screen_world_select.c
Expand Up @@ -24,10 +24,13 @@ extern TTF_Font *fontLarge;
extern SDL_Texture *imgBackground[NUM_WORLDS * 2];
extern SDL_Texture *imgWorldSelectWorldText[NUM_WORLDS];
extern int iCurrentWorld;
extern int iGameContinue;
extern struct Stats *stats;



int iWorldSelectChoice = 0;
int iResetStats = FALSE;
char *strWorldNames[NUM_WORLDS] = { "Celeritas", "Multa", "Fluctus", "Crepitus", "Gelida", "Torqueo", "Quaerere", "Spatium" };
int iBackgroundOffsetWorldSelect;

Expand All @@ -36,10 +39,15 @@ int iBackgroundOffsetWorldSelect;

void start_screen_world_select() {

printf("iResetStats: %d\n", iResetStats);

if (stats == NULL) {
stats = malloc(sizeof(struct Stats));
init_stats(stats);
} else if (iResetStats) {
init_stats(stats);
}
iResetStats = FALSE;

SDL_Color colorText = {0, 0, 255, 0};
SDL_Surface *sprText;
Expand All @@ -58,6 +66,7 @@ void start_screen_world_select() {
}



void update_screen_world_select() {
SDL_Surface *sprText;
SDL_Color colorText;
Expand Down

0 comments on commit 6ddc4d6

Please sign in to comment.