Return to Kroll Web Design home page Return to Flash / ActionScript page
« Return

Action Script 2 code for the 'Maze Craze' Flash game:

//------------------------------------------------------------	
//INTRO PAGE: GAME WILL BEGIN IF USER CLICKS ON THE 'START GAME' BUTTON:

start_btn.onRelease = function() {
	gotoAndPlay("game");
}


//------------------------------------------------------------	
//THIS IS THE 'start' SECTION: INITIALIZATION OF ARRAYS AND OTHER DATA.  ALSO, THIS IS WHERE RE-USABLE FUNCTIONS ARE LOCATED:

var speed:Number = 50;
var badGuyDirection:String = "left";
var nbrOfLives:Number = 5;
_root.nbrOfLives_txt.text = nbrOfLives;
var timeOut:Boolean = false;
var currLevel:Number = 1;
var topLevel:Number = 3;
var nbrOfCoins:Number = 0;
var score:Number = 0;
_root.score_txt.text = score;

function addCoins() {
	for (i=0; i 0)) return false;
	}	
	return true;		
}

function rightIsOpen(token) {    
	var currArray:Array;
	//Determine which of the row barrier arrays to look at,
	//based on current location of "token":	
	row = (token._y + 25) / 50;
	//build the array name for that row:
	arrayName = "row" + row; 	
	currArray = eval(arrayName);	
	for (i=0; i 0)) return false;
	}	
	return true;	
}

function upIsOpen(token) {
	var currArray:Array;
	//Determine which of the row barrier arrays to look at,
	//based on current location of "me":	
	col = (token._x + 25) / 50;
	//build the array name for that column:
	arrayName = "col" + col; 	
	currArray = eval(arrayName);	
	for (i=0; i 0)) return false;
	}	
	return true;		
}

function downIsOpen(token) {
	var currArray:Array;
	//Determine which of the row barrier arrays to look at,
	//based on current location of "token":	
	col = (token._x + 25) / 50;
	//build the array name for that column:
	arrayName = "col" + col;	
	currArray = eval(arrayName);	
	for (i=0; i 0)) return false;
	}	
	return true;		
}	

//------------------------------------------------------------	
//THIS IS THE 'level1' SECTION:

_root.levelNbr_txt.text = currLevel;

this.attachMovie("me","me",getNextHighestDepth(),{_x:25,_y:25});
this.attachMovie("badGuy","badGuy1",getNextHighestDepth(),{_x:475,_y:325});

/*
These arrays determine where the maze walls are.
With row2, for example:
"0" refers to the left border 
"4" refers to the maze wall from x:200,y:50 to x:200,y:100 
"9" refers to the maze wall from x:450,y:50 to x:450,y:100
"10" refers to the right border 
*/

var row1 = new Array(0,10);						 
var row2 = new Array(0,4,9,10);
var row3 = new Array(0,1,2,5,9,10);
var row4 = new Array(0,1,2,3,8,9,10);
var row5 = new Array(0,1,2,3,4,5,7,9,10);
var row6 = new Array(0,1,4,5,9,10);
var row7 = new Array(0,1,5,10);
var row8 = new Array(0,10);

var col1 = new Array(0,8);
var col2 = new Array(0,1,7,8);
var col3 = new Array(0,1,5,6,7,8);	
var col4 = new Array(0,1,3,6,7,8);	
var col5 = new Array(0,1,7,8);	
var col6 = new Array(0,1,2,4,7,8);	
var col7 = new Array(0,1,2,3,4,7,8);	
var col8 = new Array(0,1,3,5,7,8);	
var col9 = new Array(0,1,4,7,8);	
var col10 = new Array(0,8);

var coinArrayX = new Array(475,325,225,375,75,325);
var coinArrayY = new Array(25,75,175,200,325,375);

addCoins();

onEnterFrame = function() { 
if (timeOut == false)
{
    if (me.hitTest(badGuy1)) nextLife();
		
    if (Key.isDown(Key.LEFT)  && leftIsOpen(me))  me._x -= speed; 		
	if (Key.isDown(Key.RIGHT) && rightIsOpen(me)) me._x += speed;	
	if (Key.isDown(Key.UP)    && upIsOpen(me))    me._y -= speed;
	if (Key.isDown(Key.DOWN)  && downIsOpen(me))  me._y += speed;
	
	checkForCoinWin();
	
	moveBadGuy(badGuy1);
}	
}

