hey. i need help on a game im makin…Pong. i cant figure out how to make the ball move and bounce around the stage. and i also need help on the paddle that the ball bounces off of. if u could help me out that would be awesome. Thanx (-:
please look in the tutorials and search the forum:
hint: Collision, physics, drag
If you get stuck, we’ll do our best.
Have a look at the bit-101 tutorial called Gravity, at a certain point you have the effect you want which you can further work from to create pong.
is the gravity tutorial on Flash or on this page?
Hey, V… you’re gonna think I have it in for you, which is not true… but I dont see how Gravity applies to Pong. Pong is supposed to be a matched watched from above. I think that acceleration is a factor/friction/speed, etc… but I didnt think gravity would take play. Then again, I could simply be wrong. Which is okay, too!
Yeah I know, but at a certain point in that tutorial you have a ball bouncing off walls. So I thought it wouldn’t be that hard to figure out how to make it bounce of a pad too, since everything is clearly explained by Keith
here’s a cheap pong game i made in the past, sorry i dont have the time to comment it :trout: hope it helps!!! :}
game = {Width:600, Height:400, p1score:0, p2score:0};
game.ball = {Width:5, startSpd:3, speedInc:0.5};
game.paddle = {Width:5, Height:20, pdl1x:20, pdl2x:game.Width-20, speed:5, deflectionRate:10};
this.createTextField("p1score", 100, game.Width/2-100, 50, 50, 30);
p1format = new TextFormat();
p1format.color = 0x000000;
p1format.size = 20;
p1format.font = "Arial";
p1format.align = "center";
this.createTextField("p2score", 101, game.Width/2+50, 50, 50, 30);
p2format = new TextFormat();
p2format.color = 0x000000;
p2format.size = 20;
p2format.font = "Arial";
p2format.align = "center";
p1s = 0;
p2s = 0;
MovieClip.prototype.createBall = function() {
_root.createEmptyMovieClip("ball", 10000);
ball._visible = false;
ball.lineStyle(1, 0x000000, 100);
ball.beginFill(0xffffff, 100);
ball.moveTo(-game.ball.Width, -game.ball.Width);
ball.lineTo(-game.ball.Width, game.ball.Width);
ball.lineTo(game.ball.Width, game.ball.Width);
ball.lineTo(game.ball.Width, -game.ball.Width);
ball.lineTo(-game.ball.Width, -game.ball.Width);
};
MovieClip.prototype.createBoundries = function() {
_root.createEmptyMovieClip("boundries", 1);
boundries.lineStyle(1, 0x000000, 100);
boundries.moveTo(0, 0);
boundries.lineTo(game.Width, 0);
boundries.lineTo(game.Width, game.Height);
boundries.lineTo(0, game.Height);
boundries.lineTo(0, 0);
boundries.moveTo(game.Width/2, 0);
boundries.lineTo(game.Width/2, game.Height);
};
MovieClip.prototype.createPaddle = function(name, depth, x) {
_root.createEmptyMovieClip(name, depth);
_root[name].lineStyle(1, 0x000000, 100);
_root[name].beginFill(0xffffff, 100);
_root[name].moveTo(-game.paddle.Width, -game.paddle.Height);
_root[name].lineTo(-game.paddle.Width, game.paddle.Height);
_root[name].lineTo(game.paddle.Width, game.paddle.Height);
_root[name].lineTo(game.paddle.Width, -game.paddle.Height);
_root[name].lineTo(-game.paddle.Width, -game.paddle.Height);
_root[name]._x = x;
_root[name]._y = game.Height/2-10;
};
MovieClip.prototype.moveBall = function() {
this._x = game.Width/2;
this._y = game.Height/2;
this.dx = -game.ball.startSpd;
this.dy = -game.ball.startSpd;
this._visible = true;
this.onEnterFrame = function() {
this._x += this.dx;
this._y += this.dy;
if (this._y>game.Height-game.ball.Width) {
this.dy *= -1;
this._y = game.Height-game.ball.Width;
}
if (this._y<game.ball.Width) {
this.dy *= -1;
this._y = game.ball.Width;
}
if (this._x-game.ball.Width<0) {
this.dx = this.dx>0 ? -game.ball.startSpd : game.ball.startSpd;
this.dy = Math.ceil(Math.random()*2)>1 ? game.ball.startSpd*-1 : game.ball.startSpd;
this._x = game.Width/2;
this._y = Math.random()*(game.Height/2)+game.Height/4;
game.p2score++;
}
if (this._x+game.ball.Width>game.Width) {
this.dx = this.dx>0 ? -game.ball.startSpd : game.ball.startSpd;
this.dy = Math.ceil(Math.random()*2)>1 ? game.ball.startSpd*-1 : game.ball.startSpd;
this._x = game.Width/2;
this._y = Math.random()*(game.Height/2)+game.Height/4;
game.p1score++;
}
if ((this._x-game.ball.Width<paddle1._x+game.paddle.Width || this._x-game.ball.Width+this.dx<paddle1._x+game.paddle.Width) && this._y+game.ball.Width>paddle1._y-game.paddle.Height && this._y-game.ball.Width<paddle1._y+game.paddle.Height && this.dx<0) {
this._x = paddle1._x+game.paddle.Width+game.ball.Width;
this.dx *= -1;
this.dx += this.dx>0 ? game.ball.speedInc : -game.ball.speedInc;
this.dy += this.dy>0 ? game.ball.speedInc : -game.ball.speedInc;
this.dy += (this._y - paddle1._y)/game.paddle.deflectionRate
}
if ((this._x+game.ball.Width>paddle2._x-game.paddle.Width || this._x+game.ball.Width+this.dx>paddle2._x-game.paddle.Width) && this._y+game.ball.Width>paddle2._y-game.paddle.Height && this._y-game.ball.Width<paddle2._y+game.paddle.Height && this.dx>0) {
this._x = paddle2._x-game.paddle.Width-game.ball.Width;
this.dx *= -1;
this.dx += this.dx>0 ? game.ball.speedInc : -game.ball.speedInc;
this.dy += this.dy>0 ? game.ball.speedInc : -game.ball.speedInc;
this.dy += (this._y - paddle2._y)/game.paddle.deflectionRate
}
};
};
MovieClip.prototype.movePaddle = function(pdl) {
this.onEnterFrame = function() {
if (pdl == 1) {
if (Key.isDown(Key.CONTROL)) {
if (this._y+game.paddle.Height+game.paddle.speed<game.Height) {
this._y += game.paddle.speed;
} else {
this._y = game.Height-game.paddle.Height;
}
}
if (Key.isDown(Key.SHIFT)) {
if (this._y-game.paddle.Height-game.paddle.speed>0) {
this._y -= game.paddle.speed;
} else {
this._y = game.paddle.Height;
}
}
} else {
if (Key.isDown(Key.DOWN)) {
if (this._y+game.paddle.Height+game.paddle.speed<game.Height) {
this._y += game.paddle.speed;
} else {
this._y = game.Height-game.paddle.Height;
}
}
if (Key.isDown(Key.UP)) {
if (this._y-game.paddle.Height-game.paddle.speed>0) {
this._y -= game.paddle.speed;
} else {
this._y = game.paddle.Height;
}
}
}
};
};
MovieClip.prototype.changeScore = function(p1, p2) {
p1score.text = p1;
p1score.setTextFormat(p1format);
p2score.text = p2;
p2score.setTextFormat(p2format);
};
_root.createBoundries();
_root.createBall();
_root.createPaddle("paddle1", 2, game.paddle.pdl1x);
_root.createPaddle("paddle2", 3, game.paddle.pdl2x);
ball.moveBall();
paddle1.movePaddle(1);
paddle2.movePaddle(2);
onEnterFrame = function () {
_root.changeScore(game.p1score, game.p2score);
};
I have a mouse controled pong game somewhere, buried deep inside the My Documents/Flash folder … If you want it too, let me know.
*Originally posted by Voetsjoeba *
**I have a mouse controled pong game somewhere, buried deep inside the My Documents/Flash folder … If you want it too, let me know. **
/me feels great honour in the fact that he independantly figured out the same name and location to dump his flash stuff in as Voetsjoeba
*Originally posted by sef *
**/me feels great honour in the fact that he independantly figured out the same name and location to dump his flash stuff in as Voetsjoeba**
Hey Juice_monkey, if I were you, I’d change the link to your website (underneath every post), coz now it’s linking to www.anelfire.com, and I really hope it is supposed to be anGelfire :beam: