# [offtopic] Bouncing Algorthims

> > I'd finish it sometime, but I'm concentrating on my Kaboom clone right > > now. Fi you have any ideas on how to simulate the Mad Bomber, I'm all > > ears. :) Are you talking about the pattern in which the Mad Bomber goes back and forth? It was kind of a random back and forth pattern wasn't it? What you can do is something like this... generate a random number [0..1] every turn. If it is below a certain probability, say .15, the bomber reverses direction. If it reaches the sides of the screen, it also changes direction. It higher levels, the probability is decreased, making it more unpredictable.

damn, i wrote a big response to this also, and it didn’t go through for
some reason. I know I saved it, don’t know what happend though. anyways,
check out qdu netpong… it does what your asking for i think… you can
get it at www.addell.comOn Mon, 1 Nov 1999 craig at ic.net wrote:

Michael Fletcher wrote:

I need to know how to determin what side of the object I hit it at so I
know if I should change the sign of the deltax or the deltay.

My mail program killed off my nice response to this… so here’s the
abridged version…

I wrote a similar type game in clanlib. If you’d like to, I can make the
source available. In brief, I made it so the ball had four "hot spots"
at the 12, 3, 6, and 9 o’clock areas. If the ball was travelling at -1
units (up the screen) and hit something at the 12 o’clock target, I’d
reverse that so the ball would now travel down at 1 unit.

Let me know if you’ure interested in my code. It’s GPL’ed, but I enver
got it much beyond the demo phase, and you’re more than welcome to
whatever you want from it.

I’d finish it sometime, but I’m concentrating on my Kaboom clone right
now. Fi you have any ideas on how to simulate the Mad Bomber, I’m all
ears.

## Craig Maloney (craig at ic.net) http://ic.net/~craig Fortune for today: You are wise, witty, and wonderful, but you spend too much time reading this sort of trash.

Sorry if this is offtopic but I am having trouble finding the answer to
my question. I big plus is if you could point me to the answers to
these kind of questions.

I am writing a breakout style game with SDL.

I need to know how to determin what side of the object I hit it at so I
know if I should change the sign of the deltax or the deltay.

Thankyou.

Michael Fletcher

Michael Fletcher wrote:

I need to know how to determin what side of the object I hit it at so I
know if I should change the sign of the deltax or the deltay.

My mail program killed off my nice response to this… so here’s the
abridged version…

I wrote a similar type game in clanlib. If you’d like to, I can make the
source available. In brief, I made it so the ball had four "hot spots"
at the 12, 3, 6, and 9 o’clock areas. If the ball was travelling at -1
units (up the screen) and hit something at the 12 o’clock target, I’d
reverse that so the ball would now travel down at 1 unit.

Let me know if you’ure interested in my code. It’s GPL’ed, but I enver
got it much beyond the demo phase, and you’re more than welcome to
whatever you want from it.

I’d finish it sometime, but I’m concentrating on my Kaboom clone right
now. Fi you have any ideas on how to simulate the Mad Bomber, I’m all
ears.

## Craig Maloney (@Craig_Maloney) http://ic.net/~craig Fortune for today: You are wise, witty, and wonderful, but you spend too much time reading this sort of trash.

craig at ic.net wrote:

My mail program killed off my nice response to this… so here’s the
abridged version…

I wrote a similar type game in clanlib. If you’d like to, I can make the
source available. In brief, I made it so the ball had four "hot spots"
at the 12, 3, 6, and 9 o’clock areas. If the ball was travelling at -1
units (up the screen) and hit something at the 12 o’clock target, I’d
reverse that so the ball would now travel down at 1 unit.

Let me know if you’ure interested in my code. It’s GPL’ed, but I enver
got it much beyond the demo phase, and you’re more than welcome to
whatever you want from it.
I’d appreciate that very much thankyou.

I’d finish it sometime, but I’m concentrating on my Kaboom clone right
now. Fi you have any ideas on how to simulate the Mad Bomber, I’m all
ears.
Hey I would if I knew the game. Sorry man.—
Fight Club Rules! Fight club rules!!

Contrary to what your mothers and teachers tell you, you are not a
beautiful
and unique snowflake. You are the same decaying organic matter as
everything
else. We are all a part of the same compost heap.
– Tyler Durden

Michael Fletcher wrote:

Sorry if this is offtopic but I am having trouble finding the answer to
my question. I big plus is if you could point me to the answers to
these kind of questions.

I am writing a breakout style game with SDL.

I need to know how to determin what side of the object I hit it at so I
know if I should change the sign of the deltax or the deltay.

