0

私にはとても簡単に思えますが、私の解決策はうまくいきません。私は小さなプログラムを作成しました。これは私の最大かつ最も高度なプログラムですが、それでも小さなプログラムです。床で跳ね返り、ゆっくりとエネルギーを使い果たすボールだけです。スペースキーを押すとバウンスを再開できるようにし、矢印キーを押すと、非常に単純な速度計算 (実際には非常に単純) を使用して方向を変えることができます。

これが私の問題です。私はプログラミングに非常に慣れていません。これはまだ 2 日目であり、ステージの側壁からボールを​​跳ね返す方法が必要です。

onClipEvent(load){
velocity = 0 //Vertical Velocity, is increased and decreased by the effects of gravity and bouncing with SPACE
sideVel =0 //Side Velocity, increases when the arrow keys are pressed, decreases over time
gravity = 2 //Gravity, constant force that never changes
}
onClipEvent(enterFrame){
_x += sideVel //Moves the ball the value of Side Velocity
if (Key.isDown(Key.LEFT)) {
    sideVel -= 2 //Technically decreases Side Velocity, but really increases it in another direction
}
else {
    if(sideVel<0) { //If the button isn't being pressed Side Velocity returns to 0 over time
    sideVel += 1
    }
}
if (Key.isDown(Key.RIGHT)) {
    sideVel += 2 //Increases Side Velocity
}
else {
    if(sideVel>0) //If the button isn't being pressed Side Velocity returns to 0 over time
    sideVel -= 1
}
if (sideVel < -20){ //Side Velocity isn't allowed to go below this number
    sideVel +=2 //So we add 2
}
if (sideVel > 20) { //Same as above
    sideVel -=2
}
velocity += gravity //Regular Velocity increases by 2 every frame
_y += velocity //mcMain moves at the speed of its velocity
if(_y>=Stage.height){
if(Key.isDown(Key.SPACE)){
    velocity=-28 //Sets Velocity to -28, pretty much the same as doing a jump
}
else {
_y = Stage.height
velocity *= -0.9 //Reverses mcMain's velocity, so it bounces back into the air at a slightly slower speed
}
/*Here's the problem
if(_x>=Stage.width - 25){
    _x=Stage.width - 25
sideVel *= -1
}
if(_x<=Stage.width - 550){
    _x=Stage.width - 550
sideVel *= -1
}
}
}
4

1 に答える 1

0

MC.x++衝突が複数回登録されないように、MC が壁に当たったときに手動で MC (その他のもの) の位置を変更する必要があります。また、壁の衝突のwhile代わりにステートメントを使用ifすると、ボールが壁を通過しないようになります。

于 2013-02-02T22:12:39.033 に答える