0

私はコーディングに非常に慣れていないため、学校向けのミニゲーム タイプのプロジェクトの最後の部分を完成させるのに苦労しています。

これは、これまでのプログラムのドラフトです: http://aaronmillard.com/dir/wp-content/uploads/2013/08/Google-Doodle_Roomba.swf

ここでプログラムに実行させたいのは、ルンバが Google の上を走ったときに Google を「掃除機」にすることです。これを実現する最も簡単な方法 (私が思うに) は、Google ロゴのあるカーペット層の下に、Google ロゴのないカーペット層の正確なレプリカを用意することです。したがって、「オブジェクト (ルンバ) がオブジェクト (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