diff --git a/games/space_invaders/invader_draw.c b/games/space_invaders/invader_draw.c index 07457bf..ecd3756 100644 --- a/games/space_invaders/invader_draw.c +++ b/games/space_invaders/invader_draw.c @@ -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, - 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, +void setGuardPixel(unsigned char *guards, unsigned char x, unsigned char y, unsigned char val) { 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---------------------------*/ 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 (); diff --git a/games/space_invaders/invader_init.c b/games/space_invaders/invader_init.c index 80f067e..d6c19ca 100644 --- a/games/space_invaders/invader_init.c +++ b/games/space_invaders/invader_init.c @@ -1,42 +1,22 @@ #include +#include #include "../../compat/pgmspace.h" #include "invaders2.h" -uint8_t const peter[8][11] PROGMEM = -{ -{ 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 } }; +uint16_t const peter[8] PROGMEM = + {0x0104, 0x0088, 0x01FC, 0x0376, 0x07FF, 0x05FD, 0x0505, 0x00D8}; -uint8_t const hans[8][11] PROGMEM = -{ -{ 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 } }; +uint16_t const hans[7] PROGMEM = + {0x0000, 0x0372, 0x0552, 0x0372, 0x0552, 0x0356, 0x0000}; -void initGuards(unsigned char guards[BORG_WIDTH]) +void initGuards(unsigned char *guards) { - unsigned char x; - for (x = BORG_WIDTH; x--;) - { - guards[x] = 0; - } + memset(guards, 0, BORG_WIDTH); guards[3] = 3; guards[6] = 3; guards[10] = 3; guards[13] = 3; - } void initInvaders(Invaders * iv, unsigned char lv) @@ -44,13 +24,7 @@ void initInvaders(Invaders * iv, unsigned char lv) unsigned char x, y; // first zero out map! - for (x = MAX_INVADER_WIDTH; x--;) - { - for (y = MAX_INVADER_HEIGHT; y--;) - { - iv->map[x][y] = 0; - } - } + memset(iv->map, 0, sizeof(iv->map)); iv->speedinc = 0; iv->isEdged = 0; @@ -112,14 +86,14 @@ void initInvaders(Invaders * iv, unsigned char lv) break; 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] = 2; - } + iv->map[x][y] = (hansrow & mask) ? 3 : 1; + mask <<= 1; } } @@ -132,14 +106,17 @@ void initInvaders(Invaders * iv, unsigned char lv) break; 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; } + mask <<= 1; } } diff --git a/games/space_invaders/invader_proc.c b/games/space_invaders/invader_proc.c index ceb151c..3592307 100644 --- a/games/space_invaders/invader_proc.c +++ b/games/space_invaders/invader_proc.c @@ -43,7 +43,7 @@ void procCannon(Cannon * cn, uPixel * shot) } -unsigned char areAtBorder(Invaders * iv) +static unsigned char areAtBorder(Invaders * iv) { unsigned char 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; @@ -111,7 +111,7 @@ void procInvaders(Invaders * iv, uPixel st[MAX_SHOTS]) } 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; static unsigned char cmv = 0, imv = 0; diff --git a/games/space_invaders/invaders2.h b/games/space_invaders/invaders2.h index d140687..45de4fb 100644 --- a/games/space_invaders/invaders2.h +++ b/games/space_invaders/invaders2.h @@ -51,8 +51,8 @@ typedef struct /* GLOBALE VAR */ /****************************************************************/ #define P 3 -extern uint8_t const peter[8][11]; -extern uint8_t const hans[8][11]; +extern uint16_t const peter[8]; +extern uint16_t const hans[7]; /****************************************************************/ /* 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, unsigned char val); -unsigned char getGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x, - unsigned char y); - -void setGuardPixel(unsigned char guards[BORG_WIDTH], unsigned char x, +void setGuardPixel(unsigned char *guards, unsigned char x, 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---------------------------*/ 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); #endif