borgware-2d/games/breakout/level.c

88 lines
1.8 KiB
C
Raw Normal View History

#include "level.h"
2010-01-21 13:40:40 +00:00
static uint16_t maxscore;
/* real level definition */
2010-01-15 16:02:31 +00:00
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)
{
2010-01-21 13:40:40 +00:00
case 0:
/* space for the lower half of the level */
if (in_y > (NUM_ROWS / 3))
return sp;
return b1; /* b1-blocks for the rest */
case 1:
/* space for the lower half of the level */
2010-01-19 09:55:28 +00:00
if (in_y > (NUM_ROWS / 2))
return sp;
/* type 2 bricks for 1/4th of the field */
2010-01-19 09:55:28 +00:00
if (in_y <= (NUM_ROWS / 4))
return b2;
/* fill the rest with type 1 */
return b1;
break;
case 3:
/* add a row of solid bricks right in the middle of the field */
if (in_y == (NUM_ROWS / 2) &&
2010-01-15 14:42:46 +00:00
(in_x > (NUM_COLS / 4)) && (in_x < (NUM_COLS - (NUM_COLS / 4))))
return bs;
/* intentional fallthrough: the rest of level 3 is like level 2 */
case 2:
/* space for the lower third of the level */
2010-01-19 09:55:28 +00:00
if (in_y > (NUM_ROWS / 3))
return sp;
/* type 3 bricks for 1/8th of the field */
2010-01-19 09:55:28 +00:00
if (in_y <= (NUM_ROWS / 8))
return b3;
/* type 2 bricks for 1/4th of the field */
2010-01-19 09:55:28 +00:00
if (in_y <= (NUM_ROWS / 4))
return b2;
/* fill the rest with type 1 */
return b1;
default: /* random level generation */
/* space for the lower half of the level */
2010-01-19 09:55:28 +00:00
if (in_y > (NUM_ROWS / 2))
return sp;
2010-01-19 19:44:16 +00:00
return random8() & 0x03; /* fill field with random bricks (and spaces) */
break;
}
}
void level_init (uint8_t in_levelnum)
{
uint8_t x,y;
2010-01-21 13:40:40 +00:00
enum game_field_t tmp;
maxscore = 0;
for (x=0;x<NUM_COLS;x++)
{
for (y=0;y<NUM_ROWS;y++)
{
2010-01-21 13:40:40 +00:00
tmp = level_field (x, y, in_levelnum);
playfield_set (x,y, tmp);
if (tmp <= b3)
maxscore += tmp;
}
}
2010-01-21 13:40:40 +00:00
maxscore += score_get();
}
2010-01-21 13:40:40 +00:00
uint16_t level_getscorediff ()
{
return maxscore - score_get();
}