1

Hi friends
I am a beginer in C. I want to make a simple program in which there
are two balls on the screen.
These two balls will Strike when the user presses any key ?
Please help me with full code snippets.

6
Contributors
7
Replies
16
Views
8 Years
Discussion Span
Last Post by pseudorandom21
1

Which Compiler are you using..?If Turbo C++..,You have to know little about the functions under graphics.h.

0

Actually this question has more to do with what OS(unless its, doubtfully, hardware specific).

Just use something like OpenGL or SDL, for graphics.

0

Dude,,, It's a little harder to understand the graphics functions..

For this you must have the knowledge of the functions defined in graphics.h,,,,,:|

2

What is with all the Turbo C++ references?!! That compiler is a non-standard relic from another millennial! It's useless!

Votes + Comments
Gotta keep banging the drum!
-1
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
int i=100,j=100,f1=1,f2=1,r=50,k;
l:
// printf("\n\nEnter the co-ordinate where from you want to start to move the circle : ");
// scanf("%d%d",&i,&j);
cleardevice();
// printf("\n\nEnter the redious : " );
// scanf("%d",&r);
// if(r<i||r<j) {printf("\nWrong entry, Try again.");goto l;}
cleardevice();
getch();
while(!kbhit())
{

setcolor(WHITE);
circle(i+1,j+1,r); // printf("%d, %d",i,j);
delay(2);
/* for(k=1;k<=10;k++)
{
setcolor(k);
circle(i+1,j+1,r-(k*r/10));
delay(1);
setcolor(BLACK);
circle(i+1,j+1,r-(k*r/10));
} */
setcolor(BLACK);

circle(i+1,j+1,r);
if(i<639-r&&f1==1)
{i++;f1=1;
}
else
{i--;
if(i==r) f1=1; else f1=-1;
}
if(j<480-r&&f2==1)
{j++;f2=1;}
else
{j--;
if(j==r) f2=1;else f2=-1;
}

}
}








Try this , Here is one single ball, read it try to upgrade into two balls
Votes + Comments
More unindented TurboC crap on the end of a thread that died long ago
0
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
int i=100,j=100,f1=1,f2=1,r=50,k;
l:
// printf("\n\nEnter the co-ordinate where from you want to start to move the circle : ");
// scanf("%d%d",&i,&j);
cleardevice();
// printf("\n\nEnter the redious : " );
// scanf("%d",&r);
// if(r<i||r<j) {printf("\nWrong entry, Try again.");goto l;}
cleardevice();
getch();
while(!kbhit())
{

setcolor(WHITE);
circle(i+1,j+1,r); // printf("%d, %d",i,j);
delay(2);
/* for(k=1;k<=10;k++)
{
setcolor(k);
circle(i+1,j+1,r-(k*r/10));
delay(1);
setcolor(BLACK);
circle(i+1,j+1,r-(k*r/10));
} */
setcolor(BLACK);

circle(i+1,j+1,r);
if(i<639-r&&f1==1)
{i++;f1=1;
}
else
{i--;
if(i==r) f1=1; else f1=-1;
}
if(j<480-r&&f2==1)
{j++;f2=1;}
else
{j--;
if(j==r) f2=1;else f2=-1;
}

}
}








Try this , Here is one single ball, read it try to upgrade into two balls

Don't use "void main()", there are two proper main function headers, and they are:

int main(int argc, char *argv[]) and int main()

Using "void main()" can cause problems, for a detailed explanation as to what kind of problems it can cause please consult google.


and for your information if you ever want to upgrade to a newer compiler, (like Visual Studio Express, or MinGW) the first thing you should try is using STANDARD C++ headers, like instead of "fstream.h" it should be #include <fstream>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.