Frame 2
function startGame() {
x = int(gameWidth / 2);
y = gameHeight - 2;
xVelocity = [-1, 0, 1, 0];
yVelocity = [0, -1, 0, 1];
map = new Array();
var _local1 = 0;
while (_local1 < gameWidth) {
map[_local1] = new Array();
_local1++;
}
turnQueue = new Array();
game.createEmptyMovieClip("food", 1);
game.createEmptyMovieClip("s", 2);
scoreTextField.text = "Score: 0";
foodCounter = 0;
snakeBlockCounter = 0;
currentDirection = 1;
snakeEraseCounter = -1;
score = 0;
placeFood("new");
textMC.gotoAndStop("hide");
game.onEnterFrame = main;
gameRunning = true;
}
function main() {
if (turnQueue.length > 0) {
var _local2 = turnQueue.pop();
if ((_local2 % 2) != (currentDirection % 2)) {
currentDirection = _local2;
}
}
x = x + xVelocity[currentDirection];
y = y + yVelocity[currentDirection];
if (((((map[x][y] != SNAKE_BLOCK) && (x > -1)) && (x < gameWidth)) && (y > -1)) && (y < gameHeight)) {
game.s.attachMovie("snakeMC", snakeBlockCounter, snakeBlockCounter, {_x:x * blockSize, _y:y * blockSize});
snakeBlockCounter++;
if (typeof(map[x][y]) == "movieclip") {
score = score + 10;
scoreTextField.text = "Score: " + score;
snakeEraseCounter = snakeEraseCounter - 1;
placeFood(map[x][y]);
}
map[x][y] = SNAKE_BLOCK;
var _local1 = game.s[snakeEraseCounter];
if (_local1) {
delete map[_local1._x / blockSize][_local1._y / blockSize];
_local1.removeMovieClip();
}
snakeEraseCounter++;
} else {
gameOver();
}
}
function gameOver() {
textMC.gotoAndStop("gameOver");
delete game.onEnterFrame;
gameRunning = false;
}
function placeFood(foodMC) {
var _local1 = foodMC;
do {
var xFood = random(gameWidth);
var yFood = random(gameHeight);
} while (map[xFood][yFood]);
if (_local1 == "new") {
_local1 = game.food.attachMovie("foodMC", foodCounter, foodCounter);
foodCounter++;
}
_local1._x = xFood * blockSize;
_local1._y = yFood * blockSize;
map[xFood][yFood] = _local1;
}
stop();
blockSize = 10;
gameHeight = 25;
gameWidth = 44;
SNAKE_BLOCK = 1;
keyListener = new Object();
keyListener.onKeyDown = function () {
var _local1 = Key.getCode();
if ((_local1 > 36) && (_local1 < 41)) {
if (game.onEnterFrame != undefined) {
if ((_local1 - 37) != turnQueue[0]) {
turnQueue.unshift(_local1 - 37);
}
}
} else if (_local1 == 32) {
if (!gameRunning) {
startGame();
}
} else if (_local1 == 80) {
if (gameRunning) {
if (game.onEnterFrame) {
delete game.onEnterFrame;
textMC.gotoAndStop("paused");
} else {
game.onEnterFrame = main;
textMC.gotoAndStop("hide");
}
}
}
};
Key.addListener(keyListener);
Symbol 19 Button
on (release) {
_root.play();
}
Symbol 20 MovieClip Frame 1
_root.stop();
PercentLoaded = (_root.getBytesLoaded() / _root.getBytesTotal()) * 100;
if (PercentLoaded != 100) {
setProperty(bar, _xscale , PercentLoaded);
} else {
gotoAndStop ("loaded");
}
Symbol 20 MovieClip Frame 2
gotoAndPlay (1);
Symbol 47 MovieClip Frame 1
stop();