Create a Flash game like Cirplosion

Read all posts about "" game

Do you remember Cirplosion?

Cirplosion

It was quite successful some time ago, and now it’s time to create a game like it.

In this tutorial we’ll design the main engine. When you are going to design a game, or to write whatever script, try to explain yourself what you are about to do.

Let me try to explain with simple words what the does the script do:

* There are some blue orbs running everywhere with a linear motion
* You control a red orb moving it with the mouse
* If you click and hold mouse button, your orb start growing
* While growing, you can’t touch stage border or other orbs, or you will return small
* When you release mouse button you are ready to explode
* Pressing again mouse button will make you explode and kill all orbs you are touching
* Orbs close to explosion will move faster from now on

That’s about 75% of the original game… of course you will need to polish it and add new features.

You have only two objects: player and enemy. It’s up to you to guess their role in the game

Here it is the script:

Mouse.hide();
// the rate you circle grows when you keep mouse button pressed
// the higher the value, the fastest the growth
grow_rate = 2;
// number of enemies on stage
enemies = 15;
// enemy speed...
enemy_speed = 3;
// this is the speed to add to enemy's speed when he comes close to an explosion...
speed_add = 3;
// ... how close? addspeed_range determines it.
addspeed_range = 50;
// enemy creation
for (x=1; x<=enemies; x++) {
	enemy = _root.attachMovie("enemy", "enemy_"+_x, _root.getNextHighestDepth(), {_x:Math.random()*450+25, _y:Math.random()*450+25});
	// angle of movement... 6.28318531 = 2*Math.PI (just faster)
	enemy.angle = Math.random()*6.28318531;
	// the enemy starts with no additional speed
	enemy.addspeed = 0;
	enemy.onEnterFrame = function() {
		// updating enemy position
		this._x += (enemy_speed+this.addspeed)*Math.cos(this.angle);
		this._y += (enemy_speed+this.addspeed)*Math.sin(this.angle);
		// checking if the enemy left the stage in order to make them appear on the other side
		if (this._x>500) {
			this._x -= 500;
		}
		if (this._y>500) {
			this._y -= 500;
		}
		if (this._x<0) {
			this._x += 500;
		}
		if (this._y<0) {
			this._y += 500;
		}
		// calculating the distance between the enemy and the player   
		x_dist = this._x-player._x;
		y_dist = this._y-player._y;
		distance = x_dist*x_dist+y_dist*y_dist;
		// if the enemy is touching the player...
		if (distance<(this._width/2+player._width/2)*(this._width/2+player._width/2)) {
			// if the player is growing then reset the player
			// later he will lose a life
			if (can_grow) {
				reset_player();
			}
			// if the player is exploding, then remove the enemy   
			if (explode) {
				this.removeMovieClip();
			}
		}
		else {// if the enemy is not touching the player but it's close enough to receive speed from the explosion...
			if (distance<(this._width/2+player._width/2+addspeed_range)*(this._width/2+player._width/2+addspeed_range) and explode) {
				// inverting enemy direction
				// later it will be adjusted according to angle between the player and the enemy
				this.angle -= 3.14159265;
				// adding extra speed
				this.addspeed = speed_add;
			}
		}
	};
}
// attaching the player on stage
_root.attachMovie("player","player",_root.getNextHighestDepth());
_root.onEnterFrame = function() {
	// updating player position
	player._x = _xmouse;
	player._y = _ymouse;
	// if the player is growing...
	if (can_grow) {
		// scale up the player
		player._width += grow_rate;
		player._height += grow_rate;
		// if the player touches the edges of the scene then reset it
		if (player._x-player._width/2<0) {
			reset_player();
		}
		if (player._x+player._width/2>500) {
			reset_player();
		}
		if (player._y-player._width/2<0) {
			reset_player();
		}
		if (player._y+player._width/2>500) {
			reset_player();
		}
	}
	// if the player explodes, then reset it 
	if (explode) {
		reset_player();
	}
};
// when the player presses the mouse...
_root.onMouseDown = function() {
	// if the player has not grown, then make it grow
	if (!has_grown) {
		can_grow = true;
	}
	else {// if the player has already grown, make it explode
		explode = true;
	}
};
// when the player releases the mouse...
_root.onMouseUp = function() {
	// if he was growing...
	if (can_grow) {
		// the player has grown, now it's ready to explode
		has_grown = true;
		can_grow = false;
		player._alpha = 50;
	}
};
// simple function to reset player stats
function reset_player() {
	player._alpha = 100;
	player._width = 10;
	player._height = 10;
	explode = false;
	has_grown = false;
	can_grow = false;
}

And this is the result… play this quick Cirplosion version!

Now it’s time to add some new features and polish the game.

How will you do it? Download the source code, send me an example and get featured in the blog!

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