void moveBar(unsigned int moveDir,char * barBuffer)
{
putimage(bar_left,bar_top,barBuffer,AND_PUT);
switch (moveDir) {
case BAR_LEFT_MOVE :
if (bar_left > X_MOVE_RANGE_LEFT+10)
bar_left-=10;
break;
case BAR_RIGHT_MOVE:
if (bar_left+BAR_WIDTH < X_MOVE_RANGE_RIGHT-10)
bar_left+=10;
break;
case BAR_UP_MOVE:
if (bar_top-10 >= 200)
bar_top-=10;
break;
case BAR_DOWN_MOVE:
if (bar_top+10 <= 445)
bar_top+=10;
break;
default:
break;
}
for (i=0;i<4;i++)
if (brick_line_first_ptr[i])
return 1;
return 0;
}
int impactLine(int leftTop_y)
{
int line;
/* get brick line number which ball is in */
if ( 50<=leftTop_y && leftTop_y<= 55)
line=1;
if ( 70<=leftTop_y && leftTop_y<= 75)
line=2;
if ( 90<=leftTop_y && leftTop_y<= 95)
line=3;
if ( 110<=leftTop_y && leftTop_y<= 115)
line=4;
return line;
}
BRICK_INFOR_PTR findBrcik_JudgeImpactDir
(int ball_centre_x,int ball_centre_y,
int *impact_dir,int *Line)
{
int isfind=0,impactDir_x,whichLine;
BRICK_INFOR_PTR
check_ptr=NULL;
whichLine=impactLine(ball_centre_y+Y_movedir*5);
if (whichLine)
check_ptr=brick_line_first_ptr[whichLine-1];
if (beHitted_brick)
{
if (beHitted_brick->next && beHitted_brick->pre)
{
beHitted_brick->pre->next=beHitted_brick->next;
beHitted_brick->next->pre=beHitted_brick->pre;
}
else
if (beHitted_brick->pre && !beHitted_brick->next)
{
beHitted_brick->pre->next=NULL; /* if the brick is the last one */
brick_line_last_ptr[Line]=brick_line_last_ptr[Line]->pre;
}
else
if (!beHitted_brick->pre && beHitted_brick->next)
{
beHitted_brick->next->pre=NULL; /* if the brick is the first one */
brick_line_first_ptr[Line]=brick_line_first_ptr[Line]->next;
}
else
brick_line_first_ptr[Line]=NULL;
consecutive_hit+=1;
if (consecutive_hit>=3)
show_hortative_words(&consecutive_hit);
if (impactDir==1)
Y_movedir*=-1;
if (impactDir==2)
X_movedir*=-1;
}
}
void dispose_brick(void)
{
BRICK_INFOR_PTR
temp_brick_ptr;
int i;
for (i=0;i<4;i++)
while (brick_line_first_ptr[i])
{
temp_brick_ptr=brick_line_first_ptr[i];
brick_line_first_ptr[i]=brick_line_first_ptr[i]->next;
free(temp_brick_ptr);
}
}
void show_hortative_words(int *hitNumber)
{
int textCoordinate_top,textCoordinate_Right;
char text[20]="",number;
if (*hitNumber<10)
{
text[0]=*hitNumber+48;
sprintf (text,"%c hit GOOD!!",*hitNumber+48);
outtextxy(200,15,text);
}
else
{
text[0]=*hitNumber/10+48; text[1]=*hitNumber%10+48;
sprintf (text+2," hit PERFECT!!");
outtextxy(200,15,text);
}
}
void initialize_graphic()
{
int graphdriver=VGA,graphmode=VGAHI;
struct ball_information
{
int centre_x;
int centre_y;
int block_left; /* the coordinate of block which ball is in */
int block_top;
};
typedef struct ball_information BALL_INFOR;
while (isFinish())
{
moveBall(&(ball_infor),circleBuffer);
/* use bar to rebound ball */
reboundBall(ball_infor);
/* if the ball is out rebound of range,then quit */
isLoss(ball_infor.centre_y,circleBuffer,barBuffer,brickBuffer);
delay(10000);
/* if (kbhit()) */
moveBar(bioskey(0),barBuffer);
/*50-110 is range of brick line in*/
impactDir_y=ball_infor.centre_y+Y_movedir*CIRCLE_RADIUS;
if (impactDir_y >= 50 && impactDir_y <= 115)
hitBrick(ball_infor.centre_x,ball_infor.centre_y,brickBuffer);
} /* end rebound loop */
#endif
} /* end main program */