Learning to code

im looking into game development a while now and i am looking to pursue it as a career when im older but theres one thing.. how do i learn to code? (C++) Thanks :)

  • http://www.learncpp.com/
  • http://www.cplusplus.com/doc/tutorial/
  • http://www.cprogramming.com/tutorial/c++-tutorial.html

Grab a textbook from the likes of Savitch (eg Absolute c++) and go from front cover to back. You will learn more and understand most importantly the way to think through problems and translate that into code.

well surely you are not expecting a whole tutorial posted here right? there are plenty of resources online you can easily find for that.
i am going to assume you want tips on really what's the best approach to it


what i can advice is that you learn with the simplest api you can. there is no need to bog yourself down with idiosyncracies of a quirky API and step on eggshells around it when you are just starting out and trying to learn!

when i was starting out i had the good fortune to get into gameboy, gameboy color and gameboy advance programming and it is the best thing i could ever have done -


it is incredibly rewarding to code for a simple handheld console like this because there is no need to talk to directx or anything like that, in a game console, you talk to the dedicated hardware directly, and there aren't many wrappers around it -

if you are interested in getting to learn with some fun experiments on a fun enviroment for developing and developing GAMES in particular, i can definitely recommend you get your feet wet by trying to code for a console, gameboy/gameboyadvance is what i would recommend, but there are other consoles you can be making little games for - even the sega dreamcast seems like a good choice, of course the consoles themselves have limits which you need to understand and take advantage of, but when you're starting out that's a long ways off until you can reach the limits of the console and really get every little bit of power out of them is a job for an experienced programmer.

it is also a good idea if you want to learn to make games early on (which i also recommend you do) that you start by copying an extremely simple game such as snake, pacman, or arkanoid as they are in the realm of what a beginner can hope to do on those systems and learn a lot while doing it
it is a mistake to be greedy with your coding or make plans that are too complex in the beginning,
you need to go very gradually -

the hardest part about programming is not writing the code or coming up with algorithms, it is being disciplined to write your code in a neat manner and put everything where it should be so you can keep expanding on your code when you have 10000+ lines of code, trust me it becomes a giant mess that is is an absolute chore to work with and it will eventually depending on just how messy you are being, possibly grind your project and your work to a halt

if you can learn to keep everything orderly and to write comments next to your code, you will be doing yourself a lot of favors down the road, then you only need to focus on the more practical part.

1 Like

by the way those c++ books are good but the problem with those generic command line programming books is that you don't learn how to handle graphics or make colission detection or anything game related with them.
just make sure you keep that in mind, they are a good resource definitely, especially if you are beginning, it is a good place to start by doing hello world and learning about data structures and methods and classes and intermediate stuff but games are some of the hardest programs you can make, and that's not me making it up - thats really how it is; so try and get some game related knowledge from the beginning it can't hurt.

also it is worth noting that experience and skills in game programming are not interchangeable with skills in game design - expect your first game designs as well as your attempts at making a finished projects to fail the first several times. like there will be times you will completely misjudge how the player will react to things that you put in the game, and this will happen somewhat often until you can get a feel for it.
programming knowledge + work ethic/discipline + game design skills is what is needed to make a finished playable game these days

also avoid the pitfalls of the mediocre game programmer -
you need to learn the concepts of


-finite state machines

basically what this means is that the player can only have 1 action that he is doing at any one time. and you let the animations actually guide what the game is doing.
if they are already swinging a sword, then you don't check if they are doing anything else- you just run the sword swinging animation until it is done. if the animation is done playing, that means they are done swinging the sword. once they are done and they are back to their neutral fighting stance position you check for another action they might do. 
if you check for every action every milisecond with if statements, you will overwhelm your cpu by having it do all sorts of checkups every second - this way what the game is doing most frames is just making sure the animations play, the priority is the animations of the character and they are what drives the game logic- this way your game is always silky because all it is handling most of the time is just dealing with keeping the animations flowing smoothly

-handling things as events

think about this. a simple button - you enabled the cursor, you have defined a top-left area for your button and a bottom-right to be the 2 opposite corners of your square/rectangle that will be your button.
so what you decide to do in all your brilliance, is to have 2 conditions met; that the mouse is inside the 2 coordinates, and that the button is pressed. - this is the wrong way to do it.
instead, we can make this a lot more streamlined!!!! let's do it.
let's first have 1 condition met and then check for the other; so when the mouse is inside the square, only THEN you check for the button press, fancy huh? this is still not the best way this should be done though.
what you really want to be doing is the other way around - wait until the player even presses the button, and WHEN he does, if it is inside the square, then you have your outcome.
this way is a lot more streamlined because you don't check every milisecond to see if the mouse is inside the box, you only have to calculate ONCE when the player makes the press, so let's call the button press an EVENT. this is what you want to be doing; this way it is guaranteed that it will always be a good experience for whoever is playing the game - ; when things are not in the screen you don't ever waste computing power to draw them, this is kind of the same thing - you don't want to be wasting your processing power when the player is not pressing any buttons as much as you can avoid it

