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 k=Key.getCode();
if(k==Key.UP&&dir!=2&& canMove)
{
dir=0;a
canMove=false;
}
else if(k==Key.LEFT&&dir!=3&&canMove)
{
dir=1;
canMove=false;
}
else if(k==Key.DOWN&&dir!=0&&canMove)
{
dir=2;
canMove=false;
}
else if(k==Key.RIGHT&&dir!=1&&canMove)
{
dir=3;
canMove=false;
}
};
Key.addLisener(k);
function addPiece()
{
var p=this.attachMovie("piece","piece"+aPieceList.length,aPieceList.length);
p._x=aPieceList[aPieceList.length-1]._x;
p._y=aPieceList[aPieceList.length-1]._y;
aPiecelist.push(p);
}
function moveFood()
{
var movelt=true;
while(moveIt)
{
food._x=Math.floor(Math.random()*uwh)*unit;
food._y=Math.floor(Math.random()*uwh)*unit;
moveIt=false;
for(var i=0;i<aPieceList.length;i++)
{
if(aPieceList._x==food._x&&aPieceList._y==food._y)
{
moveIt=true;
}
}
}
}
function gameOver()
{
delete this.onEnterFrame;
tscore.text="You Lose. Score:"+score;
canMove=false;
}
function startGame()
{
for(vari=aPieceList.length-1;i>=0;i--)
{
aPieceList.removeMovieClip();
aPieceList.pop();
}
score=0;
var p=this.attachMovie("piece","piece"+aPieceList.lengh,aPieceList.length);
aPiecelist.push(p);
p._x=10*unit;
p._y=10*unit;
var food=this.attachMovie("food","food",-1);
var c=0
moveFood();
var startingLength=3;
for(var i=1;i<startingLength;i++)
{
addPiece();
}
this.onEnterFrame=function()
{
canMove=true;
tScore.text=score;
for(var i=aPieceList.length-1;i>0;i--)
{
aPieceList._x=aPieceList[i-1]._x;
aPieceList._y=aPieceList[i-1]._y;
}
if(dir==0)
{
aPieceList[0]._y-=unit;
}
else if(dir==1)
{
aPieceList[0]._x-=unit;
}
else if(dir==2)
{
aPieceList[0]._y+=unit
}
else if(dir==3)
{
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+=10*aPieceList.length/2;
moveFood();
addPiece();
}
for(var i=1;i<aPieceList.length;i++)
{
if(aPieceList[0]._x==aPieceList._x&&aPieceList[0].y==
aPieceList._y)
{
gameOver();
}
}
};
}
View User's Journal
stuff
vampirekay1
Community Member |
check out my guild rising moon ( a roleplay guild with games and more)
[img:e7bae8a884]http://i428.photobucket.com/albums/qq5/vampirekay/lunapic-125440003631067.jpg[/img:e7bae8a884]
http://www.gaiaonline.com/guilds/?guild_id=261249&_gaia_t_=1272
[img:e7bae8a884]http://i428.photobucket.com/albums/qq5/vampirekay/lunapic-125440003631067.jpg[/img:e7bae8a884]
http://www.gaiaonline.com/guilds/?guild_id=261249&_gaia_t_=1272