Create a Flash game like Rebuild Chile

You have three reasons to play Rebuild Chile:

1) It’s a good puzzle game

2) You will help the children from Chile affected by the earthquake/tsunami because all income will be donated to rebuild Chile

3) You are going to know how to create a game like it

The game is a Sokoban-like game, with fixed and movable items. So, you must be able to create a working prototype in a day. With your bulldozer, you can only push movable items, and only if they aren’t blocked by other movable items, and must push them out of the stage.

In this first part, we’ll cover map creation and basic player movement.

I am going to replicate level three. Here it is:

Since it’s a tile based game, it’s easy to build a level once you determine every tile’s content.

Each tile is represented by an unique coordinate.

In my case, 0 means the tile is empty, 1 means there is an unmovable item (a tree) and 2 means there is a movable item (a boulder).

And with a simple array you can build the entire map.

The bulldozer isn’t part of the map but it’s added later. As a general rule, the player and moving enemies shouldn’t be part of the map.

Here it is the script:

Let’s see the main functions:

draw_map: phyisically draws the level, placing movieclips in proper positions according to map array. In this case, tile size is 50×50.

place_bulldozer: places the bulldozer in the level

on_key_down and on_key_up manage in the simplest way possible player’s keyboard input. The first one just stores the last key pressed, and the second one resets last key pressed value if the player releases it.

on_enter_frame just checks if the player is pressing an arrow key, and moves the bulldozer in that way, if there is room to move (map value is equal to zero) and if it won’t leave the 9×9 grid.

And that’s it…

Use arrow keys to move the bulldozer.

This is just the beginning… the bulldozer cannot move the debris and there is no place to discard them. But we’ll see how to do it during next step.

Download the source code

** edit **: if you liked the game, consider visiting the official site

  • Hi Emmanuel, thanks for you review, I’m one of the creators of the game.

    Please spread the word, we need help to solve our children trauma.

    I sent you the URL of the main site.

    Best Regards.

  • I have spread the game.

    http://chafanhou.com/?q=rebuild-chile

    God bless the children.

  • I added the game as soon as it came out to helpout.

    http://www.thepixelcastle.com/Arcade/101543/Rebuild-Chile.html

  • Ryan

    Just a suggestion, maybe have a way so the bulldozer doesn’t move so quickly? I don’t know if you plan to do so later, but it’s a little irritating.

    But good code otherwise.

  • Emanuele Feronato

    Sure Ryan, it’s planned

  • Pingback: Emanuele Feronato - italian geek and PROgrammer()

  • Pingback: Create a Flash game like Talesworth Adventure - Emanuele Feronato()

  • Wouter

    hey Emanuele,

    Thanks for this great tutorial,

    but I am confused about one thing:

    the bulldozer pos is [6,2] which I thought would be x:6 and y:2 but it appears to be the other way around. Do you have a specific reason to do this?

    Wouter

    • Emanuele Feronato

      Hello Wouter,

      If you look at the second picture, the one with the map, you will notice the first row is (0,0),(0,1),(0,2) and so on, the second row is (1,0),(1,1),(1,2)…

      So (6,2) means 6th row, 2nd column

  • Wouter

    oops….

    that’s not so smart of me…

    thanx for your answer!

    Wouter

  • Alexandre Colella

    Great way to make colision.
    This way is more quickly than hitObjectTest with bulldozer x tree’s x debris.
    Thanks!!!

  • Pingback: Create a Flash game like Blockage - Emanuele Feronato()

  • anushi

    I cannot open this fla file. please can someone tell me the way to open it.

    • ????

      flash cs3 or later version

  • var map0:Array = new Array();
    map0[0] = [1, 1, 1, 2, 1, 2];
    map0[1] = [1, 0, 0, 0, 0, 1];
    Maybe this is not the best way to do it in AS2, but this code works (tested):

    map0[2] = [1, 3, 3, 3, 3, 3];
    map0[3] = [1, 0, 0, 0, 0, 2];
    map0[4] = [1, 0, 0, 0, 0, 2];
    map0[5] = [2, 1, 1, 1, 2, 1];
    bulldozer_pos = [2, 1];
    draw_map = function () {
    for (i=0; i<6; i++) {
    for (j=0; j0 and map0[bulldozer_pos[0]][bulldozer_pos[1]-1]>2) {
    bulldozer_pos[1]–;
    bulldozer._x -= 80;
    break;
    }
    }
    if (Key.isDown(38)) {
    if (bulldozer_pos[0]>0 and map0[bulldozer_pos[0]-1][bulldozer_pos[1]]>2) {
    bulldozer_pos[0]–;
    bulldozer._y -= 80;
    break;
    }
    }
    if (Key.isDown(39)) {
    if (bulldozer_pos[1]2) {
    bulldozer_pos[1]++;
    bulldozer._x += 80;
    break;
    }
    }
    if (Key.isDown(40)) {
    if (bulldozer_pos[0]2) {
    bulldozer_pos[0]++;
    bulldozer._y += 80;
    break;
    }
    }
    };

  • Tim

    Hey, I’m making this, but I’m doing it with a 3D array.
    Here’s a download of what I’ve got:
    http://www.megaupload.com/?d=ZAWRIPMU
    The code has no errors, but upon testing the FLA I get a blank screen. Any ideas?

  • Just a heads-up that the “official site” link is dead. Great tutorial anyways, I love how this dev is using games to help out in the real world!

  • Pingback: Second post: Following a tutorial « projectcreateagame()

  • The domain of the game seems expired, where we could get the source code of the game know ??
    nice work though, congrats