# How do I implement Breakout's “multiball” powerup?

I'm just starting out and making a breakout clone as my first game. I'm implementing all kinds of powerups, but I'm stuck on multiball. The powerup adds additional bouncing balls to the game.

So far, I've implemented powerups by just adding them to the Ball class as states. This is easy for increasing speed, making the ball sticky, changing sprites and such. When the ball is in one state it behaves in only one way.

Now, how do multiple balls fit into this? I suppose having more balls is more of a function of the game itself than the Ball, so it seems logical to make it a game state instead of a ball state. How would I do this?

• Hey, welcome to GD:SE. Glad to have you on board. This could be very open ended as a question and we try to make questions as specific to a problem as possible so others can benefit when searching later. Have you actually tried anything yet? If you have edit the question to let us know, we might be able to help you more. – Tom 'Blue' Piddock Feb 24 '14 at 9:34

I think you are stuck on trying to implement utterly dissimilar powerups using a unified system. That seems like a mistake, and it might become obvious if you thought about the idea of multiple balls outside the context of a power-up: multiple balls are simply more instances of a Ball object.

Handling multiple balls in code would not require a "gamestate", and it would not conflict with or complicate your existing "ballstate" logic. There are just more objects in play.

The only difficulty in this method is that you might need to change your update and draw logic slightly. If you have built your code around a single, global Ball instance, a good first step would be refactoring to make that code operate on a method argument. For example:

/*  the old
Ball globalBall;
void Update() {
globalBall.Move();
globalBall.Collide();
}
*/

// the new
List<Ball> allBalls;

// this old code is useful for a single ball; leave it mostly intact.
void UpdateBall(Ball ball) {
ball.Move();
ball.Collide();
}

// new code to deal with multiple Ball objects
void Update(){
foreach (ball in allBalls){
UpdateBall(ball);
}
}


The gist of it is, don't force your previous solution onto this new concept. Although sticky- and multi- might both be triggered by powerups, they are very different concepts. It's ok to create independent code paths to accomplish different game features.