saved 206 bytes

This commit is contained in:
Christian Kroll 2011-02-25 07:47:42 +00:00
parent 3725d7b420
commit 9c6a778871
4 changed files with 37 additions and 63 deletions

View File

@ -21,15 +21,7 @@ void setInvaderPixel(Invaders * iv, unsigned char x, unsigned char y,
} }
} }
unsigned char getGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x, void setGuardPixel(unsigned char *guards, unsigned char x,
unsigned char y)
{
if (x < BORG_WIDTH && y == GUARD_LINE)
return guards[x];
return 0;
}
void setGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x,
unsigned char y, unsigned char val) unsigned char y, unsigned char val)
{ {
if (x < BORG_WIDTH && y == GUARD_LINE && val <= 3) if (x < BORG_WIDTH && y == GUARD_LINE && val <= 3)
@ -39,7 +31,7 @@ void setGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x,
/*----------------------drawing Method---------------------------*/ /*----------------------drawing Method---------------------------*/
void draw(Invaders * iv, Spaceship * sc, Player * pl, Cannon * cn, void draw(Invaders * iv, Spaceship * sc, Player * pl, Cannon * cn,
unsigned char guards[BORG_WIDTH], uPixel st[MAX_SHOTS], uPixel * shot) unsigned char *guards, uPixel *st, uPixel * shot)
{ {
clearScreen (); clearScreen ();

View File

@ -1,42 +1,22 @@
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include "../../compat/pgmspace.h" #include "../../compat/pgmspace.h"
#include "invaders2.h" #include "invaders2.h"
uint8_t const peter[8][11] PROGMEM = uint16_t const peter[8] PROGMEM =
{ {0x0104, 0x0088, 0x01FC, 0x0376, 0x07FF, 0x05FD, 0x0505, 0x00D8};
{ 0, 0, P, 0, 0, 0, 0, 0, P, 0, 0 },
{ 0, 0, 0, P, 0, 0, 0, P, 0, 0, 0 },
{ 0, 0, P, P, P, P, P, P, P, 0, 0 },
{ 0, P, P, 0, P, P, P, 0, P, P, 0 },
{ P, P, P, P, P, P, P, P, P, P, P },
{ P, 0, P, P, P, P, P, P, P, 0, P },
{ P, 0, P, 0, 0, 0, 0, 0, P, 0, P },
{ 0, 0, 0, P, P, 0, P, P, 0, 0, 0 } };
uint8_t const hans[8][11] PROGMEM = uint16_t const hans[7] PROGMEM =
{ {0x0000, 0x0372, 0x0552, 0x0372, 0x0552, 0x0356, 0x0000};
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1 },
{ 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2 },
{ 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1 },
{ 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2 },
{ 1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 2 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
void initGuards(unsigned char guards[BORG_WIDTH]) void initGuards(unsigned char *guards)
{ {
unsigned char x; memset(guards, 0, BORG_WIDTH);
for (x = BORG_WIDTH; x--;)
{
guards[x] = 0;
}
guards[3] = 3; guards[3] = 3;
guards[6] = 3; guards[6] = 3;
guards[10] = 3; guards[10] = 3;
guards[13] = 3; guards[13] = 3;
} }
void initInvaders(Invaders * iv, unsigned char lv) void initInvaders(Invaders * iv, unsigned char lv)
@ -44,13 +24,7 @@ void initInvaders(Invaders * iv, unsigned char lv)
unsigned char x, y; unsigned char x, y;
// first zero out map! // first zero out map!
for (x = MAX_INVADER_WIDTH; x--;) memset(iv->map, 0, sizeof(iv->map));
{
for (y = MAX_INVADER_HEIGHT; y--;)
{
iv->map[x][y] = 0;
}
}
iv->speedinc = 0; iv->speedinc = 0;
iv->isEdged = 0; iv->isEdged = 0;
@ -112,14 +86,14 @@ void initInvaders(Invaders * iv, unsigned char lv)
break; break;
case 3: case 3:
for (x = 11; x--;) for (y = 7; y--;)
{ {
for (y = 8; y--;) uint16_t hansrow = pgm_read_word(&hans[y]);
uint16_t mask = 0x0001;
for (x = 11; x--;)
{ {
if (pgm_read_byte(&hans[y][x]) != 0) iv->map[x][y] = (hansrow & mask) ? 3 : 1;
{ mask <<= 1;
iv->map[x][y] = 2;
}
} }
} }
@ -132,14 +106,17 @@ void initInvaders(Invaders * iv, unsigned char lv)
break; break;
case 4: case 4:
for (x = 11; x--;) for (y = 8; y--;)
{ {
for (y = 8; y--;) uint16_t peterrow = pgm_read_word(&peter[y]);
uint16_t mask = 0x0001;
for (x = 11; x--;)
{ {
if (pgm_read_byte(&peter[y][x]) != 0) if (peterrow & mask)
{ {
iv->map[x][y] = 2; iv->map[x][y] = 2;
} }
mask <<= 1;
} }
} }

View File

@ -43,7 +43,7 @@ void procCannon(Cannon * cn, uPixel * shot)
} }
unsigned char areAtBorder(Invaders * iv) 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)
@ -58,7 +58,7 @@ unsigned char areAtBorder(Invaders * iv)
} }
void procInvaders(Invaders * iv, uPixel st[MAX_SHOTS]) void procInvaders(Invaders * iv, uPixel *st)
{ {
static unsigned char mv = 0; static unsigned char mv = 0;
@ -111,7 +111,7 @@ void procInvaders(Invaders * iv, uPixel st[MAX_SHOTS])
} }
void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc, void procShots(Invaders * iv, Player * pl, Cannon * cn, Spaceship * sc,
unsigned char guards[BORG_WIDTH], uPixel st[MAX_SHOTS], uPixel * shot) unsigned char *guards, uPixel *st, uPixel * shot)
{ {
unsigned char i; unsigned char i;
static unsigned char cmv = 0, imv = 0; static unsigned char cmv = 0, imv = 0;

View File

@ -51,8 +51,8 @@ typedef struct
/* GLOBALE VAR */ /* GLOBALE VAR */
/****************************************************************/ /****************************************************************/
#define P 3 #define P 3
extern uint8_t const peter[8][11]; extern uint16_t const peter[8];
extern uint8_t const hans[8][11]; extern uint16_t const hans[7];
/****************************************************************/ /****************************************************************/
/* DEFINES */ /* DEFINES */
@ -165,16 +165,21 @@ unsigned char getInvaderPixel(Invaders * iv, unsigned char x, unsigned char y);
void setInvaderPixel(Invaders * iv, unsigned char x, unsigned char y, void setInvaderPixel(Invaders * iv, unsigned char x, unsigned char y,
unsigned char val); unsigned char val);
unsigned char getGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x, void setGuardPixel(unsigned char *guards, unsigned char x,
unsigned char y);
void setGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x,
unsigned char y, unsigned char val); unsigned char y, unsigned char val);
inline static unsigned char getGuardPixel(unsigned char *guards,
unsigned char x, unsigned char y)
{
if (x < BORG_WIDTH && y == GUARD_LINE)
return guards[x];
return 0;
}
/*----------------------drawing Method---------------------------*/ /*----------------------drawing Method---------------------------*/
void draw(Invaders * iv, Spaceship * sc, Player * pl, Cannon * cn, void draw(Invaders * iv, Spaceship * sc, Player * pl, Cannon * cn,
unsigned char guards[BORG_WIDTH], uPixel ishots[MAX_SHOTS], unsigned char *guards, uPixel *ishots,
uPixel * shot); uPixel * shot);
#endif #endif