2008-12-03 05:40:16 +00:00
|
|
|
#include <stdio.h>
|
2009-01-02 02:18:20 +00:00
|
|
|
#include "../../util.h"
|
|
|
|
#include "../../compat/eeprom.h"
|
|
|
|
#include "../../compat/pgmspace.h"
|
|
|
|
#include "../../menu/menu.h"
|
|
|
|
#include "../../scrolltext/scrolltext.h"
|
2008-12-03 05:40:16 +00:00
|
|
|
#include "invaders2.h"
|
|
|
|
|
2010-01-15 12:52:15 +00:00
|
|
|
void borg_invaders();
|
|
|
|
|
|
|
|
#ifdef MENU_SUPPORT
|
2009-01-02 02:18:20 +00:00
|
|
|
// MSB is leftmost pixel
|
2011-09-04 01:08:13 +00:00
|
|
|
static const uint8_t icon[8] PROGMEM =
|
2009-01-02 02:18:20 +00:00
|
|
|
{0x66, 0x18, 0x3c, 0x5a, 0xff, 0xbd, 0xa5, 0x18}; // Invaders icon
|
|
|
|
|
|
|
|
game_descriptor_t invaders_game_descriptor __attribute__((section(".game_descriptors"))) ={
|
|
|
|
&borg_invaders,
|
|
|
|
icon,
|
|
|
|
};
|
2010-01-14 01:38:15 +00:00
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
void borg_invaders()
|
|
|
|
{
|
|
|
|
/****************************************************************/
|
|
|
|
/* INITIALIZE */
|
|
|
|
/****************************************************************/
|
2012-11-17 17:24:01 +00:00
|
|
|
offScreen_t offScreen = {{{0}}};
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
Invaders iv;
|
|
|
|
Cannon cn;
|
|
|
|
Player pl;
|
|
|
|
Spaceship sc;
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
unsigned char guards[NUM_COLS];
|
2008-12-03 05:40:16 +00:00
|
|
|
unsigned char level = 0;
|
|
|
|
unsigned char ivStatus = 0;
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
pixel st[MAX_SHOTS] =
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2012-11-17 17:24:01 +00:00
|
|
|
{255, 255},
|
|
|
|
{255, 255},
|
|
|
|
{255, 255},
|
|
|
|
{255, 255},
|
|
|
|
{255, 255},
|
|
|
|
{255, 255},
|
|
|
|
{255, 255}
|
2008-12-03 05:40:16 +00:00
|
|
|
};
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
pixel shot;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
pl.points = 0;
|
|
|
|
pl.lives = 3;
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
/* GAME LOOP */
|
|
|
|
/****************************************************************/
|
|
|
|
do
|
|
|
|
{
|
|
|
|
//----- INITIALIZE LEVEL-----//
|
|
|
|
initGuards(guards);
|
|
|
|
initInvaders(&iv, level);
|
|
|
|
|
|
|
|
//Spaceship
|
|
|
|
sc.lives = 1;
|
2012-11-17 17:24:01 +00:00
|
|
|
sc.pos = NO_SPACESHIP;
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
//Cannon
|
2012-11-17 17:24:01 +00:00
|
|
|
cn.pos = (NUM_COLS - 3) / 2;
|
2008-12-03 05:40:16 +00:00
|
|
|
cn.ready = 1;
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
while (pl.lives != 0)
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
procInvaders(&iv, st);
|
|
|
|
procSpaceship(&sc);
|
|
|
|
procShots(&iv, &pl, &cn, &sc, guards, st, &shot);
|
|
|
|
procCannon(&cn, &shot);
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
draw(offScreen, &iv, &sc, &pl, &cn, guards, st, &shot);
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
ivStatus = getStatus(&iv);
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
if (ivStatus == 2) //LOST
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
pl.lives = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (ivStatus == 1) //WON
|
|
|
|
{
|
2012-09-08 01:35:32 +00:00
|
|
|
unsigned int bonus = POINTS_FOR_LEVEL * (level + 1u) *
|
2012-11-17 17:24:01 +00:00
|
|
|
(unsigned int)(NUM_ROWS - 4 - iv.pos.y);
|
2008-12-03 05:40:16 +00:00
|
|
|
pl.points += bonus;
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
level = (level + 1) % MAX_LEVEL;
|
2008-12-03 05:40:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wait (WAIT_MS);
|
|
|
|
} //IN LEVEL LOOP
|
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
} while (pl.lives != 0); //GAME LOOP
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2012-11-17 17:24:01 +00:00
|
|
|
/****************************************************************/
|
|
|
|
/* PLAYER STAT */
|
|
|
|
/* HIGH SCORES */
|
|
|
|
/****************************************************************/
|
2009-01-02 02:18:20 +00:00
|
|
|
#ifdef SCROLLTEXT_SUPPORT
|
|
|
|
char text[64];
|
|
|
|
snprintf(text, 64, "</#points: %u", pl.points);
|
|
|
|
scrolltext(text);
|
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|