stop();


//------------------------------------------------------------	
//THIS IS THE 'level2' SECTION:

_root.levelNbr_txt.text = currLevel;

row1 = [0,10];		
row2 = [0,4,6,9,10];		
row3 = [0,1,2,5,6,7,8,9,10];		
row4 = [0,1,4,7,8,9,10];		
row5 = [0,1,8,9,10];		
row6 = [0,1,4,5,6,9,10];		
row7 = [0,3,6,8,10];		
row8 = [0,8,10];		

col1 = [0,8];
col2 = [0,1,6,8];
col3 = [0,1,3,4,5,6,8];
col4 = [0,1,3,4,5,7,8];
col5 = [0,2,4,6,7,8];
col6 = [0,3,4,7,8];
col7 = [0,1,4,6,8];
col8 = [0,1,2,5,6,8];
col9 = [0,1,8];
col10 = [0,8];

var coinArrayX = new Array(75,475,325,225,375,225,275, 75,325);
var coinArrayY = new Array(25, 25, 75,175,200,325,125,325,375);

addCoins();

onEnterFrame = function() { 
if (timeOut == false)
{
    if (me.hitTest(badGuy1)) nextLife();
			
    if (Key.isDown(Key.LEFT)  && leftIsOpen(me))  me._x -= speed; 		
	if (Key.isDown(Key.RIGHT) && rightIsOpen(me)) me._x += speed;	
	if (Key.isDown(Key.UP)    && upIsOpen(me))    me._y -= speed;
	if (Key.isDown(Key.DOWN)  && downIsOpen(me))  me._y += speed;
	
	checkForCoinWin();
	
	moveBadGuy(badGuy1);	
}	
}

stop();


//------------------------------------------------------------	
//THIS IS THE 'level3' SECTION:

_root.levelNbr_txt.text = currLevel;

this.attachMovie("badGuy","badGuy2",getNextHighestDepth(),{_x:475,_y:225});

row1 = [0,10];		
row2 = [0,10];		
row3 = [0,10];		
row4 = [0,10];		
row5 = [0,10];		
row6 = [0,10];		
row7 = [0,10];		
row8 = [0,10];		

col1 = [0,8];
col2 = [0,8];
col3 = [0,8];
col4 = [0,8];
col5 = [0,8];
col6 = [0,8];
col7 = [0,8];
col8 = [0,8];
col9 = [0,8];
col10 = [0,8];

var coinArrayX = new Array(75,475,325,225,375,225,275, 75,325);
var coinArrayY = new Array(25, 25, 75,175,200,325,125,325,375);

addCoins();

onEnterFrame = function() { 
if (timeOut == false)
{
    if (me.hitTest(badGuy1)) nextLife();
	if (me.hitTest(badGuy2)) nextLife();
		
    if (Key.isDown(Key.LEFT)  && leftIsOpen(me))  me._x -= speed; 		
	if (Key.isDown(Key.RIGHT) && rightIsOpen(me)) me._x += speed;	
	if (Key.isDown(Key.UP)    && upIsOpen(me))    me._y -= speed;
	if (Key.isDown(Key.DOWN)  && downIsOpen(me))  me._y += speed;
	
	checkForCoinWin();
	
	moveBadGuy(badGuy1);
	moveBadGuy(badGuy2);	
}	
}

stop();


//------------------------------------------------------------	
//THIS IS THE 'gameOver' SECTION:

stop();

playAgain_btn.onRelease = function() {
	gotoAndPlay("start");
}


//------------------------------------------------------------	
//THIS IS THE 'gameOverWin' SECTION:

stop();

playAgain_btn.onRelease = function() {
	gotoAndPlay("start");
}



©2009 Kroll Web Design    davidarthurkroll@verizon.net    781.449.2129

Valid XHTML 1.0 Transitional Valid CSS!