Power Up Trouble

  • I have no idea why this is being so difficult. I am creating a breakout clone and I have the following problem.

    I am attempting to add a power up that adds multiple balls to the field. Sounds easy right? Well, one attempt failed, so I am trying the following method. I have a brick class to sort out the bricks. I have a ball class for the ball. I have a ball group and a brick group. I am using a method I have seen before to switch levels. When the bricks are dead, remove the ball and brick groups (plus other active things), then, create a new level and restore the brick and ball groups plus the other things.

    The bricks are loaded as entities through the Ogmo editor and get attributes from there as well via place entity. Since I can't get bool data, for some reason. The bricks have 2 key power up stats: isPower and pType. Then if either of those are greater then 0, it's a power up and behaves accordingly. So. I have a couple power up bricks waiting in the level loaded from the editor. When the ball hits them, 3 extra balls are to appear around the ball. Which they do, hooray! Okay, NOW we switch levels.

    And the power up bricks don't create extra balls. Or they, do, and they all center on the ball? Also, the bricks aren't really killed. They disappear, but remain as invisible bricks. I also have code that checks if all the balls are gone from hitting the bottom of the screen then the player loses a life and the level 'restarts'. That no longer works either. The balls disappear but there is no restart.

    This should NOT be difficult, but it is. What the devil am I doing wrong here?

    Here is the PlayState code:


  • First of all, don't put everything into your PlayState. Just don't! There's like hundreds of code lines in there. First thing you're gonna do is to organize your code into smaller files or classes like:

    • A class for collision detecting
    • A class for collision handling
    • A class for loading the level
    • A class for just containing the game objects
    • A class for powerups
    • A class for each of HUD/GUI elements or texts
    • A class for each of anything you could come up...

    The more you split them into smaller files, the easier you can work and debug. Imagine you're gonna add even more stuff and features into the game, your PlayState's gonna bloat up to thousands of lines of code. You can't work in that. No one can.

    Psst! For collision, use FlxSignal, also check it out in the Cheat Sheet. It's gonna save your life

    Duplicated code:

    if (entityName == "Brick1") Bricks.add(new Brick(x, y, eType,isPow,pCast));
    if (entityName == "Brick2") Bricks.add(new Brick(x, y, eType,isPow,pCast));
    if (entityName == "Brick3") Bricks.add(new Brick(x, y, eType,isPow,pCast));
    // ... until "Brick28"

    Why not:

    if (FlxStringUtil.contains(entityName, "Brick"))
        Bricks.add(new Brick(x, y, eType,isPow,pCast));

  • The only thing I really want is to get this multi ball power up to work across all levels.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.