Jump to content
  • Advertisement
Sign in to follow this  
Hushed

Help with a Pong game ^-^

This topic is 4024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, just like everyone else that starts, Im making a Pong game. Entitled "Zombie Ball". The difference? One paddle is green. But this is besides the point. Im using C++ with Allegro. Ive come across having everything working, but one thing, Ball movement. This is how I think it should be set up in my head. It has two directions, a leftright, and an updown. In the beginning, randomly it picks up or down, and left or right. This is its heading. When it hits a wall, if its going up, it goes down, if its going down, the ball will shoot up. Throughout the game, it checks for winning conditions. So if the ball goes behind the paddle, the other player wins. Now, when it hits a paddle, it randomly chooses to go up, or down. If its going left, it switches to right, if its going right, it switches to left. If its not touching anything, it continues along its path. Another thing, keeping the score is fine, its outputting the score to the screen. I have an area of the screen that I can put the score, but it doesnt let me textout_ex an int variable. So I convert it to a string, it didnt work, and I convert it to a char, it didnt work. So im thinking I may have to try something other than textout_ex Now, I need to know if this is the right set of mind, and also how to create a random int, also about the textout_ex thing. Thank you GameDev ^-^ [Edited by - Hushed on July 16, 2007 5:08:58 PM]

Share this post


Link to post
Share on other sites
Advertisement
Seems like you're headed in the correct direction.

Quote:
also how to create a random int.
What language are you using?

Share this post


Link to post
Share on other sites
Ah, sorry. C++ with Allegro, edited my first post.

Also need help with the score system.
Quote:

Another thing, keeping the score is fine, its outputting the score to the screen. I have an area of the screen that I can put the score, but it doesnt let me textout_ex an int variable. So I convert it to a string, it didnt work, and I convert it to a char, it didnt work. So im thinking I may have to try something other than textout_ex


Thank you, ;)

Share this post


Link to post
Share on other sites
you can use boost::lexical_cast to cast ints to std::strings painlessly.

int score = getScore();
render.drawText(boost::lexical_cast<std::string>(score));



or you can use stringstreams (less cool!)
#include <sstream>

int i = getScore();
string str;
stringstream out;
out << i;
str = out.str();


or
#include <sstream>

template <class T>
inline std::string to_string (const T& t)
{
std::stringstream ss;
ss << t;
return ss.str();
}



random numbers

Boost also has a random number library

Share this post


Link to post
Share on other sites
Hello I googled in advance for you and found this piece of code that might help you:

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
int random_integer = rand();
cout << random_integer << endl;
}

alternatively you can go to this website http://www.daniweb.com/forums/post9554.html and find out many other examples related to random numbers.

for the score system, you just need to keep track of the score of both players and then you will need to check when the ball leaves the right side of the screen you increase the right player's score(which can be a simple variable ex: int rightPlayerScore). Thats all! Hope it helps.

Share this post


Link to post
Share on other sites
building on Hushed's post, if you are gonna use the random, but you want it too be a 1 or a 2, then you do this:


#include <cstdlib>

int rand_number=rand();
rand_number=(rand_number%2)+1;



this will set rand_number to either a 1 or a 2 (up/down) (left/right).

Share this post


Link to post
Share on other sites
Quote:
Original post by BrasiLokau
Hello I googled in advance for you and found this piece of code that might help you:

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
int random_integer = rand();
cout << random_integer << endl;
}



That's not a random number, as it's never seeded properly. Follow my first random number generator link. It discusses this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!