Subscribe Our Channel

header ads

Search This Blog

Saturday, December 18, 2021

JOGGING MAN IN C++ PROGRAMMING

 



//___________ WELCOME ALL OF YOU ON ROHIT TECH STUDY CHANNEL ______________//

//____________   C++ PROGRAM TO CREATE MAN JOGGING ____________________//


#include<graphics.h>

#include<stdio.h>

#include<conio.h>

#include<dos.h>

void body();

void first();

void second();

int i,a=0,b=0,c=0,d=0;


void main()

{

int gdriver = DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\TC\\BGI");


for(i=0;i<100;i++)

{

body();

if(i%2==0)

{

first();

}

else

{

second();

}

a=a+5;

delay(250);

cleardevice();

}

getch();

}



void first()

{

b=a;


setcolor(14);

//FIRST HAND

line(10+b,310,0+b,320);

line(10+b,308,0+b,318);

line(0+b,320,8+b,323);

line(0+b,318,8+b,323);


setcolor(10);

//SECOND HAND

line(10+b,310,15+b,320);

line(9+b,310,16+b,321);

line(15+b,320,18+b,312);

line(16+b,321,19+b,313);


setcolor(GREEN);

//FIRST LEG

setfillstyle(1,GREEN);

line(10+b,340,13+b,360);

line(13+b,360,10+b,375);

ellipse(13+b,375,0,360,4,2);

floodfill(14+b,375,GREEN);


setcolor(WHITE);

//SECOND LEG

setfillstyle(1,WHITE);

line(10+b,340,8+b,360);

line(8+b,360,1+b,364);

ellipse(2+b,367,0,360,2,4);

floodfill(3+b,367,WHITE);

}



void second()

{

c=a;


setcolor(12);

//SECOND HAND in 2

line(10+c,310,5+c,323);

line(8+c,310,4+c,323);

line(5+c,323,12+c,320);

line(4+c,323,12+c,320);

setcolor(15);


//FIRST HAND in 2

line(10+c,310,13+c,323);

line(11+c,310,14+c,324);

line(13+c,323,18+c,313);

line(14+c,324,17+c,313);


setcolor(15);


//LEG

setfillstyle(1,WHITE);

line(10+c,340,11+c,363);

line(11+c,360,7+c,375);

ellipse(9+c,375,0,360,4,2);

floodfill(10+c,375,WHITE);


setcolor(11);

setfillstyle(1,11);

line(10+c,340,13+c,360);

line(13+c,360,2+c,363);

ellipse(1+c,365,0,360,2,4);

floodfill(2+c,365,11);

}



void body()

{

// road

   setcolor(7);

   line(0,370,640,370);

   line(0,430,640,430);

   line(0,455,640,455);


   // hills

   setcolor(7);

   line(0,200,50,150);

   line(50,150,150,200);

   line(150,200,300,100);

   line(300,100,450,175);

   line(450,175,640,125);


   // sun

   setcolor(14);

   circle(475,75,25);


   // text

   settextstyle(3,0,2);

   setcolor(a);

   outtextxy(150,430,"CREATE BY ROHIT TECH STUDY");


setcolor(15);

ellipse(10+a,290,0,360,5,10);

circle(12+a,288,1);

line(10+a,300,10+a,340);

}

Download source code




Wednesday, December 15, 2021

FLYING BIRDS IN C++ PROGRAMMING

 



Download source code

//___________ WELCOME ALL OF YOU ON ROHIT TECH STUDY CHANNEL ______________//

//____________   C++ PROGRAM TO CREATE FLYING BIRDS ____________________//


#include<graphics.h>

#include<stdio.h>

#include<conio.h>

#include<dos.h>


void bird();

void Wingsup();

void Wingsdown();

int a,b,c,d,e;

int c1=20;

int c2=20;


void main()

{


int gdriver = DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\TC\\BGI");


b=0;

c=0;

d=0;


for(a=1;a<220;a++)

{


bird();

if(a%2==0)

{

Wingsup();

}

else

{

Wingsdown();

}

delay(100);

cleardevice();


b=b+3;

}

getch();

}


void bird()

{


//______birds_________//

setcolor(6);

circle(50+b,100,5);


setcolor(5);

line(53+b,98,60+b,100);

line(53+b,102,60+b,100);


setcolor(14);

circle(50+b,98,1);


setcolor(13);

ellipse(35+b,100,0,360,10,5);

line(28+b,100,15+b,95);

line(28+b,100,14+b,96);

line(29+b,100,13+b,97);

line(29+b,101,12+b,98);

line(29+b,102,10+b,99);

line(29+b,103,12+b,100);


for(int j=0;j<7;j++)

{

if(j==0){c1=40;c2=40;

}

else if(j==1){c1=-20;c2=-20;

}

else if(j==2){c1=20;c2=20;

}

else if(j==3){c1=70;c2=70;

}

else if(j==4){c1=60;c2=100;

}

else if(j==5){c1=20;c2=120;

}

else if(j==6){c1=0;c2=140;

}

else{c1=40;c2=60;

}


setcolor(14);

circle(50+b-c1,100+c2,5);


setcolor(3);

line(53+b-c1,98+c2,60+b-c1,100+c2);

line(53+b-c1,102+c2,60+b-c1,100+c2);


setcolor(13);

circle(50+b-c1,98+c2,1);


setcolor(12);

ellipse(35+b-c1,100+c2,0,360,10,5);

line(28+b-c1,100+c2,15+b-c1,95+c2);

line(28+b-c1,100+c2,14+b-c1,96+c2);

line(29+b-c1,100+c2,13+b-c1,97+c2);

line(29+b-c1,101+c2,12+b-c1,98+c2);

line(29+b-c1,102+c2,10+b-c1,99+c2);

line(29+b-c1,103+c2,12+b-c1,100+c2);

}

}


void Wingsdown()

