diff --git a/firmware/loadable/spaceinvaders.c b/firmware/loadable/spaceinvaders.c index 029625e..fbcf38a 100644 --- a/firmware/loadable/spaceinvaders.c +++ b/firmware/loadable/spaceinvaders.c @@ -1,15 +1,13 @@ #include +#include #include "basic/basic.h" +#include "basic/random.h" #include "lcd/render.h" #include "lcd/display.h" #include "lcd/allfonts.h" -//void ReinvokeISP(void); -//void EnableWatchdog(uint32_t ms); -//void delayms(uint32_t ms); - /**************************************************************************/ #define POS_PLAYER_Y 60 #define POS_PLAYER_X RESX/2-3 @@ -20,11 +18,11 @@ #define UFO_PROB 1024 -#define TYPE_PLAYER 1 +#define TYPE_PLAYER 1 #define TYPE_ENEMY_A 3 #define TYPE_ENEMY_B 2 #define TYPE_ENEMY_C 4 -#define TYPE_UFO 5 +#define TYPE_UFO 5 #define BUNKERS 3 #define BUNKER_WIDTH 10 @@ -52,16 +50,19 @@ struct gamestate { char key; void init_game(); +void init_enemy(); void check_end(); void move_ufo(); +void move_shot(); void move_shots(); void move_player(); -void move_enemay(); +void move_enemy(); void draw_score(); void draw_bunker(); void draw_player(); void draw_enemy(); void draw_shots(); +void draw_sprite(char type, char x, char y); void draw_ufo(); void screen_intro(); void screen_gameover(); @@ -163,7 +164,7 @@ void init_game(void) { game.score = 0; 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; -// } -// } -// } - if (check_bunker(game.shot_x,game.shot_y-5,1 )) + + if (check_bunker(game.shot_x,game.shot_y-5,1 )) game.shot_x=DISABLED; //check for collision with enemy, kill enemy if @@ -254,6 +242,7 @@ void move_shot() { } } } + //check for collision with ufo if (game.ufo != DISABLED && game.shot_x>game.ufo && @@ -271,10 +260,10 @@ void move_shot() { void move_shots() { - for (char col = 0; colBUNKER_X[BUNKERS-1-b] && -// game.shots_x[col]RESY-16) { -// int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1; -// 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 - + //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) { @@ -369,25 +345,12 @@ void move_enemy() { game.killed = true; } check_bunker(pos,game.enemy_row_y[row]+8,-2); - //check for collision with bunker, dirty - // for (int b=0; b=BUNKER_X[BUNKERS-1-b] && - // pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && - // game.enemy_row_y[row]+8RESY-16) { - // int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]); - // if (game.bunker[b][offset]!=0) { - // game.bunker[b][offset]&=game.bunker[b][offset]>>2; - // } - // } - // } - - + //Are we at the beginning or end? Direction change if((pos <=0 && game.direction != 1) || (pos >=RESX-10 && game.direction == 1)){ game.direction = (game.direction==1)?-1:1; - for (char r = 0; r=23?4:2; } return; @@ -401,7 +364,6 @@ void move_enemy() { } void draw_player() { - //draw_sprite(50, 20); draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); } @@ -433,7 +395,7 @@ void draw_shots() { } } - for (char col = 0; col < ENEMY_COLUMNS; col++) { + for (int col = 0; col < ENEMY_COLUMNS; col++) { if (game.shots_x[col] != DISABLED) { for (int length=0; length<=5; length++) { lcdSetPixel(game.shots_x[col], game.shots_y[col]+length,true);