Frame 1
function addPiece() {
var _local2 = this.attachMovie("piece", "piece" + aPieceList.length, aPieceList.length);
_local2._x = aPieceList[aPieceList.length - 1]._x;
_local2._y = aPieceList[aPieceList.length - 1]._y;
aPieceList.push(_local2);
}
function moveFood() {
var _local2 = true;
while (_local2) {
food._x = Math.floor(Math.random() * uwh) * unit;
food._y = Math.floor(Math.random() * uwh) * unit;
_local2 = false;
var _local1 = 0;
while (_local1 < aPieceList.length) {
if ((aPieceList[_local1]._x == food._x) && (aPieceList[_local1]._y == food._y)) {
_local2 = true;
}
_local1++;
}
}
}
function gameOver() {
delete this.onEnterFrame;
tScore.text = "GAME OVER SCORE: " + score;
canMove = false;
}
function startGame() {
var _local2 = aPieceList.length - 1;
while (_local2 >= 0) {
aPieceList[_local2].removeMovieClip();
aPieceList.pop();
_local2--;
}
score = 0;
var _local4 = this.attachMovie("piece", "piece" + aPieceList.length, aPieceList.length);
aPieceList.push(_local4);
_local4._x = 10 * unit;
_local4._y = 10 * unit;
var food = this.attachMovie("food", "food", -1);
var _local5 = 0;
moveFood();
var _local3 = 3;
_local2 = 1;
while (_local2 < _local3) {
addPiece();
_local2++;
}
this.onEnterFrame = function () {
canMove = true;
tScore.text = score;
var _local1 = aPieceList.length - 1;
while (_local1 > 0) {
aPieceList[_local1]._x = aPieceList[_local1 - 1]._x;
aPieceList[_local1]._y = aPieceList[_local1 - 1]._y;
_local1--;
}
if (dir == 0) {
aPieceList[0]._y = aPieceList[0]._y - unit;
} else if (dir == 1) {
aPieceList[0]._x = aPieceList[0]._x - unit;
} else if (dir == 2) {
aPieceList[0]._y = aPieceList[0]._y + unit;
} else if (dir == 3) {
aPieceList[0]._x = aPieceList[0]._x + unit;
}
if ((aPieceList[0]._y / unit) == 20) {
aPieceList[0]._y = 0;
} else if ((aPieceList[0]._y / unit) == -1) {
aPieceList[0]._y = 19 * unit;
} else if ((aPieceList[0]._x / unit) == -1) {
aPieceList[0]._x = 19 * unit;
} else if ((aPieceList[0]._x / unit) == 20) {
aPieceList[0]._x = 0;
}
if ((aPieceList[0]._x == food._x) && (aPieceList[0]._y == food._y)) {
score = score + ((10 * aPieceList.length) / 2);
moveFood();
addPiece();
}
_local1 = 1;
while (_local1 < aPieceList.length) {
if ((aPieceList[0]._x == aPieceList[_local1]._x) && (aPieceList[0]._y == aPieceList[_local1]._y)) {
gameOver();
}
_local1++;
}
};
}
var unit = 15;
var uwh = 20;
var canMove = false;
var dir = 2;
var score = 0;
aPieceList = new Array();
mouseListener = new Object();
mouseListener.onMouseDown = function () {
if (!canMove) {
canMove = true;
startGame();
}
};
Mouse.addListener(mouseListener);
k = new Object();
k.onKeyDown = function () {
var _local1 = Key.getCode();
if (((_local1 == 38) && (dir != 2)) && (canMove)) {
dir = 0;
canMove = false;
} else if (((_local1 == 37) && (dir != 3)) && (canMove)) {
dir = 1;
canMove = false;
} else if (((_local1 == 40) && (dir != 0)) && (canMove)) {
dir = 2;
canMove = false;
} else if (((_local1 == 39) && (dir != 1)) && (canMove)) {
dir = 3;
canMove = false;
}
};
Key.addListener(k);