2010-12-20 22:51:25 +00:00
|
|
|
#include <stdint.h>
|
2011-02-25 07:47:42 +00:00
|
|
|
#include <string.h>
|
2010-12-20 22:51:25 +00:00
|
|
|
#include "../../compat/pgmspace.h"
|
2008-12-03 05:40:16 +00:00
|
|
|
#include "invaders2.h"
|
|
|
|
|
2011-02-25 07:47:42 +00:00
|
|
|
uint16_t const peter[8] PROGMEM =
|
|
|
|
{0x0104, 0x0088, 0x01FC, 0x0376, 0x07FF, 0x05FD, 0x0505, 0x00D8};
|
|
|
|
|
|
|
|
uint16_t const hans[7] PROGMEM =
|
|
|
|
{0x0000, 0x0372, 0x0552, 0x0372, 0x0552, 0x0356, 0x0000};
|
|
|
|
|
|
|
|
void initGuards(unsigned char *guards)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2012-11-17 17:24:01 +00:00
|
|
|
memset(guards, 0, NUM_COLS);
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
#if NUM_COLS == 16
|
|
|
|
guards[2] = 3;
|
|
|
|
guards[5] = 3;
|
2008-12-03 05:40:16 +00:00
|
|
|
guards[10] = 3;
|
|
|
|
guards[13] = 3;
|
2012-11-17 17:24:01 +00:00
|
|
|
#else
|
|
|
|
unsigned const guard_min_distance = 3;
|
|
|
|
unsigned char pos;
|
|
|
|
for (pos = 0; pos <= ((NUM_COLS - (guard_min_distance - 1)) / 2); ++pos)
|
|
|
|
{
|
|
|
|
if (((pos % guard_min_distance) == 0) && (pos != 0))
|
|
|
|
{
|
|
|
|
guards[pos - 1] = 3;
|
|
|
|
guards[NUM_COLS - pos] = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void initInvaders(Invaders * iv, unsigned char lv)
|
|
|
|
{
|
|
|
|
unsigned char x, y;
|
|
|
|
|
|
|
|
// first zero out map!
|
2011-02-25 07:47:42 +00:00
|
|
|
memset(iv->map, 0, sizeof(iv->map));
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
iv->speedinc = 0;
|
|
|
|
iv->isEdged = 0;
|
|
|
|
|
|
|
|
switch (lv)
|
|
|
|
{
|
|
|
|
case 0:
|
2012-11-17 17:24:01 +00:00
|
|
|
default:
|
2008-12-03 05:40:16 +00:00
|
|
|
for (x = 0; x < 8; ++x)
|
|
|
|
{
|
|
|
|
iv->map[x][0] = 2;
|
|
|
|
iv->map[x][1] = 2;
|
|
|
|
iv->map[x][2] = 2;
|
|
|
|
iv->map[x][3] = 1;
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
iv->pos.x = (NUM_COLS - 8) / 2;
|
2008-12-03 05:40:16 +00:00
|
|
|
iv->pos.y = SPACESHIP_LINE + 1;
|
|
|
|
iv->speed = MIN_SPEED - 3;
|
|
|
|
iv->direction = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
for (x = 0; x < 8; ++x)
|
|
|
|
{
|
|
|
|
iv->map[x][0] = 3;
|
|
|
|
iv->map[x][1] = 3;
|
|
|
|
iv->map[x][2] = 2;
|
|
|
|
iv->map[x][3] = 2;
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
iv->pos.x = (NUM_COLS - 8) / 2;
|
2008-12-03 05:40:16 +00:00
|
|
|
iv->pos.y = SPACESHIP_LINE + 1;
|
|
|
|
iv->speed = MIN_SPEED - 2;
|
|
|
|
|
|
|
|
iv->direction = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
for (x = 0; x < 8; ++x)
|
|
|
|
{
|
|
|
|
iv->map[x][0] = 3;
|
|
|
|
iv->map[x][1] = 3;
|
|
|
|
iv->map[x][2] = 2;
|
|
|
|
iv->map[x][3] = 2;
|
|
|
|
iv->map[x][4] = 1;
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
iv->pos.x = (NUM_COLS - 8) / 2;
|
2008-12-03 05:40:16 +00:00
|
|
|
iv->pos.y = SPACESHIP_LINE + 1;
|
|
|
|
iv->speed = MIN_SPEED - 1;
|
|
|
|
|
|
|
|
iv->direction = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2011-02-25 07:47:42 +00:00
|
|
|
for (y = 7; y--;)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2011-02-25 07:47:42 +00:00
|
|
|
uint16_t hansrow = pgm_read_word(&hans[y]);
|
|
|
|
uint16_t mask = 0x0001;
|
|
|
|
for (x = 11; x--;)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2011-02-25 07:47:42 +00:00
|
|
|
iv->map[x][y] = (hansrow & mask) ? 3 : 1;
|
|
|
|
mask <<= 1;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
iv->pos.x = (NUM_COLS - 11) / 2;
|
2008-12-03 05:40:16 +00:00
|
|
|
iv->pos.y = SPACESHIP_LINE + 1;
|
|
|
|
|
|
|
|
iv->speed = MIN_SPEED + 2;
|
|
|
|
iv->direction = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2011-02-25 07:47:42 +00:00
|
|
|
for (y = 8; y--;)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2011-02-25 07:47:42 +00:00
|
|
|
uint16_t peterrow = pgm_read_word(&peter[y]);
|
|
|
|
uint16_t mask = 0x0001;
|
|
|
|
for (x = 11; x--;)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2011-02-25 07:47:42 +00:00
|
|
|
if (peterrow & mask)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
iv->map[x][y] = 2;
|
|
|
|
}
|
2011-02-25 07:47:42 +00:00
|
|
|
mask <<= 1;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
iv->pos.x = (NUM_COLS - 11) / 2;
|
2008-12-03 05:40:16 +00:00
|
|
|
iv->pos.y = SPACESHIP_LINE + 1;
|
|
|
|
|
|
|
|
iv->speed = MIN_SPEED + 3;
|
|
|
|
iv->direction = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|