{

c=b;


//_____wings down_________//

setcolor(10);

ellipse(35+c,106,210,360,6,15);

line(36+c,100,30+c,110);

line(39+c,107,36+c,113);

line(36+c,107,33+c,113);


for(int j=0;j<7;j++)

{

if(j==0){c1=40;c2=40;

}

else if(j==1){c1=-20;c2=-20;

}

else if(j==2){c1=20;c2=20;

}

else if(j==3){c1=70;c2=70;

}

else if(j==4){c1=60;c2=100;

}

else if(j==5){c1=20;c2=120;

}

else if(j==6){c1=0;c2=140;

}

else{c1=40;c2=60;

}


setcolor(11);

ellipse(35+c-c1,106+c2,210,360,6,15);

line(36+c-c1,100+c2,30+c-c1,110+c2);

line(39+c-c1,107+c2,36+c-c1,113+c2);

line(36+c-c1,107+c2,33+c-c1,113+c2);

}

}


void Wingsup()

{

d=b;

//______wings up______//

ellipse(35+d,94,0,150,6,15);

line(36+d,100,30+d,90);

line(36+d,87,38+d,93);

line(34+d,87,36+d,93);


for(int j=0;j<7;j++)

{

if(j==0){c1=40;c2=40;

}

else if(j==1){c1=-20;c2=-20;

}

else if(j==2){c1=20;c2=20;

}

else if(j==3){c1=70;c2=70;

}

else if(j==4){c1=60;c2=100;

}

else if(j==5){c1=20;c2=120;

}

else if(j==6){c1=0;c2=140;

}

else{

c1=40;c2=60;

}


ellipse(35+d-c1,94+c2,0,150,6,15);

line(36+d-c1,100+c2,30+d-c1,90+c2);

line(36+d-c1,87+c2,38+d-c1,93+c2);

line(34+d-c1,87+c2,36+d-c1,93+c2);

}

}

3D CAR ANIMATION IN C++ GRAPAPHICS PROGRAM | C++ PROJECT

 3D CAR ANIMATION IN C++ LANGUAGE | C++ PROJECT


Download source code

// WELCOME ALL OF YOU  ON ROHIT TECH STUDY CHANNEL //

// Animated 3D Car in Turbo C++. It consist of Lights effect, Sound Effect.//

// Press 'L' for Lights effect and 'H' for Horn.//


#include<graphics.h>

#include<conio.h>

#include<dos.h>

#include<stdlib.h>

#include<process.h>


void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\tc\\bgi");

setbkcolor(0);

int t;

while(1)

