Mail Archives: djgpp/1998/12/13/08:05:45
In article <74v3ck$rui$1 AT oak DOT prod DOT itd DOT earthlink DOT net>, "Philip Rama" <philip18 AT earthlink DOT net> 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
----------------------------------------------------------------------
- Raw text -