A simple simple ball which is bouncing....
#include dos.h
#include iostream.h
#include graphics.h
#include math.h
#include conio.h
void main()
{
int d=DETECT,m;
initgraph(&d,&m,"e:\tcc\bgi");
float x=1,y=0.00000,j=.5,count=.1;
float r=15;
setcolor(14);
line(0,215,650,215);
sleep(1);
for(int k=0;k<=7;k++)
{
for(float i=90;i<270;i+=10)
{
y=cos(((i*22/7)/180))/j;
if(y>0)
y=-y;
x+=5;
setcolor(14);
setfillstyle(1,14);
circle(x,y*100+200,r);
floodfill(x,y*100+200,14);
delay(100);
setcolor(0);
setfillstyle(1,0);
circle(x,y*100+200,r);
floodfill(x,y*100+200,0);
}
j+=count;
count+=.1;
}
getch();
}
Wednesday, October 15, 2008
Friday, October 10, 2008
VIRTUAL DRILLING MACHINE
This is the coding for VIRTUAL DRILLING MACHINE made in C.G and C++
/***************************************************************************/
/* VIRTUAL DRILLING MACHINE */
/* */
/* CG Project */
/* By Sampathirao Muralidhar B */
/* C.K.Pithawala College of Engg. & Tech. */
/* B.E. Computer-III, 5th Sem (6144) */
/***************************************************************************/
#include iostream.h
#include conio.h
#include stdlib.h
#include graphics.h
#include dos.h
#include math.h
#define MAXX 639
#define MAXY 479
#define interval 90
#define w() {setcolor(WHITE);}
#define lg() {setcolor(LIGHTGRAY);}
#define y() {setcolor(YELLOW);}
#define lb() {setcolor(LIGHTBLUE);}
#define lc() {setcolor(YELLOW);} /* label color */
#define normal DARKGRAY
#define shine LIGHTGRAY
/*****************/
/* Global Var */
/*****************/
int ret=0;
static int no=0;
int on_off=-1; /* indicates status of m/c ON->(1) or OFF->(-1) */
int x_limit=0;
static int degree=0;
static int x_co_ord[5],y_co_ord[5];
int reset=0;
int c=7; /* hole color */
/*****************/
void init_arr(int *);
void y_trans();
void y_trans_1();
void y_control(int);
int z_trans(int);
void z_control(void);
void x_control(void);
void x_trans(int);
int table_trans(int);
void point_trans(int,int);
void tool_trans(int);
void operation(void);
void m_on_off(void);
void hole(void);
void s_hole(void);
void label(void);
class stack
{
private:
int poly[8];
int top;
public:
int convert;
stack(int x1,int y1,int x2,int y2)
{
top=-1;
convert=1;
push(x1);
push(y1);
push(x2);
push(y2);
}
void push(int co_ord)
{
if(top==7)
return;
top++;
poly[top]=co_ord;
}
int pop()
{
if(top==-1)
return NULL;
int temp=poly[top];
top--;
return temp;
}
}y_handle(280,312,295,314),
z_handle(260,132,275,135),
table_obj(175,275,205,295),
point_obj(355+30,150+25,0,0),
tool_obj(185,200,196,205);
void calc(int *,int,int,int,int);
void hori_pix(int,int,int,int,int,int,int);
void verti_pix(int,int,int,int,int,int,int);
void line_fill(int,int,int,int,int,int,int,int);
void pixelize(int,int,int,int,int,int,int);
void border(void);
void my_menu();
void menu_access_opt1(void);
void menu_access_opt2(void);
void menu_access_opt3(void);
void draw(void);
int direction(int);
void msg(int,int);
/****************************************************************************/
void my_menu()
{
int i,j;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,20,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,20,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,20,1);
outtextxy(70,247,"Exit");
setcolor(LIGHTGRAY);
outtextxy(10,MAXY-30,"\n Press 'm' to access the menu or enjoy the visuals");
again:
while(!kbhit())
{
verti_pix(250,150,350,RED+GREEN,YELLOW,2,10);
}
if(getch()==(int)'m')
{
outtextxy(10,MAXY-15,"\n Use Up & Down arrow key");
menu_access_opt1();
}
else
goto again;
}
/***************************************************************************/
void pixelize(int color,int x1,int y1,int x2,int y2,int delta,int gap)
{
int i,j;
for(i=y1+1;i<=y2-1;i+=gap)
{
for(j=x1+1;j<=x2-1;j+=gap)
{
putpixel(j,i,color);
}
delay(delta);
}
}
/***************************************************************************/
void in_graph()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
}
/***************************************************************************/
my_window()
{
int i=0;
border();
pixelize(RED,3,3,MAXX-3,MAXY-3,0,2);
line_fill(RED,3,3,MAXX-3,MAXY-3,3,2,1);
while(i!=80)
{
setcolor(YELLOW);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
i=0;
setcolor(YELLOW);
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2,"Welcome to Virtual Drilling");
hori_pix(getmaxx()/2-50,getmaxy()/2+10,getmaxx()/2-50+216,YELLOW,RED,2,10);
setcolor(RED+GREEN);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+10,"CG Project");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+20,"By Sampathirao Muralidhar");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+30,"C.K.Pithawala College of Engg. & Tech.");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+40,"III-Computer (6144)");
delay(interval);
my_menu();
while(i!=80)
{
setcolor(RED);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
border();
switch(ret)
{
case 1: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(240,15,"\n Parts of Drilling M/c");
draw();
label();
break;
case 2: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(100,15,"\n Drilling & Milling M/c ");
draw();
operation();
break;
case 3: pixelize(BLACK,3,3,MAXX-3,MAXY-3,0,2);
line_fill(BLACK,3,3,MAXX-3,MAXY-3,0,1,1);
lb();
outtextxy(140,120,"Impossible is not a fact, its an opinion!!");
outtextxy(245,140,"Thanks for visiting");
w();
outtextxy(350,240,"Pree any key to Exit");
getch();
exit(0);
break;
}
return 0;
}
/***************************************************************************/
void hori_pix(int x1,int y,int x2,int color,int dissolve_color,int gap,int wt_time)
{
int x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,color);
delay(wt_time);
x_temp+=gap;
}
x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,dissolve_color);
delay(wt_time);
x_temp+=gap;
}
}
/***************************************************************************/
void verti_pix(int x,int y1,int y2,int color,int dissolve_color,int gap,int wt_time)
{
int y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,color);
delay(wt_time);
y_temp+=gap;
}
y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,dissolve_color);
delay(wt_time);
y_temp+=gap;
}
}
/**************************************************************************/
void border()
{
setcolor(WHITE);
rectangle(0,0,MAXX,MAXY);
rectangle(2,2,MAXX-2,MAXY-2);
}
/**************************************************************************/
void menu_access_opt1()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,200,65,215,0,1);
setcolor(YELLOW);
outtextxy(70,207,"Parts of Drilling M/C");
}
ch=getch();
if(ch==13)
ret=1;
else if(ch==80)
{
menu_access_opt2();
}
else if(ch==72)
{
menu_access_opt3();
}
else
menu_access_opt1();
}
/**************************************************************************/
void menu_access_opt2()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,220,65,235,0,1);
setcolor(YELLOW);
outtextxy(70,227,"Start virtual drill");
}
ch=getch();
if(ch==13)
ret=2;
else if(ch==80)
{
menu_access_opt3();
}
else if(ch==72)
{
menu_access_opt1();
}
else
menu_access_opt2();
}
/**************************************************************************/
void menu_access_opt3()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
while(!kbhit())
{
pixelize(YELLOW,50,240,65,255,0,1);
setcolor(YELLOW);
outtextxy(70,247,"Exit");
}
ch=getch();
if(ch==13)
ret=3;
else if(ch==80)
{
menu_access_opt1();
}
else if(ch==72)
{
menu_access_opt2();
}
else
menu_access_opt3();
}
/**************************************************************************/
void line_fill(int color,int x1,int y1,int x2,int y2,int wt_time,int type,int gap)
{
int i;
switch(type)
{
case 1: for(i=x1+1;i {
setcolor(color);
line(i,y1+1,i,y2-1);
delay(wt_time);
}
break;
case 2: for(i=y2-1;i>y1;i-=gap)
{
setcolor(color);
line(x1+1,i,x2-1,i);
delay(wt_time);
}
break;
}
}
/**************************************************************************/
void draw()
{
int arr[8];
border();
hori_pix(205,275,355,GREEN,DARKGRAY,2,10); /* OBJECT VIEWS */
hori_pix(205,295,355,GREEN,DARKGRAY,2,10);
verti_pix(355,150,275,GREEN,DARKGRAY,2,10);
verti_pix(415,150,275,GREEN,DARKGRAY,2,10);
setcolor(WHITE);
rectangle(355,275,415,295); /* Side view */
rectangle(355,150,415,200); /* Top view*/
putpixel(355+30,150+25,YELLOW);
hori_pix(375,175,395,BLUE,LIGHTBLUE,4,10);
verti_pix(385,165,186,BLUE,LIGHTBLUE,4,10);
setcolor(LIGHTBLUE);
outtextxy(160,200,"O");
outtextxy(160,210,"m");
outtextxy(160,220," ");
outtextxy(160,230,"S");
outtextxy(160,240,"a");
outtextxy(160,250,"i");
setcolor(WHITE); /* BODY */
rectangle(155,170,225,290);
rectangle(153,168,227,290);
w();
rectangle(180,50,200,90); /* MOTOR */
line(180,45,180,50);
line(200,45,200,50);
arc(185,45,90,180,5);
arc(195,45,0,90,5);
line(185,40,195,40);
rectangle(175,75,180,90);
rectangle(200,65,210,90);
pixelize(normal,200,65,210,90,0,1);
line_fill(WHITE,180,50,200,90,0,1,2);
rectangle(165,90,216,175); /* Head */
line_fill(LIGHTBLUE,165,90,216,175,0,2,2);
setcolor(WHITE);
outtextxy(167,96,"Ka9L13");
rectangle(180,125,200,165);
rectangle(190,130,190,160);
rectangle(185,130,195,132);
line_fill(WHITE,185,130,195,132,0,1,1);
rectangle(130,90,165,120); /* ON/OFF Board */
pixelize(LIGHTBLUE,130,90,165,120,0,2);
w();
rectangle(135,110,140,115);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
line_fill(LIGHTGREEN,155,110,160,115,0,1,1);
setcolor(WHITE);
rectangle(155,110,160,115);
circle(148,100,5);
line(148,100,148,95);
rectangle(216,130,235,160); /* Feed Lever */
line_fill(LIGHTBLUE,216,130,235,160,0,2,3);
line_fill(LIGHTBLUE,216,130,235,160,0,1,3);
line_fill(normal,235,140-3,245,150+3,0,1,1);
line_fill(WHITE,235,140,245,143,0,1,1);
w();
rectangle(235,140-3,245,150+3);
rectangle(245,130+4,250,160-4);
line(250,134,255,130);
line(250,156,255,160);
rectangle(255,130,260,160);
rectangle(260,132,275,135); /*handle*/
line_fill(BROWN,170,175,211,180,0,1,2);
line_fill(BROWN,167,190,213,195,0,1,2 );
setfillstyle(1,BROWN);
fillellipse(180,185,5,5);
fillellipse(201,185,5,5);
line_fill(BROWN,180,180,201,190,0,1,1);
w();
rectangle(170,175,211,180); /* chuck */
arc(180,185,90,270,5);
arc(201,185,270,90,5);
rectangle(167,190,213,195);
rectangle(180,195,201,200);
rectangle(185,200,196,205); /*small*/
line_fill(normal,185,200,192,205,0,1,1);
line_fill(shine,191,200,194,205,0,1,1);
line_fill(normal,193,200,196,205,0,1,1);
w();
rectangle(180,205,201,209);
line(184,225,197,225);
ellipse(184,205,180,270,4,20);
ellipse(197,205,270,360,4,20);
ellipse(193,211,270,360,4,13);
ellipse(192,211,270,360,4,14);
rectangle(186,227,195,234);
line_fill(normal,186,227,195,234,0,1,1);
line_fill(shine,191,227,194,234,0,1,1);
w();
rectangle(189,234,192,255); /*tool*/
calc(arr,189,234,192,255);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,255,190,258);
line(190,258,192,255);
rectangle(120,295,260,310); /* TABLE */
rectangle(135,290,245,295);
rectangle(175,275,205,295); /*object*/
setfillstyle(9,BROWN);
calc(arr,175,275,205,295);
fillpoly(4,arr);
rectangle(137,288,140,290); /*l-nut*/
line_fill(WHITE,137,288,140,290,0,1,1);
rectangle(240,288,243,290); /*r-nut*/
line_fill(WHITE,240,288,243,290,0,1,1);
rectangle(170,280,175,290); /*l-support*/
rectangle(168,282,170,286);
line_fill(WHITE,168,283,170,285,0,1,1);
rectangle(205,280,210,290); /*r-support*/
rectangle(210,282,212,286);
line_fill(WHITE,210,283,212,285,0,1,1);
line_fill(shine,245,313,265,325,0,2,1);
line_fill(normal,245,315,265,318,0,2,1);
line(245,320,265,320);
line_fill(WHITE,265,317,270,319,0,1,1);
w();
rectangle(245,313,265,325); /* y-Trans-r */
rectangle(265,315,270,323);
rectangle(270,313,273,325);
line(273,313,276,310);
line(273,325,276,328);
rectangle(276,310,280,328);
rectangle(280,312,295,314); /*handle*/
/****************************************/
/* x-Trans-color */
/****************************************/
line_fill(normal,135,312,245,332,0,1,1);
setfillstyle(1,normal);
arr[0]=135;
arr[1]=332;
arr[2]=155;
arr[3]=332;
arr[4]=165;
arr[5]=342;
arr[6]=155;
arr[7]=342;
fillpoly(4,arr);
arr[0]=245;
arr[2]=225;
arr[4]=215;
arr[6]=225;
fillpoly(4,arr);
w();
/****************************************/
line(135,312,245,312); //1 /* x-TRANS-r */
line(135,312,135,332); //2
line(245,312,245,332); //3
line(135,332,155,342); //4
line(155,342,165,342); //5
line(165,342,155,332); //6
line(245,332,225,342); //7
line(225,342,215,342); //8
line(215,342,225,332); //9
line(155,332,225,332); //10
line(160,334,220,334); //11
line(160,334,170,344); //12
line(220,334,210,344); //13
line(170,344,135,344); //14
line(210,344,245,344); //15
line(135,344,135,380); //16
line(245,344,245,380); //17
line(135,380,245,380); //18
/**********************/
/* x_handle back fill */
/**********************/
line_fill(BROWN,135,344,245,380,0,2,1);
setfillstyle(1,BROWN);
arr[0]=163;
arr[1]=335;
arr[2]=218;
arr[3]=335;
arr[4]=207;
arr[5]=346;
arr[6]=173;
arr[7]=346;
fillpoly(4,arr);
w();
/**********************/
circle(190,362,10);
circle(190,357,2);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
setfillstyle(1,LIGHTRED); //x_handle
fillellipse(190,357,2,2);
putpixel(190,362,YELLOW);
rectangle(80,380,135,420); //1 /* BASE */
rectangle(245,380,300,420); //2
rectangle(135,380,245,400); //3
line_fill(BROWN,134,380,246,400,0,1,2); //3
line_fill(BROWN,246,380,300,420,0,1,2); //2
line_fill(BROWN,80,380,135,420,0,1,2); //1
line_fill(normal,120,295,260,310,0,2,2); //table fill
}
/**************************************************************************/
void calc(int *p,int x1,int y1,int x2,int y2)
{
*(p)=x1;
*(p+1)=y1;
*(p+2)=x2;
*(p+3)=y1;
*(p+4)=x2;
*(p+5)=y2;
*(p+6)=x1;
*(p+7)=y2;
}
/**************************************************************************/
void y_trans()
{
int x1,y1,x2,y2,k1=0,i=-1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(3);
}
else if(y1>=324)
{
k1=direction(4);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==-12)
{
if(table_trans(-2))
{
msg(4,10);
y_control(1);
}
else msg(2,0);
degree=0;
}
degree--;
}
/***************************************************************************/
void y_trans_1()
{
int x1,y1,x2,y2,k1=0,i=1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(1);
}
else if(y1>=324)
{
k1=direction(2);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==12)
{
if(table_trans(2))
{
msg(4,10);
y_control(2);
}
else msg(2,0);
degree=0;
}
degree++;
}
/***************************************************************************/
int direction(int x)
{
static int k=0;
if(x==1 && k==0)
return 0;
if(x==3 && k==1)
return 0;
if(x==4 && k==0)
return 0;
if(x==2 && k==1)
return 0;
if(k==1) //1 for back
{
k=0;
y_handle.convert=y_handle.convert*(-1);
return 1;
}
else
{
k=1;
y_handle.convert=y_handle.convert*(-1);
return -1;
}
}
/***************************************************************************/
void y_control(int limit)
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && limit!=1)
{
y_trans();
y_control(0);
}
else if(ch==80 && limit!=2)
{
y_trans_1();
y_control(0);
}
else if(ch==27)
operation();
else
y_control(limit);
}
/***************************************************************************/
int z_trans(int z_vector)
{
int x1,y1,x2,y2;
y2=z_handle.pop();
x2=z_handle.pop();
y1=z_handle.pop();
x1=z_handle.pop();
if(y2+z_vector<=134 || y2+z_vector>=154)
{
msg(5,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
if(y1+z_vector>=141 && on_off==-1)
{
msg(6,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
else
{
msg(2,0);
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
w();
rectangle(255,130,260,160);
rectangle(x1,y1+z_vector,x2,y2+z_vector);
tool_trans(z_vector*2);
if(y1>=141)
s_hole();
z_handle.push(x1);
z_handle.push(y1+z_vector);
z_handle.push(x2);
z_handle.push(y2+z_vector);
setcolor(BLACK);
rectangle(355,273,415,274);
}
return 0;
}
/***************************************************************************/
int table_trans(int x_vector)
{
int x1,y1,x2,y2,arr[8];
setcolor(BLACK);
y2=table_obj.pop();
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
if(x1+x_vector<=164 || x2+x_vector>=216)
{
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
return 1;
}
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(BLACK,x1-55,295,x2+55,310,0,1,1);
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(BLACK,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(BLACK,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(BLACK,x1-7,282,x2-35,286,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(BLACK,x1+35,282,x2+7,286,0,1,1);
setfillstyle(9,BLACK);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
table_obj.push(x1+x_vector);
table_obj.push(y1);
table_obj.push(x2+x_vector);
table_obj.push(y2);
/********************************************/
/* REDRAW CODE */
/********************************************/
x1=x1+x_vector;
x2=x2+x_vector;
point_trans(0,-x_vector*2);
setcolor(WHITE);
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(normal,x1-55,295,x2+55,310,0,2,2);
w();
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(WHITE,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(WHITE,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(WHITE,x1-7,283,x2-35,285,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(WHITE,x1+35,283,x2+7,285,0,1,1);
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
return 0;
}
/***************************************************************************/
void point_trans(int x_vector,int y_vector)
{
int x1,y1;
y1=point_obj.pop();
x1=point_obj.pop();
if (x1+x_vector<358)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=1;
}
else if(x1+x_vector>412)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=2;
}
else
{
putpixel(x1,y1,BLACK);
hori_pix(x1-10,y1,x1+10,BLACK,BLACK,4,0);
verti_pix(x1,y1-10,y1+11,BLACK,BLACK,4,0);
point_obj.push(x1+x_vector);
point_obj.push(y1+y_vector);
/*****************/
/* REDRAW */
/*****************/
w();
rectangle(355,150,415,200);
x1=x1+x_vector;
y1=y1+y_vector;
putpixel(x1,y1,YELLOW);
hori_pix(x1-10,y1,x1+10,BLUE,LIGHTBLUE,4,0);
verti_pix(x1,y1-10,y1+11,BLUE,LIGHTBLUE,4,0);
x_limit=0;
}
}
/***************************************************************************/
void operation()
{
int ch;
line_fill(BLACK,499,34,635,43,0,2,1);
reset=0;
c=7;
msg(0,20);
lb();
outtextxy(500,15,"Press:");
w();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
outtextxy(500,50,"x:x-Translation");
outtextxy(500,65,"y:y-Translation");
outtextxy(500,80,"f:Feed tool");
outtextxy(500,95,"h:Homepage");
setcolor(LIGHTRED);
outtextxy(500,110,"Esc:To abort the");
outtextxy(500,126," operation");
again:
while(!kbhit())
{
line(548,22 ,554,22);
}
ch=getch();
switch(ch)
{
case 115:lb();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
w();
outtextxy(500,15,"Press:");
m_on_off();
break;
case 120:msg(2,20);
lb();
outtextxy(500,50,"x:x-Translation");
w();
outtextxy(500,15,"Press:");
x_control();
break;
case 121:msg(2,20);
lb();
outtextxy(500,65,"y:y-Translation");
w();
outtextxy(500,15,"Press:");
y_control(0);
break;
case 102:msg(2,10);
lb();
outtextxy(500,80,"f:Feed tool");
w();
outtextxy(500,15,"Press:");
z_control();
break;
case 104:y();
my_window();
break;
default :goto again;
}
}
/***************************************************************************/
void msg(int no,int delay)
{
int ch;
y();
outtextxy(440,445,"Message:");
line_fill(BLACK,439,463,633,474,delay,2,1);
y();
switch(no)
{
case 0: outtextxy(440,465,"Select the operation");
break;
case 1: if(on_off==1)
outtextxy(440,465,"Press Enter to STOP M/c");
else
outtextxy(440,465,"Press Enter to START M/c");
break;
case 2: outtextxy(440,465,"Use up & down arrows");
break;
case 3: outtextxy(440,465,"X-Limit reached");
break;
case 4: outtextxy(440,465,"Y-Limit reached");
break;
case 5: outtextxy(440,465,"Z-Limit reached");
break;
case 6: outtextxy(440,465,"Can't drill, M/c is OFF");
break;
case 7: while(!kbhit())
outtextxy(440,465,"Max holes, Esc twice");
if(getch()==27)
break;
else msg(7,0);
}
}
/***************************************************************************/
void m_on_off()
{
int ch,arr[8];
calc(arr,189,234,192,255);
msg(1,20);
while(!kbhit()){}
ch=getch();
if(ch==13 && on_off==-1)
{
on_off=on_off*(-1);
line_fill(RED,135,110,140,115,0,1,1);
operation();
}
else if(ch==13 && on_off==1)
{
on_off=on_off*(-1);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
operation();
}
else if(ch==27)
operation();
else m_on_off();
}
/***************************************************************************/
void z_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72)
{
z_trans(-1);
z_control();
}
else if(ch==80)
{
z_trans(1);
z_control();
}
else if(ch==27)
{
while(!z_trans(-1)){}
operation();
}
else
z_control();
}
/***************************************************************************/
void tool_trans(int z_vector)
{
int x1,y1,x2,y2,arr[8],y2_temp;
y2=tool_obj.pop();
x2=tool_obj.pop();
y1=tool_obj.pop();
x1=tool_obj.pop();
y2_temp=y2;
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
line_fill(BLACK,x1,y1,x2-4,y2,0,1,1);
line_fill(BLACK,x2-5,y1,x2-2,y2,0,1,1);
line_fill(BLACK,x2-3,y1,x2,y2,0,1,1);
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
calc(arr,189,y2+29,192,y2+50);
line_fill(BLACK,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(BLACK,191,y2+22,194,y2+29,0,1,1);
setfillstyle(4,BLACK);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
tool_obj.push(x1);
tool_obj.push(y1);
tool_obj.push(x2);
tool_obj.push(y2+z_vector);
/*********************************/
/* REDRAW */
/*********************************/
y2=y2+z_vector;
w();
rectangle(x1,y1,x2,y2);
line_fill(normal,x1,y1,x2-4,y2,0,1,1);
line_fill(shine,x2-5,y1,x2-2,y2,0,1,1);
line_fill(normal,x2-3,y1,x2,y2,0,1,1);
w();
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
line_fill(normal,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(shine,191,y2+22,194,y2+29,0,1,1);
w();
calc(arr,189,y2+29,192,y2+50);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
y2=table_obj.pop(); /*update object*/
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2);
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
if(no>4)
{
no=0;
msg(7,10);
init_arr(x_co_ord);
init_arr(y_co_ord);
reset=1;
c=0;
line_fill(BLACK,355,150,415,200,10,1,1);
line_fill(BLACK,355,275,415,295,10,2,1);
point_trans(0,0);
w();
}
else if(y2_temp+53==276 && !reset)
{
hole();
}
}
/***************************************************************************/
void x_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && x_limit!=2)
{
x_trans(1);
x_control();
}
else if(ch==80 && x_limit!=1)
{
x_trans(-1);
x_control();
}
else if(ch==27)
{
operation();
}
else
x_control();
}
/***************************************************************************/
void x_trans(int rot_vector)
{
static double x1=190,y1=357;
static int x_degree=0;
double x_temp,y_temp;
int k;
x_degree=x_degree+rot_vector;
setcolor(BLACK);
circle(190,362,10);
circle(x1,y1,2); //x_handle
/********************************/
/* REDRAW */
/********************************/
x_temp=190+(x1-190)*cos(rot_vector)-(y1-362)*sin(rot_vector);
y_temp=362+(x1-190)*sin(rot_vector)+(y1-362)*cos(rot_vector);
x1=x_temp;
y1=y_temp;
w();
circle(190,362,10);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
circle(x1,y1,2); //x_handle
setfillstyle(1,LIGHTRED);
fillellipse(x1,y1,2,2);
putpixel(190,362,YELLOW);
if(x_degree<=12||x_degree>=-12)
{
x_degree=0;
point_trans(rot_vector*2,0);
if(x_limit)
msg(3,0);
else
msg(2,0);
}
}
/***************************************************************************/
void hole()
{
int x1,y1,j,pt=0;
y1=point_obj.pop();
x1=point_obj.pop();
point_obj.push(x1); /* reload point co_ord's */
point_obj.push(y1);
for(j=0;j<=no;j++)
{
if(x_co_ord[j]==x1 && y_co_ord[j]==y1)
{
pt=1;
break;
}
}
if(!pt)
{
x_co_ord[no]=x1;
y_co_ord[no]=y1;
no+=1;
for(j=0;j<=no;j++)
{
setfillstyle(1,LIGHTRED);
fillellipse(x_co_ord[j],y_co_ord[j],2,2);
}
}
}
/***************************************************************************/
void init_arr(int *p)
{
int i;
for(i=0;i<=4;i++)
{
*(p+i)=0;
}
}
/***************************************************************************/
void s_hole()
{
int pt_x1,pt_y1,tip;
pt_y1=point_obj.pop();
pt_x1=point_obj.pop();
point_obj.push(pt_x1); /* reload point co-ord's */
point_obj.push(pt_y1);
tip=tool_obj.pop()+53;
tool_obj.push(tip-53); /* reload tool tip */
line_fill(c,pt_x1-1,275,pt_x1+1,tip,0,1,1);
rectangle(pt_x1-1,275,pt_x1+1,tip);
w();
rectangle(355,275,415,295);
}
/***************************************************************************/
void label()
{
int k=20,ch;
hori_pix(204,55,250,shine,YELLOW,2,k);
lc();
outtextxy(254,50,"\n Motor");
hori_pix(220,95,270,shine,YELLOW,2,k);
lc();
outtextxy(274,90,"\n Head");
hori_pix(76,95,126,shine,YELLOW,2,k);
lc();
outtextxy(10,85,"\n On/Off");
outtextxy(10,95," Board");
hori_pix(278,135,325,shine,YELLOW,2,k);
lc();
outtextxy(329,130,"\n Feed Lever");
hori_pix(99,188,149,shine,YELLOW,2,k);
lc();
outtextxy(44,183,"\n Body");
hori_pix(199,215,249,shine,YELLOW,2,k);
lc();
outtextxy(253,210,"\n Chuck");
hori_pix(194,240,249,shine,YELLOW,2,k);
lc();
outtextxy(253,235,"\n Tool");
hori_pix(85,300,116,shine,YELLOW,2,k);
lc();
outtextxy(10,295,"\n Table");
outtextxy(10,305," & ");
outtextxy(10,315," Object");
hori_pix(204,360,254,shine,YELLOW,2,k);
lc();
outtextxy(258,355,"\n x-Translator");
hori_pix(299,310,349,shine,YELLOW,2,k);
lc();
outtextxy(352,305,"\n y-Translator");
hori_pix(300,385,368,shine,YELLOW,2,k);
lc();
outtextxy(372,380,"\n Base");
hori_pix(420,190,470,shine,YELLOW,2,k);
lc();
outtextxy(474,185,"\n Top view");
hori_pix(420,290,470,shine,YELLOW,2,k);
lc();
outtextxy(474,285,"\n Side view");
lb();
outtextxy(500,15,"Press:");
outtextxy(500,35,"h:Homepage");
while(getch()!=104){}
my_window();
}
/***************************************************************************/
void main()
{
in_graph();
setcolor(LIGHTBLUE);
settextstyle(0,0,1);
outtextxy(10,10,"Om Sai Ram");
settextstyle(0,0,1);
border();
outtextxy(350,240,"Pree any key to START");
getch();
cleardevice();
point_obj.pop(); //flush the unwanted
point_obj.pop();
my_window();
getch();
}
/***************************************************************************/
/***************************************************************************/
/* VIRTUAL DRILLING MACHINE */
/* */
/* CG Project */
/* By Sampathirao Muralidhar B */
/* C.K.Pithawala College of Engg. & Tech. */
/* B.E. Computer-III, 5th Sem (6144) */
/***************************************************************************/
#include iostream.h
#include conio.h
#include stdlib.h
#include graphics.h
#include dos.h
#include math.h
#define MAXX 639
#define MAXY 479
#define interval 90
#define w() {setcolor(WHITE);}
#define lg() {setcolor(LIGHTGRAY);}
#define y() {setcolor(YELLOW);}
#define lb() {setcolor(LIGHTBLUE);}
#define lc() {setcolor(YELLOW);} /* label color */
#define normal DARKGRAY
#define shine LIGHTGRAY
/*****************/
/* Global Var */
/*****************/
int ret=0;
static int no=0;
int on_off=-1; /* indicates status of m/c ON->(1) or OFF->(-1) */
int x_limit=0;
static int degree=0;
static int x_co_ord[5],y_co_ord[5];
int reset=0;
int c=7; /* hole color */
/*****************/
void init_arr(int *);
void y_trans();
void y_trans_1();
void y_control(int);
int z_trans(int);
void z_control(void);
void x_control(void);
void x_trans(int);
int table_trans(int);
void point_trans(int,int);
void tool_trans(int);
void operation(void);
void m_on_off(void);
void hole(void);
void s_hole(void);
void label(void);
class stack
{
private:
int poly[8];
int top;
public:
int convert;
stack(int x1,int y1,int x2,int y2)
{
top=-1;
convert=1;
push(x1);
push(y1);
push(x2);
push(y2);
}
void push(int co_ord)
{
if(top==7)
return;
top++;
poly[top]=co_ord;
}
int pop()
{
if(top==-1)
return NULL;
int temp=poly[top];
top--;
return temp;
}
}y_handle(280,312,295,314),
z_handle(260,132,275,135),
table_obj(175,275,205,295),
point_obj(355+30,150+25,0,0),
tool_obj(185,200,196,205);
void calc(int *,int,int,int,int);
void hori_pix(int,int,int,int,int,int,int);
void verti_pix(int,int,int,int,int,int,int);
void line_fill(int,int,int,int,int,int,int,int);
void pixelize(int,int,int,int,int,int,int);
void border(void);
void my_menu();
void menu_access_opt1(void);
void menu_access_opt2(void);
void menu_access_opt3(void);
void draw(void);
int direction(int);
void msg(int,int);
/****************************************************************************/
void my_menu()
{
int i,j;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,20,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,20,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,20,1);
outtextxy(70,247,"Exit");
setcolor(LIGHTGRAY);
outtextxy(10,MAXY-30,"\n Press 'm' to access the menu or enjoy the visuals");
again:
while(!kbhit())
{
verti_pix(250,150,350,RED+GREEN,YELLOW,2,10);
}
if(getch()==(int)'m')
{
outtextxy(10,MAXY-15,"\n Use Up & Down arrow key");
menu_access_opt1();
}
else
goto again;
}
/***************************************************************************/
void pixelize(int color,int x1,int y1,int x2,int y2,int delta,int gap)
{
int i,j;
for(i=y1+1;i<=y2-1;i+=gap)
{
for(j=x1+1;j<=x2-1;j+=gap)
{
putpixel(j,i,color);
}
delay(delta);
}
}
/***************************************************************************/
void in_graph()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
}
/***************************************************************************/
my_window()
{
int i=0;
border();
pixelize(RED,3,3,MAXX-3,MAXY-3,0,2);
line_fill(RED,3,3,MAXX-3,MAXY-3,3,2,1);
while(i!=80)
{
setcolor(YELLOW);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
i=0;
setcolor(YELLOW);
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2,"Welcome to Virtual Drilling");
hori_pix(getmaxx()/2-50,getmaxy()/2+10,getmaxx()/2-50+216,YELLOW,RED,2,10);
setcolor(RED+GREEN);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+10,"CG Project");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+20,"By Sampathirao Muralidhar");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+30,"C.K.Pithawala College of Engg. & Tech.");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+40,"III-Computer (6144)");
delay(interval);
my_menu();
while(i!=80)
{
setcolor(RED);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
border();
switch(ret)
{
case 1: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(240,15,"\n Parts of Drilling M/c");
draw();
label();
break;
case 2: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(100,15,"\n Drilling & Milling M/c ");
draw();
operation();
break;
case 3: pixelize(BLACK,3,3,MAXX-3,MAXY-3,0,2);
line_fill(BLACK,3,3,MAXX-3,MAXY-3,0,1,1);
lb();
outtextxy(140,120,"Impossible is not a fact, its an opinion!!");
outtextxy(245,140,"Thanks for visiting");
w();
outtextxy(350,240,"Pree any key to Exit");
getch();
exit(0);
break;
}
return 0;
}
/***************************************************************************/
void hori_pix(int x1,int y,int x2,int color,int dissolve_color,int gap,int wt_time)
{
int x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,color);
delay(wt_time);
x_temp+=gap;
}
x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,dissolve_color);
delay(wt_time);
x_temp+=gap;
}
}
/***************************************************************************/
void verti_pix(int x,int y1,int y2,int color,int dissolve_color,int gap,int wt_time)
{
int y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,color);
delay(wt_time);
y_temp+=gap;
}
y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,dissolve_color);
delay(wt_time);
y_temp+=gap;
}
}
/**************************************************************************/
void border()
{
setcolor(WHITE);
rectangle(0,0,MAXX,MAXY);
rectangle(2,2,MAXX-2,MAXY-2);
}
/**************************************************************************/
void menu_access_opt1()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,200,65,215,0,1);
setcolor(YELLOW);
outtextxy(70,207,"Parts of Drilling M/C");
}
ch=getch();
if(ch==13)
ret=1;
else if(ch==80)
{
menu_access_opt2();
}
else if(ch==72)
{
menu_access_opt3();
}
else
menu_access_opt1();
}
/**************************************************************************/
void menu_access_opt2()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,220,65,235,0,1);
setcolor(YELLOW);
outtextxy(70,227,"Start virtual drill");
}
ch=getch();
if(ch==13)
ret=2;
else if(ch==80)
{
menu_access_opt3();
}
else if(ch==72)
{
menu_access_opt1();
}
else
menu_access_opt2();
}
/**************************************************************************/
void menu_access_opt3()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
while(!kbhit())
{
pixelize(YELLOW,50,240,65,255,0,1);
setcolor(YELLOW);
outtextxy(70,247,"Exit");
}
ch=getch();
if(ch==13)
ret=3;
else if(ch==80)
{
menu_access_opt1();
}
else if(ch==72)
{
menu_access_opt2();
}
else
menu_access_opt3();
}
/**************************************************************************/
void line_fill(int color,int x1,int y1,int x2,int y2,int wt_time,int type,int gap)
{
int i;
switch(type)
{
case 1: for(i=x1+1;i
setcolor(color);
line(i,y1+1,i,y2-1);
delay(wt_time);
}
break;
case 2: for(i=y2-1;i>y1;i-=gap)
{
setcolor(color);
line(x1+1,i,x2-1,i);
delay(wt_time);
}
break;
}
}
/**************************************************************************/
void draw()
{
int arr[8];
border();
hori_pix(205,275,355,GREEN,DARKGRAY,2,10); /* OBJECT VIEWS */
hori_pix(205,295,355,GREEN,DARKGRAY,2,10);
verti_pix(355,150,275,GREEN,DARKGRAY,2,10);
verti_pix(415,150,275,GREEN,DARKGRAY,2,10);
setcolor(WHITE);
rectangle(355,275,415,295); /* Side view */
rectangle(355,150,415,200); /* Top view*/
putpixel(355+30,150+25,YELLOW);
hori_pix(375,175,395,BLUE,LIGHTBLUE,4,10);
verti_pix(385,165,186,BLUE,LIGHTBLUE,4,10);
setcolor(LIGHTBLUE);
outtextxy(160,200,"O");
outtextxy(160,210,"m");
outtextxy(160,220," ");
outtextxy(160,230,"S");
outtextxy(160,240,"a");
outtextxy(160,250,"i");
setcolor(WHITE); /* BODY */
rectangle(155,170,225,290);
rectangle(153,168,227,290);
w();
rectangle(180,50,200,90); /* MOTOR */
line(180,45,180,50);
line(200,45,200,50);
arc(185,45,90,180,5);
arc(195,45,0,90,5);
line(185,40,195,40);
rectangle(175,75,180,90);
rectangle(200,65,210,90);
pixelize(normal,200,65,210,90,0,1);
line_fill(WHITE,180,50,200,90,0,1,2);
rectangle(165,90,216,175); /* Head */
line_fill(LIGHTBLUE,165,90,216,175,0,2,2);
setcolor(WHITE);
outtextxy(167,96,"Ka9L13");
rectangle(180,125,200,165);
rectangle(190,130,190,160);
rectangle(185,130,195,132);
line_fill(WHITE,185,130,195,132,0,1,1);
rectangle(130,90,165,120); /* ON/OFF Board */
pixelize(LIGHTBLUE,130,90,165,120,0,2);
w();
rectangle(135,110,140,115);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
line_fill(LIGHTGREEN,155,110,160,115,0,1,1);
setcolor(WHITE);
rectangle(155,110,160,115);
circle(148,100,5);
line(148,100,148,95);
rectangle(216,130,235,160); /* Feed Lever */
line_fill(LIGHTBLUE,216,130,235,160,0,2,3);
line_fill(LIGHTBLUE,216,130,235,160,0,1,3);
line_fill(normal,235,140-3,245,150+3,0,1,1);
line_fill(WHITE,235,140,245,143,0,1,1);
w();
rectangle(235,140-3,245,150+3);
rectangle(245,130+4,250,160-4);
line(250,134,255,130);
line(250,156,255,160);
rectangle(255,130,260,160);
rectangle(260,132,275,135); /*handle*/
line_fill(BROWN,170,175,211,180,0,1,2);
line_fill(BROWN,167,190,213,195,0,1,2 );
setfillstyle(1,BROWN);
fillellipse(180,185,5,5);
fillellipse(201,185,5,5);
line_fill(BROWN,180,180,201,190,0,1,1);
w();
rectangle(170,175,211,180); /* chuck */
arc(180,185,90,270,5);
arc(201,185,270,90,5);
rectangle(167,190,213,195);
rectangle(180,195,201,200);
rectangle(185,200,196,205); /*small*/
line_fill(normal,185,200,192,205,0,1,1);
line_fill(shine,191,200,194,205,0,1,1);
line_fill(normal,193,200,196,205,0,1,1);
w();
rectangle(180,205,201,209);
line(184,225,197,225);
ellipse(184,205,180,270,4,20);
ellipse(197,205,270,360,4,20);
ellipse(193,211,270,360,4,13);
ellipse(192,211,270,360,4,14);
rectangle(186,227,195,234);
line_fill(normal,186,227,195,234,0,1,1);
line_fill(shine,191,227,194,234,0,1,1);
w();
rectangle(189,234,192,255); /*tool*/
calc(arr,189,234,192,255);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,255,190,258);
line(190,258,192,255);
rectangle(120,295,260,310); /* TABLE */
rectangle(135,290,245,295);
rectangle(175,275,205,295); /*object*/
setfillstyle(9,BROWN);
calc(arr,175,275,205,295);
fillpoly(4,arr);
rectangle(137,288,140,290); /*l-nut*/
line_fill(WHITE,137,288,140,290,0,1,1);
rectangle(240,288,243,290); /*r-nut*/
line_fill(WHITE,240,288,243,290,0,1,1);
rectangle(170,280,175,290); /*l-support*/
rectangle(168,282,170,286);
line_fill(WHITE,168,283,170,285,0,1,1);
rectangle(205,280,210,290); /*r-support*/
rectangle(210,282,212,286);
line_fill(WHITE,210,283,212,285,0,1,1);
line_fill(shine,245,313,265,325,0,2,1);
line_fill(normal,245,315,265,318,0,2,1);
line(245,320,265,320);
line_fill(WHITE,265,317,270,319,0,1,1);
w();
rectangle(245,313,265,325); /* y-Trans-r */
rectangle(265,315,270,323);
rectangle(270,313,273,325);
line(273,313,276,310);
line(273,325,276,328);
rectangle(276,310,280,328);
rectangle(280,312,295,314); /*handle*/
/****************************************/
/* x-Trans-color */
/****************************************/
line_fill(normal,135,312,245,332,0,1,1);
setfillstyle(1,normal);
arr[0]=135;
arr[1]=332;
arr[2]=155;
arr[3]=332;
arr[4]=165;
arr[5]=342;
arr[6]=155;
arr[7]=342;
fillpoly(4,arr);
arr[0]=245;
arr[2]=225;
arr[4]=215;
arr[6]=225;
fillpoly(4,arr);
w();
/****************************************/
line(135,312,245,312); //1 /* x-TRANS-r */
line(135,312,135,332); //2
line(245,312,245,332); //3
line(135,332,155,342); //4
line(155,342,165,342); //5
line(165,342,155,332); //6
line(245,332,225,342); //7
line(225,342,215,342); //8
line(215,342,225,332); //9
line(155,332,225,332); //10
line(160,334,220,334); //11
line(160,334,170,344); //12
line(220,334,210,344); //13
line(170,344,135,344); //14
line(210,344,245,344); //15
line(135,344,135,380); //16
line(245,344,245,380); //17
line(135,380,245,380); //18
/**********************/
/* x_handle back fill */
/**********************/
line_fill(BROWN,135,344,245,380,0,2,1);
setfillstyle(1,BROWN);
arr[0]=163;
arr[1]=335;
arr[2]=218;
arr[3]=335;
arr[4]=207;
arr[5]=346;
arr[6]=173;
arr[7]=346;
fillpoly(4,arr);
w();
/**********************/
circle(190,362,10);
circle(190,357,2);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
setfillstyle(1,LIGHTRED); //x_handle
fillellipse(190,357,2,2);
putpixel(190,362,YELLOW);
rectangle(80,380,135,420); //1 /* BASE */
rectangle(245,380,300,420); //2
rectangle(135,380,245,400); //3
line_fill(BROWN,134,380,246,400,0,1,2); //3
line_fill(BROWN,246,380,300,420,0,1,2); //2
line_fill(BROWN,80,380,135,420,0,1,2); //1
line_fill(normal,120,295,260,310,0,2,2); //table fill
}
/**************************************************************************/
void calc(int *p,int x1,int y1,int x2,int y2)
{
*(p)=x1;
*(p+1)=y1;
*(p+2)=x2;
*(p+3)=y1;
*(p+4)=x2;
*(p+5)=y2;
*(p+6)=x1;
*(p+7)=y2;
}
/**************************************************************************/
void y_trans()
{
int x1,y1,x2,y2,k1=0,i=-1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(3);
}
else if(y1>=324)
{
k1=direction(4);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==-12)
{
if(table_trans(-2))
{
msg(4,10);
y_control(1);
}
else msg(2,0);
degree=0;
}
degree--;
}
/***************************************************************************/
void y_trans_1()
{
int x1,y1,x2,y2,k1=0,i=1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(1);
}
else if(y1>=324)
{
k1=direction(2);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==12)
{
if(table_trans(2))
{
msg(4,10);
y_control(2);
}
else msg(2,0);
degree=0;
}
degree++;
}
/***************************************************************************/
int direction(int x)
{
static int k=0;
if(x==1 && k==0)
return 0;
if(x==3 && k==1)
return 0;
if(x==4 && k==0)
return 0;
if(x==2 && k==1)
return 0;
if(k==1) //1 for back
{
k=0;
y_handle.convert=y_handle.convert*(-1);
return 1;
}
else
{
k=1;
y_handle.convert=y_handle.convert*(-1);
return -1;
}
}
/***************************************************************************/
void y_control(int limit)
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && limit!=1)
{
y_trans();
y_control(0);
}
else if(ch==80 && limit!=2)
{
y_trans_1();
y_control(0);
}
else if(ch==27)
operation();
else
y_control(limit);
}
/***************************************************************************/
int z_trans(int z_vector)
{
int x1,y1,x2,y2;
y2=z_handle.pop();
x2=z_handle.pop();
y1=z_handle.pop();
x1=z_handle.pop();
if(y2+z_vector<=134 || y2+z_vector>=154)
{
msg(5,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
if(y1+z_vector>=141 && on_off==-1)
{
msg(6,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
else
{
msg(2,0);
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
w();
rectangle(255,130,260,160);
rectangle(x1,y1+z_vector,x2,y2+z_vector);
tool_trans(z_vector*2);
if(y1>=141)
s_hole();
z_handle.push(x1);
z_handle.push(y1+z_vector);
z_handle.push(x2);
z_handle.push(y2+z_vector);
setcolor(BLACK);
rectangle(355,273,415,274);
}
return 0;
}
/***************************************************************************/
int table_trans(int x_vector)
{
int x1,y1,x2,y2,arr[8];
setcolor(BLACK);
y2=table_obj.pop();
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
if(x1+x_vector<=164 || x2+x_vector>=216)
{
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
return 1;
}
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(BLACK,x1-55,295,x2+55,310,0,1,1);
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(BLACK,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(BLACK,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(BLACK,x1-7,282,x2-35,286,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(BLACK,x1+35,282,x2+7,286,0,1,1);
setfillstyle(9,BLACK);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
table_obj.push(x1+x_vector);
table_obj.push(y1);
table_obj.push(x2+x_vector);
table_obj.push(y2);
/********************************************/
/* REDRAW CODE */
/********************************************/
x1=x1+x_vector;
x2=x2+x_vector;
point_trans(0,-x_vector*2);
setcolor(WHITE);
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(normal,x1-55,295,x2+55,310,0,2,2);
w();
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(WHITE,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(WHITE,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(WHITE,x1-7,283,x2-35,285,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(WHITE,x1+35,283,x2+7,285,0,1,1);
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
return 0;
}
/***************************************************************************/
void point_trans(int x_vector,int y_vector)
{
int x1,y1;
y1=point_obj.pop();
x1=point_obj.pop();
if (x1+x_vector<358)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=1;
}
else if(x1+x_vector>412)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=2;
}
else
{
putpixel(x1,y1,BLACK);
hori_pix(x1-10,y1,x1+10,BLACK,BLACK,4,0);
verti_pix(x1,y1-10,y1+11,BLACK,BLACK,4,0);
point_obj.push(x1+x_vector);
point_obj.push(y1+y_vector);
/*****************/
/* REDRAW */
/*****************/
w();
rectangle(355,150,415,200);
x1=x1+x_vector;
y1=y1+y_vector;
putpixel(x1,y1,YELLOW);
hori_pix(x1-10,y1,x1+10,BLUE,LIGHTBLUE,4,0);
verti_pix(x1,y1-10,y1+11,BLUE,LIGHTBLUE,4,0);
x_limit=0;
}
}
/***************************************************************************/
void operation()
{
int ch;
line_fill(BLACK,499,34,635,43,0,2,1);
reset=0;
c=7;
msg(0,20);
lb();
outtextxy(500,15,"Press:");
w();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
outtextxy(500,50,"x:x-Translation");
outtextxy(500,65,"y:y-Translation");
outtextxy(500,80,"f:Feed tool");
outtextxy(500,95,"h:Homepage");
setcolor(LIGHTRED);
outtextxy(500,110,"Esc:To abort the");
outtextxy(500,126," operation");
again:
while(!kbhit())
{
line(548,22 ,554,22);
}
ch=getch();
switch(ch)
{
case 115:lb();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
w();
outtextxy(500,15,"Press:");
m_on_off();
break;
case 120:msg(2,20);
lb();
outtextxy(500,50,"x:x-Translation");
w();
outtextxy(500,15,"Press:");
x_control();
break;
case 121:msg(2,20);
lb();
outtextxy(500,65,"y:y-Translation");
w();
outtextxy(500,15,"Press:");
y_control(0);
break;
case 102:msg(2,10);
lb();
outtextxy(500,80,"f:Feed tool");
w();
outtextxy(500,15,"Press:");
z_control();
break;
case 104:y();
my_window();
break;
default :goto again;
}
}
/***************************************************************************/
void msg(int no,int delay)
{
int ch;
y();
outtextxy(440,445,"Message:");
line_fill(BLACK,439,463,633,474,delay,2,1);
y();
switch(no)
{
case 0: outtextxy(440,465,"Select the operation");
break;
case 1: if(on_off==1)
outtextxy(440,465,"Press Enter to STOP M/c");
else
outtextxy(440,465,"Press Enter to START M/c");
break;
case 2: outtextxy(440,465,"Use up & down arrows");
break;
case 3: outtextxy(440,465,"X-Limit reached");
break;
case 4: outtextxy(440,465,"Y-Limit reached");
break;
case 5: outtextxy(440,465,"Z-Limit reached");
break;
case 6: outtextxy(440,465,"Can't drill, M/c is OFF");
break;
case 7: while(!kbhit())
outtextxy(440,465,"Max holes, Esc twice");
if(getch()==27)
break;
else msg(7,0);
}
}
/***************************************************************************/
void m_on_off()
{
int ch,arr[8];
calc(arr,189,234,192,255);
msg(1,20);
while(!kbhit()){}
ch=getch();
if(ch==13 && on_off==-1)
{
on_off=on_off*(-1);
line_fill(RED,135,110,140,115,0,1,1);
operation();
}
else if(ch==13 && on_off==1)
{
on_off=on_off*(-1);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
operation();
}
else if(ch==27)
operation();
else m_on_off();
}
/***************************************************************************/
void z_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72)
{
z_trans(-1);
z_control();
}
else if(ch==80)
{
z_trans(1);
z_control();
}
else if(ch==27)
{
while(!z_trans(-1)){}
operation();
}
else
z_control();
}
/***************************************************************************/
void tool_trans(int z_vector)
{
int x1,y1,x2,y2,arr[8],y2_temp;
y2=tool_obj.pop();
x2=tool_obj.pop();
y1=tool_obj.pop();
x1=tool_obj.pop();
y2_temp=y2;
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
line_fill(BLACK,x1,y1,x2-4,y2,0,1,1);
line_fill(BLACK,x2-5,y1,x2-2,y2,0,1,1);
line_fill(BLACK,x2-3,y1,x2,y2,0,1,1);
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
calc(arr,189,y2+29,192,y2+50);
line_fill(BLACK,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(BLACK,191,y2+22,194,y2+29,0,1,1);
setfillstyle(4,BLACK);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
tool_obj.push(x1);
tool_obj.push(y1);
tool_obj.push(x2);
tool_obj.push(y2+z_vector);
/*********************************/
/* REDRAW */
/*********************************/
y2=y2+z_vector;
w();
rectangle(x1,y1,x2,y2);
line_fill(normal,x1,y1,x2-4,y2,0,1,1);
line_fill(shine,x2-5,y1,x2-2,y2,0,1,1);
line_fill(normal,x2-3,y1,x2,y2,0,1,1);
w();
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
line_fill(normal,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(shine,191,y2+22,194,y2+29,0,1,1);
w();
calc(arr,189,y2+29,192,y2+50);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
y2=table_obj.pop(); /*update object*/
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2);
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
if(no>4)
{
no=0;
msg(7,10);
init_arr(x_co_ord);
init_arr(y_co_ord);
reset=1;
c=0;
line_fill(BLACK,355,150,415,200,10,1,1);
line_fill(BLACK,355,275,415,295,10,2,1);
point_trans(0,0);
w();
}
else if(y2_temp+53==276 && !reset)
{
hole();
}
}
/***************************************************************************/
void x_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && x_limit!=2)
{
x_trans(1);
x_control();
}
else if(ch==80 && x_limit!=1)
{
x_trans(-1);
x_control();
}
else if(ch==27)
{
operation();
}
else
x_control();
}
/***************************************************************************/
void x_trans(int rot_vector)
{
static double x1=190,y1=357;
static int x_degree=0;
double x_temp,y_temp;
int k;
x_degree=x_degree+rot_vector;
setcolor(BLACK);
circle(190,362,10);
circle(x1,y1,2); //x_handle
/********************************/
/* REDRAW */
/********************************/
x_temp=190+(x1-190)*cos(rot_vector)-(y1-362)*sin(rot_vector);
y_temp=362+(x1-190)*sin(rot_vector)+(y1-362)*cos(rot_vector);
x1=x_temp;
y1=y_temp;
w();
circle(190,362,10);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
circle(x1,y1,2); //x_handle
setfillstyle(1,LIGHTRED);
fillellipse(x1,y1,2,2);
putpixel(190,362,YELLOW);
if(x_degree<=12||x_degree>=-12)
{
x_degree=0;
point_trans(rot_vector*2,0);
if(x_limit)
msg(3,0);
else
msg(2,0);
}
}
/***************************************************************************/
void hole()
{
int x1,y1,j,pt=0;
y1=point_obj.pop();
x1=point_obj.pop();
point_obj.push(x1); /* reload point co_ord's */
point_obj.push(y1);
for(j=0;j<=no;j++)
{
if(x_co_ord[j]==x1 && y_co_ord[j]==y1)
{
pt=1;
break;
}
}
if(!pt)
{
x_co_ord[no]=x1;
y_co_ord[no]=y1;
no+=1;
for(j=0;j<=no;j++)
{
setfillstyle(1,LIGHTRED);
fillellipse(x_co_ord[j],y_co_ord[j],2,2);
}
}
}
/***************************************************************************/
void init_arr(int *p)
{
int i;
for(i=0;i<=4;i++)
{
*(p+i)=0;
}
}
/***************************************************************************/
void s_hole()
{
int pt_x1,pt_y1,tip;
pt_y1=point_obj.pop();
pt_x1=point_obj.pop();
point_obj.push(pt_x1); /* reload point co-ord's */
point_obj.push(pt_y1);
tip=tool_obj.pop()+53;
tool_obj.push(tip-53); /* reload tool tip */
line_fill(c,pt_x1-1,275,pt_x1+1,tip,0,1,1);
rectangle(pt_x1-1,275,pt_x1+1,tip);
w();
rectangle(355,275,415,295);
}
/***************************************************************************/
void label()
{
int k=20,ch;
hori_pix(204,55,250,shine,YELLOW,2,k);
lc();
outtextxy(254,50,"\n Motor");
hori_pix(220,95,270,shine,YELLOW,2,k);
lc();
outtextxy(274,90,"\n Head");
hori_pix(76,95,126,shine,YELLOW,2,k);
lc();
outtextxy(10,85,"\n On/Off");
outtextxy(10,95," Board");
hori_pix(278,135,325,shine,YELLOW,2,k);
lc();
outtextxy(329,130,"\n Feed Lever");
hori_pix(99,188,149,shine,YELLOW,2,k);
lc();
outtextxy(44,183,"\n Body");
hori_pix(199,215,249,shine,YELLOW,2,k);
lc();
outtextxy(253,210,"\n Chuck");
hori_pix(194,240,249,shine,YELLOW,2,k);
lc();
outtextxy(253,235,"\n Tool");
hori_pix(85,300,116,shine,YELLOW,2,k);
lc();
outtextxy(10,295,"\n Table");
outtextxy(10,305," & ");
outtextxy(10,315," Object");
hori_pix(204,360,254,shine,YELLOW,2,k);
lc();
outtextxy(258,355,"\n x-Translator");
hori_pix(299,310,349,shine,YELLOW,2,k);
lc();
outtextxy(352,305,"\n y-Translator");
hori_pix(300,385,368,shine,YELLOW,2,k);
lc();
outtextxy(372,380,"\n Base");
hori_pix(420,190,470,shine,YELLOW,2,k);
lc();
outtextxy(474,185,"\n Top view");
hori_pix(420,290,470,shine,YELLOW,2,k);
lc();
outtextxy(474,285,"\n Side view");
lb();
outtextxy(500,15,"Press:");
outtextxy(500,35,"h:Homepage");
while(getch()!=104){}
my_window();
}
/***************************************************************************/
void main()
{
in_graph();
setcolor(LIGHTBLUE);
settextstyle(0,0,1);
outtextxy(10,10,"Om Sai Ram");
settextstyle(0,0,1);
border();
outtextxy(350,240,"Pree any key to START");
getch();
cleardevice();
point_obj.pop(); //flush the unwanted
point_obj.pop();
my_window();
getch();
}
/***************************************************************************/
Snakeman Game
This a Snake Game in C.G and C++
//80*48
#include fstream.h
#include stdlib.h
#include process.h
#include stdio.h
#include time.h
#include dos.h
#include string.h
#include graphics.h
#include bios.h
#include conio.h
#include iomanip.h
unsigned key;
int len=0,count=0,foodtype=0,d,m,food_flag=0,j=0,i=0,display_count=10,
hscore_pos=0,x_index=0,y_index=0,mx,my,maze=1,speed=100;
long score=0,ti_elap=0,ti_rem=15,tot_ti=15,ti_init;
char *main_menu[]={{"1. Play"},{"2. Options"},{"3. Instruction"},
{"4. Hi-Score"},{"5. Exit"}};
char *game_menu[]={{"1. Mazes"},{"2. Level"},{"3. Back to Main menu"}};
char *maze_menu[]={{"1. Open"},{"2. Box"},{"3. Twisted"},
{"4. Return to Main menu"}};
char *level_menu[]={{"1. Beginner"},{"2. Intermediate"},{"3. Expert"},
{"4. Return to Main menu"}};
char *m_m[]={"P","O","I","H","E"};
char *g_m[]={"M","L","B"};
char *mm[]={"O","B","T","R"};
char *lm[]={"B","I","E","R"};
int maze3_x[][14]={{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{25},
{30},
{37,38,39,40,41,42,43,44,45,46,47,48,49,50}};
int maze3_y[][14]={{30},
{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{27,28,29,30,31,32,33,34,35,36,37,38,39,40},
{20}};
void showfood();
void end();
void show_game_menu();
void show_main_menu();
enum{UP=1,RIGHT=2,DOWN=3,LEFT=4}DIRECTION,Pre_Dir;
struct
{
unsigned x:7 ;
unsigned y:7 ;
}coordinate[1000],tail,head,food;
inline void initialise()
{
d=DETECT;
initgraph(&d,&m,"e:\tc\bgi");
cleardevice();
mx=getmaxx();
my=getmaxy();
}
void RESET()
{
len=count=foodtype=food_flag=i=j=hscore_pos=x_index=y_index=0;
display_count=10,
speed=100;
score=ti_elap=0;ti_rem=tot_ti=15;
head.x=head.y=tail.x=tail.y=food.x=food.y=0;
for(i=0;i<1000;i++)
coordinate[i].x=coordinate[i].y=0;
}
void showoff_food()
{
gotoxy(food.x,food.y);
cout<<" ";
food.x=food.y=0;
showfood();
}
int showfoodtimer(int fo_fl)
{
if(fo_fl==1)
{
if(ti_rem<=0)
{
showoff_food();
ti_rem=15;
food_flag=0;
}
else
{
ti_elap=((biostime(0,0L)-ti_init)/(speed/16));
ti_rem=(tot_ti-(ti_elap));
gotoxy(7,46);
if(ti_rem<10)
cout<<"0"< else
cout< }
}
else
{
gotoxy(7,46);
cout<<" ";
}
return 0;
}
void showfood()
{
int flag=0;
re:
food.x=random(49)+2;
food.y=random(39)+2;
for(i=0;i {
if(food.x==coordinate[i].x && food.y==coordinate[i].y)
goto re;
}
if(maze==3)
{
for(i=0;i<4;i++)
{
for(j=0;j<14;j++)
{
if(food.x==maze3_x[i][j])
flag=1;
}
for(j=0;j<14;j++)
{
if(food.y==maze3_y[i][j] && flag==1)
goto re;
}
}
}
gotoxy(food.x,food.y);
textcolor(RED);
cprintf("@");
}
void showbigfood()
{
re1:
food.x=random(49)+2;
food.y=random(39)+2;
for(int j=0;j {
if(food.x==coordinate[j].x && food.y==coordinate[j].y)
goto re1;
}
textcolor(YELLOW);
gotoxy(food.x,food.y);
cprintf("é");
}
void exit()
{
delay(50);
textmode(4);
gotoxy(10,8);
cout<<"Exiting the program";
delay(2000);
exit(0);
}
void border()
{
setcolor(GREEN);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
settextstyle(4,0,5);
outtextxy(180,40,"SNAKEMAN");
setcolor(YELLOW);
line(165,88,440,88);
setcolor(RED);
line(165,90,440,90);
}
void intro_graphics()
{
clrscr();
initialise();
border();
settextstyle(3,0,3);
setcolor(RED);
outtextxy(130,200,"Programmed By:");
settextstyle(1,0,3);
setcolor(WHITE);
outtextxy(330,200,"Manish Jain");
outtextxy(150,235,"mkj_manishjain@yahoo.co.in");
outtextxy(150,275," +91 9896455735");
settextstyle(1,0,4);
setcolor(RED);
outtextxy(120,360,"Press any key to play");
getch();
}
void showtime()
{
char datebuf[9];
char timebuf[9];
_strdate(datebuf);
_strtime(timebuf);
gotoxy(30,45);
cout<<" DATE TIME";
gotoxy(30,46);
cout< }
inline void showscore()
{
gotoxy(15,45);
cout<<"SCORE";
gotoxy(16,46);
cout< }
char *return_maze()
{
switch(maze)
{
case 1: return ("OPEN");
case 2: return ("BOX");
case 3: return ("TWISTED");
}
return "OPEN";
}
void init()
{
DIRECTION=Pre_Dir=RIGHT;
gotoxy(60,30);
cout<<"M A Z E";
gotoxy(60,32);
cout< gotoxy(5,45);
cout<<"Timer";
randomize();
_setcursortype(_NOCURSOR);
showtime();
showscore();
tail.x=10;
tail.y=10;
for(int i=10;i<15;i++)
{
coordinate[len].x=i;
coordinate[len].y=10;
gotoxy(coordinate[len].x,coordinate[len].y);
cout< len++;
}
head.x=14;
head.y=10;
textcolor(BLUE);
for(i=1;i<=50;i++)
{
j=1;
gotoxy(i,j);
cprintf("");
gotoxy(i,j+40);
cprintf("");
}
for(i=1;i<=41;i++)
{
j=1;
gotoxy(j,i);
cprintf("");
gotoxy(j+50,i);
cprintf("");
}
showfood();
}
void show_snake(int DIRECTION)
{
gotoxy(head.x,head.y);
textcolor(GREEN);
switch(DIRECTION)
{
case UP :
if(Pre_Dir==LEFT)
cprintf("Ý");
else
cprintf("Þ");
break;
case RIGHT:
if(Pre_Dir==DOWN)
cprintf("Ü");
else
cprintf("ß");
break;
case DOWN :
if(Pre_Dir==RIGHT)
cprintf("Þ");
else
cprintf("Ý");
break;
case LEFT :
if(Pre_Dir==UP)
cprintf("ß");
else
cprintf("Ü");
break;
}
}
inline void showoff()
{
gotoxy(tail.x,tail.y);
cout<<" ";
}
inline void SOUND()
{
sound(1500);
delay(55);
nosound();
}
void gameover()
{
sound(1220);
delay(500);
nosound();
initialise();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(130,180,"GAME OVER");
settextstyle(1,0,5);
setcolor(BLUE);
outtextxy(140,250,"SCORE");
gotoxy(48,16);
char *s;
ltoa(score,s,10);
outtextxy(325,250,s);
settextstyle(4,0,5);
setcolor(WHITE);
outtextxy(65,350,"Wish to continue:(Y/N):");
char ch=getche();
if(ch=='y'||ch=='Y')
{
outtextxy(510,350,"Y");
getch();
RESET();
initialise();
show_main_menu();
}
else if(ch=='n'||ch=='N')
{
outtextxy(510,350,"N");
free(maze_menu);
free(main_menu);
free(level_menu);
free(game_menu);
free(m_m);
free(mm);
free(lm);
free(g_m);
exit();
}
}
void loadmaze()
{
if(maze==3)
{
textcolor(WHITE);
for(i=1;i<15;i++)
{
gotoxy(i+1,30);
cprintf("²");
gotoxy(25,i+1);
cprintf("²");
gotoxy(36+i,20);
cprintf("²");
gotoxy(30,26+i);
cprintf("²");
}
}
}
void game()
{
init();
loadmaze();
sleep(2);
while(1)
{
if(bioskey(1))
{
key=bioskey(0);
int s=key>>8;
if(s==1)
exit();
else
if(s==72) //If UP arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=UP;
}
}
else if(s==80) //If DOWN arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=DOWN;
}
}
else if(s==77) ////If RIGHT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=RIGHT;
}
}
else if(s==75) ////If LEFT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=LEFT;
}
}
}
if(DIRECTION==2) //Right Key
head.x++;
else if(DIRECTION==1) //Up Key
head.y--;
else if(DIRECTION==4) //Left Key
head.x--;
else if(DIRECTION==3) //Down Key
head.y++;
if(maze==1) //OPEN maze
{
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
else if(maze==2) //BOX Maze
{
if(head.x>50 ||head.y>40 ||head.x<2 ||head.y<2)
gameover();
}
else if(maze==3) //TWISTED or SPIRAL Maze
{
for(i=2;i<16;i++)
{
if((head.x==25 && head.y==i)||(head.x==i && head.y==30)
||(head.x==35+i && head.y==20)||(head.x==30 && head.y==25+i))
{
gameover();
}
}
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
for(int i=0;i {
if(head.x==coordinate[i].x && head.y==coordinate[i].y)
{
gameover();
}
}
show_snake(DIRECTION);
if(head.x==food.x && head.y==food.y)
{
count++;
if(ti_rem>5)
score+=(foodtype*8)+2+(foodtype*((ti_rem*3)/2));
else
score+=(foodtype*8)+2;
ti_rem=15;
SOUND();
food.x=food.y=0;
if(count==5)
{
showbigfood();
food_flag=1;
ti_init=biostime(0,0);
showfoodtimer(1);
foodtype=1;
count=0;
}
else
{
showfood();
food_flag=0;
foodtype=0;
}
len++;
}
else
{
tail.x=coordinate[0].x;
tail.y=coordinate[0].y;
showoff();
for(int k=0;k {
coordinate[k].x=coordinate[k+1].x;
coordinate[k].y=coordinate[k+1].y;
}
}
coordinate[len-1].x=head.x;
coordinate[len-1].y=head.y;
delay(speed);
showtime();
showscore();
showfoodtimer(food_flag);
gotoxy(64,14);
cout<<"X-Cor Y-Cor";
gotoxy(65,15);
cout< }
}
void get_level_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 48:
case 28:
case 79: speed=125;
show_main_menu();
break;
case 3:
case 23:
case 80: speed=90;
show_main_menu();
break;
case 4:
case 18:
case 81: speed=55;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void get_maze_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 28:
case 24:
case 79: maze=1;
show_main_menu();
break;
case 3:
case 48:
case 80: maze=2;
show_main_menu();
break;
case 4:
case 20:
case 81: maze=3;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void getlevel()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"L E V E L");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),level_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),lm[i]);
}
get_level_choice();
}
void getmaze()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"M A Z E S");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),maze_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),mm[i]);
}
get_maze_choice();
}
void get_gm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 50:
case 28:
case 79: getmaze();
break;
case 3:
case 38:
case 80: getlevel();
break;
case 4:
case 48:
case 81: show_main_menu();
break;
default: goto get;
}
}
void show_game_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"G A M E M E N U");
settextstyle(3,0,5);
for(i=0;i<3;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),game_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),g_m[i]);
}
get_gm_choice();
}
void play()
{
cleardevice();
restorecrtmode();
textmode(64);
game();
}
void options()
{
show_game_menu();
}
void instruction()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140,"I N S T R U C T I O N S");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,190,"1. Move the snake using Arrow Keys -> ");
outtextxy(60,230," UP, DOWN, LEFT, RIGHT");
outtextxy(60,270,"2. Eat food (@,é) and make snake grow longer.");
outtextxy(60,300,"3. You will get 2 points for (@) and");
outtextxy(60,330," more points for Bonus food(é)");
outtextxy(60,365,"4. Don't let it hit the walls or its tail");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void hiscore()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140," H I S C O R E");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,220,"Sorry! This feature is not available in this version
");
outtextxy(60,270,"For further details, Contact : ");
setcolor(GREEN);
outtextxy(60,310," mkj_manishjain@yahoo.co.in");
outtextxy(60,345," Mobile no.: +91 9896455735 ");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void get_mm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 25:
case 28:
case 79: play();
break;
case 3:
case 24:
case 80: options();
break;
case 4:
case 23:
case 81: instruction();
break;
case 5:
case 35:
case 75: hiscore();
break;
case 6:
case 18:
case 76: exit();
break;
default: goto get;
}
}
void show_main_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(60,130,"M A I N M E N U");
settextstyle(3,0,5);
for(i=0;i<5;i++)
{
setcolor(WHITE);
outtextxy(67,180+(35*i),main_menu[i]);
setcolor(RED);
outtextxy(130,180+(35*i),m_m[i]);
}
get_mm_choice();
}
void end()
{
initialise();
for(j=0;j<=2;j++)
{
setcolor(RED+j);
circle(mx/2,my/2,150+j*2);
}
settextstyle(4,0,5);
outtextxy(mx/2-65,my/2-20,"The End");
getch();
closegraph();
restorecrtmode();
exit(0);
}
//MAIN FUNCTION
void main()
{
intro_graphics();
show_main_menu();
}
//80*48
#include fstream.h
#include stdlib.h
#include process.h
#include stdio.h
#include time.h
#include dos.h
#include string.h
#include graphics.h
#include bios.h
#include conio.h
#include iomanip.h
unsigned key;
int len=0,count=0,foodtype=0,d,m,food_flag=0,j=0,i=0,display_count=10,
hscore_pos=0,x_index=0,y_index=0,mx,my,maze=1,speed=100;
long score=0,ti_elap=0,ti_rem=15,tot_ti=15,ti_init;
char *main_menu[]={{"1. Play"},{"2. Options"},{"3. Instruction"},
{"4. Hi-Score"},{"5. Exit"}};
char *game_menu[]={{"1. Mazes"},{"2. Level"},{"3. Back to Main menu"}};
char *maze_menu[]={{"1. Open"},{"2. Box"},{"3. Twisted"},
{"4. Return to Main menu"}};
char *level_menu[]={{"1. Beginner"},{"2. Intermediate"},{"3. Expert"},
{"4. Return to Main menu"}};
char *m_m[]={"P","O","I","H","E"};
char *g_m[]={"M","L","B"};
char *mm[]={"O","B","T","R"};
char *lm[]={"B","I","E","R"};
int maze3_x[][14]={{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{25},
{30},
{37,38,39,40,41,42,43,44,45,46,47,48,49,50}};
int maze3_y[][14]={{30},
{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{27,28,29,30,31,32,33,34,35,36,37,38,39,40},
{20}};
void showfood();
void end();
void show_game_menu();
void show_main_menu();
enum{UP=1,RIGHT=2,DOWN=3,LEFT=4}DIRECTION,Pre_Dir;
struct
{
unsigned x:7 ;
unsigned y:7 ;
}coordinate[1000],tail,head,food;
inline void initialise()
{
d=DETECT;
initgraph(&d,&m,"e:\tc\bgi");
cleardevice();
mx=getmaxx();
my=getmaxy();
}
void RESET()
{
len=count=foodtype=food_flag=i=j=hscore_pos=x_index=y_index=0;
display_count=10,
speed=100;
score=ti_elap=0;ti_rem=tot_ti=15;
head.x=head.y=tail.x=tail.y=food.x=food.y=0;
for(i=0;i<1000;i++)
coordinate[i].x=coordinate[i].y=0;
}
void showoff_food()
{
gotoxy(food.x,food.y);
cout<<" ";
food.x=food.y=0;
showfood();
}
int showfoodtimer(int fo_fl)
{
if(fo_fl==1)
{
if(ti_rem<=0)
{
showoff_food();
ti_rem=15;
food_flag=0;
}
else
{
ti_elap=((biostime(0,0L)-ti_init)/(speed/16));
ti_rem=(tot_ti-(ti_elap));
gotoxy(7,46);
if(ti_rem<10)
cout<<"0"<
cout<
}
else
{
gotoxy(7,46);
cout<<" ";
}
return 0;
}
void showfood()
{
int flag=0;
re:
food.x=random(49)+2;
food.y=random(39)+2;
for(i=0;i
if(food.x==coordinate[i].x && food.y==coordinate[i].y)
goto re;
}
if(maze==3)
{
for(i=0;i<4;i++)
{
for(j=0;j<14;j++)
{
if(food.x==maze3_x[i][j])
flag=1;
}
for(j=0;j<14;j++)
{
if(food.y==maze3_y[i][j] && flag==1)
goto re;
}
}
}
gotoxy(food.x,food.y);
textcolor(RED);
cprintf("@");
}
void showbigfood()
{
re1:
food.x=random(49)+2;
food.y=random(39)+2;
for(int j=0;j
if(food.x==coordinate[j].x && food.y==coordinate[j].y)
goto re1;
}
textcolor(YELLOW);
gotoxy(food.x,food.y);
cprintf("é");
}
void exit()
{
delay(50);
textmode(4);
gotoxy(10,8);
cout<<"Exiting the program";
delay(2000);
exit(0);
}
void border()
{
setcolor(GREEN);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
settextstyle(4,0,5);
outtextxy(180,40,"SNAKEMAN");
setcolor(YELLOW);
line(165,88,440,88);
setcolor(RED);
line(165,90,440,90);
}
void intro_graphics()
{
clrscr();
initialise();
border();
settextstyle(3,0,3);
setcolor(RED);
outtextxy(130,200,"Programmed By:");
settextstyle(1,0,3);
setcolor(WHITE);
outtextxy(330,200,"Manish Jain");
outtextxy(150,235,"mkj_manishjain@yahoo.co.in");
outtextxy(150,275," +91 9896455735");
settextstyle(1,0,4);
setcolor(RED);
outtextxy(120,360,"Press any key to play");
getch();
}
void showtime()
{
char datebuf[9];
char timebuf[9];
_strdate(datebuf);
_strtime(timebuf);
gotoxy(30,45);
cout<<" DATE TIME";
gotoxy(30,46);
cout<
inline void showscore()
{
gotoxy(15,45);
cout<<"SCORE";
gotoxy(16,46);
cout<
char *return_maze()
{
switch(maze)
{
case 1: return ("OPEN");
case 2: return ("BOX");
case 3: return ("TWISTED");
}
return "OPEN";
}
void init()
{
DIRECTION=Pre_Dir=RIGHT;
gotoxy(60,30);
cout<<"M A Z E";
gotoxy(60,32);
cout<
cout<<"Timer";
randomize();
_setcursortype(_NOCURSOR);
showtime();
showscore();
tail.x=10;
tail.y=10;
for(int i=10;i<15;i++)
{
coordinate[len].x=i;
coordinate[len].y=10;
gotoxy(coordinate[len].x,coordinate[len].y);
cout<
}
head.x=14;
head.y=10;
textcolor(BLUE);
for(i=1;i<=50;i++)
{
j=1;
gotoxy(i,j);
cprintf("");
gotoxy(i,j+40);
cprintf("");
}
for(i=1;i<=41;i++)
{
j=1;
gotoxy(j,i);
cprintf("");
gotoxy(j+50,i);
cprintf("");
}
showfood();
}
void show_snake(int DIRECTION)
{
gotoxy(head.x,head.y);
textcolor(GREEN);
switch(DIRECTION)
{
case UP :
if(Pre_Dir==LEFT)
cprintf("Ý");
else
cprintf("Þ");
break;
case RIGHT:
if(Pre_Dir==DOWN)
cprintf("Ü");
else
cprintf("ß");
break;
case DOWN :
if(Pre_Dir==RIGHT)
cprintf("Þ");
else
cprintf("Ý");
break;
case LEFT :
if(Pre_Dir==UP)
cprintf("ß");
else
cprintf("Ü");
break;
}
}
inline void showoff()
{
gotoxy(tail.x,tail.y);
cout<<" ";
}
inline void SOUND()
{
sound(1500);
delay(55);
nosound();
}
void gameover()
{
sound(1220);
delay(500);
nosound();
initialise();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(130,180,"GAME OVER");
settextstyle(1,0,5);
setcolor(BLUE);
outtextxy(140,250,"SCORE");
gotoxy(48,16);
char *s;
ltoa(score,s,10);
outtextxy(325,250,s);
settextstyle(4,0,5);
setcolor(WHITE);
outtextxy(65,350,"Wish to continue:(Y/N):");
char ch=getche();
if(ch=='y'||ch=='Y')
{
outtextxy(510,350,"Y");
getch();
RESET();
initialise();
show_main_menu();
}
else if(ch=='n'||ch=='N')
{
outtextxy(510,350,"N");
free(maze_menu);
free(main_menu);
free(level_menu);
free(game_menu);
free(m_m);
free(mm);
free(lm);
free(g_m);
exit();
}
}
void loadmaze()
{
if(maze==3)
{
textcolor(WHITE);
for(i=1;i<15;i++)
{
gotoxy(i+1,30);
cprintf("²");
gotoxy(25,i+1);
cprintf("²");
gotoxy(36+i,20);
cprintf("²");
gotoxy(30,26+i);
cprintf("²");
}
}
}
void game()
{
init();
loadmaze();
sleep(2);
while(1)
{
if(bioskey(1))
{
key=bioskey(0);
int s=key>>8;
if(s==1)
exit();
else
if(s==72) //If UP arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=UP;
}
}
else if(s==80) //If DOWN arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=DOWN;
}
}
else if(s==77) ////If RIGHT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=RIGHT;
}
}
else if(s==75) ////If LEFT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=LEFT;
}
}
}
if(DIRECTION==2) //Right Key
head.x++;
else if(DIRECTION==1) //Up Key
head.y--;
else if(DIRECTION==4) //Left Key
head.x--;
else if(DIRECTION==3) //Down Key
head.y++;
if(maze==1) //OPEN maze
{
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
else if(maze==2) //BOX Maze
{
if(head.x>50 ||head.y>40 ||head.x<2 ||head.y<2)
gameover();
}
else if(maze==3) //TWISTED or SPIRAL Maze
{
for(i=2;i<16;i++)
{
if((head.x==25 && head.y==i)||(head.x==i && head.y==30)
||(head.x==35+i && head.y==20)||(head.x==30 && head.y==25+i))
{
gameover();
}
}
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
for(int i=0;i
if(head.x==coordinate[i].x && head.y==coordinate[i].y)
{
gameover();
}
}
show_snake(DIRECTION);
if(head.x==food.x && head.y==food.y)
{
count++;
if(ti_rem>5)
score+=(foodtype*8)+2+(foodtype*((ti_rem*3)/2));
else
score+=(foodtype*8)+2;
ti_rem=15;
SOUND();
food.x=food.y=0;
if(count==5)
{
showbigfood();
food_flag=1;
ti_init=biostime(0,0);
showfoodtimer(1);
foodtype=1;
count=0;
}
else
{
showfood();
food_flag=0;
foodtype=0;
}
len++;
}
else
{
tail.x=coordinate[0].x;
tail.y=coordinate[0].y;
showoff();
for(int k=0;k
coordinate[k].x=coordinate[k+1].x;
coordinate[k].y=coordinate[k+1].y;
}
}
coordinate[len-1].x=head.x;
coordinate[len-1].y=head.y;
delay(speed);
showtime();
showscore();
showfoodtimer(food_flag);
gotoxy(64,14);
cout<<"X-Cor Y-Cor";
gotoxy(65,15);
cout<
}
void get_level_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 48:
case 28:
case 79: speed=125;
show_main_menu();
break;
case 3:
case 23:
case 80: speed=90;
show_main_menu();
break;
case 4:
case 18:
case 81: speed=55;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void get_maze_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 28:
case 24:
case 79: maze=1;
show_main_menu();
break;
case 3:
case 48:
case 80: maze=2;
show_main_menu();
break;
case 4:
case 20:
case 81: maze=3;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void getlevel()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"L E V E L");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),level_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),lm[i]);
}
get_level_choice();
}
void getmaze()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"M A Z E S");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),maze_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),mm[i]);
}
get_maze_choice();
}
void get_gm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 50:
case 28:
case 79: getmaze();
break;
case 3:
case 38:
case 80: getlevel();
break;
case 4:
case 48:
case 81: show_main_menu();
break;
default: goto get;
}
}
void show_game_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"G A M E M E N U");
settextstyle(3,0,5);
for(i=0;i<3;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),game_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),g_m[i]);
}
get_gm_choice();
}
void play()
{
cleardevice();
restorecrtmode();
textmode(64);
game();
}
void options()
{
show_game_menu();
}
void instruction()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140,"I N S T R U C T I O N S");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,190,"1. Move the snake using Arrow Keys -> ");
outtextxy(60,230," UP, DOWN, LEFT, RIGHT");
outtextxy(60,270,"2. Eat food (@,é) and make snake grow longer.");
outtextxy(60,300,"3. You will get 2 points for (@) and");
outtextxy(60,330," more points for Bonus food(é)");
outtextxy(60,365,"4. Don't let it hit the walls or its tail");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void hiscore()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140," H I S C O R E");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,220,"Sorry! This feature is not available in this version
");
outtextxy(60,270,"For further details, Contact : ");
setcolor(GREEN);
outtextxy(60,310," mkj_manishjain@yahoo.co.in");
outtextxy(60,345," Mobile no.: +91 9896455735 ");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void get_mm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 25:
case 28:
case 79: play();
break;
case 3:
case 24:
case 80: options();
break;
case 4:
case 23:
case 81: instruction();
break;
case 5:
case 35:
case 75: hiscore();
break;
case 6:
case 18:
case 76: exit();
break;
default: goto get;
}
}
void show_main_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(60,130,"M A I N M E N U");
settextstyle(3,0,5);
for(i=0;i<5;i++)
{
setcolor(WHITE);
outtextxy(67,180+(35*i),main_menu[i]);
setcolor(RED);
outtextxy(130,180+(35*i),m_m[i]);
}
get_mm_choice();
}
void end()
{
initialise();
for(j=0;j<=2;j++)
{
setcolor(RED+j);
circle(mx/2,my/2,150+j*2);
}
settextstyle(4,0,5);
outtextxy(mx/2-65,my/2-20,"The End");
getch();
closegraph();
restorecrtmode();
exit(0);
}
//MAIN FUNCTION
void main()
{
intro_graphics();
show_main_menu();
}
ARCHERY GAME
Full Game of ARCHERY made in C.G and C++
//////////////////////////////////////////////////////////////////////////// ////////////////// ARCHERY GAME //////////////
///////////////////////////////////////////////////////
/* Programmer : Harsh chandra
Email : harshchandra@gmail.com
Reference : Graphics Under C - Yashawant Kanetkar
*/
#include iostream.h
#include conio.h
#include string.h
#include graphics.h
#include process.h
#include dos.h
#include stdio.h
#include stdlib.h
#include math.h
//structure declaration
struct scorechart
{
char player[45];
int scor;
};
struct scorechart s1[5];
//global variables
union REGS i,o;
char buff[80];
int hit=0,life=1;
int m1=1,m2=1,m3=1,m4=1,m5=1,gover=0;
int level1=1,check=0,score=0,mid,flag=0;
char buffer1[80],buffer[80];
int count=0,ascii,z1=625,scan,m=60,n=70,p=80,q=50,r;
int left=10,top=285,right=63,bottom=285;
unsigned int size,size1,size2,size3,size4,globalsize,handsize,eyesize;
void *pball,*pball1,*pball2,*pball3,*pball4,*handimage,*peye;
void *iball,*iball1,*iball2,*iball3;
//function declaration
void image1();
void image();
void hand();
void arrow(int);
int shoot(int);
void game();
void ball();
void eyelevel();
void balllevel2();
void gethighscores();
void displaytopscore();
void updatehighscore();
void writehighscorestodisk();
//function defintion
void hand()
{
setcolor(8);
setlinestyle(0,1,3);
setfillstyle(1,8);
bar(14,197,19,215);
line(19,198,23,198);
line(22,200,29,192);
line(29,192,38,192);
line(37,192,37,197);
line(32,197,54,197);
line(54,197,54,202);
line(32,202,54,202);
line(32,207,42,207);
line(32,212,42,212);
line(42,212,42,202);
line(38,212,38,217);
line(38,217,14,217);
handsize= imagesize(14,190,56,220);
/* allocate memory to hold the image */
handimage= malloc(handsize);
/* grab the image */
getimage(14,190, 56,220, handimage);
cleardevice();
}
void image1()
{
unsigned int s,s1,s2,s3;
setlinestyle(0,1,3);
setcolor(RED);
circle(500,60,20);
setfillstyle(1,12);
floodfill(500,60,RED);
circle(430,70,20);
setfillstyle(1,YELLOW);
floodfill(430,70,RED);
circle(360,80,20);
setfillstyle(1,9);
floodfill(360,80,RED);
setcolor(RED);
circle(290,50,20);
setfillstyle(1,6);
floodfill(290,50,RED);
s = imagesize(470,35,530,85); //k
s1= imagesize(400,45,460,95); //l
s3= imagesize(330,55,390,105);//e
s2= imagesize(260,25,320,75); //f
/* allocate memory to hold the image */
iball= malloc(s);
iball1=malloc(s1);
iball2=malloc(s2);
iball3=malloc(s3);
/* grab the image */
getimage(470,35, 530, 85, iball);
getimage(400,45,460,95,iball1);
getimage(330,55,390,105,iball2);
getimage(260,25,320,75,iball3);
putimage(470,35,iball,XOR_PUT);
putimage(400,45,iball1,XOR_PUT);
putimage(330,55,iball2,XOR_PUT);
putimage(260,25,iball3,XOR_PUT);
}
void conveximage()
{
setlinestyle(0,1,3);
setcolor(4);
ellipse(500, 55, 0,360,13,35);
setfillstyle(1,9);
fillellipse(500,55,13,35);
setcolor(0);
putpixel(500,55,4);
setlinestyle(0,1,1);
ellipse(500, 55, 0,360,10.5,4.5);
circle(500,55,4);
eyesize=imagesize(480,15,520,95);
peye=malloc(size);
getimage(480,15,520,95,peye);
putimage(480,15,peye,XOR_PUT);
}
void image()
{
setlinestyle(0,1,3);
setcolor(RED);
circle(460,420,25);
setfillstyle(1,YELLOW);
floodfill(460,420,4);
circle(470,330,25);
setfillstyle(1,11);
floodfill(470,330,RED);
circle(480,240,25);
setfillstyle(1,9);
floodfill(480,240,RED);
circle(490,150,25);
setfillstyle(1,3);
floodfill(490,150,RED);
circle(500,60,25);
setfillstyle(1,10);
floodfill(500,60,RED);
settextstyle(0,0,5);
sprintf(buffer,"%c",1);
outtextxy(440,400,buffer);
outtextxy(450,310,buffer);
outtextxy(460,220,buffer);
outtextxy(470,130,buffer);
outtextxy(480,40,buffer);
size = imagesize(470,30,530,90); //k
size1= imagesize(460,120,520,180); //l
size2= imagesize(450,210,510,270); //e
size3= imagesize(440,300,500,360);//f
size4= imagesize(430,390,490,450);
/* allocate memory to hold the image */
pball= malloc(size);
pball1=malloc(size1);
pball2=malloc(size2);
pball3=malloc(size3);
pball4=malloc(size4);
/* grab the image */
getimage(470,30, 530, 90, pball);
getimage(460,120,520,180,pball1);
getimage(450,210,510,270,pball2);
getimage(440,300,500,360,pball3);
getimage(430,390,490,450,pball4);
putimage(470,30,pball,XOR_PUT);
putimage(460,120,pball1,XOR_PUT);
putimage(450,210,pball2,XOR_PUT);
putimage(440,300,pball3,XOR_PUT);
putimage(430,390,pball4,XOR_PUT);
}
void getkey()
{
i.h.ah=0x00;
int86(0x16,&i,&o);
ascii=o.h.al;
scan=o.h.ah;
}
void rules()
{
char buffer[80];
cleardevice();
setbkcolor(0);
setcolor(4);
setlinestyle(0,1,3);
rectangle(0,0,640,480);
setfillstyle(1,11);
bar(3,3,637,477);
setcolor(1);
settextstyle(10,0,3);
outtextxy(245,0,"ARCHERY");
setcolor(8);
settextstyle(4,0,3);
outtextxy(15,60,"Rules To Be Followed : ");
settextstyle(0,0,0);
outtextxy(15,85,"_______________________________");
outtextxy(60,120, " Rule # 1 ð> Only One Player Can Play The Game At A Time.");
outtextxy(60,150," Rule # 2 ð> There Are Three Levels Of The game.");
outtextxy(60,180," Rule # 3 ð> Arrow Shooter Is Positioned By The ");
sprintf(buffer," UP(%c) AND DOWN(%c) KEY.",24,25);
outtextxy(444,180,buffer);
outtextxy(60,210," Rule # 4 ð> Only One Arrow Can Be Shooted At A Time.");
outtextxy(60,240," Rule # 5 ð> SpaceBar Is Used To Shoot The Arrow.");
outtextxy(60,270," Rule # 6 ð> Enter Key Is Used To Select any Option.");
outtextxy(60,300," Rule # 7 ð> Five(5) Points Is Rewarded To Each Hit One Makes.");
outtextxy(60,330," Rule # 8 ð> One Can Go To Another Level ,Crossing The Previous Level.");
outtextxy(60,360," Rule # 9 ð> Esc Key From The Main Will Terminate The Game.");
outtextxy(60,390," Rule # 10 ð> Exit Option Will Terminate The Game.");
outtextxy(340,465,"Press Any Key To Resume The game....");
getch();
cleardevice();
}
void level()
{
char buffer[80];
cleardevice();
setbkcolor(0);
setcolor(4);
setlinestyle(0,1,3);
rectangle(0,0,640,480);
setfillstyle(1,14);
bar(3,3,637,477);
setcolor(4);
settextstyle(10,0,3);
outtextxy(245,0,"ARCHERY");
setcolor(8);
settextstyle(4,0,3);
outtextxy(15,45,"Different Levels Of The Game : ");
settextstyle(0,0,1);
outtextxy(15,70,"_________________________________________");
outtextxy(50,100,"LEVEL # 1 ð> Four balloons will be moving vertically and the player has");
outtextxy(55,118," to shoot the balloon. Each hit is rewarded by 5 points.Once");
outtextxy(55,136," the score becomes 100,The player moves to another Level.The");
outtextxy(55,154," player cannot skip or jump any level.");
outtextxy(50,184,"LEVEL # 2 ð> Five monsters will be moving horizontally,the player has");
outtextxy(55,202," to shoot the ball. Each hit is rewarded by 10 points. Once");
outtextxy(55,220," the score becomes 200 , The player moves to another level.");
outtextxy(55,238," If The Ball Touches The Shooter,particular game ends then");
outtextxy(55,256," and there.");
outtextxy(50,286,"LEVEL # 3 ð> One Eye will be Enclosed in convex object moving vertically");
outtextxy(55,302," the player has to target and shoot the eye. The hit which is ");
outtextxy(55,320," closest to the eye will be rewarded accordingly. Once the ");
outtextxy(55,338," player hits the eye exactly, the player is awarded with 500 ");
outtextxy(55,356," points. Only ten arrows are provided for this level. If the ");
outtextxy(55,374," player succeeds ,the game comes to an end, else the player's ");
outtextxy(55,392," game comes to an end.");
outtextxy(340,431,"Press any key to resume the game.......");
getch();
cleardevice();
}
void updatehighscore()
{
FILE *p;
int i=0,t;
struct scorechart s;
clearviewport();
setcolor(2);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
setlinestyle(0,1,3);
ellipse(280,80,0,320,133,50);
setcolor(9);
setfillstyle(1,9);
fillellipse(280,80,133,50);
setcolor(14);
settextstyle(1,0,6);
outtextxy(160,40,"ARCHERY");
settextstyle(1,0,1);
outtextxy(230,170,"SCORE CARD");
setcolor(14);
settextstyle(1,0,1);
outtextxy(120,235,"Enter Your Name : ");
for(i=0;i<=13;i++)
{
setcolor(i);
settextstyle(1,0,1);
outtextxy(250,440,"CONGRATULATIONS!!!!!!!");
delay(100);
if(i>=13)i=0;
if(kbhit())break;
}
gotoxy(42,16);
scanf("%s",s.player);
s.scor=score;
for(i=0;i<5;i++)
{
if(s.scor>s1[i].scor){t=i;break;}
}
for(i=4;i>t;i--)
{
strcpy(s1[i].player,s1[i-1].player);
s1[i].scor=s1[i-1].scor;
}
strcpy(s1[t].player,s.player);
s1[t].scor=s.scor;
setcolor(14);
outtextxy(250,320,"Press Any Key");
getch();
}
void writehighscorestodisk()
{
int i;
FILE *p;
p=fopen("ARCHERY.TXT","w");
for(i=0;i<5;i++)
fprintf(p,"%s\t%d\n",s1[i].player,s1[i].scor);
fclose(p);
return;
}
//main begins
void main()
{
int mid;
static int c=1;
char name[30];
int gdriver = DETECT,gmode, errorcode;
count=0; score=0;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
hand();
image();
image1();
conveximage();
cleardevice();
man:
while(1)
{
cleardevice();
setcolor(WHITE);
c=1;
setbkcolor(2);
setlinestyle(2,1,3);
rectangle(4,4,635,475);
setlinestyle(0,1,3);
rectangle(0,0,640,480);
setlinestyle(0,1,3);
ellipse(320,80,0,360,133,50);
setcolor(9);
setfillstyle(1,9);
fillellipse(320, 80, 133, 50);
setcolor(14);
settextstyle(4,0,6);
outtextxy(190,40,"ARChERY");
line(322,58,322,73);
settextstyle(0,0,3);
putimage(130,175,handimage,OR_PUT);
setcolor(4);
outtextxy(180,180,"PLAY THE GAME....");
setcolor(14);
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
gethighscores();
getkey();
if(ascii==27) //esc
exit(0);
if(ascii==13)
game();
else if(((scan==80)||(scan==72))&&(c==1))
{
b: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,175,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,180,"PLAY THE GAME....");
c++;
score=0;
getkey();
if(ascii==13) { game(),score=0; goto man;}
if(scan==72) { c=5; goto g;}
else if((scan==80)&&(c==2))
{
d: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,225,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,230,"INSTRUCTIONS....");
c++;
getkey();
if(ascii==13) rules();
else if(scan==72){c-=2; goto b;}
if((scan==80)&&(c==3))
{
e: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,275,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,280,"HIGH SCORES....");
c++;
getkey();
if(ascii==13) displaytopscore();
if(scan==72) { c-=2; goto d;}
if((scan==80)&&(c==4))
{
f: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,325,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,330,"LEVELS....");
c++;
getkey();
if(ascii==13) level();
else if(scan==72) { c-=2; goto e;}
else if((scan==80)&&(c==5))
{
g: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,375,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
setcolor(4);
outtextxy(180,380,"EXIT....");
c++;
getkey();
if(ascii==13) break;
else if(scan==72) { c-=2; goto f;}
else if((scan==80))
{ c=1; goto b; }
} //g if close
} //f if
}//e if
}// d elseif
} //b if
}//while
}// main
void displaytopscore()
{
FILE *p;
int i;
char str[100];
p=fopen("ARCHERY.TXT","r");
if(p==NULL)
{
for(i=0;i<5;i++)
{
strcpy(s1[i].player,"Unknown");
s1[i].scor=0;
}
}
else
{
for(i=0;i<5;i++)
if(fscanf(p,"%s\t%d",s1[i].player,&s1[i].scor)==EOF)
fclose(p);
}
fclose(p);
cleardevice();
setlinestyle(0,1,3);
rectangle(0,0,638,478);
setlinestyle(0,1,3);
ellipse(320,80,0,360,133,50);
setcolor(9);
setfillstyle(1,9);
fillellipse(320,80,133,50);
setcolor(14);
settextstyle(1,0,6);
outtextxy(200,40,"ARCHERY");
settextstyle(1,0,1);
setcolor(RED);
outtextxy(240,160,"HIGH SCORES");
setcolor(GREEN);
settextstyle(1,0,1);
for(i=0;i<5;i++)
{
sprintf(str,"%7d --- %10s",s1[i].scor,s1[i].player);
setcolor(4);
outtextxy(170,200+(i*20),str);
}
setcolor(RED);
outtextxy(230,350,"Press ENTER Key");
getch();
// while(i!='\r')
clearviewport();
} //end displaytopscore
void gethighscores()
{
FILE *p;
int i;
char str[100];
p=fopen("ARCHERY.TXT","r");
if(p==NULL)
{
for(i=0;i<5;i++)
{
strcpy(s1[i].player,"Unknown");
s1[i].scor=0;
}
}
else
{
for(i=0;i<5;i++)
if(fscanf(p,"%s\t%d\n",s1[i].player,&s1[i].scor)==EOF)
fclose(p);
}
fclose(p);
} //end gethighscore
void game()
{
level1=1;
count=25;
score=0;
life=1;
m1=1,m2=1,m3=1,m4=1,m5=1;
cleardevice();
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
setbkcolor(0);
setcolor(9);
settextstyle(0,0,2);
outtextxy(555,250,"ARROWS");
outtextxy(555,50,"SCORE ");
outtextxy(555,150,"LEVEL");
setcolor(WHITE);
settextstyle(1,0,1);
itoa(score,buff,5);
outtextxy(585,95,buff);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
itoa(level1,buffer,5);
setcolor(WHITE);
outtextxy(585,175,buffer);
setlinestyle(0,1,3);
setcolor(4);
rectangle(left,top-10,right,bottom+10);
while((1)&&(count!=0))
{
if(score==100)
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
score+=25;
setfillstyle(1,0);
bar(0,0,550,480);
level1++,count=25;
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
settextstyle(1,0,1);
setcolor(WHITE);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
settextstyle(1,0,4);
for(int color=1;color<=14;color++)
{
setcolor(color);
outtextxy(200,200,"LEVEL 2");
delay(200);
}
setfillstyle(1,0);
bar(200,100,400,300);
}
if(level1==1)
ball();
if(level1==2&&score<200)
balllevel2();
if(score==200)
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
score+=25;
setfillstyle(1,0);
bar(0,0,550,480);
level1++,count=25;
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
settextstyle(1,0,1);
setcolor(WHITE);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
settextstyle(1,0,4);
for(int color=1;color<=14;color++)
{
setcolor(color);
outtextxy(200,200,"LEVEL 3");
delay(200);
}
setfillstyle(1,0);
bar(200,100,400,300);
}
if(level1==3&&score>=225&&life==1)
eyelevel();
if(life==0) count=0;
if(gover==1)
count=0;
if(kbhit())
{
getkey();
if(ascii==27)
break;
if(scan==57)
{
mid=(top+bottom)/2;
hit=1;
}
else if((scan==72)&&(z1>=510))
arrow(1);
else if((scan==80)&&(z1>=510))
arrow(0);
}
if(hit==1)
shoot(mid);
} //while
if(score<100)
gover=1;
if(score<500)
gover=1;
if(gover==1)
{
setcolor(1);
settextstyle(4,0,8);
outtextxy(50,180,"GAME OVER");
for(int c=1,j=10;j<=32000;j++)
{
putpixel(random(j),random(j),8);
if(j==32000){j=0;c++;}
if(c>=50)break;
}
gover=0;
}
if(score>s1[4].scor)updatehighscore();
else
clearviewport();
writehighscorestodisk();
// setcolor(4);
// rectangle(left,top-10,right,bottom+10);
cleardevice();
} //end function
void arrow(int pos)
{
int s;
//erase
setfillstyle(SOLID_FILL,0);
bar(left-5,top-15,right+5,bottom+15);
if(pos==1)//up
{
if(top==60)
top=60;
else
{
top-=15;
bottom-=15;
}
}
else
{
if(top==420)
top=420;
else
{
top+=15;
bottom+=15;
}
}
//draw arrow
setlinestyle(0,1,3);
setcolor(4);
rectangle(left,top-10,right,bottom+10);
setlinestyle(0,1,1);
}
int shoot(int mid)
{
static int z=90,delay_shoot=1;
delay_shoot++;
static int soundon=0;
if(delay_shoot>200&&z<510)
{
delay_shoot=0;
soundon=1;
setcolor(0);
if(soundon)
{
for(int Si=5; Si<10; Si++) {
sound(300*Si);
delay(1);
nosound();
}}
settextstyle(1,0,1);
outtextxy(z-30,mid,">--->");
setcolor(RED);
outtextxy(z,mid,">--->");
z+=30;
z1=z;
if(level1==1)
{
if((z>=480)&&(z<=500)&&(mid>=m-19)&&(mid<=m+19))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
}
else if((z>=410)&&(z<=430)&&(mid>=n-19)&&(mid<=n+19))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=2;
}
else if((z>=340)&&(z<=360)&&(mid>=p-19)&&(mid<=p+19))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=3;
}
else if((z>=270)&&(z<=290)&&(mid>=q-19)&&(mid<=q+19))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=4;
}
}
if(level1==2)
{
if((abs(m-z)>=0)&&(abs(m-z)<=18)&&(mid==60))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
setfillstyle(1,0);
bar(z-50,30,z+70,100);
z=500;
m1++;
}
if((abs(n-z)>=0)&&(abs(n-z)<=17)&&(mid>=120)&&(mid<=150))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=2;
setfillstyle(1,0);
bar(z-50,100,z+90,180);
z=500;
m2++;
}
if((abs(p-z)>=0)&&(abs(p-z)<=18)&&(mid>=210)&&(mid<=240))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=3;
setfillstyle(1,0);
bar(z-50,180,z+80,285);
z=500;
m3++;
}
if((abs(q-z)>=0)&&(abs(q-z)<=19)&&(mid>=310)&&(mid<=340))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=4;
setfillstyle(1,0);
bar(z-60,285,z+80,365);
z=500;
m4++;
}
if((abs(r-z)>=0)&&(abs(r-z)<=19)&&(mid>=410)&&(mid<=440))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=5;
setfillstyle(1,0);
bar(z-50,390,z+80,460);
z=500;
m5++;
}
}
if(level1==3)
{
if((z>=475)&&(z<=501)&&(mid>=m)&&(mid<=m+35))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=10;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
}
if((z>=475)&&(z<=501)&&(mid==m+30)&&(mid<=m+36))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=500;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
setcolor(1);
settextstyle(4,0,8);
outtextxy(90,180,"WINNER");
for(int c1=1,j=10;j<=25000;j++)
{
putpixel(random(j),random(j),8);
if(j==32000){j=0;c1++;}
if(c1>=50)break;
}
delay(1000);
life=0;
gover=0;
}
if((z>=475)&&(z<=501)&&(mid>=m+45)&&(mid<=m+65))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=10;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
}
}
if(z>=510)
{
setcolor(0);
outtextxy(z-30,mid,">--->");
z=90;
hit=0;
setcolor(0);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
count--;
setcolor(WHITE);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
}
} //end outer if
return 0;
}//end
void ball()
{
static int k=35,delay_ball=1,l=45,e=55,f=25;
delay_ball++;
if(delay_ball>300)
{
delay_ball=0;
//erase
delay(20);
setfillstyle(1,0);
bar(470,k,530,k+50);
bar(400,l,530,l+50);
bar(330,e,530,e+50);
bar(260,f,530,f+50);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
if(check==1)
{
k=35;
check=0;
}
if(check==2)
{
l=45;
check=0;
}
if(check==3)
{
e=55;
check=0;
}
if(check==4)
{
f=25;
check=0;
}
else if(k>=420) k=35;
else if(l>=420) l=45;
else if(e>=420) e=55;
else if(f>=420) f=25;
m=k+25; k+=8;
n=l+25; l+=6;
p=e+25; e+=7;
q=f+25; f+=9;
putimage(470,k,iball,OR_PUT);
putimage(400,l,iball1,OR_PUT);
putimage(330,e,iball2,OR_PUT);
putimage(260,f,iball3,OR_PUT);
}
} //end
void balllevel2()
{
static int k=470,l=460,e=450,f=440,g=430,delay_ball=1;
delay_ball++;
//draw arrow
if((top>=60)&&(top<=90)&&(m==62)&&(m1<=3)) {gover=1;return;}
if((top>=120)&&(top<=180)&&(n==61)&&(m2<=3)){gover=1;return;}
if((top>=210)&&(top<=270)&&(p==60)&&(m3<=3)){gover=1;return;}
if((top>=295)&&(top<=365)&&(q==60)&&(m4<=3)){gover=1;return;}
if((top>=380)&&(top<=465)&&(r==62)&&(m5<=3)){gover=1;return;}
if(delay_ball>300&&k>23&&l>17&&e>13&&f>10)
{
delay_ball=0;
delay(20);
setfillstyle(1,0);
if(m1<=3) bar(k+60,30,k,90);
if(m2<=3) bar(l+60,120,l,180);
if(m3<=3) bar(e+60,210,e,270);
if(m4<=3) bar(f+60,300,f,360);
if(m5<=3) bar(g+60,390,g,450);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
if(m1>=3)m=1000;
if(m2>=3)n=1000;
if(m3>=3)p=1000;
if(m4>=3)q=1000;
if(m5>=3)r=1000;
if(m1<=3)
{m=k,k-=8;}//k=8
if(m2<=3)
{n=l,l-=7;} //l=7
if(m3<=3)
{p=e,e-=6;} //e=6
if(m4<=3)
{q=f,f-=5;} //f=5
if(m5<=3)
{r=g;g-=4;} //g=4
if(check==1)
{
k=470;
check=0;
}
if(check==2)
{
l=460;
check=0;
}
if(check==3)
{
e=450;
check=0;
}
if(check==4)
{
f=440;
check=0;
}
if(check==5)
{
g=430;
check=0;
}
if (k<=23) k = 470;
if(l<=17) l=460;
if(e<=13) e=450;
if(f<=10) f=440;
if(g<=10) g=430;
// plot new image
if(m1<=3) putimage(k,30,pball,OR_PUT);
if(m2<=3) putimage(l,120,pball1,OR_PUT);
if(m3<=3) putimage(e,210,pball2,OR_PUT);
if(m4<=3) putimage(f,300,pball3,OR_PUT);
if(m5<=3) putimage(g,390,pball4,OR_PUT);
}
} //end
void eyelevel()
{
static int e1=15,delay_eye=1;
delay_eye++;
static int up=1;
if(delay_eye>300&&e1<405&&life!=0)
{
delay_eye=0;
delay(20);
setfillstyle(1,0);
bar(480,e1,520,e1+80);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
m=e1;
if(up)
e1+=5;
if(up==0)
e1-=5;
if(check==1)
check=0;
if(e1>=405)
{
e1=400;
up=0;
}
if(e1<=15)
{
e1=15;
up=1;}
putimage(480,e1,peye,OR_PUT);
}
} //end
//////////////////////////////////////////////////////////////////////////// ////////////////// ARCHERY GAME //////////////
///////////////////////////////////////////////////////
/* Programmer : Harsh chandra
Email : harshchandra@gmail.com
Reference : Graphics Under C - Yashawant Kanetkar
*/
#include iostream.h
#include conio.h
#include string.h
#include graphics.h
#include process.h
#include dos.h
#include stdio.h
#include stdlib.h
#include math.h
//structure declaration
struct scorechart
{
char player[45];
int scor;
};
struct scorechart s1[5];
//global variables
union REGS i,o;
char buff[80];
int hit=0,life=1;
int m1=1,m2=1,m3=1,m4=1,m5=1,gover=0;
int level1=1,check=0,score=0,mid,flag=0;
char buffer1[80],buffer[80];
int count=0,ascii,z1=625,scan,m=60,n=70,p=80,q=50,r;
int left=10,top=285,right=63,bottom=285;
unsigned int size,size1,size2,size3,size4,globalsize,handsize,eyesize;
void *pball,*pball1,*pball2,*pball3,*pball4,*handimage,*peye;
void *iball,*iball1,*iball2,*iball3;
//function declaration
void image1();
void image();
void hand();
void arrow(int);
int shoot(int);
void game();
void ball();
void eyelevel();
void balllevel2();
void gethighscores();
void displaytopscore();
void updatehighscore();
void writehighscorestodisk();
//function defintion
void hand()
{
setcolor(8);
setlinestyle(0,1,3);
setfillstyle(1,8);
bar(14,197,19,215);
line(19,198,23,198);
line(22,200,29,192);
line(29,192,38,192);
line(37,192,37,197);
line(32,197,54,197);
line(54,197,54,202);
line(32,202,54,202);
line(32,207,42,207);
line(32,212,42,212);
line(42,212,42,202);
line(38,212,38,217);
line(38,217,14,217);
handsize= imagesize(14,190,56,220);
/* allocate memory to hold the image */
handimage= malloc(handsize);
/* grab the image */
getimage(14,190, 56,220, handimage);
cleardevice();
}
void image1()
{
unsigned int s,s1,s2,s3;
setlinestyle(0,1,3);
setcolor(RED);
circle(500,60,20);
setfillstyle(1,12);
floodfill(500,60,RED);
circle(430,70,20);
setfillstyle(1,YELLOW);
floodfill(430,70,RED);
circle(360,80,20);
setfillstyle(1,9);
floodfill(360,80,RED);
setcolor(RED);
circle(290,50,20);
setfillstyle(1,6);
floodfill(290,50,RED);
s = imagesize(470,35,530,85); //k
s1= imagesize(400,45,460,95); //l
s3= imagesize(330,55,390,105);//e
s2= imagesize(260,25,320,75); //f
/* allocate memory to hold the image */
iball= malloc(s);
iball1=malloc(s1);
iball2=malloc(s2);
iball3=malloc(s3);
/* grab the image */
getimage(470,35, 530, 85, iball);
getimage(400,45,460,95,iball1);
getimage(330,55,390,105,iball2);
getimage(260,25,320,75,iball3);
putimage(470,35,iball,XOR_PUT);
putimage(400,45,iball1,XOR_PUT);
putimage(330,55,iball2,XOR_PUT);
putimage(260,25,iball3,XOR_PUT);
}
void conveximage()
{
setlinestyle(0,1,3);
setcolor(4);
ellipse(500, 55, 0,360,13,35);
setfillstyle(1,9);
fillellipse(500,55,13,35);
setcolor(0);
putpixel(500,55,4);
setlinestyle(0,1,1);
ellipse(500, 55, 0,360,10.5,4.5);
circle(500,55,4);
eyesize=imagesize(480,15,520,95);
peye=malloc(size);
getimage(480,15,520,95,peye);
putimage(480,15,peye,XOR_PUT);
}
void image()
{
setlinestyle(0,1,3);
setcolor(RED);
circle(460,420,25);
setfillstyle(1,YELLOW);
floodfill(460,420,4);
circle(470,330,25);
setfillstyle(1,11);
floodfill(470,330,RED);
circle(480,240,25);
setfillstyle(1,9);
floodfill(480,240,RED);
circle(490,150,25);
setfillstyle(1,3);
floodfill(490,150,RED);
circle(500,60,25);
setfillstyle(1,10);
floodfill(500,60,RED);
settextstyle(0,0,5);
sprintf(buffer,"%c",1);
outtextxy(440,400,buffer);
outtextxy(450,310,buffer);
outtextxy(460,220,buffer);
outtextxy(470,130,buffer);
outtextxy(480,40,buffer);
size = imagesize(470,30,530,90); //k
size1= imagesize(460,120,520,180); //l
size2= imagesize(450,210,510,270); //e
size3= imagesize(440,300,500,360);//f
size4= imagesize(430,390,490,450);
/* allocate memory to hold the image */
pball= malloc(size);
pball1=malloc(size1);
pball2=malloc(size2);
pball3=malloc(size3);
pball4=malloc(size4);
/* grab the image */
getimage(470,30, 530, 90, pball);
getimage(460,120,520,180,pball1);
getimage(450,210,510,270,pball2);
getimage(440,300,500,360,pball3);
getimage(430,390,490,450,pball4);
putimage(470,30,pball,XOR_PUT);
putimage(460,120,pball1,XOR_PUT);
putimage(450,210,pball2,XOR_PUT);
putimage(440,300,pball3,XOR_PUT);
putimage(430,390,pball4,XOR_PUT);
}
void getkey()
{
i.h.ah=0x00;
int86(0x16,&i,&o);
ascii=o.h.al;
scan=o.h.ah;
}
void rules()
{
char buffer[80];
cleardevice();
setbkcolor(0);
setcolor(4);
setlinestyle(0,1,3);
rectangle(0,0,640,480);
setfillstyle(1,11);
bar(3,3,637,477);
setcolor(1);
settextstyle(10,0,3);
outtextxy(245,0,"ARCHERY");
setcolor(8);
settextstyle(4,0,3);
outtextxy(15,60,"Rules To Be Followed : ");
settextstyle(0,0,0);
outtextxy(15,85,"_______________________________");
outtextxy(60,120, " Rule # 1 ð> Only One Player Can Play The Game At A Time.");
outtextxy(60,150," Rule # 2 ð> There Are Three Levels Of The game.");
outtextxy(60,180," Rule # 3 ð> Arrow Shooter Is Positioned By The ");
sprintf(buffer," UP(%c) AND DOWN(%c) KEY.",24,25);
outtextxy(444,180,buffer);
outtextxy(60,210," Rule # 4 ð> Only One Arrow Can Be Shooted At A Time.");
outtextxy(60,240," Rule # 5 ð> SpaceBar Is Used To Shoot The Arrow.");
outtextxy(60,270," Rule # 6 ð> Enter Key Is Used To Select any Option.");
outtextxy(60,300," Rule # 7 ð> Five(5) Points Is Rewarded To Each Hit One Makes.");
outtextxy(60,330," Rule # 8 ð> One Can Go To Another Level ,Crossing The Previous Level.");
outtextxy(60,360," Rule # 9 ð> Esc Key From The Main Will Terminate The Game.");
outtextxy(60,390," Rule # 10 ð> Exit Option Will Terminate The Game.");
outtextxy(340,465,"Press Any Key To Resume The game....");
getch();
cleardevice();
}
void level()
{
char buffer[80];
cleardevice();
setbkcolor(0);
setcolor(4);
setlinestyle(0,1,3);
rectangle(0,0,640,480);
setfillstyle(1,14);
bar(3,3,637,477);
setcolor(4);
settextstyle(10,0,3);
outtextxy(245,0,"ARCHERY");
setcolor(8);
settextstyle(4,0,3);
outtextxy(15,45,"Different Levels Of The Game : ");
settextstyle(0,0,1);
outtextxy(15,70,"_________________________________________");
outtextxy(50,100,"LEVEL # 1 ð> Four balloons will be moving vertically and the player has");
outtextxy(55,118," to shoot the balloon. Each hit is rewarded by 5 points.Once");
outtextxy(55,136," the score becomes 100,The player moves to another Level.The");
outtextxy(55,154," player cannot skip or jump any level.");
outtextxy(50,184,"LEVEL # 2 ð> Five monsters will be moving horizontally,the player has");
outtextxy(55,202," to shoot the ball. Each hit is rewarded by 10 points. Once");
outtextxy(55,220," the score becomes 200 , The player moves to another level.");
outtextxy(55,238," If The Ball Touches The Shooter,particular game ends then");
outtextxy(55,256," and there.");
outtextxy(50,286,"LEVEL # 3 ð> One Eye will be Enclosed in convex object moving vertically");
outtextxy(55,302," the player has to target and shoot the eye. The hit which is ");
outtextxy(55,320," closest to the eye will be rewarded accordingly. Once the ");
outtextxy(55,338," player hits the eye exactly, the player is awarded with 500 ");
outtextxy(55,356," points. Only ten arrows are provided for this level. If the ");
outtextxy(55,374," player succeeds ,the game comes to an end, else the player's ");
outtextxy(55,392," game comes to an end.");
outtextxy(340,431,"Press any key to resume the game.......");
getch();
cleardevice();
}
void updatehighscore()
{
FILE *p;
int i=0,t;
struct scorechart s;
clearviewport();
setcolor(2);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
setlinestyle(0,1,3);
ellipse(280,80,0,320,133,50);
setcolor(9);
setfillstyle(1,9);
fillellipse(280,80,133,50);
setcolor(14);
settextstyle(1,0,6);
outtextxy(160,40,"ARCHERY");
settextstyle(1,0,1);
outtextxy(230,170,"SCORE CARD");
setcolor(14);
settextstyle(1,0,1);
outtextxy(120,235,"Enter Your Name : ");
for(i=0;i<=13;i++)
{
setcolor(i);
settextstyle(1,0,1);
outtextxy(250,440,"CONGRATULATIONS!!!!!!!");
delay(100);
if(i>=13)i=0;
if(kbhit())break;
}
gotoxy(42,16);
scanf("%s",s.player);
s.scor=score;
for(i=0;i<5;i++)
{
if(s.scor>s1[i].scor){t=i;break;}
}
for(i=4;i>t;i--)
{
strcpy(s1[i].player,s1[i-1].player);
s1[i].scor=s1[i-1].scor;
}
strcpy(s1[t].player,s.player);
s1[t].scor=s.scor;
setcolor(14);
outtextxy(250,320,"Press Any Key");
getch();
}
void writehighscorestodisk()
{
int i;
FILE *p;
p=fopen("ARCHERY.TXT","w");
for(i=0;i<5;i++)
fprintf(p,"%s\t%d\n",s1[i].player,s1[i].scor);
fclose(p);
return;
}
//main begins
void main()
{
int mid;
static int c=1;
char name[30];
int gdriver = DETECT,gmode, errorcode;
count=0; score=0;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
hand();
image();
image1();
conveximage();
cleardevice();
man:
while(1)
{
cleardevice();
setcolor(WHITE);
c=1;
setbkcolor(2);
setlinestyle(2,1,3);
rectangle(4,4,635,475);
setlinestyle(0,1,3);
rectangle(0,0,640,480);
setlinestyle(0,1,3);
ellipse(320,80,0,360,133,50);
setcolor(9);
setfillstyle(1,9);
fillellipse(320, 80, 133, 50);
setcolor(14);
settextstyle(4,0,6);
outtextxy(190,40,"ARChERY");
line(322,58,322,73);
settextstyle(0,0,3);
putimage(130,175,handimage,OR_PUT);
setcolor(4);
outtextxy(180,180,"PLAY THE GAME....");
setcolor(14);
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
gethighscores();
getkey();
if(ascii==27) //esc
exit(0);
if(ascii==13)
game();
else if(((scan==80)||(scan==72))&&(c==1))
{
b: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,175,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,180,"PLAY THE GAME....");
c++;
score=0;
getkey();
if(ascii==13) { game(),score=0; goto man;}
if(scan==72) { c=5; goto g;}
else if((scan==80)&&(c==2))
{
d: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,225,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,230,"INSTRUCTIONS....");
c++;
getkey();
if(ascii==13) rules();
else if(scan==72){c-=2; goto b;}
if((scan==80)&&(c==3))
{
e: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,275,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,330,"LEVELS....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,280,"HIGH SCORES....");
c++;
getkey();
if(ascii==13) displaytopscore();
if(scan==72) { c-=2; goto d;}
if((scan==80)&&(c==4))
{
f: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,325,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,380,"EXIT....");
setcolor(4);
outtextxy(180,330,"LEVELS....");
c++;
getkey();
if(ascii==13) level();
else if(scan==72) { c-=2; goto e;}
else if((scan==80)&&(c==5))
{
g: setcolor(14);
setfillstyle(0,2);
bar(120,160,173,430);
putimage(130,375,handimage,OR_PUT);
settextstyle(0,0,3);
outtextxy(180,180,"PLAY THE GAME....");
outtextxy(180,230,"INSTRUCTIONS....");
outtextxy(180,280,"HIGH SCORES....");
outtextxy(180,330,"LEVELS....");
setcolor(4);
outtextxy(180,380,"EXIT....");
c++;
getkey();
if(ascii==13) break;
else if(scan==72) { c-=2; goto f;}
else if((scan==80))
{ c=1; goto b; }
} //g if close
} //f if
}//e if
}// d elseif
} //b if
}//while
}// main
void displaytopscore()
{
FILE *p;
int i;
char str[100];
p=fopen("ARCHERY.TXT","r");
if(p==NULL)
{
for(i=0;i<5;i++)
{
strcpy(s1[i].player,"Unknown");
s1[i].scor=0;
}
}
else
{
for(i=0;i<5;i++)
if(fscanf(p,"%s\t%d",s1[i].player,&s1[i].scor)==EOF)
fclose(p);
}
fclose(p);
cleardevice();
setlinestyle(0,1,3);
rectangle(0,0,638,478);
setlinestyle(0,1,3);
ellipse(320,80,0,360,133,50);
setcolor(9);
setfillstyle(1,9);
fillellipse(320,80,133,50);
setcolor(14);
settextstyle(1,0,6);
outtextxy(200,40,"ARCHERY");
settextstyle(1,0,1);
setcolor(RED);
outtextxy(240,160,"HIGH SCORES");
setcolor(GREEN);
settextstyle(1,0,1);
for(i=0;i<5;i++)
{
sprintf(str,"%7d --- %10s",s1[i].scor,s1[i].player);
setcolor(4);
outtextxy(170,200+(i*20),str);
}
setcolor(RED);
outtextxy(230,350,"Press ENTER Key");
getch();
// while(i!='\r')
clearviewport();
} //end displaytopscore
void gethighscores()
{
FILE *p;
int i;
char str[100];
p=fopen("ARCHERY.TXT","r");
if(p==NULL)
{
for(i=0;i<5;i++)
{
strcpy(s1[i].player,"Unknown");
s1[i].scor=0;
}
}
else
{
for(i=0;i<5;i++)
if(fscanf(p,"%s\t%d\n",s1[i].player,&s1[i].scor)==EOF)
fclose(p);
}
fclose(p);
} //end gethighscore
void game()
{
level1=1;
count=25;
score=0;
life=1;
m1=1,m2=1,m3=1,m4=1,m5=1;
cleardevice();
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
setbkcolor(0);
setcolor(9);
settextstyle(0,0,2);
outtextxy(555,250,"ARROWS");
outtextxy(555,50,"SCORE ");
outtextxy(555,150,"LEVEL");
setcolor(WHITE);
settextstyle(1,0,1);
itoa(score,buff,5);
outtextxy(585,95,buff);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
itoa(level1,buffer,5);
setcolor(WHITE);
outtextxy(585,175,buffer);
setlinestyle(0,1,3);
setcolor(4);
rectangle(left,top-10,right,bottom+10);
while((1)&&(count!=0))
{
if(score==100)
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
score+=25;
setfillstyle(1,0);
bar(0,0,550,480);
level1++,count=25;
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
settextstyle(1,0,1);
setcolor(WHITE);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
settextstyle(1,0,4);
for(int color=1;color<=14;color++)
{
setcolor(color);
outtextxy(200,200,"LEVEL 2");
delay(200);
}
setfillstyle(1,0);
bar(200,100,400,300);
}
if(level1==1)
ball();
if(level1==2&&score<200)
balllevel2();
if(score==200)
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
score+=25;
setfillstyle(1,0);
bar(0,0,550,480);
level1++,count=25;
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
settextstyle(1,0,1);
setcolor(WHITE);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
sprintf(buff,"%d",level1);
outtextxy(585,175,buff);
settextstyle(1,0,4);
for(int color=1;color<=14;color++)
{
setcolor(color);
outtextxy(200,200,"LEVEL 3");
delay(200);
}
setfillstyle(1,0);
bar(200,100,400,300);
}
if(level1==3&&score>=225&&life==1)
eyelevel();
if(life==0) count=0;
if(gover==1)
count=0;
if(kbhit())
{
getkey();
if(ascii==27)
break;
if(scan==57)
{
mid=(top+bottom)/2;
hit=1;
}
else if((scan==72)&&(z1>=510))
arrow(1);
else if((scan==80)&&(z1>=510))
arrow(0);
}
if(hit==1)
shoot(mid);
} //while
if(score<100)
gover=1;
if(score<500)
gover=1;
if(gover==1)
{
setcolor(1);
settextstyle(4,0,8);
outtextxy(50,180,"GAME OVER");
for(int c=1,j=10;j<=32000;j++)
{
putpixel(random(j),random(j),8);
if(j==32000){j=0;c++;}
if(c>=50)break;
}
gover=0;
}
if(score>s1[4].scor)updatehighscore();
else
clearviewport();
writehighscorestodisk();
// setcolor(4);
// rectangle(left,top-10,right,bottom+10);
cleardevice();
} //end function
void arrow(int pos)
{
int s;
//erase
setfillstyle(SOLID_FILL,0);
bar(left-5,top-15,right+5,bottom+15);
if(pos==1)//up
{
if(top==60)
top=60;
else
{
top-=15;
bottom-=15;
}
}
else
{
if(top==420)
top=420;
else
{
top+=15;
bottom+=15;
}
}
//draw arrow
setlinestyle(0,1,3);
setcolor(4);
rectangle(left,top-10,right,bottom+10);
setlinestyle(0,1,1);
}
int shoot(int mid)
{
static int z=90,delay_shoot=1;
delay_shoot++;
static int soundon=0;
if(delay_shoot>200&&z<510)
{
delay_shoot=0;
soundon=1;
setcolor(0);
if(soundon)
{
for(int Si=5; Si<10; Si++) {
sound(300*Si);
delay(1);
nosound();
}}
settextstyle(1,0,1);
outtextxy(z-30,mid,">--->");
setcolor(RED);
outtextxy(z,mid,">--->");
z+=30;
z1=z;
if(level1==1)
{
if((z>=480)&&(z<=500)&&(mid>=m-19)&&(mid<=m+19))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
}
else if((z>=410)&&(z<=430)&&(mid>=n-19)&&(mid<=n+19))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=2;
}
else if((z>=340)&&(z<=360)&&(mid>=p-19)&&(mid<=p+19))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=3;
}
else if((z>=270)&&(z<=290)&&(mid>=q-19)&&(mid<=q+19))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=4;
}
}
if(level1==2)
{
if((abs(m-z)>=0)&&(abs(m-z)<=18)&&(mid==60))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
setfillstyle(1,0);
bar(z-50,30,z+70,100);
z=500;
m1++;
}
if((abs(n-z)>=0)&&(abs(n-z)<=17)&&(mid>=120)&&(mid<=150))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=2;
setfillstyle(1,0);
bar(z-50,100,z+90,180);
z=500;
m2++;
}
if((abs(p-z)>=0)&&(abs(p-z)<=18)&&(mid>=210)&&(mid<=240))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=3;
setfillstyle(1,0);
bar(z-50,180,z+80,285);
z=500;
m3++;
}
if((abs(q-z)>=0)&&(abs(q-z)<=19)&&(mid>=310)&&(mid<=340))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=4;
setfillstyle(1,0);
bar(z-60,285,z+80,365);
z=500;
m4++;
}
if((abs(r-z)>=0)&&(abs(r-z)<=19)&&(mid>=410)&&(mid<=440))
{
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=5;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=5;
setfillstyle(1,0);
bar(z-50,390,z+80,460);
z=500;
m5++;
}
}
if(level1==3)
{
if((z>=475)&&(z<=501)&&(mid>=m)&&(mid<=m+35))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=10;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
}
if((z>=475)&&(z<=501)&&(mid==m+30)&&(mid<=m+36))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=500;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
setcolor(1);
settextstyle(4,0,8);
outtextxy(90,180,"WINNER");
for(int c1=1,j=10;j<=25000;j++)
{
putpixel(random(j),random(j),8);
if(j==32000){j=0;c1++;}
if(c1>=50)break;
}
delay(1000);
life=0;
gover=0;
}
if((z>=475)&&(z<=501)&&(mid>=m+45)&&(mid<=m+65))
{
settextstyle(1,0,1);
setcolor(0);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
score+=10;
setcolor(WHITE);
sprintf(buff,"%d",score);
outtextxy(585,95,buff);
check=1;
}
}
if(z>=510)
{
setcolor(0);
outtextxy(z-30,mid,">--->");
z=90;
hit=0;
setcolor(0);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
count--;
setcolor(WHITE);
sprintf(buff,"%d",count);
outtextxy(585,275,buff);
}
} //end outer if
return 0;
}//end
void ball()
{
static int k=35,delay_ball=1,l=45,e=55,f=25;
delay_ball++;
if(delay_ball>300)
{
delay_ball=0;
//erase
delay(20);
setfillstyle(1,0);
bar(470,k,530,k+50);
bar(400,l,530,l+50);
bar(330,e,530,e+50);
bar(260,f,530,f+50);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
if(check==1)
{
k=35;
check=0;
}
if(check==2)
{
l=45;
check=0;
}
if(check==3)
{
e=55;
check=0;
}
if(check==4)
{
f=25;
check=0;
}
else if(k>=420) k=35;
else if(l>=420) l=45;
else if(e>=420) e=55;
else if(f>=420) f=25;
m=k+25; k+=8;
n=l+25; l+=6;
p=e+25; e+=7;
q=f+25; f+=9;
putimage(470,k,iball,OR_PUT);
putimage(400,l,iball1,OR_PUT);
putimage(330,e,iball2,OR_PUT);
putimage(260,f,iball3,OR_PUT);
}
} //end
void balllevel2()
{
static int k=470,l=460,e=450,f=440,g=430,delay_ball=1;
delay_ball++;
//draw arrow
if((top>=60)&&(top<=90)&&(m==62)&&(m1<=3)) {gover=1;return;}
if((top>=120)&&(top<=180)&&(n==61)&&(m2<=3)){gover=1;return;}
if((top>=210)&&(top<=270)&&(p==60)&&(m3<=3)){gover=1;return;}
if((top>=295)&&(top<=365)&&(q==60)&&(m4<=3)){gover=1;return;}
if((top>=380)&&(top<=465)&&(r==62)&&(m5<=3)){gover=1;return;}
if(delay_ball>300&&k>23&&l>17&&e>13&&f>10)
{
delay_ball=0;
delay(20);
setfillstyle(1,0);
if(m1<=3) bar(k+60,30,k,90);
if(m2<=3) bar(l+60,120,l,180);
if(m3<=3) bar(e+60,210,e,270);
if(m4<=3) bar(f+60,300,f,360);
if(m5<=3) bar(g+60,390,g,450);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
if(m1>=3)m=1000;
if(m2>=3)n=1000;
if(m3>=3)p=1000;
if(m4>=3)q=1000;
if(m5>=3)r=1000;
if(m1<=3)
{m=k,k-=8;}//k=8
if(m2<=3)
{n=l,l-=7;} //l=7
if(m3<=3)
{p=e,e-=6;} //e=6
if(m4<=3)
{q=f,f-=5;} //f=5
if(m5<=3)
{r=g;g-=4;} //g=4
if(check==1)
{
k=470;
check=0;
}
if(check==2)
{
l=460;
check=0;
}
if(check==3)
{
e=450;
check=0;
}
if(check==4)
{
f=440;
check=0;
}
if(check==5)
{
g=430;
check=0;
}
if (k<=23) k = 470;
if(l<=17) l=460;
if(e<=13) e=450;
if(f<=10) f=440;
if(g<=10) g=430;
// plot new image
if(m1<=3) putimage(k,30,pball,OR_PUT);
if(m2<=3) putimage(l,120,pball1,OR_PUT);
if(m3<=3) putimage(e,210,pball2,OR_PUT);
if(m4<=3) putimage(f,300,pball3,OR_PUT);
if(m5<=3) putimage(g,390,pball4,OR_PUT);
}
} //end
void eyelevel()
{
static int e1=15,delay_eye=1;
delay_eye++;
static int up=1;
if(delay_eye>300&&e1<405&&life!=0)
{
delay_eye=0;
delay(20);
setfillstyle(1,0);
bar(480,e1,520,e1+80);
setcolor(2);
setlinestyle(0,1,3);
rectangle(0,0,550,478);
m=e1;
if(up)
e1+=5;
if(up==0)
e1-=5;
if(check==1)
check=0;
if(e1>=405)
{
e1=400;
up=0;
}
if(e1<=15)
{
e1=15;
up=1;}
putimage(480,e1,peye,OR_PUT);
}
} //end
Koi Mil Gaya
A scene From movie KOI MIL GAYA made in c.g......
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
int gd=DETECT,gm;
int xc=50,yc=50,xl,yl;
void earth();
void ufo()
{
int r=10,s=2;
int erx=r*2,ery=erx/5;
static int k=1;
for(int i=0;i<3;i++,k++)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(2000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc*=s,yc*=s,r*=s,erx*=s,ery*=s;
}
}
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
for(int j=0;j<6;j++)
{
yc+=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
}
void backufo()
{
int r=40,s=2;
int erx=r*2,ery=erx/5;
int k=3;
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
// cout<<"\n"<
for(int j=0;j<6;j++)
{
yc-=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
for(int i=0;i<3;i++,k--)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc/=s,yc/=s,r/=s,erx/=s,ery/=s;
}
}
}
void legs()
{
xl=xc;
yl=yc+40;
setcolor(15);
setlinestyle(0,0,3);
for(int i=1;i<6;i++)
{
line(xl,yl,xl,yl+10*i);
line(xl-30,yl-10,(xl-30)-13*i,(yl-10)+13*i);
line(xl+30,yl-10,(xl+30)+13*i,(yl-10)+13*i);
delay(500);
}
}
void backleg()
{
setcolor(0);
setlinestyle(0,0,3);
line(xl-95,yl+55,xl-30,yl-10);
line(xl+95,yl+55,xl+30,yl-10);
line(xl,yl+60,xl,yl);
}
void earth()
{
setcolor(6);
// ellipse(getmaxx()/2,getmaxy(),0,180,430,75);
setfillstyle(1,6);
line(0,getmaxy()-71,getmaxx(),getmaxy()-71);
floodfill(getmaxx()/2,getmaxy()-10,6);
}
void flash()
{
int poly[8]={xl+30,yl-10,xl+37,yl-20,xl+300,yl+48,xl+200,yl+42};
setcolor(0);
setfillstyle(1,14);
fillpoly(4,poly);
delay(1000);
setfillstyle(1,0);
fillpoly(4,poly);
}
int xe=xl+450;
int ye=yl+405;
void elliens(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,90,180,20,60);
ellipse(xe+20,ye-60,180,270,20,60);
ellipse(xe+10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe+10,ye-60,c);
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe+50,ye,90,180,20,60);
ellipse(xe+70,ye-60,180,270,20,60);
ellipse(xe+60,ye-60,0,360,9,13);
line(xe+30,ye,xe+70,ye);
setfillstyle(1,c);
floodfill(xe+50,ye-10,c);
floodfill(xe+60,ye-60,c);
}
void move()
{
for(int k=0;k<25;k++)
{
elliens(0);
xe+=10;
elliens(3);
delay(500);
}
sound(4000);
delay(4000);
nosound();
elliens(0);
}
void rtnelli(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,0,90,20,60);
ellipse(xe-20,ye-60,270,360,20,60);
ellipse(xe-10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe-10,ye-60,c);
}
void back()
{
for(int k=0;k<25;k++)
{
rtnelli(0);
xe-=10;
rtnelli(3);
delay(500);
}
}
void main()
{
initgraph(&gd,&gm,"c:/TC/bgi");
cleardevice();
earth();
ufo();
legs();
flash();
move();
back();
flash();
rtnelli(0);
backleg();
backufo();
getch();
}
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
int gd=DETECT,gm;
int xc=50,yc=50,xl,yl;
void earth();
void ufo()
{
int r=10,s=2;
int erx=r*2,ery=erx/5;
static int k=1;
for(int i=0;i<3;i++,k++)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(2000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc*=s,yc*=s,r*=s,erx*=s,ery*=s;
}
}
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
for(int j=0;j<6;j++)
{
yc+=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
}
void backufo()
{
int r=40,s=2;
int erx=r*2,ery=erx/5;
int k=3;
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
// cout<<"\n"<
for(int j=0;j<6;j++)
{
yc-=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
for(int i=0;i<3;i++,k--)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc/=s,yc/=s,r/=s,erx/=s,ery/=s;
}
}
}
void legs()
{
xl=xc;
yl=yc+40;
setcolor(15);
setlinestyle(0,0,3);
for(int i=1;i<6;i++)
{
line(xl,yl,xl,yl+10*i);
line(xl-30,yl-10,(xl-30)-13*i,(yl-10)+13*i);
line(xl+30,yl-10,(xl+30)+13*i,(yl-10)+13*i);
delay(500);
}
}
void backleg()
{
setcolor(0);
setlinestyle(0,0,3);
line(xl-95,yl+55,xl-30,yl-10);
line(xl+95,yl+55,xl+30,yl-10);
line(xl,yl+60,xl,yl);
}
void earth()
{
setcolor(6);
// ellipse(getmaxx()/2,getmaxy(),0,180,430,75);
setfillstyle(1,6);
line(0,getmaxy()-71,getmaxx(),getmaxy()-71);
floodfill(getmaxx()/2,getmaxy()-10,6);
}
void flash()
{
int poly[8]={xl+30,yl-10,xl+37,yl-20,xl+300,yl+48,xl+200,yl+42};
setcolor(0);
setfillstyle(1,14);
fillpoly(4,poly);
delay(1000);
setfillstyle(1,0);
fillpoly(4,poly);
}
int xe=xl+450;
int ye=yl+405;
void elliens(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,90,180,20,60);
ellipse(xe+20,ye-60,180,270,20,60);
ellipse(xe+10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe+10,ye-60,c);
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe+50,ye,90,180,20,60);
ellipse(xe+70,ye-60,180,270,20,60);
ellipse(xe+60,ye-60,0,360,9,13);
line(xe+30,ye,xe+70,ye);
setfillstyle(1,c);
floodfill(xe+50,ye-10,c);
floodfill(xe+60,ye-60,c);
}
void move()
{
for(int k=0;k<25;k++)
{
elliens(0);
xe+=10;
elliens(3);
delay(500);
}
sound(4000);
delay(4000);
nosound();
elliens(0);
}
void rtnelli(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,0,90,20,60);
ellipse(xe-20,ye-60,270,360,20,60);
ellipse(xe-10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe-10,ye-60,c);
}
void back()
{
for(int k=0;k<25;k++)
{
rtnelli(0);
xe-=10;
rtnelli(3);
delay(500);
}
}
void main()
{
initgraph(&gd,&gm,"c:/TC/bgi");
cleardevice();
earth();
ufo();
legs();
flash();
move();
back();
flash();
rtnelli(0);
backleg();
backufo();
getch();
}
4-Stroke Engine
This shows the full process ok 4-stroke engine.........
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
#define PI 3.141593
int gd=DETECT,gm,xc,yc;
int pst[10],inv[8],ov[8],shaft[8];
void init()
{
int epst[10]={279,109,279,159,359,159,359,109,279,109};
int einv[8]={234,19,289,69,279,79,299,59};
int eov[8]={404,19,349,69,359,79,339,59};
int eshaft[8]={309,159,319,249,329,159,309,159};
for(int i=0;i<10;i++) pst[i]=epst[i];
for(i=0;i<8;i++)
{
inv[i]=einv[i];
ov[i]=eov[i];
shaft[i]=eshaft[i];
}
}
void cyllinder()
{ // static coding
setcolor(6);
setlinestyle(0,0,1);
xc=getmaxx()/2;
yc=getmaxy()/2;
// cout<<"xc: "< circle(xc,yc+50,5);
arc(xc,yc+50,120,60,80); //inner arc
arc(xc,yc+50,120,60,90); //outer arc
circle(xc,yc+50,55);
circle(xc,yc+50,65);
circle(xc,yc+50,25);
arc(xc,yc-105,60,120,90); //upper arc
line(xc-45,yc-150,xc-45,yc-27); //left of left
line(xc-40,yc-160,xc-40,yc-20); //right of left
line(xc+45,yc-150,xc+45,yc-27); //right of right
line(xc+40,yc-160,xc+40,yc-20); //left of right
line(xc-45,yc-150,xc-85,yc-150); //lower left
line(xc-40,yc-160,xc-85,yc-160); //upper left
line(xc+45,yc-150,xc+85,yc-150); //lower right
line(xc+40,yc-160,xc+85,yc-160); //upper right
line(xc-85,yc-180,xc+85,yc-180); //upper most
line(xc-15,yc-193,xc-15,yc-180); //spark plug
line(xc+15,yc-193,xc+15,yc-180); // ''
line(xc-8,yc-195,xc-8,yc-180); // ''
line(xc+8,yc-195,xc+8,yc-180); // ''
line(xc-8,yc-195,xc,yc-215); // ''
line(xc+8,yc-195,xc,yc-215); // ''
line(xc-5,yc-180,xc-5,yc-168); // ''
line(xc+5,yc-168,xc-5,yc-168); // ''
line(xc,yc-180,xc,yc-170); // ''
line(xc+5,yc-180,xc+5,yc-170); // ''
line(xc,yc-170,xc+5,yc-170); // ''
setfillstyle(1,4);
floodfill(xc+2,yc-175,6);
line(xc-85,yc-150,xc-85,yc-180); // left stop
line(xc+85,yc-150,xc+85,yc-180); // right stop
setfillstyle(1,6);
floodfill(xc-80,yc-155,6);
}
void drawpst()
{
setlinestyle(0,0,3);
drawpoly(5,pst);
int xh=pst[0];
int yh=pst[1];
line(xh,yh+10,xh+80,yh+10);
line(xh,yh+15,xh+80,yh+15);
}
void drawin()
{
setlinestyle(0,0,3);
drawpoly(4,inv);
}
void drawout()
{
setlinestyle(0,0,3);
drawpoly(4,ov);
}
void drawshaft()
{
setlinestyle(0,0,3);
drawpoly(4,shaft);
setlinestyle(0,0,1);
int xh=shaft[2];
int yh=shaft[3];
circle(xh,yh,5);
int poly[10]={xh-8,yh-6,xh-8,yh+6,xh+8,yh+6,xh+8,yh-6,xh-8,yh-6};
line(xc-5,yc+50,xh-5,yh);
line(xc+5,yc+50,xh+5,yh);
drawpoly(5,poly);
}
void transpst(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j {
delay(15);
setcolor(0);
drawpst();
for(int i=1;i<10;i+=2)
pst[i]+=k;
setcolor(6);
drawpst();
cyllinder();
}
}
void transin(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j {
delay(15);
setcolor(0);
drawin();
for(int i=0;i<10;i++)
inv[i]+=k;
setcolor(6);
drawin();
cyllinder();
}
}
void transout(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j {
delay(15);
setcolor(0);
drawout();
for(int i=0;i<10;i++)
{
ov[i]-=k;
i++;
ov[i]+=k;
}
setcolor(6);
drawout();
cyllinder();
}
}
void transshaft(int t)
{int k=1;
if(t<0)
{k=-k;t=-t;}
float v=0;
for(int j=0;j {
double theta=double(v)*(PI/180.0);
delay(15);
setcolor(0);
drawshaft();
for(int i=1;i<8;i+=2)
{if(i==2 || i==3)
continue;
shaft[i]+=k;
}
int xr=xc;
int yr=yc+60;
int x=shaft[2];
int x1=x;
int y=shaft[3];
int y1=y;
x=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
y=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
shaft[2]=x;
shaft[3]=y;
v+=3.05;
setcolor(6);
drawshaft();
cyllinder();
}
}
void intake()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
setcolor(5);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
int xf=xc;
int yf=yc-150;
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
transin(1);
}
transin(-20);
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void comp()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
setcolor(5);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(259,69,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
}
setfillstyle(1,14);
floodfill(xf,yf,6);
}
void spark()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(4);
line(xc,yc-166,xc-2,yc-160);
line(xc-6,yc-166,xc-10,yc-160);
line(xc+3,yc-166,xc+5,yc-160);
line(xc+9,yc-166,xc+13,yc-160);
}
void expa()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(5);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
}
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void exhaust()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
// transout(1);
}
transout(20);
transout(-20);
}
void draw()
{
cyllinder();
drawpst();
drawin();
drawout();
drawshaft();
}
void contd()
{
for(int i=0;i<2;i++)
{
intake();
delay(700);
comp();
delay(700);
spark();
delay(1000);
expa();
delay(700);
exhaust();
}
}
void back()
{
cleardevice();
init();
setbkcolor(3);
draw();
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(1);
settextstyle(0,0,1);
outtextxy(150,430,"* Press ENTER to see engine strokes one by one *");
outtextxy(150,450,"* Press SPACE BAR to see continues engine cycle *");
outtextxy(382,360,"* Press 'N' for Nomenclature *");
setcolor(4);
rectangle(10,10,40,30);
outtextxy(14,16,"Esc");
outtextxy(45,16,"Press Escape to QUIT");
setcolor(11);
settextstyle(0,0,9);
outtextxy(35,310,"4");
setcolor(4);
settextstyle(0,0,3);
outtextxy(65,350,"Stroke");
setcolor(14);
settextstyle(1,0,6);
outtextxy(420,140,"Internal");
settextstyle(1,0,4);
outtextxy(425,230,"Combustion");
setcolor(11);
settextstyle(1,0,7);
outtextxy(545,90,"E");
settextstyle(1,0,6);
outtextxy(417,140," n");
settextstyle(1,0,5);
outtextxy(555,182,"g");
settextstyle(1,0,4);
outtextxy(433,230," i");
settextstyle(1,0,3);
outtextxy(559,258,"n");
settextstyle(1,0,2);
outtextxy(562,280,"e");
setcolor(15);
}
void name()
{
back();
setcolor(15);
settextstyle(2,0,6);
setlinestyle(0,0,1);
outtextxy(280,5,"Spark Plug");
outtextxy(170,25,"Intake Valve");
outtextxy(370,25,"Exhaust Valve");
line(250,120,300,120);
outtextxy(140,108,"Vccum Rings");
outtextxy(295,130,"Piston");
line(230,200,320,200);
outtextxy(135,188,"Piston Rod");
outtextxy(340,170,"Cyllinder");
line(200,250,320,250);
outtextxy(90,240,"Crank Shaft");
getch();
back();
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
back();
char choice;
int count=0;
while(choice!=27)
{
choice=getch();
switch(choice)
{
case 'n':
case 'N':
name();
count=0;
break;
case 13:switch(count)
{
case 0:
intake();
count++;
break;
case 1:comp();
count++;
break;
case 2:spark();
count++;
break;
case 3:expa();
count++;
break;
case 4:exhaust();
count=0;
break;
}
break;
case 32:back();
contd();
count=0;
break;
}
}
cleardevice();
setbkcolor(9);
settextstyle(4,0,8);
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(4);
outtextxy(50,100,"THANK YOU !!");
settextstyle(3,0,4);
outtextxy(200,250,"CREATED BY:-");
outtextxy(200,300,"VIVEK P. MEHTA");
outtextxy(200,350,"B.E. 3RD COMPUTER");
getch();
}
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
#define PI 3.141593
int gd=DETECT,gm,xc,yc;
int pst[10],inv[8],ov[8],shaft[8];
void init()
{
int epst[10]={279,109,279,159,359,159,359,109,279,109};
int einv[8]={234,19,289,69,279,79,299,59};
int eov[8]={404,19,349,69,359,79,339,59};
int eshaft[8]={309,159,319,249,329,159,309,159};
for(int i=0;i<10;i++) pst[i]=epst[i];
for(i=0;i<8;i++)
{
inv[i]=einv[i];
ov[i]=eov[i];
shaft[i]=eshaft[i];
}
}
void cyllinder()
{ // static coding
setcolor(6);
setlinestyle(0,0,1);
xc=getmaxx()/2;
yc=getmaxy()/2;
// cout<<"xc: "<
arc(xc,yc+50,120,60,80); //inner arc
arc(xc,yc+50,120,60,90); //outer arc
circle(xc,yc+50,55);
circle(xc,yc+50,65);
circle(xc,yc+50,25);
arc(xc,yc-105,60,120,90); //upper arc
line(xc-45,yc-150,xc-45,yc-27); //left of left
line(xc-40,yc-160,xc-40,yc-20); //right of left
line(xc+45,yc-150,xc+45,yc-27); //right of right
line(xc+40,yc-160,xc+40,yc-20); //left of right
line(xc-45,yc-150,xc-85,yc-150); //lower left
line(xc-40,yc-160,xc-85,yc-160); //upper left
line(xc+45,yc-150,xc+85,yc-150); //lower right
line(xc+40,yc-160,xc+85,yc-160); //upper right
line(xc-85,yc-180,xc+85,yc-180); //upper most
line(xc-15,yc-193,xc-15,yc-180); //spark plug
line(xc+15,yc-193,xc+15,yc-180); // ''
line(xc-8,yc-195,xc-8,yc-180); // ''
line(xc+8,yc-195,xc+8,yc-180); // ''
line(xc-8,yc-195,xc,yc-215); // ''
line(xc+8,yc-195,xc,yc-215); // ''
line(xc-5,yc-180,xc-5,yc-168); // ''
line(xc+5,yc-168,xc-5,yc-168); // ''
line(xc,yc-180,xc,yc-170); // ''
line(xc+5,yc-180,xc+5,yc-170); // ''
line(xc,yc-170,xc+5,yc-170); // ''
setfillstyle(1,4);
floodfill(xc+2,yc-175,6);
line(xc-85,yc-150,xc-85,yc-180); // left stop
line(xc+85,yc-150,xc+85,yc-180); // right stop
setfillstyle(1,6);
floodfill(xc-80,yc-155,6);
}
void drawpst()
{
setlinestyle(0,0,3);
drawpoly(5,pst);
int xh=pst[0];
int yh=pst[1];
line(xh,yh+10,xh+80,yh+10);
line(xh,yh+15,xh+80,yh+15);
}
void drawin()
{
setlinestyle(0,0,3);
drawpoly(4,inv);
}
void drawout()
{
setlinestyle(0,0,3);
drawpoly(4,ov);
}
void drawshaft()
{
setlinestyle(0,0,3);
drawpoly(4,shaft);
setlinestyle(0,0,1);
int xh=shaft[2];
int yh=shaft[3];
circle(xh,yh,5);
int poly[10]={xh-8,yh-6,xh-8,yh+6,xh+8,yh+6,xh+8,yh-6,xh-8,yh-6};
line(xc-5,yc+50,xh-5,yh);
line(xc+5,yc+50,xh+5,yh);
drawpoly(5,poly);
}
void transpst(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawpst();
for(int i=1;i<10;i+=2)
pst[i]+=k;
setcolor(6);
drawpst();
cyllinder();
}
}
void transin(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawin();
for(int i=0;i<10;i++)
inv[i]+=k;
setcolor(6);
drawin();
cyllinder();
}
}
void transout(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawout();
for(int i=0;i<10;i++)
{
ov[i]-=k;
i++;
ov[i]+=k;
}
setcolor(6);
drawout();
cyllinder();
}
}
void transshaft(int t)
{int k=1;
if(t<0)
{k=-k;t=-t;}
float v=0;
for(int j=0;j
double theta=double(v)*(PI/180.0);
delay(15);
setcolor(0);
drawshaft();
for(int i=1;i<8;i+=2)
{if(i==2 || i==3)
continue;
shaft[i]+=k;
}
int xr=xc;
int yr=yc+60;
int x=shaft[2];
int x1=x;
int y=shaft[3];
int y1=y;
x=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
y=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
shaft[2]=x;
shaft[3]=y;
v+=3.05;
setcolor(6);
drawshaft();
cyllinder();
}
}
void intake()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
setcolor(5);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
int xf=xc;
int yf=yc-150;
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
transin(1);
}
transin(-20);
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void comp()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
setcolor(5);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(259,69,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
}
setfillstyle(1,14);
floodfill(xf,yf,6);
}
void spark()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(4);
line(xc,yc-166,xc-2,yc-160);
line(xc-6,yc-166,xc-10,yc-160);
line(xc+3,yc-166,xc+5,yc-160);
line(xc+9,yc-166,xc+13,yc-160);
}
void expa()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(5);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
}
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void exhaust()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
// transout(1);
}
transout(20);
transout(-20);
}
void draw()
{
cyllinder();
drawpst();
drawin();
drawout();
drawshaft();
}
void contd()
{
for(int i=0;i<2;i++)
{
intake();
delay(700);
comp();
delay(700);
spark();
delay(1000);
expa();
delay(700);
exhaust();
}
}
void back()
{
cleardevice();
init();
setbkcolor(3);
draw();
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(1);
settextstyle(0,0,1);
outtextxy(150,430,"* Press ENTER to see engine strokes one by one *");
outtextxy(150,450,"* Press SPACE BAR to see continues engine cycle *");
outtextxy(382,360,"* Press 'N' for Nomenclature *");
setcolor(4);
rectangle(10,10,40,30);
outtextxy(14,16,"Esc");
outtextxy(45,16,"Press Escape to QUIT");
setcolor(11);
settextstyle(0,0,9);
outtextxy(35,310,"4");
setcolor(4);
settextstyle(0,0,3);
outtextxy(65,350,"Stroke");
setcolor(14);
settextstyle(1,0,6);
outtextxy(420,140,"Internal");
settextstyle(1,0,4);
outtextxy(425,230,"Combustion");
setcolor(11);
settextstyle(1,0,7);
outtextxy(545,90,"E");
settextstyle(1,0,6);
outtextxy(417,140," n");
settextstyle(1,0,5);
outtextxy(555,182,"g");
settextstyle(1,0,4);
outtextxy(433,230," i");
settextstyle(1,0,3);
outtextxy(559,258,"n");
settextstyle(1,0,2);
outtextxy(562,280,"e");
setcolor(15);
}
void name()
{
back();
setcolor(15);
settextstyle(2,0,6);
setlinestyle(0,0,1);
outtextxy(280,5,"Spark Plug");
outtextxy(170,25,"Intake Valve");
outtextxy(370,25,"Exhaust Valve");
line(250,120,300,120);
outtextxy(140,108,"Vccum Rings");
outtextxy(295,130,"Piston");
line(230,200,320,200);
outtextxy(135,188,"Piston Rod");
outtextxy(340,170,"Cyllinder");
line(200,250,320,250);
outtextxy(90,240,"Crank Shaft");
getch();
back();
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
back();
char choice;
int count=0;
while(choice!=27)
{
choice=getch();
switch(choice)
{
case 'n':
case 'N':
name();
count=0;
break;
case 13:switch(count)
{
case 0:
intake();
count++;
break;
case 1:comp();
count++;
break;
case 2:spark();
count++;
break;
case 3:expa();
count++;
break;
case 4:exhaust();
count=0;
break;
}
break;
case 32:back();
contd();
count=0;
break;
}
}
cleardevice();
setbkcolor(9);
settextstyle(4,0,8);
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(4);
outtextxy(50,100,"THANK YOU !!");
settextstyle(3,0,4);
outtextxy(200,250,"CREATED BY:-");
outtextxy(200,300,"VIVEK P. MEHTA");
outtextxy(200,350,"B.E. 3RD COMPUTER");
getch();
}
Subscribe to:
Posts (Atom)