{

settextstyle(2,0,5);

outtextxy(100,10,"Press L,H ,T,P");

outtextxy(100,30,"Press 1 for Quit");

as:

setcolor(13);

ellipse(380,127,20,152,130,35);

//////////////////////////////rear//////////////////////////


line(490,109,560,142);

line(560,142,569,142);

line(569,142,582,102);

line(582,102,620,92);

line(593,132,617,125);


line(617,124,627,96);

line(620,92,628,97);


line(472,86,602,96);

line(501,113,575,121);

line(443,77,475,80);


line(443,77,432,93);

line(475,80,472,85);


line(593,132,593,137);

line(593,137,600,141);

line(600,141,600,185);

line(600,185,608,192);

line(608,192,608,234);

line(608,234,586,253);

line(586,253,577,248);


/////////////////////////mirror//////////////

line(263,112,363,127);

line(193,160,263,112);

line(193,160,220,170);

line(220,170,280,180);

line(280,180,320,185);

line(320,185,363,127);

////////////////////////////////sidemirror////////////////////


line(340,194,460,169);

line(460,169,519,152);


ellipse(512,144,300,30,10,10);

ellipse(467,143,28,100,50,30);

line(510,128,521,138);

line(435,116,440,171);


////////////////////////////////////////cont////////////////


line(339,194,372,144);

ellipse(454,208,87,123,128,95);

line(372,144,384,128);

int b,x,y;


////////////////////////lower/////////////////////


line(365,298,524,264);

line(365,298,330,310);

line(330,310,323,310);



///////////////////////////////bumper//////////////////


ellipse(162,221,135,190,90,40);

line(96,193,140,174);

line(140,174,160,168);

line(160,168,192,161);


//////////////////////front////////////////


ellipse(75,246,95,190,18,18);

line(57,251,57,286);

ellipse(181,178,232,263,200,137);

ellipse(195,180,256,286,200,137);



ellipse(191,171,228,247,200,100);

ellipse(231,198,234,275,200,80);


ellipse(196,167,228,246,200,90);

ellipse(231,184,234,276,200,80);

ellipse(191,200,228,246,200,90);

ellipse(228,218,234,276,200,80);

ellipse(258,268,180,220,200,40);

ellipse(178,296,244,355,16,10);

ellipse(238,249,227,250,200,60);



/////////////wheel1/////////////////


ellipse(302,281,320,77,26,45);

ellipse(290,277,65,162,40,45);

ellipse(278,288,144,212,31,45);


/////////////wheel2////////////////////


ellipse(302+260,229,328,87,26,45);

ellipse(290+280-7,277-50+2,90,162,40,45);

ellipse(278+270,288-50,144,215,27,45);

 b=0;

int v=0;


/////////

ellipse(302+250+v,227+b,295,90,29,41);

ellipse(302+234+v,231+b,245,306,50,40);

ellipse(302+248+v,229+b,0,360,21,30);


ellipse(302+247+v,229+b,0,360,8,10);

setfillstyle(6,11);


line(546+v,201+b,546+v,220+b);

line(551+v,201+b-2,551+v,220+b);


line(546+v,238+b,546+v,257+b);

line(551+v,238+b+2,551+v,257+b+2);



line(530+v,225+b,541+v,225+b);

line(530+v,230+b,541+v,230);


line(557+v,225+b,570+v,225+b);

line(557+v,230+b,570+v,230+b);

line(563+v,206+b,552+v,222+b);

line(534+v,246+b,543+v,232+b);


line(566+v,210+b,556+v,223+b);

line(536+v,250+b,544+v,238+b);


line(536+v,207+b,546+v,222+b);

line(532+v,213+b,542+v,224+b);


line(556+v,235+b,566+v,247+b);

line(551+v,237+b,563+v,253+b);


////////////////////////////////////////////////////

v=-260;

b=56;

ellipse(302+233+v,221+b,260,60,49,51);

ellipse(302+243+v,224+b,0,360,28,35);

ellipse(300+245+v,223+b,0,360,10,12);


ellipse(285+249+v,239+b,210,260,30,33);

b=45;

v=v-4;

line(546+v,201+b,546+v,220+b+2);

line(551+v,201+b,551+v,220+b+2);

b=b+8;

line(546+v,238+b,546+v,257+b+4);

line(551+v,238+b,551+v,257+b+4);

v=v-2;

line(530+v-6,225+b,541+v,225+b);

line(530+v-6,230+b,541+v,230+b);

v=v+5;

line(557+v,225+b,570+v+3,225+b);

line(557+v-1,230+b,570+v+3,230+b);



b=b-5;

v=v-5;

line(565+v+3,206+b,552+v+4,222+b-2);

b=b+15;


line(534+v,246+b,543+v+3,232+b-5);

b=b-10;

line(566+v+7,210+b-5,556+v+4,220+b);

line(536+v-5,250+b,544+v-2,238+b-4);



line(536+v,207+b-8,545+v,222+b-5);

line(531+v,212+b-8,542+v,224+b-2);


line(556+v,235+b,566+v+3,247+b+5);

line(551+v,237+b,563+v+2,253+b+3);


///////////////////lights////////////////////////


ellipse(199,250,144,345,18,8);

line(185,245,206,230);

ellipse(223,234,340,110,8,5);

line(230,237,217,252);

line(206,230,220,229);


/////////////////////////////////////

line(90,223,152,236);

line(152,236,137,254);

line(90,223,90,242);


ellipse(240,270,104,136,100,60);

ellipse(185,237,120,160,100,60);

ellipse(80,221,357,134,10,10);


line(152,236,168,228);

///////////////////////////////////////////////


line(435,116,440,171);


//////////////////////////////////////////hp//////////


line(134,185,196,160);

line(214,212,318,185);

////////////////////LIGHT/////////////////////////////


ellipse(166,247,99,330,8,8);

ellipse(171,243,310,129,7,7);

putpixel(174,250,13);

putpixel(173,251,13);

putpixel(164,239,13);

putpixel(165,238,13);


/////////////////////////////////////////road/////////////////////

setcolor(13);

line(1,430,639,300);

line(1,445,639,315);


line(1,210,93,194);

line(1,195,194,158);

line(520,90,639,71);

line(478,86,639,56);


int c=0;

line(10,194+c,10,208+c);

line(40,189+c,40,204+c);

line(70,183+c,70,198+c);

line(100,176+c,100,190+c);

line(130,170+c,130,177+c);

line(160,166+c,160,168+c);

line(190,160+c,190,161+c);


line(190+330,78+c,190+330,89+c);


line(190+360,72+c,190+360,85+c);

line(190+390,67+c,190+390,81+c);

line(190+420,62+c,190+420,76+c);

line(190+449,57+c,190+449,71+c);


c=236;


line(10,192+c,10,208+c);

line(40,189+c-2,40,204+c-3);

line(70,183+c-3,70,198+c-3);

line(100,176+c-2,100,190+c-2);

line(130,170+c-2,130,177+c+5);

line(160,166+c-3,160,168+c+8);

line(190,160+c-4,190,161+c+9);


line(190+30,156+c-5,190+30,170+c-5);



line(190+30+30,156+c-12,190+30+30,170+c-12);


line(190+90,156+c-18,190+90,170+c-17);


line(190+120,156+c-25,190+120,170+c-25);


line(190+150,156+c-30,190+150,170+c-30);


line(190+180,156+c-37,190+180,170+c-36);



line(190+210,156+c-42,190+210,170+c-42);



line(190+240,156+c-48,190+240,170+c-48);



line(190+270,156+c-55,190+270,170+c-54);



line(190+300,156+c-61,190+300,170+c-61);

line(190+330,78+c+10,190+330,89+c+13);

line(190+360,72+c+11,190+360,85+c+13);

line(190+390,67+c+10,190+390,81+c+10);

line(190+420,62+c+8,190+420,76+c+10);

line(190+449,57+c+8,190+449,71+c+8);


/////////////////road///////////////////


setcolor(12);

line(1,310,25,306);

line(6,318,30,315);

line(1,310,6,318);

line(25,306,30,314);


setcolor(12);


line(605,310-128,629,306-128);

line(610,318-128,634,315-128);

line(605,310-128,610,318-128);

line(629,306-128,634,314-128);


setcolor(12);

line(46,302,70,298);

line(51,310,75,307);

line(46,302,51,310);

line(70,298,75,306);



setfillstyle(1,0);

floodfill(64,303,12);


setfillstyle(1,14);

floodfill(14,314,12);

floodfill(617,183,12);


setfillstyle(1,0);

floodfill(14,314,12);

floodfill(617,183,12);


setfillstyle(1,14);

floodfill(64,303,12);


t=getch();

if(t=='1')

exit(0);

if(t=='h')

{

sound(710);

delay(500);

nosound();

 ////break;/////

}

if(t=='t')

{

while(!kbhit())

{

setfillstyle(1,0);

floodfill(536,213,13);

floodfill(563,213,13);

floodfill(561,244,13);

floodfill(538,244,13);

floodfill(274,295,13);

floodfill(294,295,13);

floodfill(274,265,13);

floodfill(294,265,13);

floodfill(548,250,13);

floodfill(548,214,13);

floodfill(533,228,13);

floodfill(563,228,13);

floodfill(262,281,13);

floodfill(308,281,13);

floodfill(284,251,13);

floodfill(284,295,13);


setfillstyle(1,random(12));


floodfill(200,250,13);

delay(10);


//setfillstyle(1,11);


 floodfill(170,250,13);

 floodfill(80,230,13);

 }

setfillstyle(1,0);

floodfill(200,250,13);

delay(10);


 floodfill(170,250,13);

 floodfill(80,230,13);

}

if(t=='l')

{

while(!kbhit())

{


delay(120);

setfillstyle(6,0);

floodfill(536,213,13);

floodfill(563,213,13);

floodfill(561,244,13);

floodfill(538,244,13);

floodfill(274,295,13);

floodfill(294,295,13);

floodfill(274,265,13);

floodfill(294,265,13);


setfillstyle(1,0);

floodfill(64,303,12);


/////////////////////road//////////////


setfillstyle(9,0);


 /////////////////////color///////////////


floodfill(81-40+5,419+7,13);

floodfill(151-40,409+7,13);

floodfill(211-40,397+7,13);

floodfill(271-40,380+7,13);

floodfill(331-40,368+7,13);

floodfill(396-40,355+7,13);

floodfill(450-40,345+7,13);

floodfill(510-40,335+7,13);

floodfill(570-40,325+7,13);

floodfill(630-40,312+7,13);


//////////////////////

floodfill(50,197,13);

floodfill(110,177,13);

floodfill(166,165,13);

floodfill(527,86,13);

floodfill(587,71,13);


setfillstyle(6,14);

floodfill(548,250,13);

floodfill(548,214,13);

floodfill(533,228,13);

floodfill(563,228,13);

floodfill(262,281,13);

floodfill(308,281,13);

floodfill(284,251,13);

floodfill(284,295,13);

//////////////////////road//////////


setfillstyle(9,10);


////////////////////color//////////////////


floodfill(19,429,13);

floodfill(81,419,13);

floodfill(151,409,13);

floodfill(211,397,13);

floodfill(271,380,13);

floodfill(331,368,13);

floodfill(396,355,13);

floodfill(450,345,13);

floodfill(510,335,13);

floodfill(570,325,13);

floodfill(630,312,13);

//////////////////////////////////////

floodfill(20,197,13);

floodfill(80,187,13);

floodfill(133,174,13);

floodfill(517,86,13);

floodfill(557,81,13);

floodfill(627,70,13);


setfillstyle(1,14);

floodfill(14,314,12);

floodfill(617,183,12);


///////////////////////////////////////

setfillstyle(10,4);

floodfill(302+248,230,13);

floodfill(302+248+v,230+b,13);


/////////////light///////////////////////


setfillstyle(6,11);

floodfill(200,250,13);

floodfill(170,250,13);

floodfill(80,230,13);


delay(120);


setfillstyle(6,0);/////////////////////ty

floodfill(548,250,13);

floodfill(548,214,13);

floodfill(533,228,13);

floodfill(563,228,13);

floodfill(262,281,13);

floodfill(308,281,13);

floodfill(284,251,13);

floodfill(284,295,13);


//////////////////////road/////////////////////////


setfillstyle(9,0);


///////////////color//////////////////////////


floodfill(19,429,13);

floodfill(81,419,13);

floodfill(151,409,13);

floodfill(211,397,13);

floodfill(271,380,13);

floodfill(331,368,13);

floodfill(396,355,13);

floodfill(450,345,13);

floodfill(510,335,13);

floodfill(570,325,13);

floodfill(630,312,13);

///////////////////////////////////////////////////////

floodfill(20,197,13);

floodfill(80,187,13);

floodfill(133,174,13);

floodfill(517,86,13);

floodfill(557,81,13);

floodfill(627,70,13);

/////////////////////////////

setfillstyle(1,0);

floodfill(14,314,12);

floodfill(617,183,12);


setfillstyle(6,10);


floodfill(536,213,13);

floodfill(563,213,13);

floodfill(561,244,13);

floodfill(538,244,13);

floodfill(274,295,13);

floodfill(294,295,13);

floodfill(274,265,13);

floodfill(294,265,13);


//////////////////////road//////////////////


setfillstyle(9,14);

//////////////////////color/////////////////////


floodfill(81-40+5,419+7,13);

floodfill(151-40,409+7,13);

floodfill(211-40,397+7,13);

floodfill(271-40,380+7,13);

floodfill(331-40,368+7,13);

floodfill(396-40,355+7,13);

floodfill(450-40,345+7,13);

floodfill(510-40,335+7,13);

floodfill(570-40,325+7,13);

floodfill(630-40,312+7,13);

/////////////////////////////////////////


floodfill(50,197,13);

floodfill(110,177,13);

floodfill(166,165,13);

floodfill(527,86,13);

floodfill(587,71,13);

setfillstyle(1,14);

floodfill(64,303,12);


setfillstyle(9,4);

floodfill(302+248,230,13);

floodfill(302+248+v,230+b,13);


delay(20);

setfillstyle(1,14);


floodfill(200,250,13);


floodfill(170,250,13);

 floodfill(80,230,13);


 delay(20);

setfillstyle(1,0);


floodfill(200,250,13);

floodfill(170,250,13);

 floodfill(80,230,13);

}          }

if(t=='p')

{

int n=0;

while(!kbhit())

{

if(n<=60)

n++;

setcolor(0);

rectangle(1+1,-10,90-1,-12+n);

delay(14);


setcolor(9);

rectangle(1,-10,90,-10+n);

if(n==60)

{

outtextxy(10,10,"THANK YOU");

outtextxy(10,20,"---ROHIT");


delay(400);

 }

}

}

}

