Skip to content

Commit

Permalink
Added slider image
Browse files Browse the repository at this point in the history
  • Loading branch information
kliao2016 committed Nov 13, 2017
1 parent b2451a9 commit 8079eda
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 18 deletions.
Binary file modified BrickBreaker.elf
Binary file not shown.
Binary file modified BrickBreaker.gba
Binary file not shown.
17 changes: 9 additions & 8 deletions game.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include <stdlib.h>
#include "myLib.h"
#include "game.h"
#include "graphics.h"

/**
* Function to draw the slider on every screen
*
* @param sldptr the pointer to the slider to be drawn
*/
void drawSlider(Slider *sldptr) {
sldptr->height = SLIDERHEIGHT;
sldptr->width = SLIDERWIDTH;
sldptr->height = SLIDER_HEIGHT;
sldptr->width = SLIDER_WIDTH;
sldptr->row = SCREENHEIGHT - 15 - sldptr->height;
sldptr->col = (SCREENWIDTH / 2) - 1 - (sldptr->width / 2);
sldptr->oldRow = sldptr->row;
sldptr->oldCol = sldptr->col;
drawRect(sldptr->row, sldptr->col, sldptr->height, sldptr->width, YELLOW);
drawImage3(sldptr->row, sldptr->col, sldptr->height, sldptr->width, slider_image);
}

/**
Expand All @@ -40,7 +41,7 @@ void enableSlider(Slider *sldptr) {
if (sldptr->col + width > SCREENWIDTH) {
sldptr->col = SCREENWIDTH - width;
}
drawRect(sldptr->row, sldptr->col, height, width, YELLOW);
drawImage3(sldptr->row, sldptr->col, sldptr->height, sldptr->width, slider_image);
}

if (KEY_DOWN_NOW(BUTTON_LEFT)) {
Expand All @@ -56,7 +57,7 @@ void enableSlider(Slider *sldptr) {
if (sldptr->col < 0) {
sldptr->col = 0;
}
drawRect(sldptr->row, sldptr->col, height, width, YELLOW);
drawImage3(sldptr->row, sldptr->col, sldptr->height, sldptr->width, slider_image);
}
}

Expand Down Expand Up @@ -128,11 +129,11 @@ void handleCollisions(Ball *ballptr, Slider *sldptr) {
// Collision resolution for when bottom of ball hits top of slider
if ((ballptr->row + BALLSIZE) > sldptr->row
&& ballptr->col >= (sldptr->col - BALLSIZE)
&& ballptr->col <= (sldptr->col + SLIDERWIDTH)) {
&& ballptr->col <= (sldptr->col + SLIDER_WIDTH)) {
ballptr->row = sldptr->row - BALLSIZE;
ballptr->yDir *= -1;
ballptr->xDir = (rand() % 2 + 1) * ballptr->xDir / abs(ballptr->xDir);
ballptr->yDir = (rand() % 2 + 1) * ballptr->yDir / abs(ballptr->yDir);
// ballptr->xDir = (rand() % 2 + 1) * ballptr->xDir / abs(ballptr->xDir);
// ballptr->yDir = (rand() % 2 + 1) * ballptr->yDir / abs(ballptr->yDir);
}

}
Expand Down
Binary file modified game.o
Binary file not shown.
20 changes: 18 additions & 2 deletions graphics.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* 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
*/

Expand Down Expand Up @@ -2415,3 +2415,19 @@ const unsigned short start_screen[38400] =
0x0da5,0x0da5,0x0da5,0x0da5,0x11a5,0x11a5,0x0da5,0x0984,0x0984,0x0984,0x0d84,0x0da5,0x0da5,0x0d84,0x0d84,0x0d84
};

const unsigned short slider_image[200] =
{
0x04e9,0x1555,0x0d58,0x1178,0x1554,0x4a97,0x6716,0x72f8,0x5f17,0x5f17,0x5f17,0x5f17,0x5f17,0x5f17,0x5f17,0x5f17,
0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,0x5ef7,
0x6b17,0x66f6,0x4e78,0x1515,0x0978,0x0978,0x1155,0x08ca,0x1192,0x1dfd,0x15df,0x15fd,0x1dfa,0x575e,0x6ffd,0x73bd,
0x77dd,0x77dd,0x77dd,0x77dd,0x77dd,0x77dd,0x77dd,0x77dd,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,
0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x7bde,0x6fdd,0x6ffe,0x573f,0x1ddb,0x11fd,0x11ff,0x1e1e,0x1594,
0x0cd0,0x1d3a,0x151a,0x1117,0x1d36,0x52bb,0x677a,0x6319,0x6759,0x6759,0x6759,0x6759,0x6759,0x6759,0x6759,0x6759,
0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,0x6b59,
0x633a,0x677a,0x529b,0x1916,0x0cf7,0x111a,0x193a,0x10d1,0x144b,0x1c92,0x1872,0x1870,0x208f,0x45d3,0x5672,0x4e32,
0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,
0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4a52,0x4e32,0x5672,0x45b3,0x1c6f,0x1450,0x1872,0x1c92,0x146b,
0x0c85,0x108b,0x108b,0x0c8a,0x1069,0x252b,0x31aa,0x298b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,
0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,0x318b,
0x2d8b,0x2daa,0x252b,0x106a,0x108a,0x10ac,0x10ab,0x08a5
};
13 changes: 10 additions & 3 deletions graphics.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
/*
* 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

// Startscreen image
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
// Slider image
extern const unsigned short slider_image[200];
#define SLIDER_SIZE 400
#define SLIDER_LENGTH 200
#define SLIDER_WIDTH 40
#define SLIDER_HEIGHT 5

#endif
Binary file modified graphics.o
Binary file not shown.
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main() {

case LEVEL_NODRAW:
// Collision resolution for when ball hits bottom of screen
if (ballptr->row + BALLSIZE >= sldptr->row + SLIDERHEIGHT) {
if (ballptr->row + BALLSIZE >= sldptr->row + SLIDER_HEIGHT) {
lives -= 1;
if (lives > 0) {
state = LOSE_LIFE;
Expand Down Expand Up @@ -151,7 +151,7 @@ void setGameStage() {
fillScreen(BGCOLOR);
updateScreenText();
drawSlider(sldptr);
createBall(sldptr->row - 5, sldptr->col + (SLIDERWIDTH / 2), BALLSIZE, ballptr);
createBall(sldptr->row - 5, sldptr->col + (SLIDER_WIDTH / 2), BALLSIZE, ballptr);
numBricks = level * 3;
bricksSize = level * 3;
generateBricks(brptr, bricksSize);
Expand Down
Binary file modified main.o
Binary file not shown.
3 changes: 0 additions & 3 deletions myLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ typedef unsigned short u16;

#define SCREENHEIGHT 160
#define SCREENWIDTH 240
#define SLIDERHEIGHT 5
#define SLIDERWIDTH 45
#define BRICKHEIGHT 10
#define BRICKWIDTH 30
#define BALLSIZE 5
Expand Down Expand Up @@ -89,7 +87,6 @@ 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 slider.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 8079eda

Please sign in to comment.