Index: rockbox/apps/plugins/brickmania.c =================================================================== --- rockbox/apps/plugins/brickmania.c (revision 24802) +++ rockbox/apps/plugins/brickmania.c (working copy) @@ -380,6 +380,8 @@ #define NUM_BRICKS_ROWS 8 #define NUM_BRICKS_COLS 10 #define BRICK_IDX(row, col) (NUM_BRICKS_COLS * (row) + (col)) +#define BRICK_ROW(bnum) (bnum / NUM_BRICKS_COLS) +#define BRICK_COL(bnum) (bnum % NUM_BRICKS_COLS) /* change the first number in [ ] to however many levels there are */ static unsigned char levels[NUM_LEVELS][NUM_BRICKS_ROWS][NUM_BRICKS_COLS] = @@ -796,6 +798,7 @@ #define MAX_BALLS 10 #define MAX_FIRES 30 +#define MAX_POWERS 10 enum difficulty_options { EASY, NORMAL @@ -817,6 +820,7 @@ int brick_on_board=0; int used_balls=1; int used_fires=0; +int used_powers=0; int difficulty = NORMAL; int pad_width; int flip_sides_delay; @@ -825,9 +829,6 @@ typedef struct cube { - int powertop; /* Stores the powerup Y top pos, it is a fixed point num */ - int power; /* What powerup is in the brick? */ - bool poweruse; /* Stores whether a powerup is falling or not */ bool used; /* Is the brick still in play? */ int color; int hits; /* How many hits can this brick take? */ @@ -859,6 +860,12 @@ } sfire; sfire fire[MAX_FIRES]; +typedef struct spower { + int top; /* This stores the powerup y position, it is a fixed point num */ + int x_pos; /* This stores the (middle of) powerup x position, it is a whole number */ + int type; /* This stores the powerup type */ +} spower; +spower power[MAX_POWERS]; #define CONFIG_FILE_NAME "brickmania.cfg" #define SAVE_FILE PLUGIN_GAMES_DIR "/brickmania.save" #define HIGH_SCORE_FILE PLUGIN_GAMES_DIR "/brickmania.score" @@ -995,6 +1002,7 @@ used_balls = 1; used_fires = 0; + used_powers = 0; game_state = ST_READY; pad_type = PLAIN; pad_width = PAD_WIDTH; @@ -1013,15 +1021,10 @@ for(i=0;irand()%25; - /* +8 make the game with less powerups */ - brick[bnum].hits=levels[level][i][j]>=10? levels[level][i][j]/16-1:0; brick[bnum].hiteffect=0; - brick[bnum].powertop = TOPMARGIN + i*BRICK_HEIGHT; brick[bnum].used=!(levels[level][i][j]==0); brick[bnum].color=(levels[level][i][j]>=10? levels[level][i][j]%16: @@ -1054,11 +1057,13 @@ (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, &used_powers, sizeof(used_powers)) <= 0) || (rb->read(fd, &pad_width, sizeof(pad_width)) <= 0) || (rb->read(fd, &flip_sides_delay, sizeof(flip_sides_delay)) <= 0) || (rb->read(fd, &brick, sizeof(brick)) <= 0) || (rb->read(fd, &ball, sizeof(ball)) <= 0) || - (rb->read(fd, &fire, sizeof(fire)) <= 0)) + (rb->read(fd, &fire, sizeof(fire)) <= 0) || + (rb->read(fd, &power, sizeof(power)) <= 0)) { rb->splash(HZ/2, "Failed to load game"); } @@ -1091,11 +1096,13 @@ (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, &used_powers, sizeof(used_powers)) <= 0) || (rb->write(fd, &pad_width, sizeof(pad_width)) <= 0) || (rb->write(fd, &flip_sides_delay, sizeof(flip_sides_delay)) <= 0) || (rb->write(fd, &brick, sizeof(brick)) <= 0) || (rb->write(fd, &ball, sizeof(ball)) <= 0) || - (rb->write(fd, &fire, sizeof(fire)) <= 0)) + (rb->write(fd, &fire, sizeof(fire)) <= 0) || + (rb->write(fd, &power, sizeof(power)) <= 0)) { rb->close(fd); rb->remove(SAVE_FILE); @@ -1322,10 +1329,15 @@ } else { brick[brick_number].used=false; - /* Was there a powerup on the brick? */ - if (brick[brick_number].powerrand()%25; + /* +8 make the game with less powerups */ + if (ran> 1); + power[used_powers].type = ran; + used_powers++; } brick_on_board--; score+=SCORE_BALL_DEMOLISHED_BRICK; @@ -1425,9 +1437,9 @@ if (brick_on_board==0) brick_on_board--; - /* move the fires */ if (game_state!=ST_PAUSE) { + /* move the fires */ for(k=0;kPAD_POS_Y-POWERUP_HEIGHT && power[k].top<=PAD_POS_Y && + power[k].x_pos>=pad_pos_x && power[k].x_pos=0) + { + brickmania_init_game(false); + brickmania_sleep(2); + } + break; + case 2: /* Make the paddle sticky */ + score += SCORE_POWER_STICKY; + pad_type = STICKY; + break; + case 3: /* Give the paddle shooter */ + score += SCORE_POWER_SHOOTER; + pad_type = SHOOTER; + for(k=0;kcurrent_tick+HZ; + flip_sides_delay = FLIP_SIDES_DELAY; + flip_sides = true; + break; + case 6: /* Extra Ball */ + score += SCORE_POWER_EXTRA_BALL; + if(used_ballsrand()%2 == 0) + ball[used_balls].speedx=-SPEED_4Q_X; + else + ball[used_balls].speedx= SPEED_4Q_X; + ball[used_balls].speedy= SPEED_4Q_Y; + /* Ball is not glued */ + ball[used_balls].glue= false; + used_balls++; + } + break; + case 7: /* Long paddle */ + score+=SCORE_POWER_LONG_PADDLE; + if (pad_width==PAD_WIDTH) + { + pad_width = LONG_PAD_WIDTH; + pad_pos_x -= (LONG_PAD_WIDTH - + PAD_WIDTH)/2; + } + else if (pad_width==SHORT_PAD_WIDTH) + { + pad_width = PAD_WIDTH; + pad_pos_x-=(PAD_WIDTH- + SHORT_PAD_WIDTH)/2; + } + if (pad_pos_x < 0) + pad_pos_x = 0; + else if(pad_pos_x + pad_width > + GAMESCREEN_WIDTH) + pad_pos_x = GAMESCREEN_WIDTH-pad_width; + break; + case 8: /* Short Paddle */ + if (pad_width==PAD_WIDTH) + { + pad_width=SHORT_PAD_WIDTH; + pad_pos_x+=(PAD_WIDTH- + SHORT_PAD_WIDTH)/2; + } + else if (pad_width==LONG_PAD_WIDTH) + { + pad_width=PAD_WIDTH; + pad_pos_x+=(LONG_PAD_WIDTH-PAD_WIDTH)/2; + } + break; + } + used_powers--; + power[k].top = power[used_powers].top; + power[k].x_pos = power[used_powers].x_pos; + power[k].type = power[used_powers].type; + k--; + } + else if (power[k].top > PAD_POS_Y) + { + used_powers--; + power[k].top = power[used_powers].top; + power[k].x_pos = power[used_powers].x_pos; + power[k].type = power[used_powers].type; + k--; + } + } } /* draw the fires */ @@ -1470,6 +1591,19 @@ INT3(fire[k].top + FIRE_LENGTH)); } + /* draw the powerups */ + for(k=0;klcd_bitmap_part(brickmania_powerups,0, + INT3(POWERUP_HEIGHT)*power[k].type, + STRIDE( SCREEN_MAIN, + BMPWIDTH_brickmania_powerups, + BMPHEIGHT_brickmania_powerups), + INT3(power[k].x_pos - (POWERUP_WIDTH >> 1) ), + INT3(power[k].top), + INT3(POWERUP_WIDTH), + INT3(POWERUP_HEIGHT) ); + } /* Setup the pad line-later used in intersection test */ pad_line.p1.x = pad_pos_x; pad_line.p1.y = PAD_POS_Y; @@ -1482,181 +1616,45 @@ { for (j=0; jlcd_bitmap_part(brickmania_powerups,0, - INT3(POWERUP_HEIGHT)*brick[bnum].power, - STRIDE( SCREEN_MAIN, - BMPWIDTH_brickmania_powerups, - BMPHEIGHT_brickmania_powerups), - INT3(brickx), - INT3(brick[bnum].powertop), - INT3(POWERUP_WIDTH), - INT3(POWERUP_HEIGHT) ); - - /* Use misc_line to check if the center of the powerup - * hit the paddle. - */ - misc_line.p1.x = brickx + (POWERUP_WIDTH >> 1); - misc_line.p1.y = brick[bnum].powertop + POWERUP_HEIGHT; - - misc_line.p2.x = brickx + (POWERUP_WIDTH >> 1); - misc_line.p2.y = SPEED_POWER + brick[bnum].powertop + - POWERUP_HEIGHT; - - /* Check if the powerup will hit the paddle */ - if ( check_lines(&misc_line, &pad_line, &pt_hit) ) - { - switch(brick[bnum].power) { - case 0: /* Extra Life */ - life++; - score += SCORE_POWER_EXTRA_LIFE; - break; - case 1: /* Loose a life */ - life--; - if (life>=0) - { - brickmania_init_game(false); - brickmania_sleep(2); - } - break; - case 2: /* Make the paddle sticky */ - score += SCORE_POWER_STICKY; - pad_type = STICKY; - break; - case 3: /* Give the paddle shooter */ - score += SCORE_POWER_SHOOTER; - pad_type = SHOOTER; - for(k=0;kcurrent_tick+HZ; - flip_sides_delay = FLIP_SIDES_DELAY; - flip_sides = true; - break; - case 6: /* Extra Ball */ - score += SCORE_POWER_EXTRA_BALL; - if(used_ballsrand()%2 == 0) - ball[used_balls].speedx=-SPEED_4Q_X; - else - ball[used_balls].speedx= SPEED_4Q_X; - - ball[used_balls].speedy= SPEED_4Q_Y; - - /* Ball is not glued */ - ball[used_balls].glue= false; - used_balls++; - } - break; - case 7: /* Long paddle */ - score+=SCORE_POWER_LONG_PADDLE; - if (pad_width==PAD_WIDTH) - { - pad_width = LONG_PAD_WIDTH; - pad_pos_x -= (LONG_PAD_WIDTH - - PAD_WIDTH)/2; - } - else if (pad_width==SHORT_PAD_WIDTH) - { - pad_width = PAD_WIDTH; - pad_pos_x-=(PAD_WIDTH- - SHORT_PAD_WIDTH)/2; - } - - if (pad_pos_x < 0) - pad_pos_x = 0; - else if(pad_pos_x + pad_width > - GAMESCREEN_WIDTH) - pad_pos_x = GAMESCREEN_WIDTH-pad_width; - break; - case 8: /* Short Paddle */ - if (pad_width==PAD_WIDTH) - { - pad_width=SHORT_PAD_WIDTH; - pad_pos_x+=(PAD_WIDTH- - SHORT_PAD_WIDTH)/2; - } - else if (pad_width==LONG_PAD_WIDTH) - { - pad_width=PAD_WIDTH; - pad_pos_x+=(LONG_PAD_WIDTH-PAD_WIDTH)/2; - } - break; - } - /* Disable the powerup (it was picked up) */ - brick[bnum].poweruse = false; - } - - if (brick[bnum].powertop>PAD_POS_Y) - { - /* Disable the powerup (it was missed) */ - brick[bnum].poweruse = false; - } - } /* The brick is a brick, but it may or may not be in use */ - else if(brick[bnum].used) + if(brick[bnum].used) { /* these lines are used to describe the brick */ line bot_brick, top_brick, left_brick, rght_brick; brickx = LEFTMARGIN + j*BRICK_WIDTH; + bricky = TOPMARGIN + i*BRICK_HEIGHT; /* Describe the brick for later collision checks */ /* Setup the bottom of the brick */ bot_brick.p1.x = brickx; - bot_brick.p1.y = brick[bnum].powertop + BRICK_HEIGHT; + bot_brick.p1.y = bricky + BRICK_HEIGHT; bot_brick.p2.x = brickx + BRICK_WIDTH; - bot_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT; + bot_brick.p2.y = bricky + BRICK_HEIGHT; /* Setup the top of the brick */ top_brick.p1.x = brickx; - top_brick.p1.y = brick[bnum].powertop; + top_brick.p1.y = bricky; top_brick.p2.x = brickx + BRICK_WIDTH; - top_brick.p2.y = brick[bnum].powertop; + top_brick.p2.y = bricky; /* Setup the left of the brick */ left_brick.p1.x = brickx; - left_brick.p1.y = brick[bnum].powertop; + left_brick.p1.y = bricky; left_brick.p2.x = brickx; - left_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT; + left_brick.p2.y = bricky + BRICK_HEIGHT; /* Setup the right of the brick */ rght_brick.p1.x = brickx + BRICK_WIDTH; - rght_brick.p1.y = brick[bnum].powertop; + rght_brick.p1.y = bricky; rght_brick.p2.x = brickx + BRICK_WIDTH; - rght_brick.p2.y = brick[bnum].powertop + BRICK_HEIGHT; + rght_brick.p2.y = bricky + BRICK_HEIGHT; /* Draw the brick */ rb->lcd_bitmap_part(brickmania_bricks,0, @@ -1665,7 +1663,7 @@ BMPWIDTH_brickmania_bricks, BMPHEIGHT_brickmania_bricks), INT3(brickx), - INT3(brick[bnum].powertop), + INT3(bricky), INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) ); #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */ @@ -1676,7 +1674,7 @@ BMPWIDTH_brickmania_break, BMPHEIGHT_brickmania_break), INT3(brickx), - INT3(brick[bnum].powertop), + INT3(bricky), INT3(BRICK_WIDTH), INT3(BRICK_HEIGHT) ); #endif