Newsgroups: comp.os.msdos.djgpp From: mheumann AT hotbot DOT com (Manni Heumann) Subject: Re: Having problem with Allegro... need help. References: <74v3ck$rui$1 AT oak DOT prod DOT itd DOT earthlink DOT net> X-Newsreader: News Xpress 2.01 Date: Sun, 13 Dec 1998 11:46:45 GMT NNTP-Posting-Host: pppasc112.hrz.uni-bielefeld.de Message-ID: <3673a8f7.0@news.uni-bielefeld.de> X-Trace: 13 Dec 1998 12:45:59 +0200, pppasc112.hrz.uni-bielefeld.de Lines: 46 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article <74v3ck$rui$1 AT oak DOT prod DOT itd DOT earthlink DOT net>, "Philip Rama" wrote: >Can someone please take a look at this? I have some code that I'm going to >use for a simple "pong" game (my first game ever!!!) and wrote everything >from scratch. I'm trying to get a red circle to bounce off the sides of the >walls, but can't get it to work right. > >I wrote another function for a circle that you can move around with your >arrow keys, and I want to make it so that whenever it reaches the left side >and continues on... it'll go all the way to the right side. Like... >if (x == 0) > x == 639; >I did that with all the sides, but only the left and top sides work. I was >pretty much messing around with this one, but I never got it to work. > >Thx... >-Philip Rama > > Hi Philip! There are at least two obvious errors in your code: : 1. In the moving_circle function you calculate value = rand()%2; This makes value take the value 0 or 1. It will NEVER be 3. 2. In the movable_circle function you have a series of if statements. Just consider what will happen, when x==639 holds: you will set it to 0, which will cause the following if-statement to set it to 639 again. Also I would not use x==639, but x>638 because depending on the value of speed it might never take the value 639, but perhaps 640 and you couldn't trap that value. I suggest to place the x==? or better x>? statements within the if (key?) blocks. Hope I could help, ---------------------------------------------------------------------- Manni Heumann Bielefeld Spammer benutzen die reply-Adresse, alle anderen (hoffentlich) mheumann AT post DOT uni-bielefeld DOT de ----------------------------------------------------------------------