Create a Flash game like ColorFill – part 1

Read all posts about "" game

If you play all successful Flash games (and you should, if you want to be a Flash game developer), surely you played ColorFill.

ColorFill

In this game, you have to fill 80% of the stage with colors while avoiding collisions with enemies.

Play the game a bit then follow this prototype

The main idea to create this game is based upon the “vertical state” of arrows. I designed the arrows as horizontal ones, but if the player presses SPACE, I rotate them by 90 degrees so the left one becomes the up one and the right one becomes the down one.

There’s not any more difficulty in this first part, when I still don’t fill the area once I successfully draw a line.

Some previous concepts from Create a flash draw game like Line Rider or others – part 2 are involved in order to determine collisions between the ball and the line.

Mouse.hide();
// flag indicating if I pressed space
space_pressed = false;
// vertical_arrow = true: arrows are horizontal
// vertical_arrow = false: arrows are vertical
vertical_arrow = false;
// flag indicating if I pressed space
clicked = false;
// enemy's random angle movement 
angle = Math.random()*360;
// enemy and arrows speeds
speed = 5;
// booleans that states if the left or right arrows touched the border of the stage
left_touch = false;
right_touch = false;
// x and y speeds of the enemy
xspeed = speed*Math.cos(angle*0.0174532925);
yspeed = speed*Math.sin(angle*0.0174532925);
// enemy collision detection precision
precision = 16;
// attaching the ball = the enemy
_root.attachMovie("ball","ball",1,{_x:250, _y:200});
// creating the empty movieclip that will contain all drawings
_root.createEmptyMovieClip("line",2);
// attaching the left arrow
_root.attachMovie("left_arrow","left_arrow",3);
// attaching the right arrow
_root.attachMovie("right_arrow","right_arrow",4);
// function to be executed for the left arrow
left_arrow.onEnterFrame = function() {
	// if I did not click the mouse
	if (!clicked) {
		// if I am not in "vertical mode"...
		if (!vertical_arrow) {
			// place the arrow
			this._y = _root._ymouse;
			this._x = _root._xmouse-15;
			this._rotation = 0;
		}
		// if I am in "vertical mode"....
		else {
			// place the arrow
			this._y = _root._ymouse-15;
			this._x = _root._xmouse;
			this._rotation = 90;
		}
	}
	// if I clicked the mouse....
	else {
		// if the arrow did not touch the edge of the stage...
		if (!left_touch) {
			// if I am not in "vertical mode"...
			if (!vertical_arrow) {
				// moving the arrow
				this._x -= speed;
				// checking if the arrow touched the left edge of the stage
				if (this._x<8) {
					this._x = 8;
					left_touch = true;
				}
			}
			// if I am in "vertical mode"...
			else {
				// moving the arrow
				this._y -= speed;
				// checking if the arrow touched the upper edge of the stage
				if (this._y<8) {
					this._y = 8;
					left_touch = true;
				}
			}
		}
	}
};
// same concept for the right arrow
right_arrow.onEnterFrame = function() {
	if (!clicked) {
		if (!vertical_arrow) {
			this._y = _root._ymouse;
			this._x = _root._xmouse+15;
			this._rotation = 0;
		}
		else {
			this._y = _root._ymouse+15;
			this._x = _root._xmouse;
			this._rotation = 90;
		}
	}
	else {
		if (!right_touch) {
			if (!vertical_arrow) {
				this._x += speed;
				if (this._x>492) {
					this._x = 492;
					right_touch = true;
				}
			}
			else {
				this._y += speed;
				if (this._y>392) {
					this._y = 392;
					right_touch = true;
				}
			}
		}
	}
};
// function to be executed for the ball... it's a simple "bounce here and there"
ball.onEnterFrame = function() {
	this._x += xspeed;
	this._y += yspeed;
	if ((this._x<20) or (this._x>480)) {
		xspeed *= -1;
	}
	if ((this._y<20) or (this._y>380)) {
		yspeed *= -1;
	}
};
// function to be executed at every frame
_root.onEnterFrame = function() {
	// if I did not pressed the space....
	if (!space_pressed) {
		// checking if I am pressing the space
		if (Key.isDown(Key.SPACE)) {
			space_pressed = true;
			// switching vertical_arrow state between true and false
			vertical_arrow = !vertical_arrow;
		}
	}
	// if I pressed space...
	else {
		// checking if I released the space
		if (!Key.isDown(Key.SPACE)) {
			space_pressed = false;
		}
	}
	// checking if I clicked the mouse
	if (clicked) {
		// preparing the line style
		line.clear();
		line.lineStyle(5,"0xff0000");
		// drawing a line from an arrow to the other
		line.moveTo(left_arrow._x,left_arrow._y);
		line.lineTo(right_arrow._x,right_arrow._y);
		// checking collision between the ball and the line
		for (x=1; x

And this is the result:

Now next challenge is painting the area just closed with the line and manage new stage bounds.

Any ideas? I have a lot... meanwhile 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