|
@ -4,43 +4,36 @@ |
|
|
#include "../../random/prng.h" |
|
|
#include "../../random/prng.h" |
|
|
#include "invaders2.h" |
|
|
#include "invaders2.h" |
|
|
|
|
|
|
|
|
void procCannon(Cannon * cn, uPixel * shot) |
|
|
void procCannon(Cannon * cn, pixel * shot) |
|
|
{ |
|
|
{ |
|
|
static unsigned char mv = 0; |
|
|
static unsigned char mv = 0; |
|
|
if (mv >= CANNON_SPEED) |
|
|
if (mv++ >= CANNON_SPEED) |
|
|
{ |
|
|
{ |
|
|
mv = 0; |
|
|
mv = 0; |
|
|
if (JOYISLEFT) |
|
|
if (JOYISLEFT) |
|
|
{ |
|
|
{ |
|
|
if (cn->pos != RIGHT_BORDER) |
|
|
if (cn->pos < (NUM_COLS - 1)) |
|
|
{ |
|
|
{ |
|
|
cn->pos++; |
|
|
cn->pos++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if (JOYISRIGHT) |
|
|
else if (JOYISRIGHT) |
|
|
{ |
|
|
{ |
|
|
if (cn->pos != LEFT_BORDER) |
|
|
if (cn->pos > 0) |
|
|
{ |
|
|
{ |
|
|
cn->pos--; |
|
|
--cn->pos; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if (JOYISFIRE) |
|
|
else if (JOYISFIRE) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
if (cn->ready) |
|
|
if (cn->ready) |
|
|
{ |
|
|
{ |
|
|
shot->x = cn->pos; |
|
|
shot->x = cn->pos; |
|
|
shot->y = 14; |
|
|
shot->y = NUM_ROWS - 3; |
|
|
cn->ready = 0; |
|
|
cn->ready = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
mv++; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static unsigned char areAtBorder(Invaders * iv) |
|
|
static unsigned char areAtBorder(Invaders * iv) |
|
@ -48,21 +41,19 @@ static unsigned char areAtBorder(Invaders * iv) |
|
|
unsigned char y; |
|
|
unsigned char y; |
|
|
for (y = SPACESHIP_LINE + 1; y <= GUARD_LINE; ++y) |
|
|
for (y = SPACESHIP_LINE + 1; y <= GUARD_LINE; ++y) |
|
|
{ |
|
|
{ |
|
|
if (getInvaderPixel(iv, LEFT_BORDER, y) || getInvaderPixel(iv, |
|
|
if (getInvaderPixel(iv, NUM_COLS - 1, y) || getInvaderPixel(iv, 0, y)) |
|
|
RIGHT_BORDER, y)) |
|
|
|
|
|
{ |
|
|
{ |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void procInvaders(Invaders * iv, uPixel *st) |
|
|
void procInvaders(Invaders * iv, pixel *st) |
|
|
{ |
|
|
{ |
|
|
static unsigned char mv = 0; |
|
|
static unsigned char mv = 0; |
|
|
|
|
|
|
|
|
if (mv >= iv->speed) |
|
|
if (mv++ >= iv->speed) |
|
|
{ |
|
|
{ |
|
|
mv = 0; |
|
|
mv = 0; |
|
|
if (areAtBorder(iv) && !(iv->isEdged)) |
|
|
if (areAtBorder(iv) && !(iv->isEdged)) |
|
@ -76,29 +67,21 @@ void procInvaders(Invaders * iv, uPixel *st) |
|
|
iv->pos.x += iv->direction; |
|
|
iv->pos.x += iv->direction; |
|
|
iv->isEdged = 0; |
|
|
iv->isEdged = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
mv++; |
|
|
|
|
|
|
|
|
|
|
|
unsigned char i, y; |
|
|
unsigned char i, y; |
|
|
unsigned char spos = random8() % 16; |
|
|
unsigned char spos = random8() % UNUM_COLS; |
|
|
if (spos >= BORG_WIDTH) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
unsigned char shoot = random8(); |
|
|
|
|
|
|
|
|
|
|
|
if (shoot < SHOOTING_RATE) |
|
|
if (random8() < SHOOTING_RATE) |
|
|
{ |
|
|
{ |
|
|
for (i = 0; i < MAX_SHOTS; ++i) |
|
|
for (i = 0; i < MAX_SHOTS; ++i) |
|
|
{ |
|
|
{ |
|
|
if (st[i].x > BORG_WIDTH || st[i].y > BORG_HEIGHT) |
|
|
if (st[i].y >= NUM_ROWS) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
for (y = GUARD_LINE; y > SPACESHIP_LINE; --y) |
|
|
for (y = GUARD_LINE; y > SPACESHIP_LINE; --y) |
|
|
{ |
|
|
{ |
|
|
if (getInvaderPixel(iv, spos, y) != 0) |
|
|
if (getInvaderPixel(iv, spos, y) != 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
st[i].x = spos; |
|
|
st[i].x = spos; |
|
|
st[i].y = y + 1; |
|
|
st[i].y = y + 1; |
|
|
return; |
|
|
return; |
|
@ -107,27 +90,27 @@ void procInvaders(Invaders * iv, uPixel *st) |
|
|
} |
|
|
} |
|
|
} //for SHOTS
|
|
|
} //for SHOTS
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
unsigned char *guards, uPixel *st, uPixel * shot) |
|
|
unsigned char *guards, pixel *st, pixel * shot) |
|
|
{ |
|
|
{ |
|
|
unsigned char i; |
|
|
unsigned char i; |
|
|
static unsigned char cmv = 0, imv = 0; |
|
|
static unsigned char cmv = 0, imv = 0; |
|
|
|
|
|
|
|
|
// shuß mit einen struct mit dem shuß!!
|
|
|
|
|
|
|
|
|
|
|
|
if (cmv >= CANNON_SHOOTING_SPEED) |
|
|
if (cmv >= CANNON_SHOOTING_SPEED) |
|
|
{ |
|
|
{ |
|
|
cmv = 0; |
|
|
cmv = 0; |
|
|
if (!(cn->ready)) |
|
|
if (!(cn->ready)) |
|
|
{ |
|
|
{ |
|
|
shot->y--; |
|
|
if (shot->y > 0) |
|
|
} |
|
|
{ |
|
|
if (shot->y > BORG_HEIGHT) |
|
|
shot->y--; |
|
|
{ |
|
|
} |
|
|
cn->ready = 1; |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
cn->ready = 1; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -137,7 +120,7 @@ void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
|
|
|
|
|
|
for (i = MAX_SHOTS; i--;) |
|
|
for (i = MAX_SHOTS; i--;) |
|
|
{ |
|
|
{ |
|
|
if ( /*st[i].x < BORG_WIDTH && */st[i].y < BORG_HEIGHT) |
|
|
if (st[i].y < NUM_ROWS) |
|
|
{ |
|
|
{ |
|
|
st[i].y++; |
|
|
st[i].y++; |
|
|
} |
|
|
} |
|
@ -152,7 +135,6 @@ void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
/****************************************************************/ |
|
|
/****************************************************************/ |
|
|
|
|
|
|
|
|
// USER CANNON
|
|
|
// USER CANNON
|
|
|
|
|
|
|
|
|
unsigned char tmp; |
|
|
unsigned char tmp; |
|
|
if (!(cn->ready)) |
|
|
if (!(cn->ready)) |
|
|
{ |
|
|
{ |
|
@ -163,6 +145,7 @@ void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
st[i].x = 255; |
|
|
st[i].x = 255; |
|
|
st[i].y = 255; |
|
|
st[i].y = 255; |
|
|
cn->ready = 1; |
|
|
cn->ready = 1; |
|
|
|
|
|
goto invader_shots; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -200,21 +183,20 @@ void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//SPACESHIP
|
|
|
//SPACESHIP
|
|
|
|
|
|
|
|
|
if (shot->y == SPACESHIP_LINE) |
|
|
if (shot->y == SPACESHIP_LINE) |
|
|
{ |
|
|
{ |
|
|
if (shot->x == sc->pos || shot->x == sc->pos + 1) |
|
|
if ((shot->x <= sc->pos) && (shot->x >= sc->pos - 1)) |
|
|
{ |
|
|
{ |
|
|
sc->pos = 255; |
|
|
sc->pos = NO_SPACESHIP; |
|
|
pl->points += POINTS_FOR_SPACESHIP; |
|
|
pl->points += POINTS_FOR_SPACESHIP; |
|
|
cn->ready = 1; |
|
|
cn->ready = 1; |
|
|
goto invader_shots; |
|
|
goto invader_shots; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} // !(cn->ready)
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invader_shots: for (i = 0; i < MAX_SHOTS; ++i) |
|
|
invader_shots: |
|
|
|
|
|
for (i = 0; i < MAX_SHOTS; ++i) |
|
|
{ |
|
|
{ |
|
|
if ((tmp = getGuardPixel(guards, st[i].x, st[i].y))) |
|
|
if ((tmp = getGuardPixel(guards, st[i].x, st[i].y))) |
|
|
{ |
|
|
{ |
|
@ -224,7 +206,7 @@ void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
st[i].y = 255; |
|
|
st[i].y = 255; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (st[i].y == BORG_HEIGHT - 1) |
|
|
if (st[i].y == (NUM_ROWS - 2)) |
|
|
{ |
|
|
{ |
|
|
if (st[i].x == cn->pos) |
|
|
if (st[i].x == cn->pos) |
|
|
{ |
|
|
{ |
|
@ -240,66 +222,61 @@ void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, |
|
|
|
|
|
|
|
|
void procSpaceship(Spaceship * sc) |
|
|
void procSpaceship(Spaceship * sc) |
|
|
{ |
|
|
{ |
|
|
unsigned char rnd1 = random8(); |
|
|
unsigned char const rnd1 = random8(); |
|
|
unsigned char rnd2 = random8(); |
|
|
unsigned char const rnd2 = random8(); |
|
|
|
|
|
|
|
|
static unsigned char sct = 0; |
|
|
static unsigned char sct = 0; |
|
|
|
|
|
|
|
|
if (sc->pos > RIGHT_BORDER) |
|
|
if (sc->pos == NO_SPACESHIP) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if ((rnd1 == 73) && (rnd2 >= 200)) |
|
|
if (rnd1 == 73) |
|
|
|
|
|
{ |
|
|
{ |
|
|
if (rnd2 >= 200) |
|
|
sc->pos = NUM_COLS; |
|
|
{ |
|
|
sct = 0; |
|
|
sc->pos = RIGHT_BORDER; |
|
|
|
|
|
sct = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
if (sct == SPACESHIP_SPEED) |
|
|
if (sct++ == SPACESHIP_SPEED) |
|
|
{ |
|
|
{ |
|
|
sct = 0; |
|
|
sct = 0; |
|
|
if (sc->pos == 0) |
|
|
if (sc->pos > 0) |
|
|
{ |
|
|
{ |
|
|
sc->pos = 255; |
|
|
sc->pos--; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
sc->pos--; |
|
|
sc->pos = NO_SPACESHIP; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
sct++; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsigned char getStatus(Invaders * iv) |
|
|
unsigned char getStatus(Invaders * iv) |
|
|
{ |
|
|
{ |
|
|
|
|
|
unsigned char x, y; |
|
|
|
|
|
|
|
|
//count Invader!
|
|
|
// did invaders reached earth?
|
|
|
unsigned char x, y, inv = 0; |
|
|
for (x = NUM_COLS; x--;) |
|
|
for (x = MAX_INVADER_WIDTH; x--;) |
|
|
|
|
|
{ |
|
|
{ |
|
|
for (y = MAX_INVADER_HEIGHT; y--;) |
|
|
if (getInvaderPixel(iv, x, GUARD_LINE + 1)) |
|
|
{ |
|
|
{ |
|
|
if (iv->map[x][y] != 0) |
|
|
return 2; |
|
|
inv++; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//LEVEL BEREINIGT
|
|
|
// any invaders left?
|
|
|
if (inv == 0) |
|
|
for (x = MAX_INVADER_WIDTH; x--;) |
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
//INVADERS REACHED EARTH
|
|
|
|
|
|
for (x = BORG_WIDTH; x--;) |
|
|
|
|
|
{ |
|
|
{ |
|
|
if (getInvaderPixel(iv, x, GUARD_LINE + 1)) |
|
|
for (y = MAX_INVADER_HEIGHT; y--;) |
|
|
return 2; |
|
|
{ |
|
|
|
|
|
if (iv->map[x][y]) |
|
|
|
|
|
{ |
|
|
|
|
|
return 0; // yes
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return 0; |
|
|
// if we reach here, level was cleared \o/
|
|
|
|
|
|
return 1; |
|
|
} |
|
|
} |
|
|