circle(300,100,3);

nosound();

getch();

}

Sunday, December 12, 2021

clock animation c++ programming

 



Download source code

//____________ WELCOME ALL OF YOU ON ROHIT TECH STUDY CHANNEL _____________//

//------------------- C++ PROGRAM TO CREATE A CLOCK -----------------------//


#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<graphics.h>

#include<dos.h>

void main()

{

struct  time t;

struct arccoordstype sec_arc, min_arc, hr_arc;

int i;

int gd = DETECT,gm;

initgraph(&gd,&gm,"c://TC//BGI");


setcolor(10);

//Outer circle

circle(320,240,100);

circle(320,240,99);


//Inner circle

circle(320,240,80);

circle(320,240,79);

setcolor(WHITE);


//mark four points

line(320,160,320,165); //top

line(320,320,320,315); //bottom

line(400,240,395,240); //left

line(240,240,245,240); //right


      while(!kbhit())

      {

      printf("Time is : %2d:%2d:%3d\r",t.ti_hour%12, t.ti_min, t.ti_sec);

      setcolor(0);

      line(320,240, sec_arc.xend, sec_arc.yend);

      line(320,240, min_arc.xend, min_arc.yend);

      line(320,240, hr_arc.xend, hr_arc.yend);


      //Store time into struct t

      gettime(&t);


      //hour

      setcolor(0);

      arc(320,240,270,90-(t.ti_hour*6*5),55);

      setcolor(YELLOW);

      getarccoords(&hr_arc);

      line(320,240, hr_arc.xend, hr_arc.yend);


      //minute

      setcolor(0);

      arc(320,240,270,90-t.ti_min*6,65);

      setcolor(CYAN);

      getarccoords(&min_arc);

      line(320,240, min_arc.xend, min_arc.yend);


      //center circle

      setcolor(WHITE);

      pieslice(320,240,0,360,5);


      //second

      setcolor(0);

      arc(320,240,270,90-t.ti_sec*6,75);

      setcolor(RED);

      getarccoords(&sec_arc);

      line(320,240, sec_arc.xend, sec_arc.yend);

      delay(250);

      }

getch();

 }

