Browse Source

...

feature/2015
soeren 15 years ago
parent
commit
731e6dadcb
  1. 31
      games/breakout/ball.c
  2. 11
      games/breakout/ball.h
  3. 14
      games/breakout/breakout.c
  4. 4
      games/breakout/common.h
  5. 3
      games/breakout/level.c
  6. 2
      games/breakout/level.h
  7. 34
      games/breakout/playfield.c
  8. 5
      games/breakout/score.h

31
games/breakout/ball.c

@ -8,15 +8,18 @@ void ball_think (ball_t *b)
new_x = (b->x + b->dir_x) >> 8;
new_y = (b->y + b->dir_y) >> 8;
printf("B: %i %i, d: %i %i\n", new_x, new_y);
/* ball fell out of the field */
if (new_y >= NUM_ROWS)
ball_die (b);
// if (new_y >= NUM_ROWS)
// ball_die (b);
/* bounce in x direction */
if (check_bounce (new_x, b->y >> 8))
{
b->dir_x *= -1; /* invert x vector */
new_x += b->dir_x;
#if BOUNCE_SLOWDOWN
if (b->dir_x < 0)
@ -30,9 +33,10 @@ void ball_think (ball_t *b)
}
/* bounce in y direction */
if (check_bounce (b->x >> 8), new_y)
if (check_bounce ((b->x >> 8), new_y))
{
b->dir_y *= -1; /* invert y vector */
new_y += b->dir_y;
#if BOUNCE_SLOWDOWN
if (b->dir_y < 0)
@ -44,6 +48,9 @@ void ball_think (ball_t *b)
}
#endif
}
b->x = new_x;
b->y = new_y;
}
void ball_die (ball_t *in_b)
@ -54,3 +61,21 @@ void ball_die (ball_t *in_b)
if (in_b->strength)
ball_spawn (in_b, (NUM_COLS / 2) << 8, (NUM_ROWS-2) << 8, - random8(), random8(), START_LIFES);
}
void ball_draw (ball_t *b)
{
pixel p;
p.x = b->x;
p.y = b->y;
setpixel (p, 3);
}
void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y, uint8_t in_strength)
{
in_ball->x = in_x;
in_ball->y = in_y;
in_ball->dir_x = in_dir_x;
in_ball->dir_y = in_dir_y;
in_ball->strength = in_strength;
}

11
games/breakout/ball.h

@ -14,14 +14,7 @@ typedef struct
uint8_t strength;
} ball_t;
void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y, uint8_t in_strength)
{
in_ball->x = in_x;
in_ball->y = in_y;
in_ball->dir_x = in_dir_x;
in_ball->dir_y = in_dir_y;
in_ball->strength = in_strength;
}
void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y, uint8_t in_strength);
/* @description Called once per game tick. Move the ball further along it's vector.
*/
@ -29,4 +22,6 @@ void ball_think (ball_t *in_ball);
void ball_die (ball_t *in_b);
void ball_draw (ball_t *);
#endif /* BALL_H */

14
games/breakout/breakout.c

@ -1,13 +1,15 @@
#include <stdint.h>
#include "common.h"
void borg_breakout();
#ifdef MENU_SUPPORT
const uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
//static uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
static uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
game_descriptor_t breakout_game_descriptor __attribute__((section(".game_descriptors"))) =
{
&borg_breakout,
breakout_icon,
breakout_icon
};
#endif
@ -16,18 +18,18 @@ void borg_breakout()
uint8_t rungame = 1, num_balls = 1;
ball_t balls[1];
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 */
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() % 8), (random8() % 8), START_LIFES);
level_init(1);
while (rungame)
{
wait(50);
rebound_tick();
ball_think(balls[0]);
ball_think(&balls[0]);
playfield_draw();
ball_draw(balls[0]);
ball_draw(&balls[0]);
}
}

4
games/breakout/common.h

@ -1,12 +1,14 @@
#ifndef COMMON_H
#define COMMON_H
#include <stdint.h>
#include "../../joystick/joystick.h"
#include "../../config.h"
#include "../../autoconf.h"
#include "../../compat/eeprom.h"
#include "../../random/prng.h"
#include "../../menu/menu.h"
#include "../../compat/pgmspace.h"
#include "../../util.h"
#include "../../menu/menu.h"
#include "../../pixel.h"
#include "config.h"
#include "playfield.h"

3
games/breakout/level.c

@ -1,7 +1,8 @@
#include "level.h"
/* real level definition */
inline void level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl);
enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
{
switch (in_lvl)
{

2
games/breakout/level.h

@ -1,5 +1,5 @@
#ifndef LEVEL_H
#define LEVEL_H
#include "common.h"
void level_init (uint8_t in_levelnum)
void level_init (uint8_t in_levelnum);
#endif /* LEVEL_H */

34
games/breakout/playfield.c

@ -1,8 +1,14 @@
#include "common.h"
static enum game_field_t playfield[NUM_COLS][NUM_ROWS];
uint8_t brick_damage (uint8_t in_x, uint8_t in_y)
void playfield_set (uint8_t in_x, uint8_t in_y, enum game_field_t in_field)
{
game_field_t newtype;
playfield[in_x][in_y] = in_field;
}
void brick_damage (uint8_t in_x, uint8_t in_y)
{
enum game_field_t newtype;
if (playfield[in_x][in_y] > bs || playfield[in_x][in_y] == 0)
return;
@ -44,29 +50,35 @@ uint8_t check_bounce (uint8_t in_x, uint8_t in_y)
/* this is the actual draw function for a single field
*/
static inline void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f)
static inline void draw_single_field (uint8_t in_x, uint8_t in_y, enum game_field_t in_f)
{
pixel tmp;
uint8_t b;
switch (in_f)
{
case b1:
setPixel (in_x, in_y, 1);
return;
b = 1;
break;
case rb:
case b2:
setPixel (in_x, in_y, 2);
return;
b = 2;
break;
case b3:
case bl:
case bs:
setPixel (in_x, in_y, 3);
return;
b = 3;
break;
default: /* this includes freespace */
setPixel (in_x, in_y, 0);
return;
b = 0;
break;
}
tmp.x = in_x;
tmp.y = in_y;
setpixel (tmp, b);
}
void playfield_draw ()

5
games/breakout/score.h

@ -3,11 +3,6 @@
#ifndef SCORE_H
#define SCORE_H
static uint16_t score = 0;
void score_add(uint8_t);
void score_add (uint8_t in_score)
{
score += in_score;
}
#endif

Loading…
Cancel
Save