Archive for the ‘Breaking Block’ Category

Aug 8

Laser Frenzy EndA friend and I were discussing recently some of the special physics requirements of block breaker / Breakout / Arkanoid style games. When I put together the physics for Breaking Block, I already had a pretty strong idea of how I wanted the physics to work, though I noticed that the internet had mostly half-answers. I found that many people were asking about Breakout-style physics. Since complete information is so scarce, I’d like to share some lessons that I’ve learned while developing the physics for Breaking Block.

Be Wary of Using Physics Engines for Such a Simple Case

Physics engines are by their nature generalized, and a block breaker game, when implemented properly, has some very specific physics rules. The generalized rules of engines get in the way. Beyond the obvious things like needing to disable gravity and ensuring preservation of kinetic energy, sometimes, no matter what you do, an object takes a weird bounce in an engine-based rigidbody collision, and the angle of deflection is nowhere near acceptable (i.e. ball bounces off corner of block and travels horizontally, killing the game).
You can try to hack around this stuff all you want. At the end of the day, though, just applying movement in script using angle and velocity is cleaner, more performant, and more correct for this case. Using a physics engine for a basic block breaking game is the proverbial “Shooting a fly with an elephant gun”. Consider that the physics rules for the original arcade Breakout weren’t even implemented in a computer program at all; the rules were hard-wired into logic circuits.

Simple Ball Reflection for blocks

Handling deflections off of blocks and walls is trivial if you keep track of your ball’s angle as a direction vector, and keep your blocks orthogonal. On a vertical hit, just invert the y component of the direction vector, and on a horizontal hit, invert the x component. One common question is how to tell whether a hit is vertical or horizontal. You could inspect the collision details and look at surface normals, but with orthogonal blocks, that’s a bit more complex than what is needed. Just take the difference in position (delta) between the ball and block, scale it by the inverse aspect ratio of the block (for example, if the block is twice as long as it is high, divide the x component of the delta by 2), and see which component of the delta is smaller. A smaller y means a vertical hit, and a smaller x means a horizontal hit.
Here’s an example, with an additional Sign check added to make sure the ball is traveling toward the block. That check prevents the ball from destroying two adjacent blocks simultaneously.

var delta = (ball.transform.position - block.transform.position);
// apply aspect ratio via the scaleFactor vector
// For a horizontal block twice a wide as high, use Vector3(0.5f, 1f, 1f)
// For a vertical block twice as high as wide, use Vector3(1f, 0.5f, 1f)
// For a square block, use Vector3(1f, 1f, 1f), and so forth.
if(Mathf.Abs(delta.x) >= Mathf.Abs(delta.y))
    // scaled delta x was larger than delta y. This is a horizontal hit.
    if(Mathf.Sign(-direction.x) == Mathf.Sign(delta.x))
        ballDirection.x = -ballDirection.x;
    // scaled delta y was larger than delta x. This is a vertical hit.
    if(Mathf.Sign(-direction.y) == Mathf.Sign(delta.y))
        ballDirection.y = -ballDirection.y;

Keep the Ball In-Bounds, No Matter What

Don’t rely on colliders and other softer barriers to keep the ball in-bounds. For instance, a ball might get stuck between a moving block and a wall and pop through. Things get chaotic. Include a hard bounds check, and reflect the ball in the appropriate direction if it leaves the bounds of play.

if((direction.x > 0f && transform.position.x > fieldMinimumX) ||
    (direction.x < 0f && transform.position.x < fieldMaximumX))
    direction.x = -direction.x;

if(direction.y > 0f && transform.position.y > fieldMaximumY + 0.1f)
    direction.y = -direction.y;

Let the Paddle Control the Ball Angle

It is very common for the contact position between the ball and the paddle to govern the angle the ball will take. This is very easy to do using the horizontal difference in position between the ball and the angle. Remember to take into account any change in paddle size if your game allows it. More about that ClampBallAngle() function in a moment.

var newAngle = (
        -(ball.transform.position.x - paddle.transform.position.x) * 60f / enlargeScale
    ) + 90f;
newAngle = ClampBallAngle(newAngle);

