0 Replies - 1055 Views - Last Post: 21 May 2014 - 06:09 PM Rate Topic: -----

#1 AndreeU17  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 137
  • Joined: 29-June 13

Not sure how to read the Pong Paddle Y position in C++?

Posted 21 May 2014 - 06:09 PM

Okay so im working on a Retro Pong game. I've got mainly everything all cleared up in C++, Microsoft Visual Studio 2012.
I'm using the library SFML 2.1 in c++.

I understand how to read the paddle x position and inverse the ball. However, im not sure how to read the Y value?
Here is the bit of code were im working on the paddle (Preferably the left since the right will be same concept just opposite signs but controlled by the computer), I will put the code of what i've done with the paddle. But i will also include what each variable is initialized to:
//Window variable
float windowWidth = 500;
float windowHeight = 250;
std::string windowTitle = "RetroPong";

//LeftPaddle & RightPaddle Position, Size
float leftPaddleSize_X = 10;
float leftPaddleSize_Y = 75;
float leftPaddlePos_X = 5;
float leftPaddlePos_Y = (windowHeight / 2) - (leftPaddleSize_Y / 2);
float rightPaddleSize_X = 10;
float rightPaddleSize_Y = 75;
float rightPaddlePos_X = windowWidth - 20;
float rightPaddlePos_Y = (windowHeight / 2) - (rightPaddleSize_Y / 2);

//Pong ball Position and Radius
float pongBallRadius = 5;
float pongBallPos_X = windowWidth / 2 ;
float pongBallPos_Y = windowHeight / 2;
float pongBallDir_X = .25;
float pongBallDir_Y = .25;
float pongBallSpeed = .25;



		if(pongBall.getPosition().x <= leftPaddlePos_X + leftPaddleSize_X && 
			pongBall.getPosition().x >= leftPaddlePos_X)
                       //This does it so that it require the ball to only inverse when in a certain float range
		{
			pongBallDir_X = fabs(pongBallDir_X); // force it to be positive ---> (+) and <--- (-)
		}



Not sure how to approach the paddle process. In theory, i was assuming that i needed to constantly get the position of the Paddle (y position since its the only one to move), before that i need to get the size of the paddle Y position which is 75. I was assuming that i needed to test everytime it hit inside that paddle (or in range from 0 < x < 75). The thing is i cant seem to find an approach and need guidance, i need all the help i can get, thanks!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1