snake game in c++ graphics programing

 


Download source code

/***********  WELCOME ALL OF YOU ON ROHIT TECH STUDY CHANNEL **************/

/************        C++ PROGRAME TO CREATE SNAKE GAME      ***************/


#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<stdlib.h>

#include<stdio.h>

#include<time.h>

#include<string.h>

class Snake

{

 int p1,p2,v1,v2,v3,e1,e2,prev,now,n,colr,dsp,cnt,dly,m;

 int stp,egGen;

 int xr,yr;

 void caught();

 public:

  long scr;

 int strtX,strtY,endX,endY;

 int pos[100][2];

 void show();

 void init();

 void egg();

 void transpose();

 void gnrtCond();

 void gnrtUnCond();

 void check();

 void checkEgg();

 void move();

 void chngDir();

 void sndEt();

 void sndCgt();

 int test();

 void score();

 Snake();

 Snake(Snake*);

 ~Snake();

 };

Snake::Snake()

 {

 }

Snake::~Snake()

{


}

void Snake::checkEgg()

{

 if((e1 == p1) && (e2 == p2))

 {sndEt();

  egg();

  dly--;

  score();

  n++;

  }

}

void Snake::sndEt()

{nosound();

 sound(2500);

 delay(2);

 nosound();

}

void Snake::sndCgt()

{nosound();

 for(int x=1000;x>0;x--)

 {sound(x);

  delay(1);

  }

 nosound();

}

void Snake::score()

{ char *p;


  ltoa(scr,p,10);

  settextstyle(8,0,1);

  setcolor(0);

  outtextxy(585,40,p);

  if(egGen != 1){

  scr = scr + dly / 10;

  }

  ltoa(scr,p,10);

  setcolor(10);

  outtextxy(585,40,p);


}

void Snake::gnrtCond()

{if(n < 367)

 {if(now == 8 && (prev != 8 && prev != 2))

  {pos[0][0] = p1;

   pos[0][1] = p2 - dsp;

   prev = now;

   }

  if(now == 4 && (prev != 4 && prev != 1))

  {pos[0][0] = p1 + dsp;

   pos[0][1] = p2;

   prev = now;

   }

  if(now == 2 && (prev != 8 && prev != 2))

  {pos[0][0] = p1;

   pos[0][1] = p2 + dsp;

   prev = now;

   }

  if(now == 1 && (prev != 1 && prev != 4))

  {pos[0][0] = p1 - dsp;

   pos[0][1] = p2;

   prev = now;

   }

}

}

void Snake::gnrtUnCond()

{

  if( prev == 8 )

  {pos[0][0] = p1;

   pos[0][1] = p2 - dsp;

   }

 if( prev == 4 )

  {pos[0][0] = p1 + dsp;

   pos[0][1] = p2;

   }

 if( prev == 2 )

  {pos[0][0] = p1;

   pos[0][1] = p2 + dsp;

   }

 if( prev == 1 )

  {pos[0][0] = p1 - dsp;

   pos[0][1] = p2;

   }

 p1 = pos[0][0];

 p2 = pos[0][1];

}

void Snake::check()

{

 if(p1 > endX)

  {p1 = strtX;}

 else if(p1 < strtX)

  {p1 = endX;}


 if(p2 > endY)

  {p2 = strtY;}

 else if(p2 < strtY)

  {p2 = endY;}


 pos[0][0] = p1;

 pos[0][1] = p2;

for(int i = 1;i < n;i++)

  { if(p1 == pos[i][0] && p2 == pos[i][1])

  {caught();

   break;

  }

 }

}

void Snake::show()

{

  int x = getcolor();

  if(egGen != 1)

  {

  setcolor(getbkcolor());

  setfillstyle(1,getbkcolor());

  fillellipse(v1,v2,yr,yr);

   }

  else

   egGen = 0;

  if(egGen == 2)

   egGen--;

  setcolor(colr);

  setfillstyle(1,9);

  if(now == 8 || now == 2)

   fillellipse(pos[0][0],pos[0][1],xr,yr);

  else if(now == 4 || now == 1)

   fillellipse(pos[0][0],pos[0][1],yr,xr);

  setcolor(x);

}

void Snake::transpose()

{ int i,j,x,y;

   p1 = pos[0][0];

   p2 = pos[0][1];

   if(!egGen){

   v1 = pos[n-1][0];

   v2 = pos[n-1][1];

   }

   else

    egGen = 0;

   for(i = n-1;i >= 1;i--)

   {pos[i][0] = pos[i-1][0];

    pos[i][1] = pos[i-1][1];

   }

}

