Index: apps/plugins/brickmania.c =================================================================== --- apps/plugins/brickmania.c (revision 24762) +++ apps/plugins/brickmania.c (working copy) @@ -778,6 +778,7 @@ }; #define MAX_BALLS 10 +#define MAX_FIRES 30 enum difficulty_options { EASY, NORMAL @@ -798,6 +799,7 @@ int level=0; int brick_on_board=0; int used_balls=1; +int used_fires=0; int difficulty = NORMAL; int pad_width; int num_count; @@ -838,7 +840,7 @@ int top; /* This stores the fire y position, it is a fixed point num */ int x_pos; /* This stores the fire x position, it is a whole number */ } sfire; -sfire fire[30]; +sfire fire[MAX_FIRES]; #define CONFIG_FILE_NAME "brickmania.cfg" #define SAVE_FILE PLUGIN_GAMES_DIR "/brickmania.save" @@ -975,6 +977,7 @@ } used_balls = 1; + used_fires = 0; game_state = ST_READY; pad_type = PLAIN; pad_width = PAD_WIDTH; @@ -990,11 +993,6 @@ } } - for(i=0;i<30;i++) { - /* No fire should be active */ - fire[i].top=-1; - } - for(i=0;i<=7;i++) { for(j=0;j<=9;j++) { int bnum = i*10+j; @@ -1038,6 +1036,7 @@ (rb->read(fd, &level, sizeof(level)) <= 0) || (rb->read(fd, &brick_on_board, sizeof(brick_on_board)) <= 0) || (rb->read(fd, &used_balls, sizeof(used_balls)) <= 0) || + (rb->read(fd, &used_fires, sizeof(used_fires)) <= 0) || (rb->read(fd, &pad_width, sizeof(pad_width)) <= 0) || (rb->read(fd, &num_count, sizeof(num_count)) <= 0) || (rb->read(fd, &brick, sizeof(brick)) <= 0) || @@ -1074,6 +1073,7 @@ (rb->write(fd, &level, sizeof(level)) <= 0) || (rb->write(fd, &brick_on_board, sizeof(brick_on_board)) <= 0) || (rb->write(fd, &used_balls, sizeof(used_balls)) <= 0) || + (rb->write(fd, &used_fires, sizeof(used_fires)) <= 0) || (rb->write(fd, &pad_width, sizeof(pad_width)) <= 0) || (rb->write(fd, &num_count, sizeof(num_count)) <= 0) || (rb->write(fd, &brick, sizeof(brick)) <= 0) || @@ -1290,17 +1290,6 @@ #endif } -/* Find an unused fire position */ -static int brickmania_find_empty_fire(void) -{ - int t; - for(t=0;t<30;t++) - if (fire[t].top < 0) - return t; - - return 0; -} - void brick_hit(int brick_number) { if(!brick[brick_number].used) @@ -1419,19 +1408,38 @@ if (brick_on_board==0) brick_on_board--; - /* if the pad is fire */ - for(i=0; i<30; i++) - { - /* If the projectile is active (>0 inactive) */ - if (fire[i].top >= 0) + /* move the fires */ + if (game_state!=ST_PAUSE) + for(k=0; klcd_vline( INT3(fire[i].x_pos), INT3(fire[i].top), - INT3(fire[i].top + FIRE_LENGTH)); + fire[k].top -= SPEED_FIRE; + if (fire[k].top <0) + { + used_fires--; + fire[k].top = fire[used_fires].top; + fire[k].x_pos = fire[used_fires].x_pos; + k--; + } + else if (fire[k].x_pos >= LEFTMARGIN && fire[k].x_pos < LEFTMARGIN + 10*BRICK_WIDTH) + { + j = (fire[k].x_pos - LEFTMARGIN) / BRICK_WIDTH; + for (i = 7; !brick[10*i+j].used && brick[10*i+j].powertop>fire[k].top && i>0; i--); + if (brick[10*i+j].used) + { + score += 13; + brick_hit(10*i+j); + used_fires--; + fire[k].top = fire[used_fires].top; + fire[k].x_pos = fire[used_fires].x_pos; + k--; + } + } } - } + + /* draw the fires */ + for(k=0; klcd_vline( INT3(fire[k].x_pos), INT3(fire[k].top), + INT3(fire[k].top + FIRE_LENGTH)); /* Setup the pad line-later used in intersection test */ pad_line.p1.x = pad_pos_x; @@ -1621,30 +1629,6 @@ rght_brick.p2.x = brickx + BRICK_WIDTH; rght_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT; - /* Check if any of the active fires hit a brick */ - for (k=0;k<30;k++) - { - if(fire[k].top > 0) - { - /* Use misc_line to check if fire hit brick */ - misc_line.p1.x = fire[k].x_pos; - misc_line.p1.y = fire[k].top; - - misc_line.p2.x = fire[k].x_pos; - misc_line.p2.y = fire[k].top + SPEED_FIRE; - - /* If the fire hit the brick take care of it */ - if (check_lines(&misc_line, &bot_brick, - &pt_hit)) - { - score+=13; - /* De-activate the fire */ - fire[k].top=-1; - brick_hit(bnum); - } - } - } - /* Draw the brick */ rb->lcd_bitmap_part(brickmania_bricks,0, INT3(BRICK_HEIGHT)*brick[bnum].color, @@ -2146,13 +2130,19 @@ } else if (pad_type == SHOOTER) { - k=brickmania_find_empty_fire(); - fire[k].top=PAD_POS_Y - FIRE_LENGTH; - fire[k].x_pos = pad_pos_x + 1; /* Add 1 for edge */ + if (used_fires < MAX_FIRES) + { + fire[used_fires].top=PAD_POS_Y - FIRE_LENGTH; + fire[used_fires].x_pos = pad_pos_x + 1; /* Add 1 for edge */ + used_fires++; + } - k=brickmania_find_empty_fire(); - fire[k].top=PAD_POS_Y - FIRE_LENGTH; - fire[k].x_pos = pad_pos_x + pad_width -1; /* Sub1 edge*/ + if (used_fires < MAX_FIRES) + { + fire[used_fires].top=PAD_POS_Y - FIRE_LENGTH; + fire[used_fires].x_pos = pad_pos_x + pad_width -1; /* Sub1 edge*/ + used_fires++; + } } break; #ifdef RC_QUIT