Game Programming in C++
  • I've been working now for a couple of years on honing my skills in game programming for the PC with C++, and I find a constant lack of usable discussions on the subject. There are far too many people just posting junk, and it makes the search for anything usable that much harder. So I've started this forum thread to discuss in greater detail the finer points of C++ game programming.
  • So, I was talking with my cousin and he expressed some concern with the lack of decent tutorials about C++ for people not already familiar with the topic. So, tonight I'm posting a short tutorial on how to start programming in C++.

    First thing you need to know about when programming in C++ is where you should write your code. With C/C++, you can write your code anywhere, as long as it is on a computer. Your code can be written in a text editor, in a word processor, or any which place you chose. The important thing is that you must be able to save it in a .c, .cpp, .h, or .hpp format. For this task, I suggest one of two programs I use in windows, at least to start out. Use either Notepad++, or Bloodshed Software's Dev C++.

    There are plenty of other applications out there for compiling code, and many have great features, but these two applications are the easiest for new programmers to set up and use for writing code. A problem exists for both options, though. The problem with the first is that it is just a developer-oriented text-editor, and so is not able to compile your code (that is, turn it into a usable application). The problem with the second is that it is essentially a dead project. No development has been made to Dev-C++ in almost six years.

    That being said, for the sake of this tutorial and the ease of use, download Dev-C++ and run the installer in Windows. Once the application is set up, you will be in your work area. From there, look at your toolbars at the top. One should have an icon that looks like a white rectangle, or piece of paper, with 'new' right next to it. Click to get a drop down menu that lists four options. For the first few tutorials, we will only be concerned with the first option, which is New Source File. Click it and lets get started.

    Once into the new source file, which is simply the human readable version of your code, you are presented with a blank canvas. The first few brush strokes you will apply are simple, just type:

    #include <iostream>

    int main()
    {
    std::cout << "Hello World!" << std::endl;<br />
    return 0;
    }

    Now, go up to the toolbars again, and press the button that looks like four colored separate colored blocks. The program will ask you to save your file and give it a name. Name the file hello_world.cpp and save the file, hopefully somewhere memorable (for beginners a folder on your desktop labeled 'programming' is usually best), a new, smaller window pops up and says compiling..., then should very quickly switch to a bolded Done. You have just created your first program.

    Go to the folder that you have your source file saved in and there should now be a .exe file as well. Double click it and a window should pop up and disappear just as quickly. That window is the command prompt window, and it will only stay open as long as it has work to do unless you specifically open it to stay open.

    The quickest way to do that is to hold the windows key down and press the R button. This opens the run dialog, where you just type in 'cmd', with out the quotes of course.

    Once there, we get to use some good old DOS commands. If you saved the source file on your desktop in a folder called programming like I asked you too (okay, I didn't really, but honestly, it will make this a whole lot easier if you do), all you have to do now is type in 'chdir ./desktop/programming/hello_world'. This will launch your program in a window that will not disappear the moment it pops up, and will let you witness your handy work. In the black box should now be the words Hello World, followed by a blinking cursor.

    Congratulations! You just wrote your first C++ program.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

Categories

  • All Discussions7
  • CG Art
  • Music Production
  • Game Programming
  • Tech Support
  • Product Support
  • General

In this Discussion