Game Development Reference
In-Depth Information
level = 1;
levelText.text = level.toString();
addChild(player);
player.startDrag(true,new Rectangle(0,0,550,400));
gameState = STATE_PLAY;
}
public function playGame():void {
player.rotation += 15;
makeEnemies();
moveEnemies();
testCollisions();
testForEnd();
}
public function makeEnemies():void {
var chance:Number = Math.floor(Math.random() *100);
var tempEnemy:MovieClip;
if (chance < 2 + level) {
tempEnemy = new EnemyImage()
tempEnemy.speed = 3 + level;
tempEnemy.gotoAndStop(Math.floor(Math.random()*5) + 1);
tempEnemy.y = 435;
tempEnemy.x = Math.floor(Math.random() * 515)
addChild(tempEnemy);
enemies.push(tempEnemy);
}
}
public function moveEnemies():void {
var tempEnemy:MovieClip;
for (var i:int = enemies.length -1;i >= 0;i--) {
tempEnemy = enemies[i];
tempEnemy.y -= tempEnemy.speed;
if (tempEnemy.y < -35) {
chances++;
chancesText.text = chances.toString();
enemies.splice(i,1);
removeChild(tempEnemy);
}
}
}
public function testCollisions():void {
var sound:Sound = new Pop();
var tempEnemy:MovieClip;
for (var i:int = enemies.length -1;i >= 0;i--) {
tempEnemy = enemies[i];
if (tempEnemy.hitTestObject(player)) {
score++;
scoreText.text = score.toString();
Search WWH ::




Custom Search