Section 1
//Bullet (Game.Bullet)
package Game {
import flash.display.*;
public class Bullet extends MovieClip {
public function Bullet(_arg1:Number, _arg2:Number){
this.x = _arg1;
this.y = _arg2;
}
public function update(){
this.y = (this.y - C.BULLET_SPEED);
}
public function notInScreen():Boolean{
return ((this.y <= 0));
}
}
}//package Game
Section 2
//C (Game.C)
package Game {
public class C {
public static const PLAYER_SPEED:Number = 4;
public static const PLAYER_START_X:Number = 400;
public static const PLAYER_START_Y:Number = 415;
public static const PLAYER_LEFT_BOUND:Number = 50;
public static const PLAYER_RIGHT_BOUND:Number = 550;
public static const ENEMY_SPEED:Number = 5;
public static const ENEMY_ADVANCE:Number = 65;
public static const SPAWN_ENEMY_CHANCE:Number = 0.03;
public static const ENEMY_START_X:Number = 100;
public static const ENEMY_START_Y:Number = 30;
public static const ENEMY_STARTING_POINTS:Number = 10;
public static const ENEMY_REDUCE_POINTS:Number = 2;
public static const BULLET_SPEED:Number = 6;
public static const BULLET_DELAY:Number = 1000;
public static const PLAYER_START_SCORE:Number = 0;
}
}//package Game
Section 3
//Enemy (Game.Enemy)
package Game {
import flash.display.*;
public class Enemy extends MovieClip {
private var facing:Number;
private var score:Number;
public function Enemy(){
this.x = C.ENEMY_START_X;
this.y = C.ENEMY_START_Y;
this.facing = C.ENEMY_SPEED;
this.score = C.ENEMY_STARTING_POINTS;
}
public function update(){
this.x = (this.x + this.facing);
if ((((this.x > C.PLAYER_RIGHT_BOUND)) || ((this.x < C.PLAYER_LEFT_BOUND)))){
this.facing = (this.facing * -1);
this.y = (this.y + C.ENEMY_ADVANCE);
this.score = (this.score - C.ENEMY_REDUCE_POINTS);
};
}
public function getPointsWorth(){
return (this.score);
}
}
}//package Game
Section 4
//busey_hya (busey_hya)
package {
import flash.media.*;
public dynamic class busey_hya extends Sound {
}
}//package
Section 5
//GameController (GameController)
package {
import flash.events.*;
import Game.*;
import flash.media.*;
import flash.display.*;
import flash.text.*;
import flash.utils.*;
import flash.geom.*;
public class GameController extends MovieClip {
public var mcGameStage:MovieClip;
public var txtScorePlayer:TextField;
private var player:Player;
private var playerScore:Number;
private var enemies:Array;
private var bullets:Array;
private var lastBulletTime:Number;
private var moveX:Number;
private var fireBullet:Boolean;
private var sound1:busey_hya;
var myChannel1:SoundChannel;
private var sound2:quall_eh;
var myChannel2:SoundChannel;
public function GameController(){
sound1 = new busey_hya();
myChannel1 = sound1.play();
sound2 = new quall_eh();
myChannel2 = sound2.play();
super();
addFrameScript(0, frame1);
}
public function startGame(){
player = new Player();
player.x = C.PLAYER_START_X;
player.y = C.PLAYER_START_Y;
mcGameStage.addChild(player);
playerScore = C.PLAYER_START_SCORE;
moveX = 0;
fireBullet = false;
lastBulletTime = getTimer();
enemies = new Array();
bullets = new Array();
mcGameStage.addEventListener(Event.ENTER_FRAME, update);
addEventListener(Event.ADDED_TO_STAGE, gameAddedToStage);
if (stage != null){
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
};
}
private function gameAddedToStage(_arg1:Event):void{
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
private function keyDownHandler(_arg1:KeyboardEvent):void{
if (_arg1.keyCode == 32){
fireBullet = true;
sound1.play();
} else {
if (_arg1.keyCode == 37){
moveX = -1;
} else {
if (_arg1.keyCode == 39){
moveX = 1;
};
};
};
}
private function keyUpHandler(_arg1:KeyboardEvent):void{
if (_arg1.keyCode == 37){
moveX = 0;
} else {
if (_arg1.keyCode == 39){
moveX = 0;
};
};
}
private function update(_arg1:Event){
var _local2:*;
var _local3:*;
var _local4:*;
var _local5:*;
var _local6:*;
if (moveX > 0){
if (player.x <= C.PLAYER_RIGHT_BOUND){
player.x = (player.x + C.PLAYER_SPEED);
};
} else {
if (moveX < 0){
if (player.x > C.PLAYER_LEFT_BOUND){
player.x = (player.x - C.PLAYER_SPEED);
};
};
};
if (fireBullet){
_local4 = getTimer();
if ((_local4 - lastBulletTime) > C.BULLET_DELAY){
lastBulletTime = _local4;
_local5 = new Bullet(player.x, player.y);
bullets.push(_local5);
mcGameStage.addChild(_local5);
};
fireBullet = false;
};
if (Math.random() < C.SPAWN_ENEMY_CHANCE){
_local6 = new Enemy();
enemies.push(_local6);
mcGameStage.addChild(_local6);
};
_local2 = (enemies.length - 1);
while (_local2 >= 0) {
enemies[_local2].update();
_local2--;
};
_local2 = (bullets.length - 1);
while (_local2 >= 0) {
bullets[_local2].update();
if (bullets[_local2].notInScreen()){
mcGameStage.removeChild(bullets[_local2]);
bullets.splice(_local2, 1);
};
_local2--;
};
_local2 = (bullets.length - 1);
while (_local2 >= 0) {
_local3 = (enemies.length - 1);
while (_local3 >= 0) {
if (bullets[_local2].hitTestObject(enemies[_local3])){
playerScore = (playerScore + enemies[_local3].getPointsWorth());
mcGameStage.removeChild(bullets[_local2]);
mcGameStage.removeChild(enemies[_local3]);
bullets.splice(_local2, 1);
enemies.splice(_local3, 1);
sound2.play();
break;
};
_local3--;
};
_local2--;
};
_local3 = (enemies.length - 1);
while (_local3 >= 0) {
if (player.hitTestObject(enemies[_local3])){
mcGameStage.removeChild(player);
mcGameStage.removeChild(enemies[_local3]);
enemies.splice(_local3, 1);
gameOver();
break;
};
_local3--;
};
txtScorePlayer.text = String(playerScore);
}
private function gameOver(){
player = null;
mcGameStage.removeEventListener(Event.ENTER_FRAME, update);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
function frame1(){
startGame();
}
}
}//package
Section 6
//Player (Player)
package {
import flash.display.*;
public dynamic class Player extends MovieClip {
}
}//package
Section 7
//quall_eh (quall_eh)
package {
import flash.media.*;
public dynamic class quall_eh extends Sound {
}
}//package