0
對我來說這似乎很簡單,但是我的解決方案不起作用。我製作了一個小程序,這是我的最大和最先進的程序,但仍然是一個小程序。它只是一個從地面反彈並慢慢耗盡能量的球。我可以通過按下SPACE重新啓動彈跳功能,它可以通過按下箭頭鍵來改變方向,使用非常簡單的速度計算(實際上非常簡單)。如何在Actionscript 2.0中使一個簡單的彈跳球在牆壁上反彈
這是我的問題,我對編程非常陌生,這只是我的第二天,而且我需要一種方法將球從舞臺的側壁彈出。
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
}
}
}
好吧,我會盡力的,謝謝 –
而(this._x> 525){ \t _x = 524 \t sideVel * = -1 //這是你的意思,因爲我不能得到這個工作看起來很簡單,但我不知道 –
噢,我可以在球在地面時將球彈離牆,但不在半空中 –