Game programming

I've decided to try to program a simple game like vvvvv or something of the Mario sort and was wondering if someone could tell me where I could begin. Any pointers would be helpful. Also, is it recommended to use cpp as the language?
C++ is your best bet for a language. It is object-oriented and faster than Java. C# is an option but generally limited to Microsoft platforms.

Are you experienced in C++? Programming a game like VVVVV is not really "simple". Programming pong is simple.

Anyway... you will need to install OpenGL (http://en.wikipedia.org/wiki/OpenGL) for the graphics rendering. There are some complementary libraries you will also want to install (see Associated libraries section of wiki page above). The primary one you will want it either GLFW or freeglut.

When you are compiling the code you will want to put the OpenGL headers in the search path (e.g. -I/opt/X11/include) and link the OpenGL libraries (e.g. -l/opt/X11/lib/libGL.dylib -l/opt/X11/lib/libGLU.dylib in g++ main.cpp -o main -I/opt/X11/include -l/opt/X11/lib/libGL.dylib -l/opt/X11/lib/libGLU.dylib

Note, the paths above are SYSTEM-SPECIFIC depending on where the headers and libraries are installed (I am using Mac OS X Yosemite and macports as my package manager for GLFW/freeglut). I would recommend using CMake to generate the build rules if you plan to ever build the code on another machine because CMake has a find_package() routine that will take care of finding the headers and libraries on that system. Also with regards to the header search paths, this is assuming you are using the form #include "GL/gl.h" for including the OpenGL headers in your source code, since gl.h is in /opt/X11/include/GL/gl.h.

Personally, I haven't done graphics rendering on Windows so the following is for OS X/Linux: when building, you also need to add the X11 folder to the header search path and link against the X11 libraries since X11 is the windowing system OS X/Linux runs OpenGL in.

I would start by making a simple test.cc file that has only a box or a sphere and trying to get it display before you do any coding specific for the game. Getting something as simple as this to compile and display properly when you are starting out can take quite a while when you first start out.

Once you can do this, my personal recommendation is that you will want to take advantage of the object-oriented and polymorphism of C++ to display your scene. For example, you would want to create an abstract base class (named maybe DrawableObject and has a pure virtual function "draw()") that your game character and all the objects (obstacles, etc.) in the game inherit from and implement the "draw()" function. This way, you can simply keep two containers: all the objects and a list of the objects in the current scene. When your calculations of which objects are currently in the scene (removing the objects that aren't in the scene from the aforementioned scene-only container), the location of the characters, etc. are finished, you just simply loop over the scene-only container of DrawableObjects and call the draw() function -- Side note, I'm recommending to do the calculations completely separate from the drawing/rendering. In other words, calculate everything and THEN draw everything; don't calculate one object, then draw that object, then calculate another, and so on... Imagine the graphics representation as built on top of the calculations such that you could turn off the visualization and the code would still run. This approach has the benefit of being more flexible (e.g. calculating the step of a character and not drawing would allow you to implement higher-order integration techniques such as Runge-Kutta 4th), the executable will likely run faster since it has to jump less to the rendering instructions in the linked libraries, and it will be much cleaner and easier to debug with the drawing routines separate from the calculation routines.
Last edited on
Hey, first of all thanks a lot for taking the time and effort to type out all that and explain. By vvvvv I meant a game that's a scroller, ie, one like Mario which just scrolls along. I'm not really that experienced, but nonetheless, I'll definitely try to implement your ideas. And yeah, I'll definitely consider separating out the two. This was really helpful, thanks! :D Ill keep updating as we move along. One more. Question though, which compiler would you recommend? Turbo is quite buggy... And dev seems like a good option? I've asked a few other people, but you seem to know what would be useful so..
Well first off, none of those are compilers, they are IDEs (Integrated Development Environment). An IDE is kind of like Word for coding, in that it is basically a fancy text editor with a bunch of features/tools added in. On Windows, all of those IDEs use either MinGW or MSVC to compile the C++ code, on OS X/Linux the IDEs generally use GNU or Clang. Essentially, an IDE is a text editor that allows you to run the compiler from it (in addition to other tools like a debugger), hence the integrated part.

Anyway, since you are talking about Turbo, it's clear you are using Windows, which I don't use at all so I can't speak towards using that or dev. While I always use Xcode on my Macs, when I run Linux I've found Qt Creator and Eclipse to be very good IDEs with a slight preference for Qt Creator, and those are available on Windows I believe. Codeblocks is also another decent IDE.
Hi

Sorry for my English in advance

I want to write a simple 2D games via sprite sheets. I began from the example: C:\Qt\Qt5.4.0\Examples\Qt-5.4\opengl\qopenglwidget

It is drawing by Qt OpenGL ES. This is my example: https://github.com/8Observer8/Lesson008_TexturedSquare
how to:
- draw a square by two triangles
- put texture on the square
- move the square

It is enough for the 2D sprite game

I use GIMP a little like this: http://www.youtube.com/watch?feature=player_embedded&v=FgpIaQ4xk78

I am writing the "Battle City" game. Please test my first steps. This is exe for Win7 and source code in Qt 5.4: https://yadi.sk/d/KYHagmMJdzuns

Can you run my exe and say me "it was run or not"?

I want to study how to use Blender because I want to make 3D models for my "Battle City" game for writing "Battle City 3D" game. Maybe do you know good video tutorials?

What do you think about my way and about my code?

Pratik K, I hope you will find my example and source useful for yourself :)

I use Qt 5.4 MinGW and sometimes I work on Linux Mint
Last edited on
This is the Snake Game in Qt 5.4 OpenGL: https://github.com/8Observer8/SquareSnake

This is not my code. I only changed it from GLUT+glBegin/glEnd to Qt5.4+Shaders: http://www.youtube.com/watch?v=GiZGEFBGgKU

It is a very good OOP!

You can ran the exe: https://yadi.sk/d/v6S-tqqVdzxFR

It is a picture: http://i9.pixs.ru/storage/9/6/6/SquareSnak_1352621_15601966.png
Topic archived. No new replies allowed.