Frame 1
var lastmoved = 0;
var counter = 0;
var max_time = 200;
var player = new GridObject(player_mc, {}, {x:1, y:0});
var baddies = new Array();
var nextMove = -1;
var keyListener_obj = new Object();
var soundOn = true;
var playing = false;
Key.addListener(keyListener_obj);
keyListener_obj.onKeyDown = function () {
switch (Key.getCode()) {
case 38 :
nextMove = GridObject.UP;
return;
case 40 :
nextMove = GridObject.DOWN;
return;
case 37 :
nextMove = GridObject.LEFT;
return;
case 39 :
nextMove = GridObject.RIGHT;
return;
case 13 :
if (!alert._visible) {
break;
}
alert.retry_btn.onRelease();
}
};
alert._visible = false;
welcome._visible = false;
moveGrid = function (obj) {
obj.mc._x = (35 + (35 * obj.pos.x)) + (0.17 * ((max_time / 2) - obj.mc._xscale));
obj.mc._y = (350 - (35 * obj.pos.y)) + (0.17 * ((max_time / 2) - obj.mc._xscale));
};
movePossible = function (move, pos) {
switch (move) {
case GridObject.UP :
return(pos.y != 9);
case GridObject.DOWN :
return(pos.y != 0);
case GridObject.LEFT :
return(pos.x != 0);
case GridObject.RIGHT :
return(pos.x != 2);
}
return(false);
};
checkWin = function () {
if ((player.pos.x == 1) && (player.pos.y == 9)) {
for (var _local1 in player.moves) {
}
newRound();
}
};
transformMove = function (move) {
if (move == GridObject.UP) {
return(GridObject.DOWN);
}
if (move == GridObject.DOWN) {
return(GridObject.UP);
}
return(move);
};
makeAlert = function (message) {
playSound(2);
retryRound();
alert._visible = true;
alert.message.text = message;
playing = false;
};
playSound = function (num) {
if (soundOn) {
kirupaSound = new Sound(this);
switch (num) {
case 0 :
kirupaSound.attachSound("pop");
break;
case 1 :
kirupaSound.attachSound("cling");
break;
case 2 :
kirupaSound.attachSound("clong");
}
kirupaSound.start();
}
};
start = function () {
welcome._visible = true;
};
reset = function () {
var _local1 = 0;
while (_local1 < baddies.length) {
removeMovieClip(baddies[_local1].mc);
_local1++;
}
baddies = new Array();
retryRound();
};
retryRound = function () {
var _local1 = 0;
while (_local1 < baddies.length) {
baddies[_local1].pos = {x:1, y:9};
moveGrid(baddies[_local1]);
_local1++;
}
counter = 0;
lastmoved = 0;
nextMove = -1;
player.pos = {x:1, y:0};
player.moves = {};
moveGrid(player);
level_txt.text = baddies.length;
};
newRound = function () {
var _local3 = "bad" + baddies.length;
duplicateMovieClip (bad, _local3, this.getNextHighestDepth());
baddies.push(new GridObject(_root[_local3], player.moves, {x:1, y:9}));
_root[_local3].number.text = baddies.length;
player.moves = new Object();
retryRound();
playSound(1);
};
alert.retry_btn.onRelease = function () {
alert._visible = false;
playing = true;
retryRound();
playSound(0);
};
alert.reset_btn.onRelease = function () {
alert._visible = false;
playing = true;
reset();
playSound(0);
};
alert.sound_btn.onRelease = function () {
soundOn = !soundOn;
alert.wave.gotoAndStop(2);
if (soundOn) {
alert.wave.gotoAndStop(1);
}
};
welcome.start_btn.onRelease = function () {
welcome._visible = false;
alert.retry_btn.onRelease();
};
this.onEnterFrame = function () {
if (playing) {
counter++;
var _local2 = max_time - counter;
player_mc._xscale = _local2 / 2;
player_mc._yscale = _local2 / 2;
moveGrid(player);
time_txt.text = _local2;
if (_local2 == 0) {
makeAlert("Out of Time!");
}
checkWin();
var _local1 = 0;
while (_local1 < baddies.length) {
if (baddies[_local1].timeToMove(counter)) {
if ((baddies[_local1].pos.x < 0) || (baddies[_local1].pos.y > 9)) {
baddies[_local1].traceMoves();
}
moveGrid(baddies[_local1]);
if (player.checkCollision(baddies[_local1])) {
makeAlert("Collision!");
}
}
_local1++;
}
if (movePossible(nextMove, player.pos)) {
player.addMove(counter, transformMove(nextMove));
player.makeMove(nextMove);
lastmoved = counter;
moveGrid(player);
nextMove = -1;
_local1 = 0;
while (_local1 < baddies.length) {
if (player.checkCollision(baddies[_local1])) {
makeAlert("Collision!");
}
_local1++;
}
}
}
};
start();
Symbol 22 Button
on (release) {
getURL ("http://www.rrrrthats5rs.com", "_blank");
}
Symbol 35 MovieClip Frame 1
stop();
Symbol 35 MovieClip Frame 2
stop();
Symbol 40 MovieClip [__Packages.GridObject] Frame 0
class GridObject extends Object
{
var mc, moves, pos;
function GridObject (mc, moves, pos) {
super();
this.mc = mc;
if (!moves) {
moves = new Object();
}
if (!pos) {
pos = {x:0, y:0};
}
this.moves = moves;
this.pos = pos;
}
function addMove(counter, move) {
moves["c" + counter] = move;
}
function checkCollision(other) {
if ((pos.x == other.pos.x) && (pos.y == other.pos.y)) {
return(true);
}
return(false);
}
function makeMove(move) {
switch (move) {
case UP :
pos.y = pos.y + 1;
break;
case DOWN :
pos.y = pos.y - 1;
break;
case LEFT :
pos.x = pos.x - 1;
break;
case RIGHT :
pos.x = pos.x + 1;
}
}
function timeToMove(counter) {
var _local2 = moves["c" + counter];
if (_local2 != undefined) {
makeMove(_local2);
return(true);
}
return(false);
}
function traceMoves() {
for (var _local2 in moves) {
trace((("moves." + _local2) + " = ") + moves[_local2]);
}
}
static var UP = 0;
static var DOWN = 1;
static var LEFT = 2;
static var RIGHT = 3;
}