Hello to one & all, I did a little bit of programming this weekend (I got myself a new Xbox 360!) .... but not satisfied with the Gaming monolith, I decided to do some game programming myself. So, I implemented that very famous game played by everyone who had access to a computer in the early 90's .... And the result is here .... Now, its no big deal as its already a standardized game which has been done & played & now occupies a place only in computer museums :D , but nonetheless here it is .... its still incomplete in some ways - User Interfaces need to be strengthened & more options need to be provided, but the basic math & functionality is all there .... Am currently working on a Object Oriented Version of this in C++ with more options.

Hope you enjoy this!

HAPPY CODING!

CODE for a Ball Bouncing off the boundaries of the Screen in Graphics Mode (Non-OOP)

Code: C

/* Program to Produce a continuously moving ball, which bounces on striking a wall */

int keyhit(void){int i;char uch,tempch;if(kbhit()){ uch=getch();switch(uch){case't':case'T':// The TERMINATE (T) Key was hit - so Returning TruereturnTRUE;case'w':case'W':// The UP-Direction Key for Player I has been pressed// Testing Whether Player Bar goes out of window with such a moveif(P1.bar[1]-BARYCH<0){ sound(HFSND); nosound();}else{for(i=1;i<BARSIZE;i+=2) P1.bar[i]-=BARYCH;}returnFALSE;case's':case'S':// The DOWN-Direction Key for Player I has been pressed// Testing Whether Player Bar goes out of window with such a moveif(P1.bar[3]+BARYCH>MAXY){ sound(HFSND); nosound();}else{for(i=1;i<BARSIZE;i+=2) P1.bar[i]+=BARYCH;}returnFALSE;case'p':case'P':// The UP-Direction Key for Player II has been pressed// Testing Whether Player Bar goes out of window with such a moveif(P2.bar[1]-BARYCH<0){ sound(HFSND); nosound();}else{for(i=1;i<BARSIZE;i+=2) P2.bar[i]-=BARYCH;}returnFALSE;case'l':case'L':// The DOWN-Direction Key for Player II has been pressed// Testing Whether Player Bar goes out of window with such a moveif(P2.bar[3]+BARYCH>MAXY){ sound(HFSND); nosound();}else{for(i=1;i<BARSIZE;i+=2) P2.bar[i]+=BARYCH;}returnFALSE;

Hey thanks a lot Shabbir! .... Its really not that big a deal, as this has been a standardized & done game from sometime in the early 90's .... but as I told you, it was pure love for logic & programming that drives me & no doubt even you & others to give it a try!

NJOY CODING!

Regards,
Rajiv

PS: Any Queries about any code-segment that is not clear (sorry I didnt comment extensively on this one as I usually do) are welcome

tailhook123

2Jun2007 03:20

Re: Basic 2D Tennis in BGI

Quote:

Originally Posted by rai_gandalf

Hey thanks a lot Shabbir! .... Its really not that big a deal, as this has been a standardized & done game from sometime in the early 90's .... but as I told you, it was pure love for logic & programming that drives me & no doubt even you & others to give it a try!

NJOY CODING!

Regards,
Rajiv

PS: Any Queries about any code-segment that is not clear (sorry I didnt comment extensively on this one as I usually do) are welcome

Hey Tailhook,
Thanks for the link .... I didnt know the name of the game, but just knew that it was & still is a heck of a game .... and anyways, when I set out to code, I was plannin to code Tennis along with the court markings & stuff, but halfway I decided to revert to this "PONG" as the world calls it .... thx 4 the link - made an interesting read - especially Roddick playing Pong .... So, Pong it is .... will rename the thread if I can.

NJOY CODING

Regards,
Rajiv

PS: To use Shakespeare's quotation slightly distorted to suit the situation : "A Game by any other name would be just as enjoyable" :D

keith12125

4Jul2007 15:46

Re: Basic Pong in BGI

ok... I know I'm doing something wrong. I am using Visual C++ to compile this and I don't have a graphics.h file. Do i need to download it?

shabbir

4Jul2007 16:40

Re: Basic Pong in BGI

MS VC compiler does not support BGI graphics and so it does not have the graphics.h file.

You need to use the old days Turbo C++ 3.0 compiler for the BGI graphics program to compile