Skip to content

Commit

Permalink
Add handling for completing last level in world
Browse files Browse the repository at this point in the history
  • Loading branch information
CJLove committed Feb 29, 2020
1 parent cd27e89 commit e7a8470
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/levels.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ static const uint8_t gameOverTiles[3][11] = {
{ 103, 100, 100, 100, 100, 100, 100, 100, 100, 100, 104 }
};

// Tiles for "WORLD COMPLETE"
static const uint8_t worldCompleteTiles[3][16] = {
{ 101, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 102 },
{ 99, 23, 15, 18, 12, 4, 32, 3, 15, 13, 16, 12, 5, 20, 5, 99 },
{ 103, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 104 }
};

void completeLevel()
{
uint8_t row = 0;
Expand Down Expand Up @@ -323,4 +330,16 @@ void gameOver()
setTile(9+i,9,gameOverTiles[2][i],0);
}
sleep(5);
}

void worldComplete()
{
uint8_t i = 0;
// Disable sprites
vpoke(0x00, 0x1f4000);
for (i = 0; i < 16; i++) {
setTile(6+i,7,worldCompleteTiles[0][i],0);
setTile(6+i,8,worldCompleteTiles[1][i],0);
setTile(6+i,9,worldCompleteTiles[2][i],0);
}
}
4 changes: 3 additions & 1 deletion src/levels.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ extern uint8_t level;

extern uint8_t godMode;

extern void gameOver(void);
extern void gameOver(void);

extern void worldComplete(void);
17 changes: 10 additions & 7 deletions src/mainloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ void mainTick()
playGame();
break;
case GAME_NEW_LEVEL:
loadLevel(world,level);
displayLevel(level-1);
// Enable sprites
vpoke(0x01, 0x1f4000);
gameState = GAME_RUNNING;
if (loadLevel(world,level)) {
displayLevel(level-1);
// Enable sprites
vpoke(0x01, 0x1f4000);
gameState = GAME_RUNNING;
} else {
worldComplete();
gameState = GAME_OVER;
}
break;
case GAME_FINISH:
// Disable sprites
vpoke(0x0, 0x1f4000);
// Increase score for level completion
scoreCount = 0;
// displayScore(SCORE_COMPLETE_LEVEL);

gameState = GAME_FINISH_SCORE_COUNT;
break;
Expand Down Expand Up @@ -86,7 +89,7 @@ void mainTick()
}
break;
case GAME_OVER:
// Keep "Game Over" displayed for 5 seconds then go back to splash
// Keep "Game Over" or "WORLD COMPLETE" displayed for 5 seconds then go back to splash
sleep(5);
gameState = GAME_SPLASH;
break;
Expand Down

0 comments on commit e7a8470

Please sign in to comment.