Hello, Jycerian, zsbzsb, and all Ladies and Guys from SFML
let s see, first i ll try to draw the main loop and then to detail the heavy functions, that i already wrote before
if needed, please someone translate from my code to C++, thank you (i don t know why don t you all use C# ... it s easier and more legible)
i saw you were asking in the last reply for the ball s angle when it hits the border line, here it is all
while (true)
{
PlayerInput(); // however it is, events, etc
ComputerPaddleControl() // has it been thought or programmed?
DrawGraphics(); // however it is
BallMove(); // i ll give an idea, but perhaps it s already done
if (DetectCircunpherenceCollision( ref ballX, ref ballY ) == true)
{
ballAngle = AngleCircle();
}
else if (DetectPaddleCollision( ballX, ballY ) == true)
{
ballAngle = AnglePaddle()
}
// it would be missing the score issue, i m sorry but i insist with the goal lines, cos the ball will never be
// impeded to return, as you said, zsbzsb, it will bounce once and again on different points on the circle
// lines, even if it never hits the paddles, it can t escape from the circle
// anyway, Jycerian, you could try first if the schema and functions i wrote make the program works fine,
// weather there are or not goal lines
}
// returns true if the ball bounces on the circunpherence
private bool DetectCircunpherenceCollision( ref int ballX, ref int ballY )
{
// already written and optimized, see last version
}
// returns true if the ball bounces on the paddle
// convert paddleAngle to radians before passing it to the Sin or Cos
private bool DetectPaddleCollision( int ballX, int ballY )
{
int a, SideX;
Paddle.Radius = paddleTexture.Width / 2; // however it is
Paddle.Height = paddleTexture.Height; // however it is
SideX = Math.Cos (paddleAngle) * Paddle.Radius;
for (a = Paddle.Origin.X - SideX; a<= Paddle.Origin.X + SideX; a++)
{
if (Distance( Ball.Origin.X, Ball.Origin.Y, a, Math.Sin(paddleAngle) * a / Math.Cos(paddleAngle) )
< ball.Radius + Math.Cos(paddleAngle) * Paddle.Height / 2)
return true;
}
return false;
}
// returns the ball s angle (in degrees) when it bounces on the circle line
private int AngleCircle()
{
int angle, tangentAngle;
// the circunpherence s tangent line at the collision point behaves as a paddle, then we get its angle and
// then we get the new ball s angle; we add PI/2 (90 degrees) cos the tangent is normal to the radius
tangentAngle = (Math.Asin( (ballY - 240) / radius ) + PI / 2) * 180 / PI; // converted to degrees
angle = 180 - 2 * tangentAngle - ballAngle; // here we use the same formula than when the ball
// bounces with the paddle
return angle;
}
// returns the ball s angle (in degrees) when it bounces on the paddle
private int AnglePaddle()
{
int angle;
angle = 180 - 2 * paddleAngle - ballAngle;
return angle;
}
// makes the ball move - i don t know if already implemented
private void BallMove()
{
Ball.Position.X += Math.Cos(ballAngle) * 5.0;
Ball.Position.Y -= Math.Sin(ballAngle) * 5.0;
}
I will repeat, i couldn t run this program Jycerian that sent the link, because of the MSVCP110.DLL file ... now, could any member tell me how to fix that, so i can see the game?
i don t know about DLL s nor OS s very much ... just programming
thank you
please let us know if now, the Pong works fine now
and be carefull with the variable names, if you have any doubt tell me
Pablo