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:

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

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

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 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.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 13 comments

  1. Prototype of a Flash game like Poux : Emanuele Feronato - italian geek and PROgrammer

    on November 17, 2007 at 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 17, 2007 at 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 17, 2007 at 3:20 am

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

  4. shiv1411

    on November 17, 2007 at 7:35 am

    I agree with s0d4player.
    Anyways nice tutorial again!

  5. abhilash

    on November 17, 2007 at 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 17, 2007 at 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 17, 2007 at 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 17, 2007 at 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 17, 2007 at 8:51 pm

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

  10. Massimo M.

    on November 18, 2007 at 5:04 am

    hi emanuele very good and fast tutorial !!!

  11. shiv1411

    on November 18, 2007 at 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 18, 2007 at 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 13, 2008 at 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