# Making pong clone, what's next?

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

## Recommended Posts

So after messing around for a while in C++ (basically copy-pasting like a newbie) I decided to do something graphical. I downloaded Gosu (http://www.libgosu.org/) got some of there code (copy+paste job) and edited from there and for the first time it's something that I understand.
#include <Gosu.hpp>

#include <scoped_ptr.hpp>
#include <shared_ptr.hpp>
#include <lexical_cast.hpp>

#include <cmath>
#include <cstdlib>
#include <list>
#include <vector>
class Player
{
boost::scoped_ptr<Gosu::Image> image;
double posX, posY, velX, velY, angle;

public:
explicit Player(Gosu::Graphics& graphics)
{
std::wstring filename = Gosu::sharedResourcePrefix() + L"player.png";
image.reset(new Gosu::Image(graphics, filename));
posX = posY = velX = velY = angle = 0;
}

void warp(double x, double y)
{
posX = x;
posY = y;
}

void up()
{
velY += Gosu::offsetY(angle, 0.5);
}

void down()
{
velY -= Gosu::offsetY(angle, 0.5);
}

void move()
{
posX += velX;
while (posX < 0)
posX += 640;
while (posX > 640)
posX -= 640;

posY += velY;
while (posY < 0)
posY += 480;
while (posY > 480)
posY -= 480;

velX *= 0.95;
velY *= 0.95;
}

void draw() const
{
image->drawRot(posX, posY, 1, angle);
}
};
class GameWindow : public Gosu::Window
{
boost::scoped_ptr<Gosu::Image> backgroundImage;
Player player;

public:
GameWindow()
: Window(640, 480, false), player(graphics())
{
setCaption(L"Ping Pang Pow");
std::wstring filename = Gosu::sharedResourcePrefix() + L"main.png";
backgroundImage.reset(new Gosu::Image(graphics(), filename, false));

player.warp(100, 240);
}

void update()
{
if (input().down(Gosu::kbUp) || input().down(Gosu::gpButton0))
player.up();
if (input().down(Gosu::kbDown) || input().down(Gosu::gpButton1))
player.down();
player.move();
}

void draw()
{
player.draw();
backgroundImage->draw(0, 0, 0);
}

void buttonDown(Gosu::Button btn)
{
if (btn == Gosu::kbEscape)
close();
}
};
int main(int argc, char* argv[])
{
GameWindow window;
window.show();
}


If you don't feel like compiling that, all that is is' 1 paddle that goes up and down (and goes through the bottom of the screen and shows up at the top) and I wonder, now what? I guess next would be adding another paddle or a ball (which would also need collision detection) but after googling and browsing the forums, I really don't know how to do any of that. So could anyone point me in the right direction? thanks

##### Share on other sites
The next step is easy. Realise that you cannot really learn by copying and pasting.

Go back to basics. This usually means console applications. Have you made many of them? Making games like "guess the number" or "tic tac toe" will teach you how to write program logic.

Collision detection is a little bit of math coupled with a good bit of program logic.

Learning to program works best if you write lots of small programs yourself. Do you have a book you are learning from? Make sure you can do all the exercises. The point of them is to get you used to translating how you *think* you can solve a problem into code that will *actually* solve a problem.

##### Share on other sites
Quote:
 Original post by rip-offThe next step is easy. Realise that you cannot really learn by copying and pasting.Go back to basics. This usually means console applications. Have you made many of them? Making games like "guess the number" or "tic tac toe" will teach you how to write program logic.Collision detection is a little bit of math coupled with a good bit of program logic.Learning to program works best if you write lots of small programs yourself. Do you have a book you are learning from? Make sure you can do all the exercises. The point of them is to get you used to translating how you *think* you can solve a problem into code that will *actually* solve a problem.

No book, but a-thanks for the reply

##### Share on other sites
After pong, there is nothing greater. It was and is the greatest game around! :)

Seriously though, what Rip-off says is true. Copy-and-pasting doesn't achieve too much, it does help to gain an understanding.. but a very basic one.

Writing small applications & games is a great way to go. Don't bite off more than you can chew, otherwise you'll tend to find yourself encountering problems that are overwhelming resulting in a lot of incomplete projects.

Personally I started off with (very) basic stuff such as little 2D GDI programs, map makers, solution finding apps (reading memory and giving the best possible outcome). Then moved onto 3D (DirectX 7) of basic games but with enhanced lighting, effects, etc. Once I had that sorted moved onto OpenGL full-immersive tech demo's.
Now I play with 3D Tools app programming, basic graphical engines, etc.

It really comes down to understanding the concepts, the logic, the process, methodology. Problem solving & logic as Rip-off says. No one can really suggest what to "do next" as only you know what level of understanding you are at.

##### Share on other sites
I have to agree with rip-off here, you really need to learn programming if you can draw one paddle you should have no problem drawing the other and same with ball. Since you just copy other peoples work, you really are not getting anywhere, and you obviously don't get it as well as you think you do if you do not know where to go from there. I strongly suggest doing basic stuff in console applications before you think about going forward to graphics. I am not trying to be a dick here, honestly it is in your best interest, trust me. I have been doing C++ for almost 2 years now and I still am learning a lot. I am also getting my degree in Game Software Development. I will tell you if you think you are going to learn over night and make something really awesome you have a lot to learn besides programming, like design aspects of making a program. I would recommend using Google and searching c++ tutorials and start with a hello world program and move on from there. It is really boring stuff but it is nice when you start to understand the language and you can create your own methods of doing things.

##### Share on other sites
I'm around the same level as you, OP. I just finished a Pong clone and now I'm working on a BreakOut clone.

You should really finish up/polish your version of Pong. Doing so shouldn't be hard; if you go over the tutorials and understand how things are being drawn to the screen, adding new objects and controlling them is a snap. I'm not sure how Gosu does its thing, but what you need to do is make another class to represent the AI paddle, and another to represent the ball. Both will have images, like your Player class, and both will have move(), warp(), draw() etc. Call these methods in the correct places and you've got new objects on the screen.

Collision detection can be as simple or complex as you'd like it. Think about what constitutes a collision in the real world. If two objects collide, part of one object is touching/within the other. This is what you have to check for in your game. Eventually you'll want to allow for the ball to be deflected differently depending on where along the paddle it collides. In this instance, again, think about what you need to check for and how you can check for it.

After Pong, I think BreakOut is a nice stepping stone. It's more complex, but it's similar enough to Pong that you don't get too lost.

Good luck, and let us know how it goes!

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628730
• Total Posts
2984423

• 25
• 11
• 10
• 16
• 14