Index: apps/plugins/brickmania.c =================================================================== --- apps/plugins/brickmania.c (revision 22348) +++ apps/plugins/brickmania.c (working copy) @@ -222,25 +222,25 @@ #define SCROLL_BACK(x) (0) #endif -#include "pluginbitmaps/brickmania_pads.h" -#include "pluginbitmaps/brickmania_short_pads.h" -#include "pluginbitmaps/brickmania_long_pads.h" +#include "pluginbitmaps/brickmania_left_pads.h" +#include "pluginbitmaps/brickmania_right_pads.h" +#include "pluginbitmaps/brickmania_middle_pads.h" #include "pluginbitmaps/brickmania_bricks.h" #include "pluginbitmaps/brickmania_powerups.h" #include "pluginbitmaps/brickmania_ball.h" #include "pluginbitmaps/brickmania_gameover.h" -#define PAD_WIDTH BMPWIDTH_brickmania_pads -#define PAD_HEIGHT (BMPHEIGHT_brickmania_pads/3) -#define SHORT_PAD_WIDTH BMPWIDTH_brickmania_short_pads -#define LONG_PAD_WIDTH BMPWIDTH_brickmania_long_pads +#define PAD_EDGE BMPWIDTH_brickmania_left_pads +#define PAD_UNIT BMPWIDTH_brickmania_middle_pads +#define PAD_HEIGHT (BMPHEIGHT_brickmania_middle_pads/3) #define BRICK_HEIGHT (BMPHEIGHT_brickmania_bricks/7) #define BRICK_WIDTH BMPWIDTH_brickmania_bricks #define LEFTMARGIN ((LCD_WIDTH-10*BRICK_WIDTH)/2) -#define POWERUP_HEIGHT (BMPHEIGHT_brickmania_powerups/9) +#define POWERUP_NUM 9 +#define POWERUP_HEIGHT (BMPHEIGHT_brickmania_powerups/POWERUP_NUM) #define POWERUP_WIDTH BMPWIDTH_brickmania_powerups #define BALL BMPHEIGHT_brickmania_ball -#define HALFBALL ((BALL+1)/2) +#define HALFBALL (BALL/2) #define GAMEOVER_WIDTH BMPWIDTH_brickmania_gameover #define GAMEOVER_HEIGHT BMPHEIGHT_brickmania_gameover @@ -272,9 +272,9 @@ #define PAD_POS_Y (GAMESCREEN_HEIGHT - PAD_HEIGHT - 1) -int levels_num = 29; +#define LEVELS_NUM 29 -static unsigned char levels[29][8][10] = { +static unsigned char levels[LEVELS_NUM][8][10] = { { /* level1 */ {0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1}, {0x2,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x2}, @@ -568,6 +568,11 @@ }; #define MAX_BALLS 10 +#define MAX_FIRES 30 +#define MAX_POWERUPS 10 +#define DEF_UNITS 3 +#define MIN_UNITS 1 +#define MAX_UNITS 5 enum difficulty_options { EASY, NORMAL @@ -576,27 +581,27 @@ int pad_pos_x; int life; enum { ST_READY, ST_START, ST_PAUSE } game_state = ST_READY; -int pad_type; +int pad_type=0; int score=0,vscore=0; bool flip_sides=false; int level=0; int brick_on_board=0; int used_balls=1; +int used_fires=0; +int used_powerups=0; int difficulty = NORMAL; -int pad_width; +int pad_units=DEF_UNITS; +int pad_width=2*PAD_EDGE+DEF_UNITS*PAD_UNIT; int num_count; bool resume = false; typedef struct cube { - int powertop; - int power; - char poweruse; char used; int color; int hits; int hiteffect; } cube; -cube brick[80]; +cube brick[8][10]; typedef struct balls { int pos_x; @@ -614,8 +619,16 @@ int top; int left; } sfire; -sfire fire[30]; +sfire fire[MAX_FIRES]; +typedef struct power { + int type; + int top; + int left; +} power; + +power powerup[MAX_POWERUPS]; + #define CONFIG_FILE_NAME "brickmania.cfg" #define SAVE_FILE PLUGIN_GAMES_DIR "/brickmania.save" #define HIGH_SCORE PLUGIN_GAMES_DIR "/brickmania.score" @@ -630,9 +643,10 @@ static void brickmania_init_game(int new_game) { int i,j; + pad_units=DEF_UNITS; + pad_width=2*PAD_EDGE+DEF_UNITS*PAD_UNIT; + pad_pos_x=LCD_WIDTH/2-pad_width/2; - pad_pos_x=LCD_WIDTH/2-PAD_WIDTH/2; - for(i=0;irand()%25; - /* +8 make the game with less powerups */ - - brick[i*10+j].hits=levels[level][i][j]>=10? + for(i=0;i<8;i++) { + for(j=0;j<10;j++) { + brick[i][j].hits=levels[level][i][j]>=10? levels[level][i][j]/16-1:0; - brick[i*10+j].hiteffect=0; - brick[i*10+j].powertop=TOPMARGIN+i*BRICK_HEIGHT+BRICK_HEIGHT; - brick[i*10+j].used=(levels[level][i][j]==0?0:1); - brick[i*10+j].color=(levels[level][i][j]>=10? + brick[i][j].hiteffect=0; + brick[i][j].used=(levels[level][i][j]==0?0:1); + brick[i][j].color=(levels[level][i][j]>=10? levels[level][i][j]%16: levels[level][i][j])-1; if (levels[level][i][j]!=0) brick_on_board++; } } + /* add one life per achieved level */ + if (difficulty==EASY && life<2) { + score-=100; + life++; + } } } @@ -704,11 +709,16 @@ if(rb->read(fd, &level, sizeof(level)) <= 0) break; if(rb->read(fd, &brick_on_board, sizeof(brick_on_board)) <= 0) break; if(rb->read(fd, &used_balls, sizeof(used_balls)) <= 0) break; + if(rb->read(fd, &used_fires, sizeof(used_fires)) <= 0) break; + if(rb->read(fd, &used_powerups, sizeof(used_powerups)) <= 0) break; if(rb->read(fd, &pad_width, sizeof(pad_width)) <= 0) break; if(rb->read(fd, &num_count, sizeof(num_count)) <= 0) break; if(rb->read(fd, &brick, sizeof(brick)) <= 0) break; if(rb->read(fd, &ball, sizeof(ball)) <= 0) break; if(rb->read(fd, &fire, sizeof(fire)) <= 0) break; + if(rb->read(fd, &powerup, sizeof(powerup)) <= 0) break; + if(rb->read(fd, &pad_units, sizeof(pad_units)) <= 0) break; + pad_width=2*PAD_EDGE+pad_units*PAD_UNIT; vscore = score; resume = true; break; @@ -736,44 +746,43 @@ rb->write(fd, &level, sizeof(level)); rb->write(fd, &brick_on_board, sizeof(brick_on_board)); rb->write(fd, &used_balls, sizeof(used_balls)); + rb->write(fd, &used_fires, sizeof(used_fires)); + rb->write(fd, &used_powerups, sizeof(used_powerups)); rb->write(fd, &pad_width, sizeof(pad_width)); rb->write(fd, &num_count, sizeof(num_count)); rb->write(fd, &brick, sizeof(brick)); rb->write(fd, &ball, sizeof(ball)); rb->write(fd, &fire, sizeof(fire)); + rb->write(fd, &powerup, sizeof(powerup)); + rb->write(fd, &pad_units, sizeof(pad_units)); rb->close(fd); } /* brickmania_sleep timer counting the score */ static void brickmania_sleep(int secs) { - bool done=false; char s[20]; int count=0; int sw, w; - while (!done) { - if (vscore == score) { - if (count==0) - count=*rb->current_tick+HZ*secs; - if (*rb->current_tick>=count) - done=true; - } else { - if (vscorescore) - vscore--; - rb->snprintf(s, sizeof(s), "%d", vscore); - rb->lcd_getstringsize(s, &sw, &w); + while (vscore != score) { + if (vscoresnprintf(s, sizeof(s), "%d", vscore); + rb->lcd_getstringsize(s, &sw, &w); #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) - rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s); + rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s); #else - rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s); + rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 2, s); #endif - rb->lcd_update_rect(0,0,LCD_WIDTH,w+2); - } + rb->lcd_update_rect(0,0,LCD_WIDTH,w+2); rb->yield(); } + count=*rb->current_tick+HZ*secs; + while (*rb->current_tickyield(); } static int brickmania_help(void) @@ -823,8 +832,8 @@ "G", "Glue:", "ball", "sticks", "to", "paddle", "", "B", "Ball:", "generates", "another", "ball", "", "FL", "Flip:", "flips", "left / right", "movement", "", - "<->", "or", ":", "enlarges", "the", "paddle", "", - ">-<", "or", ">S<:", "shrinks", "the", "paddle", "", + "<->", "or", "", ":", "enlarges", "the", "paddle", "", + ">-<", "or", ">S<", ":", "shrinks", "the", "paddle", "", }; static struct style_text formation[]={ { 0, TEXT_CENTER|TEXT_UNDERLINE }, @@ -838,6 +847,10 @@ { 67, C_GREEN }, { 74, C_YELLOW }, { 80, C_RED }, + { 86, C_GREEN }, + { 88, C_GREEN }, + { 94, C_BLUE }, + { 96, C_BLUE }, { -1, 0 } }; int button; @@ -929,50 +942,43 @@ } } -static int brickmania_pad_check(int ballxc, int mode, int pon ,int ballnum) +static void brickmania_brick_hit(int i,int j) { - /* pon: positive(1) or negative(0) */ - - if (mode==0) { - if (pon == 0) - return -ballxc; - else - return ballxc; - } else { - if (ball[ballnum].x > 0) - return ballxc; - else - return ballxc*-1; + if (brick[i][j].hits > 0) { + brick[i][j].hits--; + brick[i][j].hiteffect++; + score+=2; } + else { + int t; + t=rb->rand()%25; + if (tcurrent_tick; while(true) { /* Convert CYCLETIME (in ms) to HZ */ - end = *rb->current_tick + (CYCLETIME * HZ) / 1000; - + end+=(CYCLETIME * HZ) / 1000; if (life >= 0) { #ifdef HAVE_LCD_COLOR rb->lcd_set_background(LCD_BLACK); @@ -991,8 +997,8 @@ if (flip_sides) { if (*rb->current_tick>=sec_count) { - sec_count=*rb->current_tick+HZ; - if (num_count!=0) + sec_count+=HZ; + if (num_count!=1) num_count--; else flip_sides=false; @@ -1022,11 +1028,7 @@ if (vscoresnprintf(s, sizeof(s), "%d", vscore); rb->lcd_getstringsize(s, &sw, NULL); -#if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s); -#else - rb->lcd_putsxy(LCD_WIDTH/2-sw/2, 0, s); -#endif /* continue game */ if (game_state==ST_PAUSE) { @@ -1053,322 +1055,193 @@ if (brick_on_board==0) brick_on_board--; - /* if the pad is fire */ - for(i=0;i<30;i++) { - if (fire[i].top+7>0) { - if (game_state!=ST_PAUSE) - fire[i].top-=4; - rb->lcd_vline(fire[i].left, fire[i].top, fire[i].top+7); + /* check fires */ + for(k=0;k=TOPMARGIN && fire[k].top=LEFTMARGIN && fire[k].leftlcd_vline(fire[k].left, fire[k].top, fire[k].top+7); } - /* the bricks */ - for (i=0;i<=7;i++) { - for (j=0;j<=9;j++) { - if (brick[i*10+j].power<9) { - if (brick[i*10+j].poweruse==2) { - if (game_state!=ST_PAUSE) - brick[i*10+j].powertop+=2; - rb->lcd_bitmap_part(brickmania_powerups,0, - POWERUP_HEIGHT*brick[i*10+j - ].power, - POWERUP_WIDTH, - LEFTMARGIN+j*BRICK_WIDTH+ - (BRICK_WIDTH/2-POWERUP_WIDTH/2), - brick[i*10+j].powertop, - POWERUP_WIDTH, - POWERUP_HEIGHT); - } - } - - if ((pad_pos_xLEFTMARGIN+j*BRICK_WIDTH+5) && - brick[i*10+j].powertop+6>=PAD_POS_Y && - brick[i*10+j].poweruse==2) { - switch(brick[i*10+j].power) { - case 0: - life++; - score+=50; - break; - case 1: - life--; - if (life>=0) { - brickmania_init_game(0); - brickmania_sleep(2); + /* the powerups */ + for(i=0;ipowerup[i].left) && + powerup[i].top+POWERUP_HEIGHT>=PAD_POS_Y) { + switch(powerup[i].type) { + case 0: + life++; + score+=50; + break; + case 1: + life--; + if (life>=0) { + brickmania_init_game(0); + brickmania_sleep(2); + end = *rb->current_tick; + } + break; + case 2: + score+=34; + pad_type=1; + break; + case 3: + score+=47; + pad_type=2; + for(k=0;k LCD_WIDTH) + pad_pos_x = LCD_WIDTH-pad_width; + for (k=0;k=pad_pos_x+pad_width) + ball[k].pos_x=pad_pos_x+pad_width-1; } - break; - case 2: - score+=34; - pad_type=1; - break; - case 3: - score+=47; - pad_type=2; - for(k=0;kcurrent_tick+HZ; - num_count=10; - flip_sides=!flip_sides; - break; - case 6: - score+=23; - if(used_ballsrand()%2 == 0 ? - -1 : 1; - ball[used_balls].y= -4; - ball[used_balls].glue= false; - used_balls++; + for(k=0;kcurrent_tick+HZ; + num_count=10; + flip_sides=!flip_sides; + break; + case 6: + score+=23; + if (used_ballsrand()%2==0?-1:1; + ball[used_balls].y=-4; + ball[used_balls].tempy=0; + ball[used_balls].tempx=0; + ball[used_balls].pos_y=PAD_POS_Y-BALL; +// ball[used_balls].pos_x=pad_pos_x+(pad_width/2)-2; + ball[used_balls].pos_x=powerup[i].left+(POWERUP_WIDTH-BALL)/2; + ball[used_balls].glue=false; + used_balls++; + } + break; + case 7: + score+=23; + if (pad_units LCD_WIDTH) + pad_pos_x = LCD_WIDTH-pad_width; + break; + case 8: + if (pad_units>MIN_UNITS) { + pad_units--; + pad_width-=PAD_UNIT; + pad_pos_x+=PAD_UNIT/2; + for (k=0;k=pad_pos_x+pad_width) + ball[k].pos_x=pad_pos_x+pad_width-1; } - break; - case 7: - score+=23; - 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 > LCD_WIDTH) - pad_pos_x = LCD_WIDTH-pad_width; - break; - case 8: - 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; - } - brick[i*10+j].poweruse=1; - } - - if (brick[i*10+j].powertop>PAD_POS_Y) - brick[i*10+j].poweruse=1; - - brickx=LEFTMARGIN+j*BRICK_WIDTH; - bricky=TOPMARGIN+i*BRICK_HEIGHT; - if (pad_type==2) { - for (k=0;k<30;k++) { - if (fire[k].top+7>0) { - if (brick[i*10+j].used==1 && - (fire[k].left+1 >= brickx && - fire[k].left+1 <= brickx+BRICK_WIDTH) && - (bricky+BRICK_HEIGHT>fire[k].top)) { - score+=13; - fire[k].top=-16; - if (brick[i*10+j].hits > 0) { - brick[i*10+j].hits--; - brick[i*10+j].hiteffect++; - score+=3; - } - else { - brick[i*10+j].used=0; - if (brick[i*10+j].power!=10) - brick[i*10+j].poweruse=2; - brick_on_board--; - } - } } - } + break; } + used_powerups--; + powerup[i].type=powerup[used_powerups].type; + powerup[i].left=powerup[used_powerups].left; + powerup[i].top=powerup[used_powerups].top; + i--; + } + else if (powerup[i].top>PAD_POS_Y) { + used_powerups--; + powerup[i].type=powerup[used_powerups].type; + powerup[i].left=powerup[used_powerups].left; + powerup[i].top=powerup[used_powerups].top; + i--; + } + else + rb->lcd_bitmap_part(brickmania_powerups,0,POWERUP_HEIGHT*powerup[i].type,POWERUP_WIDTH, + powerup[i].left,powerup[i].top,POWERUP_WIDTH,POWERUP_HEIGHT); + } - if (brick[i*10+j].used==1) { + /* the bricks */ + for (i=0;i<8;i++) { + for (j=0;j<10;j++) { + if (brick[i][j].used==1) { rb->lcd_bitmap_part(brickmania_bricks,0, - BRICK_HEIGHT*brick[i*10+j].color, + BRICK_HEIGHT*brick[i][j].color, BRICK_WIDTH, LEFTMARGIN+j*BRICK_WIDTH, TOPMARGIN+i*BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT); #ifdef HAVE_LCD_COLOR /* No transparent effect for greyscale lcds for now */ - if (brick[i*10+j].hiteffect>0) + if (brick[i][j].hiteffect>0) rb->lcd_bitmap_transparent_part(brickmania_break,0, - BRICK_HEIGHT*brick[i*10+j].hiteffect, + BRICK_HEIGHT*brick[i][j].hiteffect, BRICK_WIDTH, LEFTMARGIN+j*BRICK_WIDTH, TOPMARGIN+i*BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT); #endif } - /* Somewhere in here collision checking is done b/w ball and - * brick. - */ - for(k=0;k= - brickx && - ball[k].pos_x+ball[k].x+HALFBALL <= - brickx+BRICK_WIDTH) && - ((bricky-4ball[k].pos_y+BALL) || - (bricky+4>ball[k].pos_y+BALL+BALL && - bricky0)) { - ball[k].tempy=bricky-ball[k].pos_y-BALL; - } - else if ((ball[k].pos_x+ball[k].x+HALFBALL >= - brickx && - ball[k].pos_x+ball[k].x+HALFBALL <= - brickx+BRICK_WIDTH) && - ((bricky+BRICK_HEIGHT+4>ball[k].pos_y && - bricky+BRICK_HEIGHTball[k].pos_y-BALL)) && - (ball[k].y <0)) { - ball[k].tempy= - -(ball[k].pos_y-(bricky+BRICK_HEIGHT)); - } - - if ((ball[k].pos_y+HALFBALL >= - bricky && - ball[k].pos_y+HALFBALL <= - bricky+BRICK_HEIGHT) && - ((brickx-4ball[k].pos_x+BALL) || - (brickx+4>ball[k].pos_x+BALL+BALL && - brickx0)) { - ball[k].tempx=brickx-ball[k].pos_x-BALL; - } - else if ((ball[k].pos_y+ball[k].y+HALFBALL >= - bricky && - ball[k].pos_y+ball[k].y+HALFBALL <= - bricky+BRICK_HEIGHT) && - ((brickx+BRICK_WIDTH+4>ball[k].pos_x && - brickx+BRICK_WIDTHball[k].pos_x- - BALL)) && (ball[k].x <0)) { - ball[k].tempx= - -(ball[k].pos_x-(brickx+BRICK_WIDTH)); - } - - if ((ball[k].pos_x+HALFBALL >= brickx && - ball[k].pos_x+HALFBALL <= - brickx+BRICK_WIDTH) && - ((bricky+BRICK_HEIGHT==ball[k].pos_y) || - (bricky+BRICK_HEIGHT-6<=ball[k].pos_y && - bricky+BRICK_HEIGHT>ball[k].pos_y)) && - (ball[k].y <0)) { /* bottom line */ - if (brick[i*10+j].hits > 0) { - brick[i*10+j].hits--; - brick[i*10+j].hiteffect++; - score+=2; - } - else { - brick[i*10+j].used=0; - if (brick[i*10+j].power!=10) - brick[i*10+j].poweruse=2; - } - - ball[k].y = ball[k].y*-1; - } - else if ((ball[k].pos_x+HALFBALL >= brickx && - ball[k].pos_x+HALFBALL <= - brickx+BRICK_WIDTH) && - ((bricky==ball[k].pos_y+BALL) || - (bricky+6>=ball[k].pos_y+BALL && - bricky0)) { /* top line */ - if (brick[i*10+j].hits > 0) { - brick[i*10+j].hits--; - brick[i*10+j].hiteffect++; - score+=2; - } - else { - brick[i*10+j].used=0; - if (brick[i*10+j].power!=10) - brick[i*10+j].poweruse=2; - } - - ball[k].y = ball[k].y*-1; - } - - if ((ball[k].pos_y+HALFBALL >= bricky && - ball[k].pos_y+HALFBALL <= - bricky+BRICK_HEIGHT) && - ((brickx==ball[k].pos_x+BALL) || - (brickx+6>=ball[k].pos_x+BALL && - brickx 0)) { /* left line */ - if (brick[i*10+j].hits > 0) { - brick[i*10+j].hits--; - brick[i*10+j].hiteffect++; - score+=2; - } - else { - brick[i*10+j].used=0; - if (brick[i*10+j].power!=10) - brick[i*10+j].poweruse=2; - } - ball[k].x = ball[k].x*-1; - - } - else if ((ball[k].pos_y+HALFBALL >= bricky && - ball[k].pos_y+HALFBALL <= - bricky+BRICK_HEIGHT) && - ((brickx+BRICK_WIDTH== - ball[k].pos_x) || - (brickx+BRICK_WIDTH-6<= - ball[k].pos_x && - brickx+BRICK_WIDTH> - ball[k].pos_x)) && - (ball[k].x < 0)) { /* Right line */ - if (brick[i*10+j].hits > 0) { - brick[i*10+j].hits--; - brick[i*10+j].hiteffect++; - score+=2; - } - else { - brick[i*10+j].used=0; - if (brick[i*10+j].power!=10) - brick[i*10+j].poweruse=2; - } - - ball[k].x = ball[k].x*-1; - } - - if (brick[i*10+j].used==0) { - brick_on_board--; - score+=8; - } - } - } - } /* for k */ } /* for j */ } /* for i */ /* draw the pad */ - rb->lcd_bitmap_part(pad_width==PAD_WIDTH?brickmania_pads: - pad_width==LONG_PAD_WIDTH?brickmania_long_pads: - brickmania_short_pads, - 0,pad_type*PAD_HEIGHT,pad_width, - pad_pos_x, PAD_POS_Y, pad_width, PAD_HEIGHT); + rb->lcd_bitmap_part(brickmania_left_pads,0,pad_type*PAD_HEIGHT,PAD_EDGE,pad_pos_x,PAD_POS_Y,PAD_EDGE,PAD_HEIGHT); + for (k=0;klcd_bitmap_part(brickmania_middle_pads,0,pad_type*PAD_HEIGHT,PAD_UNIT,pad_pos_x+PAD_EDGE+k*PAD_UNIT,PAD_POS_Y,PAD_UNIT,PAD_HEIGHT); + rb->lcd_bitmap_part(brickmania_right_pads,0,pad_type*PAD_HEIGHT,PAD_EDGE,pad_pos_x+PAD_EDGE+pad_units*PAD_UNIT,PAD_POS_Y,PAD_EDGE,PAD_HEIGHT); + /* the balls */ if (game_state!=ST_PAUSE) { for(k=0;k0?BALL-1:0))/BRICK_HEIGHT-1; + j=(ball[k].pos_x+HALFBALL-LEFTMARGIN+BRICK_WIDTH)/BRICK_WIDTH-1; + if (i>=0 && i<8 && j>=0 && j<10 && brick[i][j].used==1) { + ball[k].tempy = TOPMARGIN+BRICK_HEIGHT*i+(ball[k].y>0?-BALL:BRICK_HEIGHT)-ball[k].pos_y; + brickmania_brick_hit(i,j); + ball[k].y *= -1; + } + i=(ball[k].pos_y+HALFBALL-TOPMARGIN+BRICK_HEIGHT)/BRICK_HEIGHT-1; + j=(ball[k].pos_x+ball[k].x-LEFTMARGIN+BRICK_WIDTH+(ball[k].x>0?BALL-1:0))/BRICK_WIDTH-1; + if (i>=0 && i<8 && j>=0 && j<10 && brick[i][j].used==1) { + ball[k].tempx = LEFTMARGIN+BRICK_WIDTH*j+(ball[k].x>0?-BALL:BRICK_WIDTH)-ball[k].pos_x; + brickmania_brick_hit(i,j); + ball[k].x *= -1; + } - if ((ball[k].pos_x >= pad_pos_x && + if ((ball[k].pos_x + BALL > pad_pos_x && ball[k].pos_x <= pad_pos_x+pad_width) && (PAD_POS_Y-4ball[k].pos_y+BALL) && (ball[k].y >0)) @@ -1382,10 +1255,11 @@ else if ((4>ball[k].pos_x && 0= GAMESCREEN_HEIGHT) { if (used_balls>1) { @@ -1397,14 +1271,6 @@ ball[k].x = ball[used_balls].x; ball[k].tempx = ball[used_balls].tempx; ball[k].glue = ball[used_balls].glue; - - ball[used_balls].x=0; - ball[used_balls].y=0; - ball[used_balls].tempy=0; - ball[used_balls].tempx=0; - ball[used_balls].pos_y=PAD_POS_Y-BALL; - ball[used_balls].pos_x=pad_pos_x+(pad_width/2)-2; - k--; continue; } else { @@ -1412,6 +1278,7 @@ if (life>=0) { brickmania_init_game(0); brickmania_sleep(2); + end = *rb->current_tick; } } } @@ -1424,78 +1291,61 @@ } if ((ball[k].pos_y+BALL >= PAD_POS_Y && - (ball[k].pos_x >= pad_pos_x && - ball[k].pos_x <= pad_pos_x+pad_width)) && - game_state!=ST_READY && !ball[k].glue) { - - if ((ball[k].pos_x+HALFBALL >= pad_pos_x && - ball[k].pos_x+HALFBALL <= - pad_pos_x+(pad_width/2/4)) || - (ball[k].pos_x +HALFBALL>= - pad_pos_x+(pad_width-(pad_width/2/4)) && - ball[k].pos_x+HALFBALL <= pad_pos_x+pad_width)) { - - ball[k].y = -2; - if (ball[k].pos_x != 0 && - ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = brickmania_pad_check(6,0, - ball[k].pos_x+2<=pad_pos_x+ - (pad_width/2)?0:1,k); - + (ball[k].pos_x+BALL > pad_pos_x && + ball[k].pos_x < pad_pos_x+pad_width)) && + game_state!=ST_READY && !ball[k].glue) { + if (pad_type==1 && ball[k].y>0) { + ball[k].y=0; + ball[k].pos_y=PAD_POS_Y-BALL; + ball[k].glue=true; } - else if ((ball[k].pos_x+HALFBALL >= - pad_pos_x+(pad_width/2/4) && - ball[k].pos_x+HALFBALL <= - pad_pos_x+2*(pad_width/2/4)) || - (ball[k].pos_x+HALFBALL >= - pad_pos_x+(pad_width-2*(pad_width/2/4)) && - ball[k].pos_x+HALFBALL <= - pad_pos_x+(pad_width-(pad_width/2/4)) )) { - - ball[k].y = -3; - if (ball[k].pos_x != 0 && - ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = brickmania_pad_check(4,0, - ball[k].pos_x+2<=pad_pos_x+ - (pad_width/2)?0:1,k); - - } - else if ((ball[k].pos_x+HALFBALL >= - pad_pos_x+2*(pad_width/2/4) && - ball[k].pos_x+HALFBALL <= - pad_pos_x+3*(pad_width/2/4)) || - (ball[k].pos_x+2 >= - pad_pos_x+(pad_width-3*(pad_width/2/4)) && - ball[k].pos_x+2 <= - pad_pos_x+ ((pad_width/2)-2*(pad_width/2/4)) )) { - - ball[k].y = -4; - if (ball[k].pos_x != 0 && - ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = brickmania_pad_check(3,0, - ball[k].pos_x+2<=pad_pos_x+ - (pad_width/2)?0:1,k); - - } - else if ((ball[k].pos_x+HALFBALL >= - pad_pos_x+3*(pad_width/2/4) && - ball[k].pos_x+HALFBALL <= - pad_pos_x+4*(pad_width/2/4)-2) || - (ball[k].pos_x+2 >= pad_pos_x+(pad_width/2+2) && - ball[k].pos_x+2 <= - pad_pos_x+(pad_width-3*(pad_width/2/4)) )) { - - ball[k].y = -4; - if (ball[k].pos_x != 0 && - ball[k].pos_x+BALL!=LCD_WIDTH) - ball[k].x = brickmania_pad_check(2,1,0,k); - - } else { - ball[k].y = -4; + switch (((ball[k].pos_x+HALFBALL-(pad_pos_x+PAD_EDGE))*7+3+(pad_units*PAD_UNIT))/ + (pad_units*PAD_UNIT)) { + case 1: + ball[k].y=-3; + i=-4; + break; + case 2: + ball[k].y=-4; + i=-3; + break; + case 3: + ball[k].y=-4; + i=ball[k].x>0?2:-2; + break; + case 4: + ball[k].y=-4; + i=ball[k].x; + break; + case 5: + ball[k].y=-4; + i=ball[k].x>0?2:-2; + break; + case 6: + ball[k].y=-4; + i=3; + break; + case 7: + ball[k].y=-3; + i=4; + break; + default: + /* left edge */ + if (ball[k].pos_x+HALFBALL < pad_pos_x+PAD_EDGE) { + ball[k].y=-2; + i=-6; + } + /* right edge */ + else { + ball[k].y=-2; + i=6; + } + } + if (ball[k].pos_x != 0 && ball[k].pos_x != LCD_WIDTH-BALL) + ball[k].x = i; } } - if (!ball[k].glue) { ball[k].pos_x+=ball[k].tempx!=0?ball[k].tempx:ball[k].x; ball[k].pos_y+=ball[k].tempy!=0?ball[k].tempy:ball[k].y; @@ -1503,27 +1353,18 @@ ball[k].tempy=0; ball[k].tempx=0; } - - if (ball[k].pos_y+5 >= PAD_POS_Y && - (pad_type==1 && !ball[k].glue) && - (ball[k].pos_x >= pad_pos_x && - ball[k].pos_x <= pad_pos_x+pad_width)) { - ball[k].y=0; - ball[k].pos_y=PAD_POS_Y-BALL; - ball[k].glue=true; - } } /* for k */ } rb->lcd_update(); if (brick_on_board < 0) { - if (level+1current_tick; } else { rb->lcd_getstringsize("Congratulations!", &sw, NULL); @@ -1555,26 +1396,16 @@ if (rb->button_hold()) button = QUIT; #endif - + i=0; #ifdef HAVE_TOUCHSCREEN if(button & BUTTON_TOUCHSCREEN) { short touch_x, touch_y; touch_x = rb->button_get_data() >> 16; touch_y = rb->button_get_data() & 0xffff; - if(touch_y >= PAD_POS_Y && touch_y <= PAD_POS_Y+PAD_HEIGHT) - { - pad_pos_x += (flip_sides ? -1 : 1) * ( (touch_x-pad_pos_x-pad_width/2) / 4 ); + if(touch_y >= PAD_POS_Y && touch_y < PAD_POS_Y+PAD_HEIGHT) + i =(touch_x-pad_pos_x-pad_width/2) / 4; - if(pad_pos_x < 0) - pad_pos_x = 0; - else if(pad_pos_x+pad_width > LCD_WIDTH) - pad_pos_x = LCD_WIDTH-pad_width; - for(k=0;k LCD_WIDTH) { - for(k=0;k LCD_WIDTH) + i = LCD_WIDTH-pad_width-pad_pos_x; + pad_pos_x+=i; + for(k=0;k