AS3 - 迷宫游戏 - 显示完整屏幕的麻烦

时间:2014-05-05 01:32:23

标签: actionscript-3 flash actionscript

我的AS3代码有点麻烦,我做了一个简单的迷宫游戏,你必须收集四个“DNA”,一旦你收集了它们,就会弹出一个完整的屏幕说祝贺。

请你能帮我解决这个问题吗,一旦用户收集了所有四个DNA对象(实例名称为“DNA1”,“DNA2”,“DNA3”和“DNA4”,我想要“完整屏幕” “移动到X = 512,Y = 384的位置的对象。

非常感谢任何帮助!

我在下面提供了我的代码。希望你能帮助我。

import flash.events.KeyboardEvent;
import flash.events.Event;

stage.addEventListener(KeyboardEvent.KEY_DOWN, checkkeysdown);
stage.addEventListener(KeyboardEvent.KEY_UP, checkkeysup);

var moveup:Boolean=false;
var movedown:Boolean=false;
var moveleft:Boolean=false;
var moveright:Boolean=false;

var speed:Number=5;



function checkkeysdown(mykey:KeyboardEvent) 
{
if (mykey.keyCode==Keyboard.UP)
{ 
moveup=true;
}

if (mykey.keyCode==Keyboard.DOWN)
{ 
movedown=true;
}

if (mykey.keyCode==Keyboard.LEFT)
{ 
moveleft=true;
}

if (mykey.keyCode==Keyboard.RIGHT)
{ 
moveright=true;
}
}




function checkkeysup(mykey:KeyboardEvent) 
{
if (mykey.keyCode==Keyboard.UP)
{ 
moveup=false;
}

if (mykey.keyCode==Keyboard.DOWN)
{ 
movedown=false;
}

if (mykey.keyCode==Keyboard.LEFT)
{ 
moveleft=false;
}

if (mykey.keyCode==Keyboard.RIGHT)
{ 
moveright=false;
}
}




stage.addEventListener(Event.ENTER_FRAME, gameloop);


function gameloop (evt:Event)
{
if (moveup==true) 
{
if (!maze.hitTestPoint(player.x,player.y-5,true))
{
player.y-=speed;    
}
}

if (movedown==true) 
{
if (!maze.hitTestPoint(player.x,player.y+5,true))
{
player.y+=speed;    
}
}

if (moveleft==true) 
{
if (!maze.hitTestPoint(player.x-5,player.y,true))
{
player.x-=speed;    
}
}

if (moveright==true) 
{
if (!maze.hitTestPoint(player.x+5,player.y,true))
{
player.x+=speed;    
}
}




pickUp();
}

function pickUp()
{
if (player.hitTestObject(DNA1))
{
DNA1.x=5000;
}

if (player.hitTestObject(DNA2))
{
DNA2.x=5000;
}

if (player.hitTestObject(DNA3))
{
DNA3.x=5000;
}

if (player.hitTestObject(DNA4))
{
DNA4.x=5000;
}

}

1 个答案:

答案 0 :(得分:2)

将其添加到pickUp函数的末尾。

if ( DNA1.x==5000 && DNA2.x==5000 && DNA3.x==5000 && DNA4.x==5000){
   completeScreen.x = 512;
   completeScreen.y = 384;
}

这应该可行,但更好的方法可能是添加一些布尔值来重新检查,而不是像这些。

var DNA1Collected:Boolean = false;
var DNA2Collected:Boolean = false;
var DNA3Collected:Boolean = false;
var DNA4Collected:Boolean = false;

然后,当玩家收集它们时,您可以将它们设置为true。如果你想要做一些事情,除了将x移动到-5000,你的if语句仍将有效。