I learned C++ and SFML, What now?

Started by
10 comments, last by wicked357 11 years, 10 months ago
Hi good people!

OK, So I am learning C++ for more than a year now. I have watched some online tutorials (which sucked) So I decided to buy a book. I have read the book and I can say I am comfortable with the language now. After that I read some documentations on SFML. Now i'm trying to make Arkanoid, Breakout clone. But I don't know how to do things, what classes I should write, how every class interacts with each other. How to handle maps. And I need to learn some math about vectors and stuff. But I can't find a book or tutorial that covers it all...
I can find books but they are written for 3D games, and 3D maths. I don't know what to do. I'm REALLY lost...

I would like to hear how YOU learned to program games. What did you read, what tutorials have you read/watched? And how much math do I really need to learn.
“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
Advertisement
Have you checked out http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx ? Great set of tutorials using SFML and C++ to make a small Pong game. Not a huge game, but still enough to give you an idea what you'll need.

Have you checked out http://www.gamefroms...PP-Edition.aspx ? Great set of tutorials using SFML and C++ to make a small Pong game. Not a huge game, but still enough to give you an idea what you'll need.

Yeah I have checked it. But this is TOTALY not enough. It is really awesome article. Only if there could be more...
So yeah... I guess i'm doomed
“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
I learned by doing. At the time I didn't have internet or programmer friends, so apart from some very basic stuff, I made games on my own.

I guess that's the best way: doing it. Not just reading some book or maybe do the exercises in it.

For the specific examples you wrote:

1. What classes should you write? Well, that's a reason why I don't think learning C++ as a first language is good. Starting to think in classes up front is not a beginner topic in my opinion, but maybe I'm wrong about that one. Just hack for starting. Heck the shit out of the code so you learn what can be done or not, what leads to an unmaintainable mess, and what not etc.

2. Class interaction: the same as above (again: it's just my opinion, someone correct me if I'm wrong). Don't think in therms of classes, think in terms of desired behaviour, functions, and how you can break down bigger tasks to smaller ones that you can tackle, test, whatever. The more precisely and detailed you design the behaviour, the closer you will be to actually implementing it.

3. Map handling. There's no "map handling". There is file loading (not necessarily), arrays, data in the arrays, and accessing/manipulating the data.

4. Yup, you have to learn some maths, some "vector algebra" most importantly.


Maybe you should start smaller. Like Pong.


So to sum up: start small, invent and hack, and learn by trying things out on your own, not from some game making tutorials. you have to learn problem solving, and you can only do that on your iwn. Tutorials are only good (in my opinion) for very specific things, like explaining the use of specific features of specific APIs. Just like documentations. Use them as references but don't try to learn to think from them.


(I have the feeling there there are some BS in my post, but anyway...)

I learned by doing. At the time I didn't have internet or programmer friends, so apart from some very basic stuff, I made games on my own.

I guess that's the best way: doing it. Not just reading some book or maybe do the exercises in it.

For the specific examples you wrote:

1. What classes should you write? Well, that's a reason why I don't think learning C++ as a first language is good. Starting to think in classes up front is not a beginner topic in my opinion, but maybe I'm wrong about that one. Just hack for starting. Heck the shit out of the code so you learn what can be done or not, what leads to an unmaintainable mess, and what not etc.

2. Class interaction: the same as above (again: it's just my opinion, someone correct me if I'm wrong). Don't think in therms of classes, think in terms of desired behaviour, functions, and how you can break down bigger tasks to smaller ones that you can tackle, test, whatever. The more precisely and detailed you design the behaviour, the closer you will be to actually implementing it.

3. Map handling. There's no "map handling". There is file loading (not necessarily), arrays, data in the arrays, and accessing/manipulating the data.

4. Yup, you have to learn some maths, some "vector algebra" most importantly.


Maybe you should start smaller. Like Pong.


So to sum up: start small, invent and hack, and learn by trying things out on your own, not from some game making tutorials. you have to learn problem solving, and you can only do that on your iwn. Tutorials are only good (in my opinion) for very specific things, like explaining the use of specific features of specific APIs. Just like documentations. Use them as references but don't try to learn to think from them.


(I have the feeling there there are some BS in my post, but anyway...)


Thanks! Your post really helped me out.
“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
Just pratice really. I used xoax.net to get a foot on C++ and then I found some tutorials online how to make a win32 project. And I had

Sams Teach Yourself C++ in 24 Hours book. I followed along the book and the tutorials but I was making my own stuff rather than what they were doing. My goal was a small rpg text game. Which I was able to make somehow.

I guess similar to how you are feeling now, I felt kind of lost just following tutorials from the very begining. When I tried to do my own stuff, I was like frozen so to say.

While making that game, I acutally thought I would quit C++. Its too complex and I didnt know what the hell I was doing. There is a learning curve and you can only get over it by experiance and not giving up I guess. My little text game saw 3 revisions. But as I build it up, I started to see that my class design didnt work. Thought how to do it better.
I started planing things. Just a small plan.

Slowly you would get better and see how things are connected and how to make better classes. Initially there was only 1 class. But by breaking up the game and building it up step by step I got better.

Dont worry you are not doomed. Just relax a bit. Take a step back. Maybe try to plan the classes on paper to see how they make look like in the game. Who knows, maybe it would work ;)


[quote name='Inuyashakagome16' timestamp='1340023186' post='4950223']
Have you checked out http://www.gamefroms...PP-Edition.aspx ? Great set of tutorials using SFML and C++ to make a small Pong game. Not a huge game, but still enough to give you an idea what you'll need.

