Jump to content

help with pong game

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
aloishis89

aloishis89

    Newbie

  • Members
  • PipPip
  • 12 posts
I am learning C and am trying to write the game pong. I am actually writing it for gameboy. It is pretty simple, its just a paddle that is controlled by the up and down arrows and a ball that bounces around. I made it so that the paddle is 5 pixels from the edge of the screen. That way, when the ball hits the paddle, it bounces back, but if it hits the edge of the screen, then that counts as a life. Once you use up 3 lives, it goes to a game over screen. The problem is this line:


if((((ball_column < (5)) && (ball_row < paddle_row) && (ball_row > (paddle_row+20))) || (ball_column < (1)))) delta_column = 1;

//note that the paddle is 5 pixels wide and it is 5 pixels from the 

//edge of the screen




It is supposed to look at the position of the ball. If it is between the 2 rows that are on top and bottom of the paddle AND is 1 column in front of the edge, then it bounces. Or, if it hits the edge of the screen, then it bounces. That line now always runs the OR statement. I can post more code if needed. Thanks for any help.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What is it not doing that you expected it to? Based on your description, it looks correct.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
aloishis89

aloishis89

    Newbie

  • Members
  • PipPip
  • 12 posts
the ball is supposed to bounce off of the left edge of the screen when the paddle misses, but bounce off 10 pixels in front of the edge when you hit it (so its looks like it is bouncing off of the paddle). Right now it only bounces off the edge of the screen, regardless of where the paddle is, so it seems like the paddle is not 'hard'.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
(ball_row < paddle_row) && (ball_row > (paddle_row+20))
I think you have your < and > reversed.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
aloishis89

aloishis89

    Newbie

  • Members
  • PipPip
  • 12 posts
That did it, thanks.