Skip to content

Commit

Permalink
Can go to main screen from any screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kliao2016 committed Nov 13, 2017
1 parent ad555e7 commit b5bd541
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
Binary file modified BrickBreaker.elf
Binary file not shown.
Binary file modified BrickBreaker.gba
Binary file not shown.
4 changes: 2 additions & 2 deletions game.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ void handleBrickCollisions(Brick *brptr, Ball *ballptr, int *numBricks, int bric
*(numBricks) -= 1;
cur->isHit = 1;
ballptr->xDir *= -1;
ballptr->col += (ballptr->xDir * 5);
ballptr->col = ballptr->col + (ballptr->xDir * 5);
} else if ((((ballptr->row + BALLSIZE) == brptr->row)
|| (ballptr->row == (brptr->row + BRICKHEIGHT)))
&& ((ballptr->col >= (cur->col - BALLSIZE))
&& (ballptr->col <= (cur->col + BRICKWIDTH)))) {
*(numBricks) -= 1;
cur->isHit = 1;
ballptr->yDir *= -1;
ballptr->row += (ballptr->yDir * 5);
ballptr->row = ballptr->row + (ballptr->yDir * 5);
}
drawRect(cur->row, cur->col, BRICKHEIGHT, BRICKWIDTH, cur->color);
}
Expand Down
28 changes: 23 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ int bricksSize;
int level = INITIAL_LEVEL;
int lives = INITIAL_LIVES;
char textBuffer[75];
int enterPressed = 0;
int zPressed = 0;
int backPressed = 0;

int main() {
// Enable GBA Mode3
REG_DISPCTL = MODE3 | BG2_ENABLE;

int enterPressed = 0;
int aPressed = 0;

// Game Loop
while(1) {
waitForVblank();
Expand Down Expand Up @@ -64,6 +64,7 @@ int main() {
state = WIN_GAME;
}
}
backToMain();
break;

case NEXT_LEVEL:
Expand All @@ -76,6 +77,7 @@ int main() {
state = LEVEL;
enterPressed = 1;
}
backToMain();
break;

case LOSE_LIFE:
Expand All @@ -84,10 +86,11 @@ int main() {
break;

case LOSE_LIFE_NO_DRAW:
if (!aPressed && KEY_DOWN_NOW(BUTTON_A)) {
if (!zPressed && KEY_DOWN_NOW(BUTTON_A)) {
state = LEVEL;
enterPressed = 1;
}
backToMain();
break;

case GAME_OVER:
Expand All @@ -100,6 +103,7 @@ int main() {
state = START;
enterPressed = 1;
}
backToMain();
break;

case WIN_GAME:
Expand All @@ -112,14 +116,18 @@ int main() {
resetGame();
enterPressed = 1;
}
backToMain();
break;
}

if (!KEY_DOWN_NOW(BUTTON_START)) {
enterPressed = 0;
}
if (!KEY_DOWN_NOW(BUTTON_A)) {
aPressed = 0;
zPressed = 0;
}
if (!KEY_DOWN_NOW(BUTTON_SELECT)) {
backPressed = 0;
}
}

Expand Down Expand Up @@ -211,3 +219,13 @@ void updateScreenText() {
sprintf(textBuffer, "LIVES: %d", lives);
drawString3(SCREENHEIGHT - 10, SCREENWIDTH - sizeof(textBuffer) + 20, textBuffer, GREEN);
}

/**
* Function to go back to start screen
*/
void backToMain() {
if (!backPressed && KEY_DOWN_NOW(BUTTON_SELECT)) {
state = START;
backPressed = 1;
}
}
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ void gameWon();
void resetGame();
void setUpNextLevel();
void updateScreenText();
void backToMain();
Binary file modified main.o
Binary file not shown.

0 comments on commit b5bd541

Please sign in to comment.