Skip to content

Commit

Permalink
Added brick system
Browse files Browse the repository at this point in the history
  • Loading branch information
kliao2016 committed Nov 12, 2017
1 parent 6aa913b commit 1ba47e3
Show file tree
Hide file tree
Showing 14 changed files with 2,516 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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ PROGNAME = BrickBreaker
# that will be compiled into your program. For example
# if you have main.c and myLib.c then in the following
# line you would put main.o and myLib.o
OFILES = main.o myLib.o font.o game.o
OFILES = main.o myLib.o font.o game.o graphics.o

# The header files you have created.
# This is necessary to determine when to recompile for files.
# This should be a space (SPACE!) separated list of .h files
HFILES = game.h myLib.h
HFILES = game.h myLib.h graphics.h

################################################################################
# These are various settings used to make the GBA toolchain work
Expand Down
33 changes: 33 additions & 0 deletions game.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,37 @@ void handleCollisions(Ball *ballptr, Slider *sldptr) {
ballptr->row = sldptr->row - ballptr->size;
ballptr->yDir *= -1;
}

}

/**
* Function to generate bricks on the level
*
* @param bricks the list of bricks to generate
*/
void generateBricks(int numBricks) {
u16 colors[] = {RED, GREEN, BLUE, YELLOW, WHITE};
int numcolors = sizeof(colors)/sizeof(colors[0]);
Brick brick;
Brick *brptr = &brick;
int row = 30;
int col = 45;

for (int i = 0; i < numBricks; i++) {
u16 color = colors[i % numcolors];
brptr->row = row;
brptr->col = col;
brptr->height = 10;
brptr->width = 30;
brptr->color = color;
if ((i + 1) % 3 == 0) {
row += brptr->height;
}
drawRect(brptr->row, brptr->col,
brptr->height,
brptr->width,
color);
col = col + 30 + (brptr->width);

}
}
10 changes: 6 additions & 4 deletions game.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Game Structs */
typedef struct {
const int height;
const int width;
int height;
int width;
int row;
int col;
unsigned short color;
Expand All @@ -12,7 +12,9 @@ typedef enum {
START,
START_NODRAW,
LEVEL1,
LEVEL1_NODRAW
LEVEL1_NODRAW,
GAME_OVER,
GAME_OVER_NO_DRAW

} GAMEState;

Expand Down Expand Up @@ -44,4 +46,4 @@ void enableSlider(Slider *sldptr);
void createBall(int row, int col, int size, Ball *ballptr);
void startLevel(Ball *ballptr, Slider *sldptr);
void handleCollisions(Ball *ballptr, Slider *sldptr);
void generateBricks();
void generateBricks(int numBricks);
Binary file modified game.o
Binary file not shown.
2,417 changes: 2,417 additions & 0 deletions graphics.c

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions graphics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Exported with nin10kit v1.7
* Time-stamp: Saturday 11/11/2017, 23:33:50
*
* Image Information
* -----------------
* /home/kevinliao/Dropbox/cs2110/hw9/brick_breaker/start_screen.jpg 240@160
*
* All bug reports / feature requests are to be filed here https://github.com/TricksterGuy/nin10kit/issues
*/

#ifndef GRAPHICS_H
#define GRAPHICS_H

extern const unsigned short start_screen[38400];
#define START_SCREEN_SIZE 76800
#define START_SCREEN_LENGTH 38400
#define START_SCREEN_WIDTH 240
#define START_SCREEN_HEIGHT 160

#endif

Binary file added graphics.o
Binary file not shown.
34 changes: 33 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include "myLib.h"
#include "game.h"
#include "graphics.h"

int main() {
// Enable GBA Mode3
Expand All @@ -11,6 +12,8 @@ int main() {
Slider *sldptr = &slider;
Ball ball;
Ball *ballptr = &ball;
int level;
//int lives = 3;

int enterPressed = 0;

Expand All @@ -19,7 +22,6 @@ int main() {
waitForVblank();
switch (state) {
case START:
drawString3(79, 50, "Press ENTER to Start Game", YELLOW);
state = START_NODRAW;
break;

Expand All @@ -31,14 +33,35 @@ int main() {
break;

case LEVEL1:
level = 1;
drawSlider(sldptr);
createBall(sldptr->row - 5, sldptr->col + (sldptr->width / 2), 5, ballptr);
generateBricks(level * 3);
drawString3(5, 5, "Level 1", GREEN);
state = LEVEL1_NODRAW;
break;

case LEVEL1_NODRAW:
enableSlider(sldptr);
startLevel(ballptr, sldptr);

// Collision resolution for when ball hits bottom of screen
if ((ballptr->row + ballptr->size) > 160) {
state = GAME_OVER;
}
break;

case GAME_OVER:
fillScreen(BLACK);
drawString3(79, 90, "GAME OVER", YELLOW);
state = GAME_OVER_NO_DRAW;
break;

case GAME_OVER_NO_DRAW:
if (!enterPressed && KEY_DOWN_NOW(BUTTON_START)) {
state = START;
enterPressed = 1;
}
break;
}

Expand All @@ -50,3 +73,12 @@ int main() {
return 0;

}

/**
* Function to setup the start screen
*/
void startScreen() {
fillScreen(BLACK);
drawImage3(0, 0, START_SCREEN_HEIGHT, START_SCREEN_WIDTH, start_screen);
drawString3(105, 50, "Press ENTER to Start Game", YELLOW);
}
2 changes: 2 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Prototypes */
void startScreen();
Binary file modified main.o
Binary file not shown.
1 change: 1 addition & 0 deletions myLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct

extern unsigned short *videoBuffer;
extern const unsigned char fontdata_6x8[12288];
extern const unsigned short start_screen[38400];

/* Prototypes */
void setPixel(int row, int col, unsigned short color);
Expand Down
Binary file added start_screen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1ba47e3

Please sign in to comment.