PDA

View Full Version : Pong game


macca1554
09-13-2009, 05:48 AM
Hi guys, I did a pong game tutorial and changed everything so that the pads are on the Y axis instead of X. I managed to get everything moving correctly, except everything is at a fraction of the speed of the version from the tutorial with the pads at top and bottom. Also, the ball does not spin properly when it is hit.

Here is the tutorials script

stop();

_root.pscore = 0;
_root.escore = 0;
_root.epad.speed = _global.espeed;

function start() {
_root.epad._x = 220;
_root.ppad._x = 255;
_root.ball._x = 255;
_root.ball._y = 200;
_root.ball.xspeed = 1;
_root.ball.yspeed = 10;
if (escore == 10) {
_global.won = "enemy";
_root.gotoAndStop('final');
}
if (pscore == 10) {
_global.won = "player";
_root.gotoAndStop('final');
}
}

start();



ppad.onEnterFrame = function() {
if (Key.isDown(Key.LEFT) and ppad._x>50) {
ppad._x -= 10;
}
if (Key.isDown(Key.RIGHT) and ppad._x<500) {
ppad._x += 10;
}
if (this.hitTest(_root.ball)) {
_root.ball.yspeed = _root.ball.yspeed*-1;
ballrotation = (_root.ball._x-_root.ppad._x)/10;
_root.ball.xspeed += ballrotation;
}
};

epad.onEnterFrame = function() {
if (_root.ball._x>_root.epad._x) {
epad._x += _root.epad.speed;

}
if (_root.ball._x<_root.epad._x) {
epad._x -= _root.epad.speed;
}
if (this.hitTest(_root.ball)) {
_root.ball.yspeed = _root.ball.yspeed*-1;
ballrotation = (_root.ball._x-_root.epad._x)/10;
_root.ball.xspeed += ballrotation;
}
};

ball.onEnterFrame = function() {
_root.ball._y += _root.ball.yspeed;
_root.ball._x += _root.ball.xspeed;
if (this._x>550) {
this.xspeed = this.xspeed*-1;
}
if (this._x<0) {
this.xspeed = this.xspeed*-1;
}
if (this._y<0) {
_root.pscore++;
start();
}
if (this._y>400) {
_root.escore++;
start();
}
};


and this is mine

stop();

_root.pscore = 0;
_root.escore = 0;
_root.epad.speed = _global.espeed;

function start() {
_root.epad._Y = 150;
_root.ppad._Y = 150;
_root.ball._x = 255;
_root.ball._y = 200;
_root.ball.yspeed = 1;
_root.ball.xspeed = 10;

if (escore == 10) {
_global.won = "enemy";
_root.gotoAndStop('gameover');
}
if (pscore == 10) {
_global.won = "player";
_root.gotoAndStop('gameover');
}
}

start();



ppad.onEnterFrame = function() {
if (Key.isDown(87) and ppad._y>50) {
ppad._y -= 10;
}
if (Key.isDown(83) and ppad._y<350) {
ppad._y += 10;
}
if (this.hitTest(_root.ball)) {
_root.ball.xspeed = _root.ball.xspeed*-1;
ballrotation = (_root.ball._y-_root.ppad._y)/10;
_root.ball.xspeed += ballrotation;
}
};

epad.onEnterFrame = function() {
if (_root.ball._y>_root.epad._y) {
epad._y += _root.epad.speed;

}
if (_root.ball._y<_root.epad._y) {
epad._y -= _root.epad.speed;
}
if (this.hitTest(_root.ball)) {
_root.ball.xspeed = _root.ball.xspeed*-1;
ballrotation = (_root.ball._y-_root.epad._y)/10;
_root.ball.yspeed += ballrotation;
}
};
ball.onEnterFrame = function() {
_root.ball._y += _root.ball.yspeed;
_root.ball._x += _root.ball.xspeed;

if (this._y>400) {
this.yspeed = this.yspeed*-1;
}
if (this._y<0) {
this.yspeed = this.yspeed*-1;
}
if (this._x<0) {
_root.pscore++;
start();
}
if (this._x>550) {
_root.escore++;
start();
}
}
;


Thanks in advance for the help :p

sam.uk.net
09-13-2009, 03:30 PM
Hi

Haven't got time to look through all your code, but I saw a possible cause for your problem.


_root.epad._Y = 150;
_root.ppad._Y = 150;


The _y should be in lowercase like:


_root.epad._y = 150;
_root.ppad._y = 150;


Hope that helps! :cool: It might be the main fix or it could be one of many problems with it.

Good luck.

sam.uk.net

macca1554
09-14-2009, 08:30 AM
Thanks mate but there that didnt really change much :( help appreciated tho