Yeah I have checked it. But this is TOTALY not enough. It is really awesome article. Only if there could be more...
So yeah... I guess i'm doomed
[/quote]
It at least gives you a framework of sorts to understand. You should be looking at each part individually, not the whole picture.


I learned by doing. At the time I didn't have internet or programmer friends, so apart from some very basic stuff, I made games on my own.

I guess that's the best way: doing it. Not just reading some book or maybe do the exercises in it.

For the specific examples you wrote:

1. What classes should you write? Well, that's a reason why I don't think learning C++ as a first language is good. Starting to think in classes up front is not a beginner topic in my opinion, but maybe I'm wrong about that one. Just hack for starting. Heck the shit out of the code so you learn what can be done or not, what leads to an unmaintainable mess, and what not etc.

2. Class interaction: the same as above (again: it's just my opinion, someone correct me if I'm wrong). Don't think in therms of classes, think in terms of desired behaviour, functions, and how you can break down bigger tasks to smaller ones that you can tackle, test, whatever. The more precisely and detailed you design the behaviour, the closer you will be to actually implementing it.

3. Map handling. There's no "map handling". There is file loading (not necessarily), arrays, data in the arrays, and accessing/manipulating the data.

4. Yup, you have to learn some maths, some "vector algebra" most importantly.


Maybe you should start smaller. Like Pong.


So to sum up: start small, invent and hack, and learn by trying things out on your own, not from some game making tutorials. you have to learn problem solving, and you can only do that on your iwn. Tutorials are only good (in my opinion) for very specific things, like explaining the use of specific features of specific APIs. Just like documentations. Use them as references but don't try to learn to think from them.


(I have the feeling there there are some BS in my post, but anyway...)

That's very true. Start small, LIKE PONG. I started with SFML with that tutorial I posted and I edited a few of the classes and played with the shapes. All of that is experience and learning you'll need.
I actually got into game programming by learning how "Metroid" worked. Not the best example for a pc-based modern game though.
As far as 2d games go, it's a lot easier than 3d, so that's one advantage of starting with a breakout game. Basically you're dealing with sprites, and backgrounds which are just bigger sprites that get drawn first. A 2d "map" is usually represented by an array. You can make it a static 2d array like map[100][100], or you can make it a 1d and use math to figure out how to translate from 2d coordinates to a 1d array offset:
[source lang="cpp"]offset = (coordY * width) + coordX;
[/source]
Each element in the array would be a tile number, and you could then render the image for that tile to the screen. Put that in 'for' loops for x and y and you've got yourself a map. For ease (not so efficient) you could just store a separate sf::Image for each tile. I'm not sure if SFML lets you render only part of the image or not, but what I've done in the past with DirectDraw (before it was obsolete) and windows GDI, was to basically have a "tileset" image divided into a 16x16 grid of tiles. Then you c an find the x/y coordinates of the tile you want within the source image by:
[source lang="cpp"]sourceY = int(tileNum / tilesPerRowInSourceImage) * tileHeight;
sourceX = int(tileNum % tilesPerRowInSourceImage) * tileWidth;
[/source]
Of course that's limited to 256 tiles, but you can make the dimensions larger. If you're using openGL textures though, you want to make your source image size a power of 2 or certain drivers might try to do a messy resize on it. I usually reserve tile # 0 for transparent.

One caveat is that certain image formats and GL textures put the origin (0,0) at the bottom-left of the image, while some systems start at the top left. If that happens just use (height-y) obviously. Not sure about SFML, I'm just starting to learn that myself.

There's a free program called "Mappy" that might be good for designing your levels. That will give you some test data to work with at least. It can save a raw format that you can just binary read into your map array. It's based on that second approach where all the tiles are stored in a single image.

One major hurdle to overcome is how to handle collision detection. There are math formulas on the internet for this, if you know the right math jargon to look for. You'd probably want something like "line segment intsersect test". There's one that can tell you the exact coordinates where it intersects. I like it better than a simple yes/no test because it lets you get right up to the edge. What I did once upon a time was to loop through all the non-zero tiles on the screen, and for each edge of the tile, figure out the x/y coordinates of the line that represented that edge. Then calculate the line segment from the current position to next frame position of the ball, and see if these intersect. (Edit: This can be optimized by only looking at tiles which are near to the ball. You can also eliminate half the edges by paying attention to the velocity of the ball. if it's traveling right, you only need to check the left edges of tiles, and so on.)

As for classes, it's really not necessary to make it fully OOP, but it wouldn't hurt to learn how to make a proper OOP project. I would at least have a class for the paddle or "Vaus", maybe one for user input cause you want to store the state of the input devices every time you get an input event from SFML, and probably one for the map. If you can manage to display a basic tile map I think you'll start figuring the rest of it out from there. Good luck! smile.png

Now i'm trying to make Arkanoid, Breakout clone. But I don't know how to do things, what classes I should write, how every class interacts with each other. How to handle maps. And I need to learn some math about vectors and stuff. But I can't find a book or tutorial that covers it all...

One of the best things about programming is that it doesn't matter if you know exactly to do. You learn every day. Just take a stab at it. Practice. You won't get it perfectly right the first time (or the first several times), but you sure as heck will learn a lot.

And if you can't find resources online to help you, here's what you can do: take your best guess at solving it and do your best. Once you hit a roadblock or can't get your head around something, come and post on these forums, showing people what you want to do, what you've tried, and what the problem is. You'll learn a lot.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Thanks guys! You gave me some really good advice's. I don't use forum very much (I made only 6 posts or so) But from now I'm going to use it more often :)
“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh

This topic is closed to new replies.

Advertisement