-object oriented programming
i am going to use a quote to explain this;
"In an object-oriented approach to making nachos, you first identify the types of objects in the problem: chips, beans, cheese, jalapeños, and an oven. Then you begin the task of modeling those objects in software, without regard for the details of how they might be used in the final program.
For example, you can model cheese as an object in isolation from the other objects and then combine it with the beans, the chips, the jalapeños, and the oven and make them interact.
(but the microwave oven is a complex piece of machinery, where as chips are just flour tortillas..)
[it's too messy!];
You don’t want the details of oven-building mixed into
the details of nacho-building!. If you can’t define the objects and pull
them from the morass of details to deal with separately, you must deal
with all the complexities of the problem at the same time.
Someday, you may need to replace the microwave oven
with another type of oven. You should be able to do so as long as the
two ovens have the same interface. Without being clearly delineated
and developed separately, one object type can’t be cleanly removed and
replaced with another.
[you want to make your game objects reusable];
Ovens are used to make lots of different dishes. You
don’t want to create a new oven every time you encounter a new recipe.
Having solved a problem once, you want to be able to reuse the solution
in other places within my program. If you’re lucky, you may be able to
reuse it in future programs as well."

keep this in mind and learn to think of those elements in your code as objects that are separate code from your other objects and can be taken out of the program and put in a different program by itself and still work the same way.

these concepts will save you a lot of headaches down the line once you have a grasp of it

i think i have put a lot of good info on game programming here for you that is not necessarily what you find in a typical course for beginners on game programming; this is the stuff they DONT tell u!

1 Like

The both of you have really helped me out! I will get the C++ book and start coding for the gameboy advanced. Thank you so much! :)

Always look at code examples and C++ documentation. These can be very helpful when you are trying to figure things out.

I am taking an intro to programming logic course at a local college. Going straight into books you buy might get you to the syntax faster but it might be good to get an idea of the logic first and then learn the syntax. A community college shouldn't be too expensive if you’re taking one class, I think mine costs around $300.

In a time where a lot of games are built on pre-existing engines , would it not be a good Idea to download an engine and just jump into the deep end? Sure Unity is C# not C++ but as a dev you eventually end up learning multiple languages anyway.

C# would be an easy start and you could get something going quickly and easily without getting discouraged. As your skills improve you can delve deeper into game programming fundamentals and learn C++ either by yourself or as part of your tertiary education.

Just a thought , Most people who start from the bottom up trying to build a game never actually get there , because they are still writing their engine.

Also , Unity isn't the only engine out there , Unreal just released their engine for free, Im not sure about the scripting though or even what language it's done in , so thats why I mentioned Unity. I just see Unity as a good start into game dev these days.

technically speaking no. modding an engine is not the same as learning programming;
i have been on both sides; when i see quake modders work on the source code; they are doing guesswork on it to change things, reverse engineering on it - nowadays it is a bit more fancy - when you work with unrealengine3 which a lot of games are using now you are using the prepackaged tools to make a game - but it will never teach you what the proper groundwork is to build those features - it is simply not programming it is a lot more like modding but without the guesswork - i would call it a lesson in game design and game logic, which is important, but if the OP was serious about wanting to learn programming, then learning how to handle states and manage code is something you won't get out of using unrealengine even if you are pushing the limits of what that engine can do ;

if you want to learn both programming AND game design, but you can't be bothered to go through the books and the confusing syntax of C# or whatever - then try the game maker studio;
they have made some legit games with it and it is not a adobe flash-like graphical user interface like unity is - it is more like programming and it will teach you programming; game maker studio is the one simplified API i can recommend for learners of programming

game maker studio > unity for this reason; unity is too much like adobe flash editors and it discourages true programming, while game maker studio actually invites you to learn their own language GML which is very similar to C (basically you are learning all the same syntax as C)
but you can also code in a fun graphical way.

but i can second what you said about C#.
monogame/xna is a great place to start as well for a beginner, it is similar to console programming because in part it is console programming (xbox)

Most people who start from the bottom up trying to build a game never
actually get there , because they are still writing their engine.

this is true, so i'll drop this piece of advice again for the OP. (mentioned before it was best to make simple games)

for a single person or an indie studio the most advanced engine you should aim for is something like shovel knight realistically - don't go thinking you can make an engine with one zillion features and use it to make your game; if you want to make a game like crysis then use unrealengine3. you don't want to make ragdoll physics from scratch or build the vis tree or anything like that.
if you want to make an advanced 3d game by yourself the best thing you can do is learn monogame or xna, but it will still take a few years to make an engine and all the while you will have no game developed -

so to recap:
-if you have a simple idea, you are good, you can even do it in c++ and code in directx.
-if you have a medium sized, sort of ambitious idea, even a simple game in 3d, you need to use xna
-if you have a very complex idea, use a good engine with a lot of features like unrealengine

but if you just want to learn how to properly make games and programming and about problems in game design, then game maker studio is a good choice and their community is great.

1 Like