void Snake::move()

{ int st = 0;

  do{

   if(!kbhit())

   {checkEgg();

    if(!st)

     show();

    else

     st = 0;

    delay(dly/4);

    transpose();

    delay(dly/4);

    gnrtUnCond();

    delay(dly/4);

    check();

   delay(dly/4);

    }

   else if(stp){

   chngDir();

   gnrtCond();

   check();

   show();

   st = 1;

   }

   }while(stp);

}

void Snake::init()

{time_t tm;

 srand(time(&tm));

 dsp = 20;

 n = 5;

 prev = 4;

 for(int i = 4;i >= 0;i--)

 {pos[i][0] = 201 + (n - i - 1) * dsp;

  pos[i][1] = 301;

  }

  strtX = 21;

  strtY = 21;

  endX = 481;

  endY = 361;

  colr = 14;

  now = prev;

  dsp = 20;

  stp = 111;

  cnt = -1;

  scr = 0;

  dly = 150;

   xr = 3;

   yr = 9;

  egg();

  egGen = 1;

  score();

  int x = getcolor();

  setlinestyle(0,1,3);

  setcolor(15);

  rectangle(strtX-15,strtY-15,endX+15,endY+15);

  rectangle(endX+25,strtY-15,getmaxx()-15,endY+15);

  rectangle(strtX-15,endY+25,getmaxx()-15,getmaxy()-5);

  line(endX+25,strtY+75,getmaxx()-15,strtY+75);

  line(endX+25,strtY+200,getmaxx()-15,strtY+200);

  line(endX+25,strtY+275,getmaxx()-15,strtY+275);

  setlinestyle(0,1,1);

  settextstyle(8,0,1);

  setcolor(11);

  outtextxy(514,40,"SCORE");

  setcolor(14);

  settextstyle(11,0,5);

  outtextxy(524,110," CONTROLS ");

  outtextxy(522,135,"p = PAUSE");

  outtextxy(522,155,"g = RESUME");

  outtextxy(522,175,"e = EXIT");

  setcolor(10);

  outtextxy(513,195,"   ROHIT  ");

  setcolor(10);

  outtextxy(512,205," TECH STUDY ");

  setcolor(CYAN);

  settextstyle(4,0,9);

  outtextxy(getmaxx()-500,getmaxy()-110,"SNAKE");

  settextstyle(8,0,1);

  setcolor(x);

}

void Snake::caught()

{

 stp = 0;

 sndCgt();

for(int i=0;i<=7;i++)

 {

 if(i%2)

  {

  setcolor(10);

   outtextxy(512,250,"GAME OVER");

   delay(900);

   }

  else

  {

  setcolor(0);

   outtextxy(512,250,"GAME OVER");

   delay(500);

  }

  }

sleep(1);

}

void Snake::chngDir()

{int clr;

 fillsettingstype *p;

 char x = getch();

 if(x == 72)

  now = 8;

 else if(x == 77)

  now = 4;

 else if(x == 80)

  now = 2;

 else if(x == 75)

  now = 1;

 else if(x == 'e')

  caught();

 else if(x == 'p')

 {

  int twnkl = 1;

  settextstyle(11,0,9);

  while(1)

  {if(kbhit())

   {int c = getch();

    if(c == 'g')

    {

    clr = getcolor();

     setcolor(0);

     rectangle(endX+40,endY-10,getmaxx()-35,getmaxy()-160);

     outtextxy(endX+60,endY-29,"PAUSE");

     break;

     }

    }

   else

   {if(twnkl%2)

    {

    clr = getcolor();

     setcolor(10);

     rectangle(endX+40,endY-10,getmaxx()-35,getmaxy()-160);

     outtextxy(endX+60,endY-29,"PAUSE");

     setcolor(clr);

      delay(1000);

     }

    else

    {

     clr = getcolor();

     setcolor(0);

     rectangle(endX+40,endY-10,getmaxx()-35,getmaxy()-160);

     outtextxy(endX+60,endY-29,"PAUSE");

     delay(1000);

    }

   }

   twnkl++;

  }

    settextstyle(8,0,1);

 }

}

Snake::Snake(Snake *p)

{

 *p=NULL;

}

void Snake::egg()

{ do

  {e1 = (rand() % 100) * dsp + strtX;

   e2 = (rand() % 100) * dsp + strtY;

   }while(test());

  int x = getcolor();

  setcolor(7);

  setfillstyle(1,random(15)+1);

  fillellipse(e1,e2,xr+2,xr+2);

  setcolor(x);

  egGen = 2;

}

int Snake::test()

{ for(int i=0;i<n;i++)

  {if(e1 == pos[i][0] && e2 == pos[i][1])

    break;

   if(v1 == e1 && v2 == e2)

    break;

   if((e1 >= endX+1) || (e2 >= endY+1))

    break;

   }

 if(i != n)

  return 1;

 else

  return 0;

}


void main()

{Snake snk;

 int gd=DETECT,gm,i,j,k,x,y;

 clrscr();

 initgraph(&gd,&gm,"c:\\tc\\bgi");

 snk.init();

 snk.move();


 closegraph();

 restorecrtmode();

 }

Snake game in C++ Programming


Download source code




//----------WELCOME ALL OF YOU ON ROHIT TECH STUDY  CHANNEL----------------//

//__________C++ GRAPHICS PROGRAM TO MAKE RATTLE SNAKE GAME_________________//


#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <dos.h>

#include <iostream.h>

#include <fstream.h>

#include <string.h>



void main(void)

