Page 1 of 1

My Pong Game

Posted: Fri Jun 17, 2016 4:44 pm
by Marksie
Hi all,

I have just set up SFML on Visual Studio and I am attempting my first ever graphical game.
I have decided to jump in right at the deep end and go for Pong.
Please see below for my progress so far.
Pong1.PNG
Pong1.PNG (40.16 KiB) Viewed 5711 times
So far I can move the left hand paddle up and down. No collision detection so it just goes off the screen.

More to follow.

Re: My Pong Game

Posted: Sat Jun 18, 2016 4:05 am
by Marksie
OK I have gotten up early this morning and decided to crack on with this modern day masterpiece.

I have gotten the ball moving, so far it heads towards the left hand side of the screen.
I have added some basic collision detection as per below, this means that if the ball hits my paddle it changes the speed so it goes in the opposite direction.

Code: Select all

// Check Poistion of ball for Paddle collisions

		boundingBoxBall = Ball.getGlobalBounds();
		RectangleBox = rectangle.getGlobalBounds();
		PCRectangleBox = PCrectangle.getGlobalBounds();
		
		if (boundingBoxBall.intersects(RectangleBox))
		{
			BallX = 3;
		}

		if (boundingBoxBall.intersects(PCRectangleBox))
		{
			BallX = -3;
		}


		Ball.move(BallX, BallY);
My next steps are as follows:

Get the Computer controlled paddle moving.
Get collision detection set up, so that paddles cannot go off the screen.

Re: My Pong Game

Posted: Sat Jun 18, 2016 4:39 am
by Marksie
I have implemented some basic code to get the computer paddle moving:

Code: Select all

//Move the computer controlled paddle

		//Move the paddle up
		if (BallPos.y < PaddlePos.y)
		{
			PCrectangle.move(0, -1);
		}

		//Move the paddle down
		if (BallPos.y > PaddlePos.y)
		{
			PCrectangle.move(0, 1);
		}

Re: My Pong Game

Posted: Sat Jun 18, 2016 2:37 pm
by dandymcgee
Cool! Thanks for sharing your progress. It looks like you're getting through this pretty quick, nice work!