Hey world. Im trying to make a very old game much better than it currently is. It is a possibly better version of Pong and so far its been going great except for one problem that i just can't fix. The computer opponent is shaking for some reason. Can someone help me with this problem?
I have the swf attached (it is not the real one, I just changed the colors of the paddles, ball, etc.)
here is the AS2 code for it so far:
ActionScript Code:
init();
function init(){
Mouse.hide();
_root.onEnterFrame = function(){
quit();
player._y = _root._ymouse;
}
//ball.dy=5;
ball.dx=10;
opp.speed=6;
//if opp speed is same as ball dx, opp has perfect AI
}
ball.onEnterFrame = function(){
ball.move();
ball.walls();
ball.bounce();
}
ball.move = function(){
ball._x += ball.dx;
ball._y += ball.dy;
}
ball.walls = function(){
if (ball._y < 0){
ball.dy = -ball.dy;
}
if (ball._y > Stage.height){
ball.dy = -ball.dy;
}
if (ball._x < 0){
ball._x = Stage.width;
}
if (ball._x > Stage.width){
ball._x = 0;
}
}
ball.bounce = function(){
if (ball.hitTest(player)){
ball.dy = getDy(player);
ball.dx = -ball.dx;
}
if (ball.hitTest(opp)){
ball.dy = getDy(opp);
ball.dx = -ball.dx;
}
}
function getDy(paddle){
relY = ball._y - paddle._y;
relPerc = relY / paddle._height;
newDy = relPerc * 20;
return newDy;
}
opp.onEnterFrame = function(){
//opp._y = ball._y; //perfect AI
if (ball._y < opp._y){
//move opp up
opp.dy = -opp.speed;
} else if (ball._y > opp._y){
//move opp down
opp.dy = opp.speed;
}
opp._y += opp.dy;
}
function quit(){
var key = new String("Q").charCodeAt(0);
if (Key.isDown(key)){
_root.gotoAndStop("start");
}
}
see what you can do to fix the problem plz!