Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- blockSize = 8;
- gameHeight = 70;
- gameWidth = 50;
- TRON_BLOCK = 1;
- keyListener = new Object();
- keyListener.onKeyDown = function() {
- var keyCode = Key.getCode();
- if (keyCode > 36 && keyCode < 41) {
- if (game.onEnterFrame != undefined) {
- if (keyCode-37 != turnQueue[0]) {
- turnQueue.unshift(keyCode-37);
- }
- }
- } else if (keyCode == 32) {
- if (!gameRunning) {
- startGame();
- }
- }
- };
- Key.addListener(keyListener);
- Mouse.addListener(mouseListener);
- function startGame() {
- x = int(gameWidth/2);
- y = gameHeight-2;
- xVelocity = [-1, 0, 1, 0];
- yVelocity = [0, -1, 0, 1];
- map = new Array();
- for (var n=0;n<gameWidth;n++) {
- map[n] = new Array();
- }
- turnQueue = new Array();
- game.createEmptyMovieClip("s", 2);
- tronBlockCounter = 0;
- currentDirection = 1;
- game.onEnterFrame = main;
- gameRunning = true;
- }
- function gameOver() {
- delete game.onEnterFrame;
- gameRunning = false;
- }
- function main() {
- if (turnQueue.length > 0) {
- var dir = turnQueue.pop();
- if (dir % 2 != currentDirection % 2) {
- currentDirection = dir;
- }
- }
- x += xVelocity[currentDirection];
- y += yVelocity[currentDirection];
- if (map[x][y] != TRON_BLOCK && x > -1 && x < gameWidth && y > -1 && y < gameHeight) {
- game.s.attachMovie("tronMC", tronBlockCounter, tronBlockCounter, {_x: x*blockSize, _y: y*blockSize});
- tronBlockCounter++;
- map[x][y] = TRON_BLOCK;
- } else {
- gameOver();
- }
- }
Advertisement