Coptor




#include <iostream.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>


union REGS in,out;


void blades(int x , int y ,int spin,int size)
{
setcolor(CYAN);
setfillstyle(SOLID_FILL,CYAN);
sector(x+50,y,spin+0,spin+20,size,10);
sector(x+50,y,spin+180,spin+200,size,10);
}


void copterbody(int x , int y)
{
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
bar(x+49,y,x+52,y+5);
fillellipse(x+50,y+20,30,15);
bar(x+30,y+40,x+70,y+42);
sector(x+45,y+32,220,240,10,10);
sector(x+55,y+32,310,330,10,10);
bar(x-10,y+20,x+40,y+30);
fillellipse(x-10,y+20,8,8);
setcolor(BLUE);
setfillstyle(SOLID_FILL,BLUE);
sector(x+50,y+20,0,90,30,15);
}


void erase(int x , int y , int w1x , int w1y ,int w2x , int w2y , int hard)
{
setfillstyle(SOLID_FILL,BLACK);
bar(x-20,y-15,x+100,y+50);
bar(w1x,w1y,w1x+25,w1y+80+hard);
bar(w2x,w2y,w2x+25,w2y+80+hard);
}


int main()
{
int gd=DETECT,gm,x,y,spin=0,cl=0,ch,w1x,w1y,w2x,w2y,score=0,hard=0;
clrscr();
randomize();
initgraph(&gd,&gm,"c:\\tc\\bgi");
y=getmaxy()/2;
x=getmaxx()/4;
w1x=getmaxx();
w1y=getmaxy()/2;
w2x=getmaxx();
w2y=getmaxy()/2;
in.x.ax=1;
in.x.ax=2;
int86(51,&in,&out);
setfillstyle(INTERLEAVE_FILL,1);
bar(0,getmaxy()-60,getmaxx(),getmaxy());
bar(0,0,getmaxx(),60);
gotoxy(30,20);
cout<<"click to start the game";
while(cl==0)
{
in.x.ax=3;
int86(51,&in,&out);
cl=out.x.bx;
}
gotoxy(30,20);
cout<<"                       ";


while(1)
{
gotoxy(37,28);
cout<<"Score="<<score++;
w1x-=5;
w2x-=5;


setfillstyle(HATCH_FILL,2);
bar(w1x,w1y,w1x+25,w1y+80+hard);
bar(w2x,w2y,w2x+25,w2y+80+hard);
copterbody(x,y);
blades(x,y,spin,50);
blades(x-60,y+20,spin,5);
sound(700);
delay(10);
sound(800);
delay(10);
sound(900);
delay(10);


if(kbhit())
{
ch=getch();
if(ch==27)
{
delay(1000);
closegraph();
return 0;
}
else if(ch==112)
{
gotoxy(35,20);
cout<<"Game Paused";
while(!kbhit())
{}
gotoxy(35,20);
cout<<"           ";
}
}
else if(cl==0)
{
y+=4;
}
else if(cl==2)
{
y-=7;
}
else
{
y-=4;
}
if((y<70||y>getmaxy()-104) || (x+80>w1x && x-10<w1x+25 && y<w1y+80 && y+35>w1y || x+80>w2x && x-10<w2x+25 && y<w2y+80 && y+35>w2y))
{
gotoxy(35,17);
cout<<"You Crashed";
gotoxy(35,21);
cout<<" Game over";
delay(1000);
closegraph();
return 0;
}


erase(x,y,w1x,w1y,w2x,w2y,hard);
in.x.ax=3;
int86(51,&in,&out);
cl=out.x.bx;
if(w2x==getmaxx()/2)
{
w1x=getmaxx();
w1y=random(getmaxy()-200-hard)+60;
}
if(w1x==getmaxx()/2)
{
w2x=getmaxx();
w2y=random(getmaxy()-200-hard)+60;
if(hard<50)
hard+=2;
}


if(spin==160)
{
spin+=20;
}
else if(spin==340)
{
spin=0;
}
spin+=40;
}//end of while
}//end of main

Comments

Popular Posts