# Implementing powerups for my Breakout clone

I'm making a simple Breakout clone in Python that will have very many powerups/powerdowns (so far I came up with 26). Some will affect the paddle (paddle missile, two paddles, short paddle, etc.), some will affect the ball (slow ball, destructo-ball, invisible ball, etc.), some will affect the bricks (brick scramble, move up, bricks indestructible, etc.), and some will affect other game aspects (extra life, more points, less points, etc.). I'm pretty sure I have the code to draw the falling powerups and test for collisions with the paddle down, but I'm confused about how to code the effects of the powerups. Since there are very many powerups, it seemed inefficient to add specific methods to each component as done in this tutorial. However, I can't think of an other ways to implement the powerups. I found a page that hints at some way to design powerup behavior using classes, but I'm at a loss for how to do that. (A short example would help.) Please give me a short code example of another way to implement the effects of the powerups.

• possible duplicate of Implementing Power-Ups in a game – MichaelHouse Jun 19 '12 at 20:41
• The answer for that one seems to be to put modifiers in every class that is affected by the powerup. (The link to the other answer is broken :( ) That is the same solution as the tutorial I linked to. Is that the only way to do it? – Eva Jun 19 '12 at 21:09
• Eva, I've posted an answer that might help. It's my interpretation of the accepted answer on the question I linked. Additionally, I didn't have any problems with the link in the other answer. Perhaps try again? – MichaelHouse Jun 19 '12 at 21:50

I think this question should still be closed and I'm just using this space to better explain the answer found here. Sorry, I haven't used Python in years, and only used it a little bit so this answer is not Python oriented at all.

Paddle {

}

}


Then as an example powerup, you'd have something like:

PaddlePowerup implements Powerup {
PowerupType type
EffectType effect;

switch(effect) {
case PowerupType.GROW:
break;
case PowerupType.SHRINK:
break;
case PowerupType.INVISIBLE:
break;
...
}
}
public static void pickedUp(Ball targetBall) {
switch(effect) {
case PowerupType.INVISIBLE:
targetBall.setVisible(false);
break;
case PowerupType.SLOW:
targetBall.setSpeed(targetBall.getSpeed() * 0.5f);
break;
...
}
}
}


The other answer doesn't go into how to do different power ups for different objects, like the ball, bricks or global parameters.

public void triggerPickup(Powerup powerup) {
switch(powerup.type) {