Talking about Cirplosion game, Actionscript 3, Flash and Game development.
Some days ago I published Create a Flash game like Cirplosion using AS2, now it’s time to do it using AS3.
AS3 is becoming more and more popular so I think it’s time to give it more exposure.
This is the uncommented AS3 version of Cirplosion.
I would like you to compare it with AS2 one.
I am preparing a line-by-line explanation of all differences between AS2 and AS3 versions.
This will be very helpful for all people out there that are afraid to start coding AS3.
While AS2 is far from being obsolete (in my opinion), you can’t ignore it exists and it’s better than AS2
package {
import flash.display.Sprite;
import flash.ui.Mouse;
import flash.events.*;
public class cirplosionas3 extends Sprite {
var grow_rate = 2;
var enemies = 15;
var enemy_speed = 3;
var speed_add = 3;
var addspeed_range = 50;
var has_grown = false;
var can_grow = false;
var explode = false;
var playersprite: player = new player();
public function cirplosionas3() {
Mouse.hide();
for (x=1; x<=enemies; x++) {
var enemysprite: enemy = new enemy();
enemysprite.x = Math.random()*450+25;
enemysprite.y = Math.random()*450+25;
enemysprite.anglez = Math.random()*6.28318531;
enemysprite.addspeed = 0;
enemysprite.addEventListener(Event.ENTER_FRAME,move_enemy);
addChild(enemysprite);
}
addChild(playersprite);
addEventListener(Event.ENTER_FRAME,main);
addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
addEventListener(MouseEvent.MOUSE_UP,mouseup);
}
public function move_enemy(event:Event) {
var current_enemy:enemy = (event.currentTarget as enemy);
var x_dist = 0;
var y_dist = 0;
var distance = 0;
current_enemy.x+=(enemy_speed+current_enemy.addspeed)*Math.cos(current_enemy.anglez);
current_enemy.y+=(enemy_speed+current_enemy.addspeed)*Math.sin(current_enemy.anglez);
if (current_enemy.x>500) {
current_enemy.x -= 500;
}
if (current_enemy.y>500) {
current_enemy.y -= 500;
}
if (current_enemy.x<0) {
current_enemy.x += 500;
}
if (current_enemy.y<0) {
current_enemy.y += 500;
}
x_dist = current_enemy.x-playersprite.x;
y_dist = current_enemy.y-playersprite.y;
distance = x_dist*x_dist+y_dist*y_dist;
if (distance<(current_enemy.width/2+playersprite.width/2)*(current_enemy.width/2+playersprite.width/2)) {
if (can_grow) {
reset_player();
}
if (explode) {
current_enemy.removeEventListener(Event.ENTER_FRAME,move_enemy);
removeChild(current_enemy);
}
}
else {
if (distance<(current_enemy.width/2+playersprite.width/2+addspeed_range)*(current_enemy.width/2+playersprite.width/2+addspeed_range) && explode) {
current_enemy.anglez -= 3.14159265;
current_enemy.addspeed = speed_add;
}
}
}
public function main(event:Event) {
playersprite.x = mouseX;
playersprite.y = mouseY;
if (can_grow) {
playersprite.width += grow_rate;
playersprite.height += grow_rate;
if (playersprite.x-playersprite.width/2<0) {
reset_player();
}
if (playersprite.x+playersprite.width/2>500) {
reset_player();
}
if (playersprite.y-playersprite.width/2<0) {
reset_player();
}
if (playersprite.y+playersprite.width/2>500) {
reset_player();
}
}
if (explode) {
reset_player();
}
}
public function mousedown(event:Event) {
if (!has_grown) {
can_grow = true;
}
else {
explode = true;
}
}
public function mouseup(event:Event) {
if (can_grow) {
has_grown = true;
can_grow = false;
playersprite.alpha = 0.5;
}
}
public function reset_player() {
playersprite.alpha = 1;
playersprite.width = 10;
playersprite.height = 10;
explode = false;
has_grown = false;
can_grow = false;
}
}
}
Download the source code… no need to publish the result because it’s the same as AS2 version.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.