Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Cirplosion game, Actionscript 3, Flash and Game development.

After the porting of String Avoider, it’s time to see another old classic ported into AS3: Cirplosion.

I already published the AS2 version with all comments in this post, so it’s time to see what can be done with AS3.

I modified a bit some rules to make the game harder:

* There are some blue orbs running everywhere with a linear motion
* Orbs bounce on stage borders
* 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
* While you are ready to explode, you can collide with blue orbs but you can’t hit stage borders
* Press again mouse button and you will explode turning transparent all orbs you are touching
* Beware of transparent orbs as they are still deadly
* semi transparent orbs as well as orbs close to explosion will move faster from now on

Will you be able to turn all orbs semi transparent?

This is the main class:

package {
	import flash.display.Sprite;
	import flash.ui.Mouse;
	import flash.events.Event;
	import flash.events.MouseEvent;
	public class Main extends Sprite {
		private var enemiesAmount:Number=15;
		private var explosionRange:Number=50;
		private var enemy:Enemy;
		private var enemyVector:Vector.=new Vector.();
		private var player:Player;
		public function Main() {
			Mouse.hide();
			for (var i:int=0; i

This is Player class

package {
	import flash.display.Sprite;
	public class Player extends Sprite {
		public var isGrowing:Boolean=false;
		public var readyToExplode:Boolean=false;
		public var isExploding:Boolean=false;
		private var growthRate:Number=2;
		public function updatePosition():void {
			x=stage.mouseX;
			y=stage.mouseY;
			if (isGrowing) {
				width+=growthRate;
				height+=growthRate;
			}
			if (x-width/2<0||x+width/2>500||y-height/2<0||y+height/2>500) {
				init();
			}
		}
		public function init():void {
			isExploding=false;
			readyToExplode=false;
			isGrowing=false;
			width=10;
			height=10;
			alpha=1;
		}
		public function getReady():void {
			isGrowing=false;
			readyToExplode=true;
			alpha=0.5;
		}
	}
}

and this is Enemy Class

package {
	import flash.display.Sprite;
	public class Enemy extends Sprite {
		public var movingAngle:Number=2*Math.random()*Math.PI;
		public var bonusSpeed:Number=3;
		public var speed:Number=3;
		public function Enemy() {
			x=25+Math.random()*450;
			y=25+Math.random()*450;
		}
		public function updatePosition():void {
			x+=speed*Math.cos(movingAngle);
			y+=speed*Math.sin(movingAngle);
			if (x>500 || x<0) {
				x=Math.round(x/500)*500;
				movingAngle=Math.PI-movingAngle;
			}
			if (y>500||y<0) {
				y=Math.round(y/500)*500;
				movingAngle=2*Math.PI-movingAngle;
			}
		}
		public function addSpeed():void {
			speed+=bonusSpeed;
			bonusSpeed=0;
		}
	}
}

Download the source code and try to make a decent game out of this prototype.

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.