Browse Source

foo

feature/2015
soeren 15 years ago
parent
commit
49ab4eecc2
  1. 5
      games/breakout/ball.h
  2. 14
      games/breakout/breakout.c
  3. 5
      games/breakout/common.h
  4. 6
      games/breakout/config.h
  5. 2
      games/breakout/level.c
  6. 12
      games/breakout/playfield.c
  7. 9
      games/breakout/playfield.h
  8. 2
      games/breakout/score.h

5
games/breakout/ball.h

@ -27,9 +27,6 @@ void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x
*/ */
void ball_think (ball_t *in_ball); void ball_think (ball_t *in_ball);
/* @description Change the ball's moving vector according to bounce and collision type
*/
void ball_bounce (ball_t *in_ball, enum collision_t in_coltype);
void ball_die (ball_t *in_b) void ball_die (ball_t *in_b);
#endif /* BALL_H */ #endif /* BALL_H */

14
games/breakout/breakout.c

@ -1,13 +1,13 @@
#include "common.h"
#include "../../menu/menu.h" void borg_breakout();
#ifdef MENU_SUPPORT #ifdef MENU_SUPPORT
static uint8_t icon[8] PROGMEM = const uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
{0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
game_descriptor_t invaders_game_descriptor __attribute__((section(".game_descriptors"))) ={ game_descriptor_t breakout_game_descriptor __attribute__((section(".game_descriptors"))) =
{
&borg_breakout, &borg_breakout,
icon, breakout_icon,
}; };
#endif #endif
@ -17,6 +17,7 @@ void borg_breakout()
ball_t balls[1]; ball_t balls[1];
ball_init (balls[0]); ball_init (balls[0]);
rebound_init();
/* spawn a ball in the middle bottom of the field, let it move upwards with random speed & x-direction */ /* spawn a ball in the middle bottom of the field, let it move upwards with random speed & x-direction */
ball_spawn (balls[0], (NUM_COLS / 2) << 8, (NUM_ROWS-2) << 8, - random8(), random8(), START_LIFES); ball_spawn (balls[0], (NUM_COLS / 2) << 8, (NUM_ROWS-2) << 8, - random8(), random8(), START_LIFES);
@ -24,6 +25,7 @@ void borg_breakout()
while (rungame) while (rungame)
{ {
rebound_tick();
ball_think(balls[0]); ball_think(balls[0]);
playfield_draw(); playfield_draw();
ball_draw(balls[0]); ball_draw(balls[0]);

5
games/breakout/common.h

@ -2,11 +2,16 @@
#define COMMON_H #define COMMON_H
#include <stdint.h> #include <stdint.h>
#include "../../config.h" #include "../../config.h"
#include "../../autoconf.h"
#include "../../compat/eeprom.h"
#include "../../random/prng.h" #include "../../random/prng.h"
#include "../../menu/menu.h"
#include "../../compat/pgmspace.h"
#include "../../pixel.h" #include "../../pixel.h"
#include "config.h" #include "config.h"
#include "playfield.h" #include "playfield.h"
#include "ball.h" #include "ball.h"
#include "score.h" #include "score.h"
#include "level.h" #include "level.h"
#include "rebound.h"
#endif /* COMMON_H */ #endif /* COMMON_H */

6
games/breakout/config.h

@ -6,3 +6,9 @@
/* initial amount of lifes */ /* initial amount of lifes */
#define START_LIFES 3 #define START_LIFES 3
/* rebound size */
#define REBOUND_SIZE 5
/* "color" of the rebound */
#define REBOUND_COLOR 2

2
games/breakout/level.c

@ -21,7 +21,7 @@ inline void level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
case 3: case 3:
/* add a row of solid bricks right in the middle of the field */ /* add a row of solid bricks right in the middle of the field */
if (in_y == (NUM_ROWS / 2) && if (in_y == (NUM_ROWS / 2) &&
(in_x > (NUM_COLS / 4) && in_x < (NUM_COLS - (NUM_COLS / 4))) (in_x > (NUM_COLS / 4)) && (in_x < (NUM_COLS - (NUM_COLS / 4))))
return bs; return bs;
/* intentional fallthrough: the rest of level 3 is like level 2 */ /* intentional fallthrough: the rest of level 3 is like level 2 */

12
games/breakout/playfield.c

@ -44,26 +44,26 @@ uint8_t check_bounce (uint8_t in_x, uint8_t in_y)
/* this is the actual draw function for a single field /* this is the actual draw function for a single field
*/ */
static inline void draw_single_field (game_field_t in_f) static inline void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f)
{ {
switch (in_f) switch (in_f)
{ {
case b1: case b1:
setPixel (); setPixel (in_x, in_y, 1);
return; return;
case rb: case rb:
case b2: case b2:
setPixel (in_x, in_y, 2);
return; return;
case b3: case b3:
case bl: case bl:
case bs: case bs:
setPixel (in_x, in_y, 3);
return; return;
default: /* this includes freespace */ default: /* this includes freespace */
setPixel (in_x, in_y, 0);
return; return;
} }
@ -77,7 +77,7 @@ void playfield_draw ()
{ {
for (y=0;y<NUM_COLS;y++) for (y=0;y<NUM_COLS;y++)
{ {
draw_single_field (x,y, playfield[x][y]);
} }
} }
} }

9
games/breakout/playfield.h

@ -1,18 +1,15 @@
#include <stdint.h>
#include "ball.h"
#include "score.h"
#ifndef PLAYFIELD_H #ifndef PLAYFIELD_H
#define PLAYFIELD_H #define PLAYFIELD_H
#include "common.h"
/* entries for the playing field */ /* entries for the playing field */
enum game_field_t enum game_field_t
{ {
sp = 0, /* space */ sp = 0, /* space */
b1 = 1, b2 = 2, b3 = 3, /* bricks */ b1 = 1, b2 = 2, b3 = 3, /* bricks */
bs = 4 /* solid (unbreakable) brick */ bs = 4, /* solid (unbreakable) brick */
bl, /* ball */ bl, /* ball */
rb, /* rebound */ rb /* rebound */
}; };

2
games/breakout/score.h

@ -6,7 +6,7 @@
static uint16_t score = 0; static uint16_t score = 0;
void score_add(uint8_t); void score_add(uint8_t);
score_add (uint8_t in_score) void score_add (uint8_t in_score)
{ {
score += in_score; score += in_score;
} }

Loading…
Cancel
Save