Now I know why Dijkstra said goto''s were a bad idea.
John B
pong
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
December 20, 2002 03:10 PM
Oh my gosh!
Dude have you ever heard of indenting code properly along with some white spaces to make it more readable. Plus I see way too many GOTO''s which are NOT needed.
Dude have you ever heard of indenting code properly along with some white spaces to make it more readable. Plus I see way too many GOTO''s which are NOT needed.
Try and clean up your code, that is horrible.
As for your problem, the ball moves two pixels at a time, so it may move beyond the edge of the screen by one pixel, which would cause your collision tests to be false. Instead of checking if the ball is at the edge, check if it is at or beyond it. There may be other problems though, since I didn''t really read much of the code.
As for your problem, the ball moves two pixels at a time, so it may move beyond the edge of the screen by one pixel, which would cause your collision tests to be false. Instead of checking if the ball is at the edge, check if it is at or beyond it. There may be other problems though, since I didn''t really read much of the code.
int player1_score = 0, player2_score = 0; // Scores of the players.int paddle1 = 300, paddle2 = 300; // The positions of the paddles.while(player1_score < 10 && player2_score < 10) // while both players have less than 10 points. { int bx = 400; // Ball's position on the x axis. int by = 300; // Ball's position on the y axis. int dx; // Ball's direction on the x axis. int dy; // Ball's direction on the y axis. dx = rand()%2?1:-1; // Have the ball randomly move in either a positive dy = rand()%2?1:-1; // or negetive direction on each axis. while(true) // Main loop. We do drawing, updating, and input from the user here. { bx += dx; // Move ball on the x axis. by += dy; // Move ball on the y axis. if(bx >= 799) // Ball hit the right of the screen. { if(by < paddle2 - 50 || by > paddle2 + 50) // Player 2 missed the ball. { ++player1_score; // Increase player 1's score. break; // Break out of the main loop. } dx = -1; // Reverse the ball's direction on the x axis. } if(by >= 599) // Ball hit the bottom of the screen. dy = -1; // Reverse the ball's direction on the y axis. if(bx <= 0) // Ball hit the left of the screen. { if(by < paddle1 - 50 || by > paddle1 + 50) // Player 1 missed the ball. { ++player2_score; // Increase player 2's score. break; // Break out of the main loop. } dx = 1; // Make the ball move in a positive direction on the x axis. } if(by <= 0) // Ball hit the top of the screen. dy = 1; // Make the ball move in a positive direction on the y axis. /* Do drawing, input from player, and whatever else here. */ } }/* The game is now over. Congradulate the winner. */
[EDIT] Fixed a bug. I also filled in the missing gfx code and user input code and tested it, so I know it works.
[edited by - smart_idiot on December 20, 2002 11:33:38 PM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
December 20, 2002 04:09 PM
PAST:
quote: Original post by craphead
im 11 years old and want to start programming i use dev-c++ and all i can do is do a game where it asks your name then repeats it. oh yea and where do i start?
shuv-it
PRESENT:
quote: Original post by craphead
im making pong in sdl i need to make the ball bounce and move by itself. Cone3d doesnt have anything and the way gamedev does bouncing doesnt work with me. "thats ho i got into my last mess"
shuv-it
FUTURE:
keep up the good work
I agree. I didn''t think he''d stick around this long.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Craphead''s code is evil scary.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement