Creation of a Flash Stabilize! clone using Box2D – part 3

Here we are with the 3rd step.

Read steps 1 and 2, then continue with this post.

One thing I missed in Stabilize! was the “next” feature, something showing the block we are going do drop after the current one.

The first time I saw this feature was in Tetris… now try to imagine yourself playing Tetris without the “next” piece displayed somewhere on the screen. What a lack of strategy!!

So we are going to introduce the “next” feature in this game.

In order to do this, we must have different crates. So now each crate has a random color (from 1 to 5) and a random weight (from 1 to 9).

The principle of this feature is to randomly generate both the current and the next crate when we start the game, and give the player the current one.

When the player drops the current crate, give him the previously generated “next” one and randomly generate the next “next” one, that will be given to the player once he drops the old “next” one, and so on.

So here it is the commented script:

And this is the result:

The “next” crate is the one under the bar. Download the source code

Next time, we’ll see how to remove crates when three or more of them have the same color and collide