setup = function()
{
firing = false; // Is player firing?
fireRate = 10; // Frame delay between shots
enemyTime = 0; // Enemy creation timer
enemyRate = 30; // Frame delay between enemy waves
score = 0;
score_txt.text = score;
counter = 20; // Game time
counter_txt.text = counter;
ship.onMouseDown = function()
{
firing = true;
repeatTime = 0;
}
ship.onMouseUp = function()
{
firing = false;
}
ship.onEnterFrame = function()
{
this.destx = _xmouse;
var diffx = (this.destx - this._x)
this._x += diffx * .15;
if (firing && repeatTime == 0)
{
createProjectile("bullet", this._x,
this._y - 5, 0, -15);
}
repeatTime ++;
repeatTime %= fireRate;
if (enemyTime == 0)
{
var sx = Math.random() * 100 + 80;
createEnemy("bob", sx, -30);
createEnemy("bob", 200, -30);
createEnemy("bob", 400 - sx, -30);
}
enemyTime ++;
enemyTime %= 30;
}
doCounter = function()
{
counter--;
counter_txt.text = counter;
if (counter == 0)
{
delete ship.onEnterFrame;
delete bgscroller.onEnterFrame;
enemyLayer.removeMovieClip();
projectileLayer.removeMovieClip();
startButton._visible = true;
clearInterval(countID);
}
}
countID = setInterval(doCounter, 1000);
_root.createEmptyMovieClip("projectileLayer", 99);
projectileCount = 0;
_root.createEmptyMovieClip("enemyLayer", 98);
enemyCount = 0;
ship.swapDepths(100);
ship.gotoAndStop(1);
bgscroller.onEnterFrame = function()
{
if (this._y >= 500)
{
this._y = 0;
}
this._y+=5;
}
}
createProjectile = function(type, x, y, dx, dy)
{
var nm = "proj" + projectileCount;
projectileLayer.attachMovie(type, nm, projectileCount);
projectileLayer[nm]._x = x;
projectileLayer[nm]._y = y;
projectileLayer[nm].dx = dx;
projectileLayer[nm].dy = dy;
projectileLayer[nm].onEnterFrame = function()
{
this._x += this.dx;
this._y += this.dy;
if (this._y < 0) this.removeMovieClip();
for (var i = 0; i < 10; i++)
{
var enm = "enemy" + i;
if (this.hitTest(enemyLayer[enm]) && enemyLayer[enm]._currentframe == 1)
{
enemyLayer[enm].play();
score++;
score_txt.text = score;
this.removeMovieClip();
}
}
}
projectileCount ++;
projectileCount %= 10;
}
createEnemy = function(type, x, y)
{
var nm = "enemy" + enemyCount;
enemyLayer.attachMovie(type, nm, enemyCount);
enemyLayer[nm]._x = x;
enemyLayer[nm].xline = x;
enemyLayer[nm]._y = y;
enemyLayer[nm].dy = Math.random() * 3 + 10;
enemyLayer[nm].t = Math.random() * 6.28;
enemyLayer[nm].onEnterFrame = function()
{
this._x = this.xline + Math.sin(this.t) * 100;
this._y += this.dy;
this.t += 0.1;
if (this._currentframe == 1 && ship.hitTest(this._x, this._y, true))
{
counter = 1;
doCounter();
ship.play();
}
if (this._y > 500) this.removeMovieClip();
}
enemyCount ++;
enemyCount %= 10;
}
startButton.onRelease = function()
{
this._visible = false;
setup();
}
No comments:
Post a Comment