=p[i].y_pos-20&&sh.y_pos<=p[i].y_pos+20&&sh.x_pos=p[i+1].y_pos-20&&sh.y_pos<=p[i+1].y_pos+20&&sh.x_pos
=p[i+2].y_pos-20&&sh.y_pos<=p[i+2].y_pos+20&&sh.x_pos
=p[i+3].y_pos-20&&sh.y_pos<=p[i+3].y_pos+20&&sh.x_pos
=p[i].y_pos-20&&sh.y_pos<=p[i].y_pos+20&&sh.x_pos>p[i].x_pos)
{
hit=1;
switch(i)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
else
if(sh.y_pos>=p[i+1].y_pos-20&&sh.y_pos<=p[i+1].y_pos+20&&sh.x_pos>p[i+1].x_pos)
{
hit=1;
switch(i+1)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
else
if(sh.y_pos>=p[i+2].y_pos-20&&sh.y_pos<=p[i+2].y_pos+20&&sh.x_pos>p[i+2].x_pos)
{
hit=1;
switch(i+2)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
else
if(sh.y_pos>=p[i+3].y_pos-20&&sh.y_pos<=p[i+3].y_pos+20&&sh.x_pos>p[i+3].x_pos)
{
hit=1;
switch(i+3)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
setcolor(YELLOW);
line(x-20,y,x-800,y);
setcolor(BLUE);
delay(100);
line(x-20,y,x-800,y);
setcolor(WHITE);
break;
case SOUTH:/*down*/
if(sh.x_pos>=p[i].x_pos-20&&sh.x_pos<=p[i].x_pos+20&&sh.y_pos
=p[i+1].x_pos-20&&sh.x_pos<=p[i+1].x_pos+20&&sh.y_pos
=p[i+2].x_pos-20&&sh.x_pos<=p[i+2].x_pos+20&&sh.y_pos
=p[i+3].x_pos-20&&sh.x_pos<=p[i+3].x_pos+20&&sh.y_pos
=p[i].x_pos-20&&sh.x_pos<=p[i].x_pos+20&&sh.y_pos>p[i].y_pos)
{
hit=1;
switch(i)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
else
if(sh.x_pos>=p[i+1].x_pos-20&&sh.x_pos<=p[i+1].x_pos+20&&sh.y_pos>p[i+1].y_pos)
{
hit=1;
switch(i+1)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
else
if(sh.x_pos>=p[i+2].x_pos-20&&sh.x_pos<=p[i+2].x_pos+20&&sh.y_pos>p[i+2].y_pos)
{
hit=1;
switch(i+2)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
else
if(sh.x_pos>=p[i+3].x_pos-20&&sh.x_pos<=p[i+3].x_pos+20&&sh.y_pos>p[i+3].y_pos)
{
hit=1;
switch(i+3)
{
case 0: ltr=1; break;
case 1: ttb=1; break;
case 2: rtl=1; break;
case 3: btt=1; break;
}
}
setcolor(YELLOW);
line(x,y-20,x,y-800);
setcolor(BLUE);
delay(100);
line(x,y-20,x,y-800);
setcolor(WHITE);
break;
}
for(i=0;i<=3;i++)
{
p[i].x_pos=0;
p[i].y_pos=0;
}
/*refreshing the record*/
return(hit);
/* of a positions*/
}
/*draws the green boxes */
int environment(int x,int y,int pos)
{
int i;
p[pos].x_pos=x;
p[pos].y_pos=y;
/*conditions to check for collision
checks whether the center of box x,y is within the area
(sh_xpos-20,sh_ypos-20)
(sh_xpos+20,sh_ypos+20)*/
if(x>=sh.x_pos-20&&x<=sh.x_pos+20&&y>=sh.y_pos-20&&y<=sh.y_pos+20)
{
put_banner();
getch();
closegraph();
restorecrtmode();
gotoxy(30,12);
textcolor(YELLOW);
cprintf("YOU HAVE SCORED :%d",hitcount);
getch();
exit(0);
}
setfillstyle(SOLID_FILL,LIGHTGREEN);
bar(x-10,y-10,x+10,y+10);
delay(20);
setfillstyle(SOLID_FILL,BLUE);
bar(x-10,y-10,x+10,y+10);
setcolor(WHITE);
return(0);
}
/*puts a banner at the End of Game*/
int put_banner()
{
setcolor(YELLOW);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
outtextxy((getmaxx()/2)-260,(getmaxy()/2)-20,"SORRY YOU`VE BEEN HIT");
return 0;
}
void refresh(void)
{
int i;
for(i=0;i<4;i++)
{
p[i].x_pos=0;
p[i].y_pos=0;
}
}