[CS3] Changing a Moving MC's Direction
Hey, everybody. I am trying to make a game of pong, but I can't properly reverse the direction of the ball when it touches the walls and paddles. If anybody knows how to solve this, please help me. This is my current code on the ball itself:
Code:
onClipEvent (enterFrame) {
// Speed and Direction
BallSpeed = 1;
_root.Direction = random(2);
if (_root.Direction=0) {
this._x = (_root.Ball._x -= BallSpeed);
this._y = (_root.Ball._y -= BallSpeed);
}
if (_root.Direction=1) {
this._x = (_root.Ball._x += BallSpeed);
this._y = (_root.Ball._y += BallSpeed);
}
// HitTests
if (this.hitTest(_root.MaxHeight)) {
this._y = (_root.Ball._y += BallSpeed);
}
if (this.hitTest(_root.MinHeight)) {
this._y = (_root.Ball._y -= BallSpeed);
}
if (this.hitTest(_root.RightPaddle)) {
this._x = (_root.Ball._x -= BallSpeed);
}
if (this.hitTest(_root.LeftPaddle)) {
this._x = (_root.Ball._x += BallSpeed);
}
}
Thanks in advance!