Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


[SFML] I Finished Pong! I Can't Believe It!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
33 replies to this topic

#21 Servant of the Lord   Crossbones+   -  Reputation: 20348

Like
1Likes
Like

Posted 28 September 2012 - 07:42 PM

First you store the variable as a integer, and that's what you increment when the paddle is hit.

Then, when ready to draw, you MyString.SetText() a std::string, not an integer directly.
//When paddle is hit...
score++; //Update the score.

//Convert the score to text.
std::string scoreAsText = convert_a_int_to_a_string(score); //'convert_a_int_to_a_string' is an imaginary function that doesn't exist.

//Set the new text.
MyString.SetText(scoreAsText);

//When ready to draw each frame
RenderWindow.Draw(MyString); //Or whatever...

To convert an int to a string, you could use std::stringstream.
std::stringstream is used to format text, similar to how std::cout works (same interface).
std::stringstream formattedText;
formattedText << "Score: " << score;

std::string convertedToText = formattedText.str(); //Turn the data stream into a std::string.
MyString.SetText(convertedToText);

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


Sponsor:

#22 GameC++Expert93   Members   -  Reputation: 121

Like
1Likes
Like

Posted 28 September 2012 - 09:48 PM

First you store the variable as a integer, and that's what you increment when the paddle is hit.

Then, when ready to draw, you MyString.SetText() a std::string, not an integer directly.

//When paddle is hit...
score++; //Update the score.

//Convert the score to text.
std::string scoreAsText = convert_a_int_to_a_string(score); //'convert_a_int_to_a_string' is an imaginary function that doesn't exist.

//Set the new text.
MyString.SetText(scoreAsText);

//When ready to draw each frame
RenderWindow.Draw(MyString); //Or whatever...

To convert an int to a string, you could use std::stringstream.
std::stringstream is used to format text, similar to how std::cout works (same interface).
std::stringstream formattedText;
formattedText << "Score: " << score;

std::string convertedToText = formattedText.str(); //Turn the data stream into a std::string.
MyString.SetText(convertedToText);


mm i could be wrong as to how pong works, but why would you update the score when the paddle is hit? i thought in pong the score should only be updated if that persons paddle does not end up hitting the ball

#23 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 08:19 AM

I made it so it auto updates to dropbox. Also, I fixed it so that it actually takes skill through balancing it.

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#24 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 08:33 AM

Just updated to add a MainMenu splash screen with only one button (That takes up the whole screen!)

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#25 Servant of the Lord   Crossbones+   -  Reputation: 20348

Like
0Likes
Like

Posted 29 September 2012 - 09:45 AM

mm i could be wrong as to how pong works, but why would you update the score when the paddle is hit? i thought in pong the score should only be updated if that persons paddle does not end up hitting the ball

You're correct - I wasn't sure why the OP requested that either. I didn't know what to call the variable, so I just called it "score". Perhaps "bounces" would be a better name, but it depends on the OP's intent.

"I have a variable in my ball class that keeps the amountofhits, whenever I hit the paddle this increments. But, I don't know how to set my text equal to this variable: MyString.SetText(variable); doesn't work. Any Ideas?"

Edited by Servant of the Lord, 29 September 2012 - 09:47 AM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#26 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 01:18 PM

Well, to clarify, I meant that you want to see how far you can go, because the AI never fails. So whenever the ball hits the paddle and bounces off of it, the score is increased because you went farther. Also, I updated it.
In This Update:
Fixed the MainMenu.h problems, and made the Play button work, so that everything else on the screen won't play the game.

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#27 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 01:34 PM

Updated:
In This Update:
Added a game over screen (Soon to be a class, I'm working on it).

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#28 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 02:30 PM

This is the final Update, I promise :)
ChangeLog:
Added GameOver class and fixed everything, feel free to play!

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#29 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 02:57 PM

Sorry, another update :)
ChangeLog:
Made the ball move at a random speed and at a random angle at the start of each game.
(Also, look in the console for your score!)

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#30 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 04:32 PM

I SWEAR: THIS IS THE LAST UPDATE!!!!!!!!!!!!!!!!
CHANGELOG:
+Added Score Counter
-Took away bad programming. (There was lots of it!)

LINK

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#31 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 29 September 2012 - 04:50 PM

Okay, i'm still adding things:
CHANGELOG:
+Displays your final score on the game over screen
+Made Programming Cleaner

LINK

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#32 GameC++Expert93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 29 September 2012 - 10:18 PM

Okay, i'm still adding things:
CHANGELOG:
+Displays your final score on the game over screen
+Made Programming Cleaner

LINK


mm we all are happy you have completed your pong game :) but idk if any programmers especially advance ones would go as far to keep updated with your changes or to try the changes out. After all it is just pong and is fairly easy to build your own pong game within 30 mins maybe not even that if your a fast typer

#33 frazchaudhry   Members   -  Reputation: 1151

Like
1Likes
Like

Posted 29 September 2012 - 11:53 PM


Okay, i'm still adding things:
CHANGELOG:
+Displays your final score on the game over screen
+Made Programming Cleaner

LINK


mm we all are happy you have completed your pong game Posted Image but idk if any programmers especially advance ones would go as far to keep updated with your changes or to try the changes out. After all it is just pong and is fairly easy to build your own pong game within 30 mins maybe not even that if your a fast typer


I think its commendable that you're still adding stuff to your game and polishing it in the process. It shows commitment to your game, this is very important. When I made pong I didn't do all of this and went to something else, now for me the last part of polishing everything up in a game is the hardest part. I'm still no expert but I can tell you that creating fully finished and polished products is very very important.

#34 stitchs   Crossbones+   -  Reputation: 1307

Like
0Likes
Like

Posted 30 September 2012 - 10:33 AM

Is there anyway you can publish an .exe of the game as I would like to play it and see what you came up with without having to run it through VS/linking all the necessary library files. This video might help you:



I know it's for Allegro 5 but the skills might be transferable to SFML (though I have never used it, so please take with a pinch of salt.)

Regards,

Stitchs.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS