Bubble game, day 3: Shoot ’em up

For the third day of this project, I worked mostly on getting a shooting mechanism to launch the next ball onto the board. This also meant I had to introduce simple physics into the game and re-created some the Bubble class in order to make it work. The game’s main Update function grew a lot here. Here’s the pseudocode for it:

// See if the current bubble is moving, then update as necessary.
if (currentBubble.IsMoving())
{
    UpdateBubblePosition();

    // Find picking/target spot with the updated position
    picked = PickClosestBubbleSpot(currentBubble);

    // Check if bubble collided based on target spot
    // If there's an empty spot in the first row, just add it in
    if (currentBubble.InTopRow())
    {
        AddBubbleToSpot(currentBubble, picked);
        FindTotalMatches(picked);
    }
    else
    {
        FindSurroundingBubbles(picked)
        foreach (neighbor)
        {
            // Check each neighbor for collision until it found one
            if (currentBubble.CollidedWith(currentBubble))
            {
                AddBubbleToSpot(currentBubble, picked);
                FindTotalMatches(picked);
            }
        }
    }
    // At this point, all color matches have been counted
}
else
{
    // Bubble is waiting to be launched
    if (MouseButtonPressed())
        LaunchBubble();
}
// Clear any bubbles if there have been at least 3 matched
UpdateBubblesToClear();

The bubble launcher is what I’ve been doing most of the day, though I didn’t spend much time working on the game. But I can say there were some bugs along the way, such as trying to position bubbles from an empty array (which caused the game to crash), and bubbles replacing existing bubbles in rows that start off being empty.

Not much else to show graphically, as it’s all still the same, so I won’t be posting screenshots. After fixing all those related bugs, I added an animation to make the bubbles drop after they have been matched. The dropped bubbles still have their original row and column location, but their actual position on the screen is updated. After they leave the screen, the bubble Type is cleared to 0 and the positions re-calculated.

Now, time to add a scoring system, and some standard rules to make the game more flexible.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s