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();
}
Monday, April 25, 2011
Thursday, April 21, 2011
WHACK - A - CAPSULE ASC code
titleScreen.onRelease = function()
{
this._visible = false;
startgame();
}
startgame = function()
{
for (var i = 0; i < 9; i++)
{
var nm = "m" + i;
_root[nm].onPress = function()
{
if (this._currentframe == 10)
{
this.play();
whacks++;
scoreDisplay.whack_txt.text = whacks;
doWhackAt(_xmouse, _ymouse);
}
}
_root[nm].onEnterFrame = function()
{
if (this._currentframe == 1)
{
if ((Math.random() * 100) < 1)
{
this.play();
}
}
else if (this._currentframe == 10)
{
if ((Math.random() * 100) < 10)
{
this.play();
}
}
}
}
whacks = 0;
scoreDisplay.whack_txt.text = whacks;
endTime = getTimer() + 30000;
_root.onEnterFrame = function()
{
var etime = endTime - getTimer();
if (etime <= 0)
{
scoreDisplay.time_txt.text = "Time Up";
for (var i = 0; i < 9; i++)
{
var nm = "m" + i;
delete _root[nm].onPress;
delete _root[nm].onEnterFrame;
_root[nm].stop();
delete _root.onEnterFrame;
}
}
else
{
scoreDisplay.time_txt.text = Math.ceil(etime / 1000) + " sec";
}
}
}
wcnt = 0;
doWhackAt = function(x, y)
{
var nm = "wc" + wcnt;
_root.attachMovie("whackSign", nm, wcnt + 99);
_root[nm]._x = x;
_root[nm]._y = y;
_root[nm]._xscale = _root[nm]._yscale = 60;
_root[nm].onEnterFrame = function()
{
this._alpha -= 10;
if (this._alpha <= 10)
{
delete this.onEnterFrame;
this.removeMovieClip();
}
}
wcnt++;
wcnt %= 5;
}
{
this._visible = false;
startgame();
}
startgame = function()
{
for (var i = 0; i < 9; i++)
{
var nm = "m" + i;
_root[nm].onPress = function()
{
if (this._currentframe == 10)
{
this.play();
whacks++;
scoreDisplay.whack_txt.text = whacks;
doWhackAt(_xmouse, _ymouse);
}
}
_root[nm].onEnterFrame = function()
{
if (this._currentframe == 1)
{
if ((Math.random() * 100) < 1)
{
this.play();
}
}
else if (this._currentframe == 10)
{
if ((Math.random() * 100) < 10)
{
this.play();
}
}
}
}
whacks = 0;
scoreDisplay.whack_txt.text = whacks;
endTime = getTimer() + 30000;
_root.onEnterFrame = function()
{
var etime = endTime - getTimer();
if (etime <= 0)
{
scoreDisplay.time_txt.text = "Time Up";
for (var i = 0; i < 9; i++)
{
var nm = "m" + i;
delete _root[nm].onPress;
delete _root[nm].onEnterFrame;
_root[nm].stop();
delete _root.onEnterFrame;
}
}
else
{
scoreDisplay.time_txt.text = Math.ceil(etime / 1000) + " sec";
}
}
}
wcnt = 0;
doWhackAt = function(x, y)
{
var nm = "wc" + wcnt;
_root.attachMovie("whackSign", nm, wcnt + 99);
_root[nm]._x = x;
_root[nm]._y = y;
_root[nm]._xscale = _root[nm]._yscale = 60;
_root[nm].onEnterFrame = function()
{
this._alpha -= 10;
if (this._alpha <= 10)
{
delete this.onEnterFrame;
this.removeMovieClip();
}
}
wcnt++;
wcnt %= 5;
}
Wednesday, April 6, 2011
BLOCK BREAKER ACTIONSCRIPT CODE
function buildboard ()
{
_root.createEmptyMovieClip("board", 1);
board._x = 0;
board._y = 0;
grid = new Array();
bcnt = 0;
for (var j = 4; j < 9; j++)
{
grid[j] = new Array();
for (var i = 0; i < 10; i++)
{
var nm = "block_" + j + "_" + i;
board.attachMovie("block", nm, bcnt);
board[nm]._x = i * 32;
board[nm]._y = j * 16;
var btype = (j) % 4 + 1
board[nm].gotoAndStop(btype);
grid[j][i] = btype;
bcnt++;
}
}
}
paddle.onEnterFrame = function()
{
var xpos = _xmouse;
if (xpos > (320 - (this._width / 2)))
xpos = 320 - (this._width / 2);
if (xpos < (this._width / 2))
xpos = this._width / 2;
this._x = xpos;
}
fadercnt = 0;
function makeFader(x, y)
{
var nm = "fader" + fadercnt;
board.attachMovie("fader", nm, fadercnt + 9999);
board[nm]._x = x;
board[nm]._y = y;
score+=100;
score_txt.text = score;
fadercnt++;
if (fadercnt == bcnt)
{
Mouse.show();
lives_txt.text = "YOU WIN";
delete ball.onEnterFrame;
}
}
function ballAction()
{
this._x += this.dx;
this._y += this.dy;
if (this._x < 0)
{
this._x = 0;
this.dx *= -1;
}
if (this._x > 320)
{
this._x = 320;
this.dx *= -1;
}
if (this._y < 0)
{
this._y = 0;
this.dy *= -1;
}
if (this._y > 400)
{
// Lose a life
lives--;
lives_txt.text = lives;
if (lives == 0)
{
Mouse.show();
lives_txt.text = "GAME OVER";
delete ball.onEnterFrame;
}
else
{
this._x = 160;
this._y = 200;
this.dx = 0;
this.dy = 6;
}
}
if (this._y < paddle._y && (this._y + this.dy) > paddle._y && (this._x + this.dx) > paddle._x - 41 && (this._x + this.dx) < paddle._x + 41)
{
this.dy = -6;
this.dx = (this._x - paddle._x) / 5;
}
var grdx = Math.floor(this._x / 32);
var grdy = Math.floor(this._y / 16);
var ngrdx = Math.floor((this._x + this.dx) / 32);
var ngrdy = Math.floor((this._y + this.dy) / 16);
if (grid[grdy][ngrdx] > 0)
{
grid[grdy][ngrdx] = 0;
var bnm = "block_" + grdy + "_" + ngrdx;
board[bnm].removeMovieClip();
makeFader(ngrdx * 32, grdy * 16);
this.dx *= -1;
}
if (grid[ngrdy][grdx] > 0)
{
grid[ngrdy][grdx] = 0;
var bnm = "block_" + ngrdy + "_" + grdx;
board[bnm].removeMovieClip();
makeFader(grdx * 32, ngrdy * 16);
this.dy *= -1;
}
if (grid[ngrdy][ngrdx] > 0)
{
grid[ngrdy][ngrdx] = 0;
var bnm = "block_" + ngrdy + "_" + ngrdx;
board[bnm].removeMovieClip();
makeFader(ngrdx * 32, ngrdy * 16);
this.dy *= -1;
this.dx *= -1;
}
}
function startClick()
{
buildboard();
lives = 5;
score = 0;
score_txt.text = score;
lives_txt.text = lives;
ball.onEnterFrame = ballAction;
ball._x = 160;
ball._y = 200;
ball.dx = 0;
ball.dy = 6;
Mouse.hide();
}
startButton.addEventListener("click", startClick);
{
_root.createEmptyMovieClip("board", 1);
board._x = 0;
board._y = 0;
grid = new Array();
bcnt = 0;
for (var j = 4; j < 9; j++)
{
grid[j] = new Array();
for (var i = 0; i < 10; i++)
{
var nm = "block_" + j + "_" + i;
board.attachMovie("block", nm, bcnt);
board[nm]._x = i * 32;
board[nm]._y = j * 16;
var btype = (j) % 4 + 1
board[nm].gotoAndStop(btype);
grid[j][i] = btype;
bcnt++;
}
}
}
paddle.onEnterFrame = function()
{
var xpos = _xmouse;
if (xpos > (320 - (this._width / 2)))
xpos = 320 - (this._width / 2);
if (xpos < (this._width / 2))
xpos = this._width / 2;
this._x = xpos;
}
fadercnt = 0;
function makeFader(x, y)
{
var nm = "fader" + fadercnt;
board.attachMovie("fader", nm, fadercnt + 9999);
board[nm]._x = x;
board[nm]._y = y;
score+=100;
score_txt.text = score;
fadercnt++;
if (fadercnt == bcnt)
{
Mouse.show();
lives_txt.text = "YOU WIN";
delete ball.onEnterFrame;
}
}
function ballAction()
{
this._x += this.dx;
this._y += this.dy;
if (this._x < 0)
{
this._x = 0;
this.dx *= -1;
}
if (this._x > 320)
{
this._x = 320;
this.dx *= -1;
}
if (this._y < 0)
{
this._y = 0;
this.dy *= -1;
}
if (this._y > 400)
{
// Lose a life
lives--;
lives_txt.text = lives;
if (lives == 0)
{
Mouse.show();
lives_txt.text = "GAME OVER";
delete ball.onEnterFrame;
}
else
{
this._x = 160;
this._y = 200;
this.dx = 0;
this.dy = 6;
}
}
if (this._y < paddle._y && (this._y + this.dy) > paddle._y && (this._x + this.dx) > paddle._x - 41 && (this._x + this.dx) < paddle._x + 41)
{
this.dy = -6;
this.dx = (this._x - paddle._x) / 5;
}
var grdx = Math.floor(this._x / 32);
var grdy = Math.floor(this._y / 16);
var ngrdx = Math.floor((this._x + this.dx) / 32);
var ngrdy = Math.floor((this._y + this.dy) / 16);
if (grid[grdy][ngrdx] > 0)
{
grid[grdy][ngrdx] = 0;
var bnm = "block_" + grdy + "_" + ngrdx;
board[bnm].removeMovieClip();
makeFader(ngrdx * 32, grdy * 16);
this.dx *= -1;
}
if (grid[ngrdy][grdx] > 0)
{
grid[ngrdy][grdx] = 0;
var bnm = "block_" + ngrdy + "_" + grdx;
board[bnm].removeMovieClip();
makeFader(grdx * 32, ngrdy * 16);
this.dy *= -1;
}
if (grid[ngrdy][ngrdx] > 0)
{
grid[ngrdy][ngrdx] = 0;
var bnm = "block_" + ngrdy + "_" + ngrdx;
board[bnm].removeMovieClip();
makeFader(ngrdx * 32, ngrdy * 16);
this.dy *= -1;
this.dx *= -1;
}
}
function startClick()
{
buildboard();
lives = 5;
score = 0;
score_txt.text = score;
lives_txt.text = lives;
ball.onEnterFrame = ballAction;
ball._x = 160;
ball._y = 200;
ball.dx = 0;
ball.dy = 6;
Mouse.hide();
}
startButton.addEventListener("click", startClick);
Subscribe to:
Posts (Atom)