Create a Flash game like Cirplosion

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:

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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!

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4.80 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» 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.

7 Responses to “Create a Flash game like Cirplosion”

  1. Cool on August 22nd, 2008 11:04 pm

    Cool always wanted to make a game like this

  2. Kesh on August 23rd, 2008 8:08 am

    great idea.

  3. Kesh on August 23rd, 2008 8:10 am

    I am going to make the levels and i will submit it :)

  4. JDog053 on August 23rd, 2008 11:54 am

    Looking good. My first major game is nearly completed too !

  5. Jai on August 29th, 2008 8:21 am

    it’s kind of like filler, in how it expands and the ball collisions.

Leave a Reply




Trackbacks

  1. Flash Tutorials | AS3, AS2 Flash game tutorials roundup part 2 | Lemlinh.com on August 24th, 2008 12:00 am

    [...] Read more [...]

  2. Create a Flash game like Cirplosion - AS3 version : Emanuele Feronato on August 28th, 2008 12:17 am

    [...] days ago I published Create a Flash game like Cirplosion using AS2, now it’s time to do it using [...]

flash games company