diff --git a/firmware/applications/spaceinvaders.c b/firmware/applications/spaceinvaders.c index b6fc4c7..80e2edb 100644 --- a/firmware/applications/spaceinvaders.c +++ b/firmware/applications/spaceinvaders.c @@ -20,6 +20,10 @@ void delayms(uint32_t ms); #define TYPE_ENEMY_A 2 #define TYPE_ENEMY_B 3 #define TYPE_ENEMY_C 4 + +#define BUNKERS 2 +#define BUNKER_WIDTH 10 +static const BUNKER_X[] = {20,RESX-BUNKER_WIDTH-20}; static const ENEMY_WIDTHS[] = {10,11,8}; struct gamestate { @@ -29,13 +33,14 @@ struct gamestate { char shots_y[ENEMY_COLUMNS]; char alive; char move, direction, lastcol; - bool killed, step; + bool killed; + bool step; uint32_t score; char level; char rokets; char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; char enemy_row_y[ENEMY_ROWS]; - + uint8_t bunker[BUNKERS][BUNKER_WIDTH]; } game; char key; @@ -47,12 +52,19 @@ void init_game(void) { game.move = 0; game.direction = -1; game.lastcol = ENEMY_COLUMNS-1; - game.killed = false; + game.killed = 0; game.step = false; init_enemy(); + for (char col=0; colBUNKER_X[BUNKERS-1-b] && + game.shot_xRESY-16) { + int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]<<1; + game.shot_x=DISABLED; + } + } + } + //check for collision with enemy, kill enemy if for (int row=0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { @@ -114,8 +140,29 @@ void move_shots() { game.shots_x[col] = DISABLED; return; } - + //check for collision with bunker + for (int b=0; bBUNKER_X[BUNKERS-1-b] && + game.shots_x[col]RESY-16) { + int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b]); + if (game.bunker[b][offset]!=0) { + game.bunker[b][offset]&=game.bunker[b][offset]>>1; + game.shots_x[col]=DISABLED; + } + } + } //check for collision with player + + if (game.shots_y[col] >= RESY-13 && + game.shots_x[col] > game.player+1 && + game.shots_x[col] < game.player+6) { + + game.killed = true; + } + + //move shots down game.shots_y[col] += 1; } } @@ -168,34 +215,6 @@ void move_enemy() { game.move = game.alive-1; } -void move_enemy2() { - if(game.move == 0) { - bool next = false; - for (int col = game.lastcol; col < ENEMY_COLUMNS || col <= 0; col+=game.direction) { - for (int row = 0; row < ENEMY_ROWS; row++) { - char pos = game.enemy_x[row][col]; - //There is an enemy on this row - if (pos != DISABLED) { - if((pos <=0 && game.direction== -1) || - (pos >=RESX-8 && game.direction == 1)){ - game.direction *= -1; - //TODOmove down - return; - } - game.enemy_x[row][col] += game.direction; - next = true; - } - } - if (next){ - game.lastcol += game.direction; - return; - } - } - game.move = game.alive; - return; - } - game.move--; -} void draw_player() { //draw_sprite(50, 20); draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); @@ -211,6 +230,12 @@ void draw_enemy() { } } +void draw_bunker() { + for (int b=0; b