Prevent Degenerate Angles

In every FUN block breaking game I’ve played, I’ve never seen the ball travel at an angle that was close to horizontal or close to vertical. Horizontal angles are not fun because inevitably the player winds up waiting for the ball to trolley-car endlessly between the two walls. Vertical angles are not fun because they make it too easy to aim shots and volley balls with minimal effort. Steps need to be taken to prevent the ball from taking one of these angles.
If you are only using reflections to modify the angle everywhere else, then this only needs to be done when the ball is launched or collides with the paddle. This function is written with that in mind, a more general solution would be needed if the angle needs to be fixed in other situations. Note that in this case, it is much more convenient to express the ball angle as an actual angle rather than a direction vector.

private float ClampBallAngle(float angle)
    if(angle > 150f)
        return 150f;
    if(angle < 30f)
        return 30f;
    if(angle <= 90f && angle > 75f)
        return 75f;
    if(angle >= 90f && angle < 105f)
        return 105f;
    return angle;

Make Sure Your Collisions Happen

One drawback to not using a physics engine for movement is that you lose the engine's ability to do some of the more dynamic collision detection for cases where an object completely passes through another between updates. There are several ways to compensate for this:

  • Use a shorter update loop, and make sure it is a loop with a guaranteed time interval. In Unity I am using FixedUpdate for the really important physics, and have the fixed update rate set at 100fps.
  • Limit your top speeds. Do the math to ensure that an object at its top speed cannot move more than 25% (arbitrary number, adjust as necessary) of the way through another object in a single update frame.
  • Use raycasting. Cast a ray from an object's previous position to its current position to see if it passed through anything. I did not wind up having to take this approach with Breaking Block, but it is viable and I have used it in past games. Unity actually has a very handy SphereCast() function that is like a raycast, but accounts for an object's radius.

Track Dead-Object State to Prevent Incorrect Simultaneous Collisions

This is critical to things like multi-ball play, laser power ups, anything that makes it so that a block can be hit by two separate objects in the same frame. It may not apply to all engines, but in Unity at least, when you request that an object be destroyed, the actual destruction is deferred until the end of the update loop. This causes a situation where a block can be scored as destroyed twice, by two different balls, by a ball and a laser, by a ball and an alien, etc.
To prevent this, the first collision should set a death flag on the block. The collision code should check this flag, and take no action if the block is already dead.

In Conclusion

Hopefully these tips will help you in your quest to build a block breaker game. A block breaker game is a good exercise for any aspiring game developer, with a strongly-defined problem, limited scope, and lots of room for creativity.

Jul 28

Title Screen Breaking Block continues to have strong daily download and engagement numbers. Between both platforms, Breaking Block has been downloaded over 2,500 times, and currently has a 7-day average daily user count of 485. iOS downloads still lead the pack, with Android showing some strengthening over the weekend thanks to a very brief and very interesting ad campaign.

I honestly thought things would have started petering out after the ad campaign ended, but to my pleasant surprise, downloads have started to pick up again, with yesterday being my strongest day since the iOS launch. I’m not sure how much longer the downloading will continue at this pace, so I will enjoy it while I can.

Thank you again to everyone who has downloaded and everyone who continues to play Breaking Block. Please remember to rate the game on your respective platforms!

Planet Level Compared to any of my other game releases, the Breaking Block Appstore release has been amazing.

I had received Appstore approval late Monday night. I got up early the next morning, before any activity had been reported. I had cleared my schedule so that I could spend the day marketing the release for both platforms.

Chartboost usually has the most-frequently updated statistics, so I was using that to monitor the progress throughout the day. The updates started coming in at roughly an hourly rate: 10, 20, 40, 70, 175 – the faster the number grew, the more excited I got. By the time it hit 20, it was already a record for one-day downloads. All prior records quickly became meaningless.

