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.
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.
My Pong Game
Moderator: PC Supremacists
Re: My Pong Game
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.
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.
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);
Get the Computer controlled paddle moving.
Get collision detection set up, so that paddles cannot go off the screen.
Re: My Pong Game
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);
}
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: My Pong Game
Cool! Thanks for sharing your progress. It looks like you're getting through this pretty quick, nice work!
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!