Sign in to follow this  
sup1

How should i learn to make games in c++

Recommended Posts

sup1    106
I been having a lot of trouble making a game by myself in c++. I know c++, I know how to implement anything I just don't know how to make all the classes work into a game it just turn into a lot of useless coding and the game never get off the basic drawing, input etc.

I read sfml game developemt and the choice the author make are working and I say to myself "I would have never thought of making a scene node class and doing x that way"

I just think I can't put my thoughts into working classes and make them communite the right way and make it work.

Any help.

Sorry I got bad English and I am not a native English speaker.

And a grammar edits are welcome and tag fixing.

Share this post


Link to post
Share on other sites
Nicholas Kong    1535

There are several options you can take:

 

1) Use a game library compatible with c++. Do not re-invent the wheel.

 

In terms of how to organize it, try googling an open source c++ pong game. Don't look at the game logic. Just get a sense of how the code base is organized.

 

1) I am not sure how much c++ you know. But having a good grasp of object-oriented concepts and basic understanding of how the coordinates of the

graphics canvas are represented is a must.

 

My experience is with Java but I can offer you advice on how to organize the classes.

 

For Pong, you can organize it this way :

1) Vector2D <- every object whether it be the ball or paddle will move in two dimensional motion thus their x and y coordinates will change. You can create object of this class

to represent your object's position and velocity.

2) GameComponent <- this will be an interface that contains your update and draw function

3) Game <- This will contain your basic game loop(update, draw, gamelogic)

4) Ball <- How would you represent the ball in the game? You will need to understand how to read an image in C++ and draw that image on to a canvas. There is probably a class that can be display as a circle or oval in the c++ game library. The choice is yours.

5) Paddle <- same idea like the ball only you are using a different image or you can use a class that can be displayed as a rectangle if one exist in the game library

6) Sprite <- This will be the class that implements your GameComponent interface. Your Ball and Paddle will inherit from this class.

 

Hopefully, this helps. Using a game library will make your game development easier. There is no reason to re-invent the wheel. There should be an API or at least some form of documentation of the functions and classes you can use of the game library you are using for your basic game.

 

Post your codebase for your game so people can see where you are stuck.

 

If your game is not getting basic drawing and input, you should definitely take the time to understand how drawing and input works before making pong.

Edited by warnexus

Share this post


Link to post
Share on other sites
DekuTree64    1168

What kind of game are you making?

 

If you're having trouble going from low level to high level, maybe try going the other way. Design a level, and then study every moving/changing thing, and then design classes for each of them. Also think in terms of data. In a side scroller, the map will need to store the tileset image, tile map data, collision data, locations to spawn enemies/powerups/player. Then the game code will probably need a class for the tileset, a class for tile map layers (which has a pointer to a tileset, and draws the map to the screen based on scrolling position and such), possibly a class for the collision data, although sometimes I just use the main tile map layer, with a lookup table of collision types for each tile in the tileset. Then a class for the map as a whole, which is mostly just a collection of those other classes, along with an entity list.

 

The entities will need one or more classes, with code to move according to player input or AI, and check against the map collision data, and get drawn to the screen some way or another (I usually use a separate sprite system with a render list, independent of the map and its entity list)

 

Then some code to control what map gets loaded, and what happens when you reach the end of a level (easiest is to just load the next map). Once you get your map editor or text-edited map data done so you can enter enemy positions and such, then the code will read it, spawn everything, and voila, a game.

Edited by DekuTree64

Share this post


Link to post
Share on other sites
Krohm    5030

I'm afraid I have to point you to ApochPiQ's Become a Good Programmer in Six Really Hard Steps.

Long story short: you crack your head open till you can figure out how to make those classes comminicate. There's no reading, nor learning. Adding more APIs might make it worse instead of better. Designing interfaces and protocols (sequence of function calls) comes from experience and you have to build that.

What you need to do is to really focus less on implementing and more in designing, or engineering if you want.

Also try to keep a decent documentation for your own code using doxygen: if you find that you cannot document something clearly, that means the concept regarding that class is unclear even to you.

And this is why you cannot connect the classes together: they don't have a "shape" you can perceive.

 

Also, if you tried to make a game (a single game) I'm afraid that's just normal. Just keep doing that.

Share this post


Link to post
Share on other sites
sup1    106

There are several options you can take:
 
1) Use a game library compatible with c++. Do not re-invent the wheel.
 


I use sfml but are there any other you would recommend?

Share this post


Link to post
Share on other sites
sup1    106

 
1) I am not sure how much c++ you know. But having a good grasp of object-oriented concepts.


I know inheritance, virtual function, multiple inheritance, reference, pointers, stl, and the basic c++.
And I made my own string class and smart pointer class.
Is that enough or I need to know and what?

Share this post


Link to post
Share on other sites
Nicholas Kong    1535


1) I am not sure how much c++ you know. But having a good grasp of object-oriented concepts.

I know inheritance, virtual function, multiple inheritance, reference, pointers, stl, and the basic c++.
And I made my own string class and smart pointer class.
Is that enough or I need to know and what?
Personally, I never used sfml.

Even making a simple game like Pong requires knowledge in keyboard events and mouse events because your game will be using keyboard or mouse to control the paddle.

You also need to have basic knowledge of the graphics window from the library you are using because the paddle and ball will actually be drawn to a graphics context or graphical surface.

You also need to understand the behaviors of the x and y coordinates of the ball and paddle. What would happen to your x and y when your ball or paddle moves in different directions?

You also need to know how to read the image and display an image.

You also need to write your game loop with update and draw functions. Because a game has to be in a loop otherwise your program will stop running. Each object in the game will need to be updated and drawn every frame.

Long story short: Consult the game programming library API and tutorial articles to get the basic fundamentals down. Start applying what you read. Edited by warnexus

Share this post


Link to post
Share on other sites
TheComet    3896

Some major free game development libraries are:

 

Additional libraries people use are:

Edited by TheComet

Share this post


Link to post
Share on other sites
EddieV223    1839

SFML2 is the best 2d library.  It's one of the few that is object oriented so using it will teach you good habits.  Check my sig for more info.  Also it uses openGL and openAL for graphics and sound so the classes are very good examples of code that you would write if you wanted to write your own low level openGL/AL code.

 

To the OP, what you need is a lot of practice making object oriented code.  Start simple making a pong game doesn't require scene nodes.  With sfml you could make a pong game in a hundred lines of code I bet, and it would be pretty clean code.  You could make a paddle class, a ball class, and simply use the sf::FloatRect class for collision detection.

 

Once you complete something easy like this, then set the bar a little higher, make a breakout style game, followed by a simple shooter, for example.  Use the sfml2 book as your guide, remember that while they use very high level abstractions in books quite a bit you don't have to, keep it simple especially at first, when you get more skilled you'll stumble into situations that you realize a certain design pattern or abstraction could be used here to simply things.  Do not force yourself into using them prematurely, doing so will confuse you.

Edited by EddieV223

Share this post


Link to post
Share on other sites
ShadowKGames    339

The easiest way for me personally was this way, first I learnt C# years back because it was simple (well kind of) to understand. Played with it at a high level, found out how basics like Raycasting, Physics (gravity, quaternion, Vertices etc.) worked.. Then I moved onto shaders, such examples are shaderlab, looking at how scripts interacted with shaders. How FXAA / MLAA / MSAA / Bumped Specular / BDIFF Bloom etc. worked.  I then moved onto C++, which ironically enough isn't a million miles away from C#.

 

 

 

,  

Edited by ShadowKGames

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this