Prototype of a Flash game like Poux - Part 2

November 22nd update: part 3 released
November 28th update: Finished project released

Ok... this is the quickest prototype update ever. Yesterday I came with the Prototype of a Flash game like Poux, a bit incomplete because you could merely watch tiles grow.

It was a 50 lines prototype, and today I am publishing the second part, with another 50 lines (now we have 100 lines and an almost complete game!).

Now you can use your mouse to click on contiguous same colored tiles to remove them.

Light, camera, actionscript:

ACTIONSCRIPT:
  1. // declaration of the array that will contain the game
  2. field = Array();
  3. // number of frames to pass before inserting a new row
  4. interval = 50;
  5. // tiles placed so far
  6. tiles_placed = 0;
  7. // loop that initializes the field
  8. for (x=0; x<10; x++) {
  9.     field[x] = Array();
  10.     for (y=0; y<10; y++) {
  11.         field[x][y] = 0;
  12.     }
  13. }
  14. // function that places a line of tiles in the bottom of the field
  15. function place_line() {
  16.     for (x=0; x<10; x++) {
  17.         tiles_placed++;
  18.         // if the spot is not empty, must shift the colum
  19.         if (field[x][0] != 0) {
  20.             push_blocks(x);
  21.         }
  22.         tile = attachMovie("tile", "tile_"+tiles_placed, tiles_placed, {_x:10+32*x, _y:300});
  23.         num = Math.floor(Math.random()*8)+1;
  24.         tile.gotoAndStop(num);
  25.         field[x][0] = tiles_placed;
  26.     }
  27. }
  28. // function to be executed at every frame
  29. _root.onEnterFrame = function() {
  30.     interval--;
  31.     if (interval == 0) {
  32.         interval = 50;
  33.         place_line();
  34.     }
  35. };
  36. // function that shifts the column of blocks
  37. function push_blocks(col_number) {
  38.     for (i=9; i>=0; i--) {
  39.         if (field[col_number][i] != 0) {
  40.             if (i != 9) {
  41.                 field[col_number][i+1] = field[col_number][i];
  42.                 _root["tile_"+field[col_number][i]]._y -= 32;
  43.             } else {
  44.                 // if I have more than 10 blocks in a column, remove the 10th block
  45.                 // In a normal game, it would be "game over"
  46.                 _root["tile_"+field[col_number][i]].removeMovieClip();
  47.             }
  48.         }
  49.     }
  50. }
  51. // when the player clicks...
  52. onMouseDown = function () {
  53.     // obtain tile clicked according to mouse position
  54.     x_tile_clicked = Math.floor((_root._xmouse-10)/32);
  55.     y_tile_clicked = -Math.floor((_root._ymouse-300)/32);
  56.     if ((x_tile_clicked>=0) and (x_tile_clicked<=9) and (y_tile_clicked>=0) and (y_tile_clicked<=9)) {
  57.         if (field[x_tile_clicked][y_tile_clicked] != 0) {
  58.             remove_tiles(x_tile_clicked, y_tile_clicked, 1);
  59.             update_field();
  60.         }
  61.     }
  62. };
  63. // removing tiles of the same color of the one clicked
  64. function remove_tiles(tx, ty, clicked) {
  65.     // checking tile color according to its current frame
  66.     tile_type = _root["tile_"+field[tx][ty]]._currentframe;
  67.     // check if the tile to remove is the one you clicked. In this case, wait to have at least two tiles to remove
  68.     if (!clicked) {
  69.         _root["tile_"+field[tx][ty]].removeMovieClip();
  70.         field[tx][ty] = 0;
  71.     }
  72.     if ((field[tx+1][ty] != 0) and (_root["tile_"+field[tx+1][ty]]._currentframe == tile_type)) {
  73.         remove_tiles(tx+1, ty);
  74.     }
  75.     if ((field[tx-1][ty] != 0) and (_root["tile_"+field[tx-1][ty]]._currentframe == tile_type)) {
  76.         remove_tiles(tx-1, ty);
  77.     }
  78.     if ((field[tx][ty+1] != 0) and (_root["tile_"+field[tx][ty+1]]._currentframe == tile_type)) {
  79.         remove_tiles(tx, ty+1);
  80.     }
  81.     if ((field[tx][ty-1] != 0) and (_root["tile_"+field[tx][ty-1]]._currentframe == tile_type)) {
  82.         remove_tiles(tx, ty-1);
  83.     }
  84. }
  85. // update the field, making tiles fall if bottom tiles disappear
  86. function update_field() {
  87.     for (i=0; i<10; i++) {
  88.         for (j=1; j<10; j++) {
  89.             if ((field[i][j] != 0) and (field[i][j-1] == 0)) {
  90.                 falling = j-1;
  91.                 while ((field[i][falling] == 0) and (falling>=0)) {
  92.                     field[i][falling] = field[i][falling+1];
  93.                     _root["tile_"+field[i][falling+1]]._y += 32;
  94.                     field[i][falling+1] = 0;
  95.                     falling--;
  96.                 }
  97.             }
  98.         }
  99.     }
  100. }

