Adding a new twist to the prototype of a Flash game like Poux

Read all posts about "" game

Do you remember the Poux tutorial series?

If not, then read parts 1, 2 and 3 and take a look at the finished project known as Christmas Couples.

I always say using prototypes to create games is a good idea, and the almost 7,000,000 plays Christmas Couples had since its release confirm my theory.

Anyway, the “twist” is you must remove adjacent tiles by drawing on them.

You must connect two or more adjacent tiles with the same color with the “pen”, and if you have the precision of a surgeon, you can also connect tiles diagonally!

Oh, well, take the commented actionscript

// declaration of the array that will contain the game
field = Array();
// declaration of the arrat that will contain the tiles to be removed
tiles_to_remove = Array();
// number of frames to pass before inserting the first row
interval = 1;
// 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;
	}
}
// creation of the movieclip where to place tiles
createEmptyMovieClip("tiles", 1);
// creation of the movieclip where to draw
createEmptyMovieClip("drawing", 2);
// flag that states if the I can draw or not
can_draw = false;
// function that places a line of tiles in the bottom of the field
function place_line() {
	// 1 row = 10 tiles
	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);
		}
		// placing the tile       
		tile = tiles.attachMovie("tile", "tile_"+tiles_placed, tiles_placed, {_x:10+32*x, _y:300});
		// assigning a random color (frame) to the tile
		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() {
	// decreasing the interval
	interval--;
	// placing a row and set a new interval if the interval reached zero
	if (interval<0) {
		interval = 200;
		place_line();
	}
	// if I can draw...       
	if (can_draw) {
		// determining on which tile I should draw
		x_tile_drawing = Math.floor((_root._xmouse-10)/32);
		y_tile_drawing = -Math.floor((_root._ymouse-300)/32);
		if (field[x_tile_drawing][y_tile_drawing] != 0) {
			// draw a line until my mouse
			drawing.lineTo(_root._xmouse, _root._ymouse);
			// determining the color of the tile I am drawing on
			current_color = _root.tiles["tile_"+field[x_tile_drawing][y_tile_drawing]]._currentframe;
			// if the current color is different than the one I started drawing on...
			if (current_color != starting_color) {
				// stop drawing
				stop_drawing();
			} else {
				// if the current color the same as the one I started drawing on...
				// insert_it determines if I have to insert the current tile in the array of tiles to be removed
				insert_it = true;
				// scanning the array of tiles to be removed
				for (x=0; x=0; i--) {
		// if the place is not empty...
		if (field[col_number][i] != 0) {
			// if I don't have a column with 10 blocks...
			if (i != 9) {
				// shift the blocks
				field[col_number][i+1] = field[col_number][i];
				_root.tiles["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.tiles["tile_"+field[col_number][i]].removeMovieClip();
			}
		}
	}
}
// when I click...
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 the tile clicked exists...
	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) {
			// set the starting color as the one of the tile I am clicking on
			starting_color = _root.tiles["tile_"+field[x_tile_clicked][y_tile_clicked]]._currentframe;
		}
	}
	// set the drawing style  
	drawing.lineStyle(5, 0x000000);
	// moving the pen to my mouse position
	drawing.moveTo(_root._xmouse, _root._ymouse);
	// now I can drag
	can_draw = true;
};
// when I release...
onMouseUp = function () {
	// if the array of tiles to be removed has more than one element...
	if (tiles_to_remove.length>1) {
		// scanning all array
		for (x=0; x=0)) {
					field[i][falling] = field[i][falling+1];
					_root.tiles["tile_"+field[i][falling+1]]._y += 32;
					field[i][falling+1] = 0;
					falling--;
				}
			}
		}
	}
}
// stop drawing
function stop_drawing() {
	// now I can't draw
	can_draw = false;
	// clearing the drawing
	drawing.clear();
	// deleting and reinitializing the array. It's just a quick way to clear it
	delete (tiles_to_remove);
	tiles_to_remove = Array();
}

And play with it

Finally, download the source code.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers