stop();
startGame_btn.addEventListener(MouseEvent.CLICK , startGameFun);
helpGame_btn.addEventListener(MouseEvent.CLICK , helpGameFun);
function startGameFun(e:MouseEvent)
{
play();
}
function helpGameFun(e:MouseEvent)
{
//TweenLite.to(helpgame_mc , 1.0 , {x:stage.stageWidth/2 , y:stage.stageHeight/2});
helpgame_mc.x = stage.stageWidth/2;
helpgame_mc.y = stage.stageHeight/2;
helpgame_mc.play();
}
stop();
var coneArray:Array = new Array(20);
var boneArray:Array = new Array(2);
var her:Hero = new Hero();
for(var i:int = new int(0) ; i<coneArray.length ; i++)
{
coneArray[i] = new Cone();
}
for(i = 0; i<boneArray.length ; i++)
{
boneArray[i] = new Bone();
}
var coneMoveTimeArray:Array = new Array(coneArray.length);
var boneMoveTimeArray:Array = new Array(boneArray.length);
setGame();
function setGame()
{
time_tex.text = "0";
score_tex.text = "0";
for(var i:int = new int(0) ; i<coneArray.length ; i++)
{
coneArray[i].x = Math.abs(Math.random())*stage.stageWidth;
coneArray[i].y = - Math.abs(Math.random()*stage.stageHeight);
coneArray[i].scaleX = coneArray[i].scaleY = Math.abs(Math.random()*0.5) +0.3;
coneMoveTimeArray[i] = new int(Math.abs(Math.random()*5) +1);
}
for(i = 0; i<boneArray.length ; i++)
{
boneArray[i].x = Math.abs(Math.random())*stage.stageWidth;
boneArray[i].y = - Math.abs(Math.random()*stage.stageHeight);
boneArray[i].scaleX = boneArray[i].scaleY = Math.abs(Math.random()*0.5) +0.3;
boneMoveTimeArray[i] = new int(Math.abs(Math.random()*5) +1);
}
her.x = stage.stageWidth/2;
her.y = stage.stageHeight - her.height;
addChildAt(her , 5);
for(i = 0; i < coneArray.length ; i++)
{
addChildAt(coneArray[i] , 1);
}
for(i = 0; i < boneArray.length ; i++)
{
addChildAt(boneArray[i] , 1);
}
}
//=========================================================================================
var time:Timer = new Timer(100);
time.addEventListener("timer" , RePain);
time.start();
function RePain(e:TimerEvent)
{
for(var i = 0; i < coneArray.length ; i++)
{
coneArray[i].y += 0.5*9.8*(coneMoveTimeArray[i]++);
if(coneArray[i].y >= stage.stageHeight)
{
coneArray[i].x = Math.abs(Math.random())*stage.stageWidth;
coneArray[i].y = - Math.abs(Math.random()*stage.stageHeight);
coneArray[i].scaleX = coneArray[i].scaleY = Math.abs(Math.random()*0.5) +0.3;
coneMoveTimeArray[i] = new int(Math.abs(Math.random()*5) +1);
}
if(her.hitTestObject(coneArray[i]))
{
coneArray[i].x = Math.abs(Math.random())*stage.stageWidth;
coneArray[i].y = - Math.abs(Math.random()*stage.stageHeight);
coneArray[i].scaleX = coneArray[i].scaleY = Math.abs(Math.random()*0.5) +0.3;
coneMoveTimeArray[i] = new int(Math.abs(Math.random()*5) +1);
score_tex.text = (Number(score_tex.text)+5).toString();
}
}
for(i = 0; i < boneArray.length ; i++)
{
boneArray[i].y += 0.5*9.8*(boneMoveTimeArray[i]++);
if(boneArray[i].y >= stage.stageHeight)
{
boneArray[i].x = Math.abs(Math.random())*stage.stageWidth;
boneArray[i].y = - Math.abs(Math.random()*stage.stageHeight);
boneArray[i].scaleX = boneArray[i].scaleY = Math.abs(Math.random()*0.5) +0.3;
boneMoveTimeArray[i] = new int(Math.abs(Math.random()*5) +1);
}
if(her.hitTestObject(boneArray[i]))
{
GameOver();
}
}
time_tex.text = (Number(time_tex.text)+1).toString();
}
//==================================================
stage.addEventListener(KeyboardEvent.KEY_DOWN , keyboardFun);
stage.addEventListener(KeyboardEvent.KEY_DOWN , keyboardFun);
function keyboardFun(e:KeyboardEvent)
{
if(e.keyCode == 37)
{
her.x-=10;
}
else if(e.keyCode == 39)
{
her.x +=10;
}
}
//================================================================
function GameOver()
{
time.stop();
her.alpha = 0.2;
for(var i = 0; i < coneArray.length ; i++)
{
coneArray[i].alpha = 0.8;
}
for(i = 0; i < boneArray.length ; i++)
{
//removeChild(boneArray[i]);
boneArray[i].alpha = 0.8;
}
returnmenu_btn.y += stage.stageWidth/2-100;
again_btn.y += stage.stageWidth/2-100;
}
//==========================================================
returnmenu_btn.addEventListener(MouseEvent.CLICK , returnmenuFun);
again_btn.addEventListener(MouseEvent.CLICK , againFun);
function returnmenuFun(e:MouseEvent)
{
gotoAndStop(1);
removeChild(her);
for(var i = 0; i < coneArray.length ; i++)
{
removeChild(coneArray[i]);
}
for(i = 0; i < boneArray.length ; i++)
{
removeChild(boneArray[i]);
}
fscommand("quit");
}
function againFun(e:MouseEvent)
{
time.reset();
time.start();
setGame();
returnmenu_btn.y -= stage.stageWidth/2-100;
again_btn.y -= stage.stageWidth/2-100;
her.alpha = 1.0;
for(var i = 0; i < coneArray.length ; i++)
{
coneArray[i].alpha = 1.0;
}
for(i = 0; i < boneArray.length ; i++)
{
//removeChild(boneArray[i]);
boneArray[i].alpha = 1.0;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/75798.html
標籤:其它游戲引擎