{

   int gdriver = DETECT, gmode, errorcode;

   void

*body,*food,*tail1,*tail2,*tail3,*tail4,*head1,*head2,*head3,*head4;

   int x, y,X[5000],Y[5000],i=3,

maxx,maxy,speed=100,bo=10,t[10],score=0,hscore=20;

   unsigned int size;

   char a='6',b,scor[4],hs[4];

   int k=2,l,r1,r2,f=0,z=100,first=0,second=1;;

   r1=300;

   r2=350;


   ifstream infile("c:\tc\bin\rattle.txt");

   infile.getline(hs,4);

   infile.close();

   hscore = atoi(hs);


   /* initialize graphics and local variables */

   initgraph(&gdriver, &gmode, "c:\\tc\\bgi");


   /* read result of initialization */

   errorcode = graphresult();


   if (errorcode != grOk)

   {

      printf("Graphics error: %s", grapherrormsg(errorcode));

      printf("Press any key to halt:");

      getch();

      exit(1);

   }

   maxx = getmaxx();

   maxy = getmaxy();

   y = 160;

   x = 80;

   for(int j=0; j<=3; j++)

   {

X[i-j]=x-bo*(j+1);

Y[i-j]=y;


   }


   //body


   setfillstyle(1,2);

   bar(10,10,20,20);

   setcolor(0);

   setlinestyle(0,1,3);

   line(9,9,21,21);

   line(9,21,21,9);

   size = imagesize(10,10,20,20);

   body = malloc(size);

   getimage(10,10,20,20,body);

   cleardevice();


   setcolor(0);

   //tail1-right

   t[0]=20; t[1]=10;

   t[2]=10; t[3]=10;

   t[4]=20; t[5]=15;

   t[6]=10; t[7]=20;

   t[8]=20; t[9]=21;

   fillpoly(5, t);

   size = imagesize(10,10,20,21);

   tail1 = malloc(size);

   getimage(10,10,20,21,tail1);

   cleardevice();


   //tail2-left

   t[0]=10; t[1]=10;

   t[2]=20; t[3]=10;

   t[4]=10; t[5]=15;

   t[6]=20; t[7]=20;

   t[8]=10; t[9]=21;

   fillpoly(5, t);

   size = imagesize(10,10,20,21);

   tail2 = malloc(size);

   getimage(10,10,20,21,tail2);

   cleardevice();


   //tail3-up

   t[0]=10; t[1]=20;

   t[2]=10; t[3]=10;

   t[4]=15; t[5]=20;

   t[6]=20; t[7]=10;

   t[8]=20; t[9]=21;

   fillpoly(5, t);

   size = imagesize(10,10,20,21);

   tail3 = malloc(size);

   getimage(10,10,20,21,tail3);

   cleardevice();


   //tail4-down

   t[0]=10; t[1]=10;

   t[2]=10; t[3]=21;

   t[4]=15; t[5]=10;

   t[6]=20; t[7]=21;

   t[8]=20; t[9]=10;

   fillpoly(5, t);

   size = imagesize(10,10,20,21);

   tail4 = malloc(size);

   getimage(10,10,20,21,tail4);

   cleardevice();


   //head1-right

   setlinestyle(1,1,1);

   setcolor(2);

   fillellipse(10,10,10,5);

   setcolor(4);

   //eyes

   fillellipse(15,7,1,1);

   fillellipse(15,13,1,1);

   size = imagesize(10,5,20,15);

   head1 = malloc(size);

   getimage(10,5,20,15,head1);


   //head2-left

   //eyes

   fillellipse(5,7,1,1);

   fillellipse(5,13,1,1);

   size = imagesize(0,5,10,15);

   head2 = malloc(size);

   getimage(0,5,10,15,head2);

   cleardevice();


   //head3-up

   //eyes

   setcolor(2);

   fillellipse(12,12,5,10);

   setcolor(4);

   fillellipse(9,6,1,1);

   fillellipse(15,6,1,1);

   size = imagesize(7,2,18,12);

   head3 = malloc(size);

   getimage(7,2,18,12,head3);


   //head4-down

   //eyes

   fillellipse(9,17,1,1);

   fillellipse(15,17,1,1);

   size = imagesize(7,12,18,22);

   head4 = malloc(size);

   getimage(7,12,18,22,head4);

   cleardevice();


   //food

   setcolor(15);

   setfillstyle(1,15);

   fillellipse(10,10,3,5);

   size = imagesize(5,3,15,17);

   food = malloc(size);

   getimage(5,3,15,17,food);

   cleardevice();


    /* repeat until a key is pressed */

   maxx=getmaxx();

   maxy=getmaxy();

   setlinestyle(0,1,3);

   setcolor(9);

   rectangle(0,0,maxx,maxy);

   setlinestyle(0,1,2);

   line(maxx-150,0,maxx-150,maxy);

   setcolor(8);

   setfillstyle(1,8);

   bar(maxx-147,3,maxx-3,63);

   setcolor(12);

   int maze=1;

   if(maze==1)

   {

   setfillstyle(1,6);

   bar(4,4,maxx-154,14);

   bar(4,4,14,maxy-4);

   bar(4,maxy-4,maxx-154,maxy-14);

   bar(maxx-154-10,4,maxx-154,maxy-4);

   }


   settextstyle(0,0,1);

   delay(300);

   outtextxy(maxx-125,45,"RATTLE SNAKE");

    outtextxy(maxx-115,10,"MODIFY BY");

   outtextxy(maxx-135,30,"ROHIT TECH STUDY");

   delay(300);

   setcolor(11);

   setlinestyle(0,1,2);

   rectangle(maxx-145,65,maxx-5,205);

   outtextxy(maxx-128,70,"INSTRUCTIONS");

   delay(200);

   setcolor(6);

   outtextxy(maxx-140,90,"Commands      Key");

   delay(300);

   setcolor(8);

   outtextxy(maxx-140,110," Move Up      8");

   delay(50);

   outtextxy(maxx-140,130," Move Down    5");

    delay(50);

   outtextxy(maxx-140,150," Move Right   6");

    delay(50);

   outtextxy(maxx-140,170," Move Left    4");

    delay(50);

   outtextxy(maxx-140,190," Exit         0");

   delay(200);

   setcolor(12);

   setlinestyle(0,1,2);

   rectangle(maxx-145,210,maxx-5,350);

   setcolor(1);

   outtextxy(maxx-130,220,"Player's Name");

   setcolor(15);

   outtextxy(maxx-100,230,"ROHIT");

   setcolor(4);

   delay(200);

   itoa(score,scor,10);

   outtextxy(maxx-140,250,"Score");

   outtextxy(maxx-50,250,scor);

   delay(200);

   setcolor(10);

   outtextxy(maxx-140,280,"Level");

   delay(200);

   setcolor(13);

   outtextxy(maxx-140,310,"Maze        1");

   delay(200);

   setcolor(14);

   outtextxy(maxx-140,340,"High Score  ");

   outtextxy(maxx-50,340,hs);


   for(j=0; j<=1000; j++)

   {

putpixel(random(maxx-150),random(maxy),6);

delay(1);

   }


   while (a!='0')

   {


       // plot new image

      if(a=='6')

    putimage(x, y, head1, XOR_PUT);

      if(a=='4')

    putimage(x, y, head2, XOR_PUT);

      if(a=='8')

    putimage(x, y, head3, XOR_PUT);

      if(a=='5')

    putimage(x, y, head4, XOR_PUT);


      for(j=0; j<k; j++)

      {

   putimage(X[i-j], Y[i-j], body, XOR_PUT);

      }


      if((X[i-j-1]-X[i-j])<0  && (Y[i-j-1]-Y[i-j])==0)

    putimage(X[i-j], Y[i-j], tail1, XOR_PUT);


      if((X[i-j-1]-X[i-j])>0  && (Y[i-j-1]-Y[i-j])==0)

    putimage(X[i-j], Y[i-j], tail2, XOR_PUT);


      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])<0)

    putimage(X[i-j], Y[i-j], tail3, XOR_PUT);


      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])>0)

    putimage(X[i-j], Y[i-j], tail4, XOR_PUT);


      delay(speed);


      if(second==1)

      {

setcolor(15);

outtextxy(maxx-140,360,"Press Any Key...");

getch();

setcolor(0);

outtextxy(maxx-140,360,"Press Any Key...");

a='6';


second=2;

      }



      if(first==1)

      {

setcolor(15);

outtextxy(maxx-140,360,"Congratulations  ");

sound(100);

delay(300);

nosound();

getch();

setcolor(0);

outtextxy(maxx-140,360,"Congratulations  ");

second++;

first=2;


      }


