Where to start C++ Programming
Abstract
A very quick start guide to provide direction in beginning C++ programming including various useful links by other authors.
The Beginning
In general, if you are new to programming altogether, then a higher level language should be used as your first language. A common favourite is Python which is still commonly used today in games, applications and web development.
If you still want to use C++ as your first language for whatever reason, then completely forget about programming for anything beyond the PC for the present. It will only add an extra layer of complexity that will stop you from learning the language and the main concepts of programming.
Learn the fundamentals first, these include:
- Variables
- Conditional Statements
- Loops
- Functions
- Return values
- Parameter passing
Gamedev have a C++ workshop that has been going for a while now that you still might be able to catch up. C++ Language Tutorial from the cplusplus website is considered to be decent and ToohrVyk’s unfinished but promising tutorial set. Finally, there are free eBooks on the Internet that are highly acclaimed such as C++: A Dialog. However, nothing will substitute a good real book on paper. Many programmers recommend Beginning C++ Game Programming by Michael Dawson as a good introduction into the language which covers most areas well. At this point, you be mostly working with text in a console (i.e. command prompt).
Targets
- Guess the number
- The computer randomly chooses a number and the player has to guess the number based on feedback from the program.
- Hangman
- The computer randomly chooses a word from a list inside a file and the player has to guess the word by letter.
Beyond Text
After this you can move onto more language specific areas such as the pointers, references, const usage, inline functions, header/source organisation and more importantly the Standard C++ Library. One of the best books in this area would be Thinking in C++ Vol1 and Vol2 by Bruce Eckel and can be downloaded for free in various formats and the C++ FAQ Lite.
Also you can start looking at graphical libraries such as SDL and OpenGL, both of which are cross platform and work on many other hardware platforms such as the GP2X, PSP Dreamcast and XBox. This means that you can develop the game on the PC and with some minor changes to the code, recompile and it should work on other hardware platforms that the libraries have been ported to as well.
LazyFoo’s SDL and Nehe’s OpenGL tutorials are the best in these areas.
Targets
- Snake
- A graphical clone of Snake. Focus on data structures (for the snake’s body), game states and efficient collision checks.
- Tetris
- A graphical clone of the popular Tetris game. Basically an extension of what was learnt from the previous Snake game.
- Pong
- A graphical clone of the popular Pong game. Focus on time based movement, basic physics and basic AI.
- A 3D maze level
- The player should be able to free roam around a 3D world loaded from a file. The graphical detail should not need to be anything higher then Doom.
Object Orientated Programming (OOP)
During the above projects, you should have at least encountered references to OOP and possibly design patterns. Below are a selection of PDFs on the five principles of OOP:
- The Single Responsibility Principle
- The Liskov Substitution Principle
- The Interface Segregation Principle
- The Dependency Inversion Principle
- The Open-Closed Principle
Sourcemaking also have a nice site on Design Patterns, Anti Patterns and Refractoring.
Working on games? At the bottom line, there is little difference in approach to designing a Word Processor and a Game. They both require careful thought and preparation before starting otherwise you end up with a very hacky and messy code base (commonly referred to spaghetti code) which will hinder your project’s progress like a brick wall as you try to extend/expand the program.
Mathematics
Keep up your math skills at a good level, especially areas such as Trigonometry, Algebra and Vector math. They are invaluable in programming especially game programming. Later on, you will need to have some knowledge of matrix math when dealing with 3D scenes. The FAQs below will give you a quick overview on Matrix and Vector math.
Other bits of information
- Organizing Code Files in C and C++
- Game Programming Wiki
- Doing a platform/jump and run game? Take a look at jnrdev
- Building a Game Engine? Take a look at the Enginuity series: Part 1, Part 2, Part 3, Part 4, Part 5.
[...] Continue read here. Posted by yaustar Filed in Articles Tags: Articles, cpp, development [...]
A very great wrap up about learning game programming!
I think from the steps above I still need to tackle APIs (Direct3D), OOP Principles, more math, and more game projects..
I did a pong, snake, and frogger clone using SDL a while ago (hey, it fits the target you mentioned up there :p). However, now that my understanding of C++ became deeper, I realized that a lot parts of them are poor. If I managed to fix/optimize them in my spare time, do you think they could be included in a portfolio? Or is it a big NO to put those clones as a part of a portfolio?
Clones are fine to be demo material. Make sure it is polished and complete though, attention to detail is key.
Ideally something unique/unusual helps as it stands out more but polished and complete clones with good code is perfectly valid.