PONG as my first game

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 11-05-2001
program man
PONG as my first game
As my first C++ game I'm making PONG. I have a good understanding of loops, ifs, functions, and graphics and am willing to learn other things to make this work. I need to make the ball move and bounce off walls and paddles. I know I probably have to use a loop to do this but how do I make the ball bounce.
So far I have this source for the game part:
//field dimensions are 600 X 440
for (x=20;x<=580;x=x+.1)
{
y=y+.08;
testWindow.SetBrush(White);
testWindow.DrawCircle(x-.1, y-.08, 15); //Draws circle with a 15 r
testWindow.SetBrush(RED);
testWindow.Drawcircle(x, y, 15);
}
this loop draws a red ball then covers it up with a white one (because white is the background color) every time. The ball will just move slanted in animation all the way past the edge of bottom center of the screen. How do I make it bounce? I know I have to change the y coordinate to start getting smaller, but how? Also, if it's not too much trouble, can you tell me how to make paddles move with arrowkey input? Thanks a lot!
• 11-05-2001
gamegod3001
Not to hard

You need you use if statments

to have it find the top of your screen

if (y ==15) // 15 is your r

• 11-05-2001
Leeman_s
hmm...
That looks easy enough, what graphics thing are you using...directx, open gl, allegro?
• 11-06-2001
program man
PONG graphics
I'm sorry, I don't know which one, my teacher just gave us all the disk to put the software onto our regular C++ program. I can tell you I have to include <graphics.h> and using namespace std, but that's it. It's just simple 2D graphics. I've tried various if statements but I can't get it to do it right. and I've tried some nested loops but to no avail. Can anyone help me?
• 11-06-2001
gamegod3001
graphics.h is your graphics, (witch means you are using dos)

Ok first you don't want to to move your ball with a loop.

PHP Code:

``` //includes int main () { int ballx, bally; //balls x and y axis center postion int player1x, player1y; //players padles the corner  /* place the ball in the center and put the paddles down.  */   //now for the collesion detection //start moving the ball ballx++ ; bally++; for (int x=0; x==1; x=x) // loop { if (bally=15) // if the ball hits the top of the screen bally--  /* since this is homework you can figur out the bottom and player paddles as well as how they move */ //loose if (ballx= player1x-Width of paddle- 5)  x=1;  //sets x to one ending the loop } return 0; }  ```
This will get you started.
• 11-07-2001
program man
PONG
that didn't even make the ball move, and secondly I'm a beginner so I don't know what "ballx++" and "bally++" means. I tried that and the ball didn't move. I'm only familiar with something like "++a", which adds one every time within a loop. I don't understand how you can redraw the ball over and over without a loop either. Please help/explain your method. Thanks.
• 11-07-2001
gamegod3001
Sorry

put the ballx++ and ballyx++ inside the for loop, and put in the function to redraw the ball right after it.

ballx++ increases the value by 1.
• 11-08-2001
Magos
> for (int x=0; x==1; x=x)

I might be wrong, but I don't think this for-loop will work. It will loop as long as x=1 (x==1), but since you set x to 0 (int x=0) it will never loop. And exactly what is the meaning of this code: x=x???

It would be a lot better to use this:

int x=1;
while(x==1)
{
//Game loop
}

> if (bally=15)

This will probably not work like you want it to. It should be ==, not =
• 11-08-2001
program man
keyboard input
OK, I got the ball moving and bouncing, but how do I make the paddle move when arrow keys are pressed? Do you use GetKeyPress? Would this work:
testWindow.GetKeyPress(ckey);
if (ckey==ARROW)
{
switch (ckey)
{
break;
break;
}
}
else if (ckey==ESCAPE)
x=1; //just to end loop and stop game;
system("CLS");

//Keep in mind, this is all within the larger for loop
Thankyou.
• 11-13-2001
program man
How can I make the computer paddle move so that the computer is beatable? If I just set the y-variables of the paddle (top and bottom) equal to the where the ball is then the computer is unbeatable, but how can I make it so the paddle moves slowly and allows you to beat the computer? Help me please. Also, I need to set up a 2 player game, but the keyboard input would be hard to do since you have 2 people hitting keys at the same time, so how do you do it? Thanks.
• 11-13-2001
Jeremy G
velocity is the key. Set the computer paddle to move up and down with the ball, but only at a max speed. for higher levels make it a higher velocity.
• 11-14-2001
program man
I know that, but how do you make it move at that set speed, hitting the ball sometimes but missing it other times? How, do I make the bal stop fashing so much? It's really annoying. And how do I allow 2 people to press buttons at the same time and move seperate paddles for a 2-play mode? Because right now, if one player were to hold a button down the computer would just ignore the other player's commands. Thanks.
• 11-17-2001
program man
keyboard
How do I make the computer accept input from 2 users at the same time to move corresponding paddles? Please, if someone could just help me with this I could finish the game.
• 11-17-2001
SyntaxBubble
I think...
I think all you have to do is use different keys. Example:

Player 1: Arrow keys
Player 2: a, s, d, f

I think that's right
• 11-19-2001
program man
Yeah I know
I know that, but if someone held a button down it would ignore the other player. How do I do it?
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last