The scripts has some comments so it shouldn't be too hard for you to understand how things work.

Now try to click on contiguous tiles...

A game in only 100 lines (comments included). Tomorrow I'll add 100 more lines coding some powerups and other weird things and I'll have my second one-day game to continue my experiment.

Take the source code... see you... and read part 3

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...

» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

13 Responses to “Prototype of a Flash game like Poux - Part 2”

  1. Prototype of a Flash game like Poux : Emanuele Feronato - italian geek and PROgrammer on November 17th, 2007 2:53 am

    [...] 17th update: part 2 released Ok, I know, you are asking for full tutorials and not prototypes, but you have to know [...]

  2. Teal on November 17th, 2007 3:20 am

    It works nicely, but the screen fills up way to fast. When I was trying it for myself, I slowed that down a ton.

    Also, can you please finish the platform tutorials? I’m working on a new platform game, and so far it only has one level with the stuff you showed us how to do (I just changed the map), so I really need a new tutorial!

  3. s0d4player on November 17th, 2007 3:20 am

    Awe, you didn’t give us enough time to figure how to do it ourselves.

  4. shiv1411 on November 17th, 2007 7:35 am

    I agree with s0d4player.
    Anyways nice tutorial again!

  5. abhilash on November 17th, 2007 8:39 am

    usually I don’t like playing these type of games,but i’ll try this tutorial if this works in flash 7mx.

  6. Frederik J on November 17th, 2007 8:51 am

    Nice tutorial, emanuele. And a fast release of part 2 :)
    Now you just need the animation!
    /Frederik J

  7. Tony on November 17th, 2007 1:18 pm

    That’s what I call a fast release!
    I think the best thing would be a space of three-four days between part1 and 2.
    How’s your one-week game going?

    Thank you for all these tutorials!!

  8. abhilash on November 17th, 2007 6:46 pm

    sorry for asking again & again about blogs but i promise this is the last time, is there any age limit for creating a blog on wordpress.com

  9. Emanuele Feronato on November 17th, 2007 8:51 pm

    In most services the minimum age limit is 13 as far as I know

  10. Massimo M. on November 18th, 2007 5:04 am

    hi emanuele very good and fast tutorial !!!

  11. shiv1411 on November 18th, 2007 8:57 am

    hi emanuele,
    sorry for disturbing u again about submitting to Mochi. Please explain in detail what to do and how to do.

    Anyways check ur email that u gave me that day. U will find my 6 level game “bounceria” in there.

  12. shiv1411 on November 18th, 2007 2:07 pm

    Hi emanuele,
    you got to read this that I met a number of success today -

    1. I finally entered into Mochi.
    2. I entered my game into Newgrounds. The url is http://www.newgrounds.com/portal/view/410851
    You can find it on the latest releases.
    3. My graph grew to 194 within the first 3 hours of submission at mochiads.

    Did u recieve my “bounceria” .

    Check it out.

  13. Martin on August 13th, 2008 4:45 pm

    Please can someone explain to me how and why this bit works (lines 54&55):

    x_tile_clicked = Math.floor((_root._xmouse 10)/32);
    y_tile_clicked = -Math.floor((_root._ymouse-300)/32);

    I was thinking that to get the position of the tiles the code would just be something like:

    x_tile_clicked = _root._xmouse;
    y_tile_clicked = _root._ymouse;

    Thanks

Leave a Reply