0

我对编码非常陌生,并且无法完成学校迷你游戏类型项目的最后一点。

所以这是该程序到目前为止的样子:http: //aaronmillard.com/dir/wp-content/uploads/2013/08/Google-Doodle_Roomba.swf

现在我想要程序做的是当 Roomba 驶过它时“真空”谷歌。实现这一点(我认为)的最简单方法是在带有谷歌徽标的地毯层下方有一个没有谷歌徽标的地毯层的精确复制品。所以我需要编写类似“当对象(roomba)通过对象(carpetwithgooglelogo)使对象(carpetwithgooglelogo)不透明度为0时”之类的代码。我只是无法弄清楚如何在代码中说出来。

目前的代码如下所示:

// Assign 4 booleans for the 4 arrow keys
var keyUp = false;
var keyDown = false;
var keyLeft = false;
var keyRight = false;

// Add the keyboard event (KEY_DOWN) on the stage
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
function pressKey(pEvent)
{
// If an arrow key is down, switch the value to true to the assigned variable
if (pEvent.keyCode == 38)
{
    keyUp = true;
}
else if (pEvent.keyCode == 40)
{
    keyDown = true;
}
else if (pEvent.keyCode == 37)
{
    keyLeft = true;
}
else if (pEvent.keyCode == 39)
{
    keyRight = true;
}
}
// Add the keyboard event (KEY_UP) on the stage
stage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);
function releaseKey(pEvent)
{
// If the arrow key is up, switch the value to false to the assigned variable
if (pEvent.keyCode == 38)
{
    keyUp = false;
}
else if (pEvent.keyCode == 40)
{
    keyDown = false;
}
else if (pEvent.keyCode == 37)
{
    keyLeft = false;
}
else if (pEvent.keyCode == 39)
{
    keyRight = false;
}
}

// Set the velocity of the object
var speed = 4;
// And the rotation speed
var rotationSpeed = 6;

// Add an enter frame event on the moving object
myCircle.addEventListener(Event.ENTER_FRAME, circleEnterFrame);
function circleEnterFrame(pEvent)
{
// Set the default velocity to 0 if no key is pressed
var velocity = 0;
if (keyUp)
{
    // If the key up is pressed set the new velocity to the speed value
    velocity = speed;
}
if (keyDown)
{
    // If the key down is pressed set the new velocity to the half speed value
    velocity = -speed/2;
}
if (keyLeft)
{
    // rotate the object
    pEvent.currentTarget.rotation -=  rotationSpeed;
}
if (keyRight)
{
    // rotate the object
    pEvent.currentTarget.rotation +=  rotationSpeed;
}

// Convert the degreeAngle to the radian angle
var angleRadian = pEvent.currentTarget.rotation / 180 * Math.PI;

// Move the object with the radian angle and the object speed
pEvent.currentTarget.x +=  Math.cos(angleRadian) * velocity;
pEvent.currentTarget.y +=  Math.sin(angleRadian) * velocity;

}

任何帮助将不胜感激!谢谢!

4

1 回答 1

0

最简单的方法是执行以下操作:

if( roomba.hitTestObject(google)){
    google.alpha = 0;
}

您必须使用ENTER_FRAME事件在每一帧上检查这一点。

如果这令人困惑,请在评论中告诉我,我将用更多代码进行澄清。

于 2013-08-12T00:43:42.440 回答