The number was still climbing by the hundreds when I went to bed. Yesterday, I found out that the final, official total for the first day was 980. Nearly a thousand, on Breaking Block’s first day on the Appstore. I think the main factor that fueled this quick rise was Breaking Block’s appearance in the Free list directly on the front page of the Arcade Games section of the iTunes store. It looks to me like all game releases hit this list, but only the newest releases closest to the beginning of the alphabet each day are shown on the front page, as far as I’ve observed. Should this be the case? I’d think it would be better to randomize the front page choices for egalitarian exposure. At any rate, I’m grateful for the exposure I received.

Yesterday, Breaking Block moved into the second day section of the Free list, and predictably, activity slowed considerably. It is still far above the level of traffic I am accustomed to, though. It does not seem that the Apple numbers are official yet, but there were at least 300 new downloads yesterday. Apple’s official numbers for yesterday show an additional 452 downloads. Many players also returned for a second day, according to Chartboost’s “Uniques” metric, which measured that the number of unique devices that ran the game yesterday was far greater than the number of new installs.

Reviews on both Appstore and Google Play have been positive for the most part, with the only actionable negative feedback so far being over my choice of tilt-only controls. If demand from interested players warrants it, I will add a different control scheme, though telling me I’ve already lost you as a customer is not a real motivator for me to do so =P.

I’m not sure where things will go from here. No matter what happens, this is a release I can be proud of, with nearly 1,300 downloads in 2 days. Thank you to everyone who has downloaded, played, and rated the game. I hope you enjoy it for many weeks and months to come!


posted by Duke
Jul 22

Laser Frenzy End The iOS launch of Breaking Block is going better than I had dared to hope. Already today, Breaking Block has been installed 376 times according to my Chartboost stats, and the night is still young. I’m absolutely ecstatic!

Breaking Block has now surpassed Vintage Pachinko in total downloads to become king of the Smiling Cat stable of games, with 523 installs across both platforms.

And it is not showing any sign of slowing down – Chartboost’s numbers are slow to update, and there is a bit of ad revenue unaccounted for in the current numbers that suggests these numbers will continue to climb through the evening.

I won’t know until tomorrow how I’m doing with in-app purchases, since that’s when the official numbers from today should come down from Apple.

Pyramid Level Breaking Block is finally available on the Appstore for iOS. Yes, the game that seemed somehow minorly hexed against the Appstore approval process has been thoroughly dehexed and is now in its proper place, thank you very much (three rejections vs. one legitimate yet obscure issue, fixed, with a successful appeal of the third rejection on the 24th day of the process).

On the Android side, Breaking Block keeps doing better and better. With very little post-release marketing, it still is drawing a steady number of downloads per day, and daily game activity keeps increasing. Breaking Block has already surpassed Prepare for Warp in total downloads, and at this rate, it will soon surpass Vintage Pachinko in downloads. Now that the iOS version is out, I am kicking off my post-release marketing campaign for Breaking Block on both platforms starting today.

One thing I could use on both platforms is more ratings. So far, there have been only 7 ratings for 140 downloads. If you already have the game, please take a moment to rate it so that the game continues to receive more exposure. Yes, I know it forces you to join Google+, and that really sucks. Maybe you can find a creative use for the unwanted Google+ account. ¯\_(ツ)_/¯

It’s ironic that what is admittedly my least original mobile game in terms of gameplay is turning out to be my most popular downloaded game so far. I won’t be abandoning my long-term plans to develop original games anytime soon. Knowing it is possible to do a successful iteration of a classic is just another weapon in my arsenal.

City LevelThe good news: Breaking Block has already surpassed the 100 download mark on the Android side, making it my fastest moving mobile launch yet. I’ve not even started marketing in earnest yet since I am still waiting on the iOS launch.

The bad news: Apple found a bug during their review of Breaking Block, forcing another round of submit-and-wait. The bug prevented in-app purchases, but only if you have zero blocks, which is why it was not caught during my testing. It makes sense that in their testing they would make a beeline for the IAP before earning any blocks. The latest binary is in review now, so hopefully on Monday it will be approved.

Lesson learned: If I want to do simultaneous mobile launches in the future, I can’t use my past experience of getting Vintage Pachinko and Prepare for Warp through the approval process the first time as a guide on lead-time. I need to be leaving at least 3 weeks.

