Game Programming for Beginners
Jan 10, 2013β
There are so many computer languages that many beginners get lost in them and never learn anything. Below are the most appropriate languages for Mac and iOS development here.
This is one of the most prefered languages by programmers. While it may look complex at times, it’s actually very logical. In the 1990s and early 2000’s, most games were written in pure C. Marathon, Duke Nukem 3D, Quake 3, and dozens of games using the id Tech 3 engine are just a few. While these days most games are not (for various reasons), for small independent games, it’s still a perfectly good choice.
One of the most difficult parts to understand about the C programming language is memory management and pointers. For beginners, this can be very confusing so when jumping straight into C for your first game it can be pretty slow. The great thing about learning it, though, is that once you know them you can learn almost any new language in a day.
These days, instead of writing games in C most professional/industry games are written using C++ foundations (game engines). The fundamental difference between C and C++ is that C++ is an “object oriented” language. Object oriented programming (OOP) is a very broad topic beyond the scope of this article, but to put it simply, unlike a procedural language such as C where all of the possible actions and processes your code performs are organized into one big list of “functions” which call each other, object oriented programming languages offer a way to structure all of those actions and process into a hierarchy of “classes” which group together closely related bits of data and functions.
While OOP is the modern way to approach programming, there a few caveats to the C++ language itself. There’s a lot that’s happening behind the scenes and sometimes your app may behave differently, making your debugging life a living hell. C++ is also a very complex language. Once you get into multiple inheritance, templates, operator overloading, etc, you’ll quickly discover why some forum members dislike C++ and would rather use C. On flip side, you don’t need to use all of those features, so you can certainly use C++ cherry-picking the nice parts.
Objective-C / Objective-C++
Objective-C is what’s used when you develop Cocoa applications for Mac OS X and iOS. Objective-C is a strict superset of C meaning that any legal C code is legal Objective-C code, but Objective-C also goes further by adding object oriented capabilities. It’s a very clean language and is often used by beginners, since Cocoa and Objective-C offer simple ways to do complex things, or things that would be complex to do in other languages. You could say that this language is like an OOP version of C, without the dangers of C++.
Objective-C++ is a superset of Objective-C which also allows it seamlessly interact with C++ code. This means that when you use Objective-C++, you can use C, C++, and Objective-C syntax all within in the same program. This has great advantages, allowing you to combine an existing cross-platform C++ foundation with a Objective-C front end to interact with Cocoa in Mac OS X or iOS. It’s a very powerful capability.
Java got its popularity from being a language allowing developers to write a Java-based program (called an applet) and embed it in a website. Since then Java has matured and spread to become a commanding force in server-based applications, but for end-user applications (like games), it’s not very common to see. Even still, it is possible write games using it. Java’s biggest draw is that cross platform ability where you can write a program once, and it’ll work on multiple platforms. It’s an interesting way to create cross platform games without having to deal with porting. While it is possible, if you want to create a complex 3D game, don’t use Java. A straightforward and practical reason not to, is simply because not many people do, which means the amount of available help and reusable code available is going to be slim. (Java can be used for simple 3D games. Runescape is an example of this.)
An excellent IDE and library to get started with Java is Processing, free at http://processing.org. There is also the Lightweight Java Game Library LWJGL. LWJGL provides developers access to high performance crossplatform libraries such as OpenGL and OpenAL allowing for state of the art 3D games and 3D sound. Additionally LWJGL provides access to controllers such as gamepads, steering wheels, and joysticks, all in a simple and straightforward API.
Python with PyGame or Pyglet
One language that is growing ever more popular among newbie game developers is Python and the game libraries PyGame and Pyglet. Python is a pretty simple language to get the hang of, and it’s powerful enough to write really good games. An advantage to using a language like Python which has dynamic typing and a garbage collector is that you don’t need to learn as many nitty gritty details as you would with a C-like language. Instead of focusing on the syntax of the code, you can focus on what the code does. When you start with a language like Python, it will be a good stepping stone for moving on to C/C++/etc later. Do a Google search for Python and PyGame or Pyglet tutorials, and you may well be on your way.
Large modern game engines almost always include the use a scripting language. There are two halves to a game. The first is all of the lower level core β the graphics renderer, sound mixing, networking, physics, etc β and the other half is the actual game logic itself β AI, triggers, weapon characteristics, etc. The first half tends to be performance-critical; It needs to be as efficient and as fast as possible, while the all of the game logic is relatively simple that game developers put more importance on the readability as well as speed and ease of change in that code. For that reason, scripting languages are often used to control a lot of the game’s logic, while a lower level language, like a C variant, is used for the performance-critical pieces of the code.
If you have a modding background, you’ll almost certainly have used scripting languages like UnrealScript or Lua. While scripting is very common to see used in AAA games, it’s not necessary for you to try to add a scripting language in your game. Higher level languages like Lua, Python, Ruby, etc offer freedom from the compiler and generally stricter syntax, they are in no way necessary to create games. Plenty of games have been made without them, even recent AAA games. So when you’re starting out, looking at writing your first few games, do not try to go straight to the top and build a super fast an efficient C-based game engine, and tack on a Lua bridge for game logic scripting. Instead, just concentrate on learning how to build your game, and actually finish it.