I'm attaching the source code of a C++ program that is compiled with Turbo C++
compiler on virtual box. The program is intended to make an animation of a man
walking in
rain with an umbrella. Anyone with some C++ skills can patch the code. Clearly
comment any changes. Anything that seems to be good should done to the source
code. And
make your suggestions at the end. And please try to manage a SDL Linux
alternative of
the program on the move. Manage the source code as follows.
When you change a line comment the previous one and code in the
alternative.When you add something, document it clearlyManage the same source
code.After making changes compile it and push back.Do not stick with the latest
source code but with the best.Don't spam please.Try to make portable
code...---------------------------------------------------------------------------
//Here is the code...
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
//Subroutine for generating oscillating values between 0 and 3
int sineGen(int cntr)
{
int k=cntr%7;
switch(k)
{
case 0:
case 6:
return 0;
case 1:
case 5:
return 1;
case 2:
case 4:
return 2;
case 3:
return 3;
}
}
//A cartition coordinate
struct Mpoints
{
int x;
int y;
};
//Draws and manages the man
class Man
{
Mpoints p[14];
int a,b;
int step0[14][2];
int step1[14][2];
int step2[14][2];
int step3[14][2];
int stepcntr;
public:
Man(int da,int db)
{
a=da; b=db;
step0[0][0]=0; step0[0][1]=0;
step0[1][0]=0; step0[1][1]=15;
step0[2][0]=0; step0[2][1]=30;
step0[3][0]=-15; step0[3][1]=55;
step0[4][0]=15; step0[4][1]=80;
step0[5][0]=-15; step0[5][1]=55;
step0[6][0]=15; step0[6][1]=80;
step0[7][0]=0; step0[7][1]=80;
step0[8][0]=15; step0[8][1]=115;
step0[9][0]=15; step0[9][1]=115;
step0[10][0]=-15; step0[10][1]=150;
step0[11][0]=-15; step0[11][1]=150;
step0[12][0]=0; step0[12][1]=150;
step0[13][0]=0; step0[13][1]=150;
step1[0][0]=0; step1[0][1]=0;
step1[1][0]=0; step1[1][1]=15;
step1[2][0]=0; step1[2][1]=30;
step1[3][0]=-10; step1[3][1]=57;
step1[4][0]=17; step1[4][1]=73;
step1[5][0]=-20; step1[5][1]=53;
step1[6][0]=10; step1[6][1]=76;
step1[7][0]=0; step1[7][1]=80;
step1[8][0]=10; step1[8][1]=115;
step1[9][0]=25; step1[9][1]=110;
step1[10][0]=-25; step1[10][1]=145;
step1[11][0]=-5; step1[11][1]=145;
step1[12][0]=-10; step1[12][1]=150;
step1[13][0]=10; step1[13][1]=148;
step2[0][0]=0; step2[0][1]=0;
step2[1][0]=0; step2[1][1]=15;
step2[2][0]=0; step2[2][1]=30;
step2[3][0]=5; step2[3][1]=55;
step2[4][0]=30; step2[4][1]=60;
step2[5][0]=-30; step2[5][1]=50;
step2[6][0]=-10; step2[6][1]=70;
step2[7][0]=0; step2[7][1]=80;
step2[8][0]=-2; step2[8][1]=115;
step2[9][0]=25; step2[9][1]=110;
step2[10][0]=-35; step2[10][1]=135;
step2[11][0]=-5; step2[11][1]=145;
step2[12][0]=-25; step2[12][1]=145;
step2[13][0]=10; step2[13][1]=148;
step3[0][0]=0; step3[0][1]=0;
step3[1][0]=0; step3[1][1]=15;
step3[2][0]=0; step3[2][1]=30;
step3[3][0]=10; step3[3][1]=55;
step3[4][0]=40; step3[4][1]=40;
step3[5][0]=-36; step3[5][1]=35;
step3[6][0]=-30; step3[6][1]=67;
step3[7][0]=0; step3[7][1]=80;
step3[8][0]=-10; step3[8][1]=110;
step3[9][0]=35; step3[9][1]=105;
step3[10][0]=-45; step3[10][1]=125;
step3[11][0]=15; step3[11][1]=135;
step3[12][0]=-38; step3[12][1]=135;
step3[13][0]=25; step3[13][1]=140;
stepcntr=1;
}
forMan(int at,int push)
{
if(a>=640)
a=-100;
else
a+=push;
int i=0;
switch(at)
{
case 0:
for(i=0;i<14;i++)
{
p[i].x=a+step0[i][0];
p[i].y=b+step0[i][1];
}
break;
case 1:
for(i=0;i<14;i++)
{
p[i].x=a+step1[i][0];
p[i].y=b+step1[i][1];
}
break;
case 2:
for(i=0;i<14;i++)
{
p[i].x=a+step2[i][0];
p[i].y=b+step2[i][1];
}
break;
case 3:
for(i=0;i<14;i++)
{
p[i].x=a+step3[i][0];
p[i].y=b+step3[i][1];
}
break;
default:break;
}
}
drawMan()
{
setcolor(15);
circle(p[0].x,p[0].y,15);
line(p[1].x,p[1].y,p[2].x,p[2].y);
line(p[2].x,p[2].y,p[3].x,p[3].y);
line(p[2].x,p[2].y,p[5].x,p[5].y);
line(p[2].x,p[2].y,p[7].x,p[7].y);
line(p[3].x,p[3].y,p[4].x,p[4].y);
line(p[5].x,p[5].y,p[6].x,p[6].y);
line(p[7].x,p[7].y,p[8].x,p[8].y);
line(p[7].x,p[7].y,p[9].x,p[9].y);
line(p[8].x,p[8].y,p[10].x,p[10].y);
line(p[9].x,p[9].y,p[11].x,p[11].y);
line(p[10].x,p[10].y,p[12].x,p[12].y);
line(p[11].x,p[11].y,p[13].x,p[13].y);
return 0;
}
eraseMan()
{
setcolor(0);
circle(p[0].x,p[0].y,15);
line(p[1].x,p[1].y,p[2].x,p[2].y);
line(p[2].x,p[2].y,p[3].x,p[3].y);
line(p[2].x,p[2].y,p[5].x,p[5].y);
line(p[2].x,p[2].y,p[7].x,p[7].y);
line(p[3].x,p[3].y,p[4].x,p[4].y);
line(p[5].x,p[5].y,p[6].x,p[6].y);
line(p[7].x,p[7].y,p[8].x,p[8].y);
line(p[7].x,p[7].y,p[9].x,p[9].y);
line(p[8].x,p[8].y,p[10].x,p[10].y);
line(p[9].x,p[9].y,p[11].x,p[11].y);
line(p[10].x,p[10].y,p[12].x,p[12].y);
line(p[11].x,p[11].y,p[13].x,p[13].y);
return 0;
}
};
//Draws and manages a RainDrop...!
class RainDrop
{
int x,y;
public:
RainDrop()
{
x=random(639);y=random(30);
}
drawDrop()
{
setcolor(15);
putpixel(x,y,15);
putpixel(x+1,y-1,7);
putpixel(x+2,y-2,8);
return 0;
}
eraseDrop()
{
putpixel(x,y,getbkcolor());
putpixel(x+1,y-1,getbkcolor());
putpixel(x+2,y-2,getbkcolor());
return 0;
}
stepDrop(int step)
{
eraseDrop();
if(x<=0) x=random(639);
else x-=step;
if(y>=400) y=0;
else y+=step;
drawDrop();
return 0;
}
};
//Add one more class that can draw & manage an umbrella...
int main()
{
int a=DETECT,b;
initgraph(&a,&b,"..\\bgi");
RainDrop Rain[1024];
Man M(-300,300);
int i=0,k=0;
getch();
do
{
Rain[i++].stepDrop(random(i%64));
i=i>=1023?0:i+1;
if(i%1000==0)
{
M.forMan(sineGen(k++),10);
M.drawMan();
for(int tt=0;tt<1000;tt++)
{ Rain[i++].stepDrop(random(i%64));
i=i>=1023?0:i+1;
}
M.eraseMan();
}
}
while(!kbhit());
return 0;
}
//TODO
//Do anything that seems to be good.
//Make a SDL diff of the program
---------------------------------------------------------------
Subin Sebastian
College Of Engineering, Munnar
+91-944-6475-826
"Support Free Software"
--~--~---------~--~----~------------~-------~--~----~
"Freedom is the only law".
"Freedom Unplugged"
http://www.ilug-tvm.org
You received this message because you are subscribed to the Google
Groups "ilug-tvm" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For details visit the website: www.ilug-tvm.org or the google group page:
http://groups.google.com/group/ilug-tvm?hl=en
-~----------~----~----~----~------~----~------~--~---