// erase old image

      if(a=='6')

    putimage(x, y, head1, XOR_PUT);

      if(a=='4')

    putimage(x, y, head2, XOR_PUT);

      if(a=='8')

    putimage(x, y, head3, XOR_PUT);

      if(a=='5')

    putimage(x, y, head4, XOR_PUT);



      for(j=0; j<k; j++)

      {

   putimage(X[i-j], Y[i-j], body, XOR_PUT);


      }


      if((X[i-j-1]-X[i-j])<0  && (Y[i-j-1]-Y[i-j])==0)

    putimage(X[i-j], Y[i-j], tail1, XOR_PUT);


      if((X[i-j-1]-X[i-j])>0  && (Y[i-j-1]-Y[i-j])==0)

    putimage(X[i-j], Y[i-j], tail2, XOR_PUT);


      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])<0)

    putimage(X[i-j], Y[i-j], tail3, XOR_PUT);


      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])>0)

    putimage(X[i-j], Y[i-j], tail4, XOR_PUT);



      if(f==0)

      {

putimage(r1,r2,food,XOR_PUT);

f=1;

      }


      z--;

if((x>=r1 && y>=r2 && x<=r1+10 && y<=r2+10)||

(x<=r1 && y<=r2 &&x>=r1-10 && y>=r2-10) || z==0)

      {

if(z!=0)

{

sound(800);

delay(20);

setcolor(0);

score += 10;

outtextxy(maxx-50,250,scor);

itoa(score,scor,10);

if(score>hscore)

{

strcpy(hs,scor);

setfillstyle(1,1);

bar(maxx-140,337,maxx-20,348);

setcolor(14);

outtextxy(maxx-50,340,hs);

outtextxy(maxx-140,340,"High Score  ");

if(first==0)

{

first=1;

}

}

setcolor(4);

outtextxy(maxx-50,250,scor);

k++;

nosound();

}

z=100;

putimage(r1,r2,food,XOR_PUT);

repr1:

r1=random(450);

    if(r1<50)

       goto repr1;

repr2:

r2=random(400);

    if(r2<50)

goto repr2;


f=0;

      }



      i++;

      X[i]=x;

      Y[i]=y;


b=a;

if(kbhit())

{

rep:

a=getch();


if((b=='6' && a=='4') || (b=='4' && a=='6'))

a=b;


if((b=='8' && a=='5') || (b=='5' && a=='8'))

a=b;


if(a!='6' && a!='4' && a!='8' && a!='0' && a!='5')

a=b;

      }


      if(a=='8')

y -= bo;


      if(a=='5')

y += bo;


      if(a=='4')

x -= bo;


      if(a=='6')

x += bo;


 for(j=i+1; j<i-k; j--)

 {

 if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10))

 {

 if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10))

 {

 a='0';

 }


 outtextxy(maxx-140,360,"C");


 }


 if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10))

 {

 if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10))

 {

 a='0';

 }


 outtextxy(maxx-140,360,"C");

 }


 }


if(maze==1)

{

if(x<=14 || x>=maxx-184 || y<=14 || y>=maxy-14)

{

a='0';

}

}

}


if(score>hscore)

{

ofstream onfile("c:\tc\bin\rattle.txt");

onfile<<scor;

onfile.close();

   }


   setcolor(15);

   outtextxy(maxx-140,390," Gameover");

   sound(100);

   delay(400);

   nosound();

   getch();

   /* clean up */

   free(body);

   closegraph();

}

 

Featured Post

Happy Republic Day Wish Using HTML and CSS | 26 January wish using HTML/CSS

 Happy Republic Day Wish Using HTML and CSS, 26 January wish using HTML/CSS <!-- WELCOME ALL OF YOU ON COMPUTER SOFT SKILLS CHANNEL -----...

Popular Posts