## This is called “collision detection” and is extremely important in all arcade games. How do you even figure out in your program whether you hit a block or something? Once, by means of some collision detection algorithm, you figure out which block was hit, you can easily determine where it was hit by looking at where your ball was before it hit the block. I don’t think that should be too difficult to program.–

| Rafael R. Sevilla @Rafael_R_Sevilla |
| Instrumentation, Robotics, and Control Laboratory |

College of Engineering, University of the Philippines, Diliman

Michael Fletcher wrote:

Sorry if this is offtopic but I am having trouble finding the answer to
my question. I big plus is if you could point me to the answers to
these kind of questions.
With this sort of thing you should just sit and think about it. The

I am writing a breakout style game with SDL.
Okay.

I need to know how to determin what side of the object I hit it at so I
know if I should change the sign of the deltax or the deltay.
1st of all you should be using velocityX and velocityY ( I assume deltaX
is pels/frame, you should be using pels/second). To answer your
question I need more information like how you are storing the data
regarding which bricks currently exist. I think you just need a couple
of nested if statements and an equation to model the intersection of the
ball with the edge of the block. This is pretty much just algebra. If
you want a more specific answer, send me the code that stores the
current game state.

Stuart–
This signature has been infected by the signature virus.

craig at ic.net wrote:

I’d finish it sometime, but I’m concentrating on my Kaboom clone right
now. Fi you have any ideas on how to simulate the Mad Bomber, I’m all
ears.

:-)–
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

@Craig_Maloney wrote:

I’d finish it sometime, but I’m concentrating on my Kaboom clone right
now. Fi you have any ideas on how to simulate the Mad Bomber, I’m all
ears.

``````    -Sam Lantinga, Lead Programmer, Loki Entertainment Software
``````

Awww MAN. It would figure someone else did it before me. Ahhh well…
Now I have a yardstick to make mine BETTER.

## Craig Maloney (@Craig_Maloney) http://ic.net/~craig Fortune for today: You are wise, witty, and wonderful, but you spend too much time reading this sort of trash.

Prasanth Kumar wrote:

> > I'd finish it sometime, but I'm concentrating on my Kaboom clone right > > now. Fi you have any ideas on how to simulate the Mad Bomber, I'm all > > ears. :) Are you talking about the pattern in which the Mad Bomber goes back and forth? It was kind of a random back and forth pattern wasn't it? What you can do is something like this... generate a random number [0..1] every turn. If it is below a certain probability, say .15, the bomber reverses direction. If it reaches the sides of the screen, it also changes direction. It higher levels, the probability is decreased, making it more unpredictable.

You want the wander steering behaviour in one dimension.

http://www.red.com/cwr/steer/Wander.html--
Marc Lepage
Software Developer
Molecular Mining Corporation
http://www.molecularmining.com/

Craig Maloney wrote:

Awww MAN. It would figure someone else did it before me. Ahhh well…
Now I have a yardstick to make mine BETTER.

Thanks for showing me this SAM… :l

Well, upon further inspection, I’d have to take a few yardsticks (i.e.
Football field) to make mine even half as good as Mad Bomber. Great job,
guys!

## Craig Maloney (@Craig_Maloney) http://ic.net/~craig Fortune for today: You are wise, witty, and wonderful, but you spend too much time reading this sort of trash.

Stuart Anderson wrote:

1st of all you should be using velocityX and velocityY ( I assume deltaX
is pels/frame, you should be using pels/second). To answer your
question I need more information like how you are storing the data
regarding which bricks currently exist. I think you just need a couple
of nested if statements and an equation to model the intersection of the
ball with the edge of the block. This is pretty much just algebra. If
you want a more specific answer, send me the code that stores the
current game state.
I was leaving the pels/second instead of pels/frame for later because
this
game is going to be multiplayer and not be specific to a certain
resolution. I would like to get some of the game working now.

I am not sure about the Algebra involved? Could you explain it to me

This is how I remember it and I have omitted everything I thought was
unnecessary. The rest is at
http://zidj.dyndns.org/~zidj/mpong-0.1.5.tar.gz

class Object {
static Object *first;
Object *next;
int x,y,dx,dy;

``````int collide(Object *o) {
if ( (y >= (o->y + o->surface->h)) ||
(x >= (o->x + o->surface->w)) ||
(o->y >= (y+surface->h)) ||
(o->x >= (x+surface->w))
) return false;
return true;
}

virtual void think();
``````

}

class MoveableObject : public Object {
void move() {
x = x + deltax;
y = y + deltay;
}
}

class BallObject : public MoveableObject {
void think();
}

void BallObject::think() {
// Check for collisions with all objects.
for(Object *o = Object::getFirst(); o; o = o->getNext()) {
move(); // Move the ball around
// Do collisions
if(collide(o)) {
// How to move the ball???
}
}
}