Classic Gameplay I just flipped the switch to make Breaking Block live on the Google Play store. It will take a few hours for it to appear in the Google Play Store, so it should be available for download in the wee hours of the US morning.

Unfortunately, it looks like the iOS version is slightly delayed. It seems I did not get my package submitted to Apple in time to get approved for tomorrow’s release. Next time I will try to get that timing better. There is still a chance that it may get turned around tomorrow. I am not counting on it due to the upcoming holiday weekend, so I am stating my mia culpa’s now. Likely it will be approved Monday or Tuesday of next week (7/7 or 7/8).

I hope everyone enjoys my newest game, whether you get to download it tomorrow or early next week.

Breaking Block is RTM

posted by Duke
Jun 28

Planet Level Today I put the last of the finishing touches on Breaking Block, ensured one last time that everything is in good working order on both platforms, and submitted to the Appstore for approval. I’m actually a couple of days late with this, so I’m hoping that since this is my third Appstore game, the approval process will be quick. The Android side of things is all ready to go.

Now, I am at a crossroads. There are several viable projects that I could choose take up next. I still have more ideas for mobile games, however, Steam has also caught my attention and I have a couple of game ideas that would work really well there. Whichever way I go, I’d like to have something to show in time for OGDE in October.

Here is my short list of potential projects, in no particular order:

  • A 2.5D, tiled 3rd-person puzzle game for mobile platforms
  • A vocabulary/word puzzle game for mobile platforms
  • A tycoon-style sim/builder for Steam/PC (including Steam Early Access)
  • Dungeon’s Fortune – An episodic JRPG for Steam/PC with procedurally generated dungeons
  • Dehoarder 2 – First person decluttering mayhem (Yes, I’ve noticed that y’all are still talking about the original game!)

As you can see, this is enough work to keep me busy for at least the next 3 years. If you have any thoughts as to which project I should work on next, please let me know! I’ll be deciding in the next couple of weeks.

Jun 24

Boss Fight Just now, I finished my “100% completion” test, where I played Breaking Block all the way through to full completion with no cheats, with all coins collected, all achievements attained, and all upgrades owned. There were lots of interesting moments. A lot of strategizing on powerup payloads was done, which showed that the meta-gameplay had emerged well. Another interesting property is that the star score calculation causes levels that are heavy with multihit blocks to be some of the hardest to achieve 3-star scores on. The best moment, though, came when earning the final coin needed for 100% completion. The coin in question needed to be earned by defeating the final boss using 3 or fewer balls.

When I set out to design the final boss encounter, I wanted it to be the most exciting five minutes of block-breaking gameplay ever. The battle is set out over 3 phases, with each phase presenting its own challenges. On average I can do EACH PHASE in 2 or 3 balls, so I know I had my work cut out for me. After several failed attempts last evening, I tried again early this morning.

The run started out on the wrong foot. I botched triggering one of my powerups, totally my fault in mis-aiming. I faced an uphill battle from there. Slowly, I began to make up for the lost powerup. The balls kept going faster, faster, and I just stayed with it. After a couple of minutes, I cleared the first phase, and moved on to phase two.

A lucky powerup drop had put me in perfect position to deal with phase two. Another perfectly deployed powerup, and I had put myself in good position for the attack. I just had to be fast, precise, and methodical. At some point in this phase, I lost my first ball. Two more to work with, I said to myself, but it was at this time I became aware that my hands were starting to shake with excitement. I managed to pull myself together and finished off phase two.

I had reserved one of my powerups for phase three, and again, I deployed it perfectly, exposing my target to attack. The ball’s speed had maxed out by now, and I just kept relentlessly attacking, attacking, attacking. And then, just when I thought I was going to lose it, the screen lit up with explosions, and I had done it. It took all of my restraint not to shout in excitement in the early, quiet six o’clock hour.

As the level completion screen tallied my earnings and achievements, I looked at the level time. 5:12. I smiled and laughed to myself, because I knew that that was definitely the most exciting five minutes of block-breaking gameplay I had ever experienced.

Jun 16

Gameplay highlights for my new mobile game Breaking Block – Combos, Powerups, Boss Battles, and more awesomeness!