ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

2D Game Programming In C++ under Windows

Updated on October 1, 2020

In This tutorial Series:

How Do They Do it?

Games aren't new, they have been around us almost from the beginning. And as soon as Computers came, Computer Games followed. I play Games, you play Games, we all play Games. Games like Sim-City, Age Of Empire Series, Skyrim, NFS Series, GTA, and every other of the genre-buster of this decade, as well as the ol' & good Mario, Dave (my fav), Tetris, and the most recent Global phenomenon The Angry Birds. The Influence of Games in our individual as well as social life is Just Undeniable! The recent success of Zynga Games. Yes, the giant behind the social games like Farmville, CityVille etc. proves the point. Gaming Industry is a living, growing & thriving Empire, in its own rights. Games are interactive, Games are addictive & Games make us feel Good!

But at one or other point in our time, we hit, "Whoa! Wish I could do that as well! Wish I could make a game." Sometimes we complain in sheer disgust, "Damn, this is so boring, anyone could make a better Game." Once you're into it, making games, things change, you begin appreciating and seeing games, from the eyes of 'The Creator'.

None are 2D, but these are just damn cool!
None are 2D, but these are just damn cool!

Again, How Do They Do It!?

If you just say Games, I've written Tic-tac-toe, Soduku Games that run in back-white console. Its only logic and ASCII characters!

But then, when we say Games, we're referring to those glossy, graphical 2D/3D games around us. Mind there are 2.5D 's as well!

Games are written in Programming Languages, the particular choice lies, with the proficiency of the developer, target Platform, budget, deadlines etc. C++ is very popular for writing Games for PC, C# is easier to develop with (cons: Higher memory usage). Java dominates the Mobile Phone Platforms. Python & Basic are also good. Recently HTML5 Game programming has emerged as platform-independent implementation. And everyone of us knows the Flash Games, you'll learn Action Script & bit of JavaScript for that.

Believe me, to start with, its just about loading some images, move them, manipulate them, display some text, and think logic for all of this! So its damn simple, for anyone with even slight programming background!

But All I have done as of yet, is to have my C++ compiler carry out the Algorithm, and output Text To The Console!

Nothing Graphical, nothing catchy! End of the Story? No! You're basically writing programs targeting the DOS or DOS-like environments, i.e. the Consoles. For GUI (Graphical User Environment) Applications and Computer Games, you have to interact with the underlying OS, use APIs (Application-Programming Interface). Graphics Libraries & Game Programming Libraries make this task easier, by abstracting out the Low Level Details, we usually won't like to bother about. Again, C/C++ provides no such capabilities in the language itself, for designing GUIs or fancy Graphics. But using the language, APIs can be utilized for achieving the purpose.

What was graphics.h bdw?

Still obsessed with Turbo C++ 3.0?It was part of Borland's Compiler's Graphics Library, and it targeted the DOS environment. Its available for gcc compiler, and you can perform low level routines, like drawing and rotating shapes. And we use something similar here, but much more powerful, and updated, and can give you descent GUIs for Games, because focus is on how to implement Game Logic flexibly, so we can't spend all the time in plotting a line.


You'll see, soon enough.

To a computer programmer, with some experience, things are clearer, but not everyone bothers to explore. To others, its just another World, the 'Third Level' ! Well whether a programmer or not, we all have The Curious Person inside of us. And Question of The Day is : "How To Program a Computer Game?"

Wait! Before I take you to the World of Game Programming (believe me, its too deep, and I'm gonna show you the way in), there's something I'd like to mention.

This Tutorial Series shows (Including the tutorials following this one) how to create a 2-D Game. The Programming language is C/C++ (And I'm bound to this, at least for this tutorial, since the library used, is for C/C++) . So, you should be familiar to C/C++, because this tutorial is meant to introduce you to Game Programming, not the programming Language itself. We'll use ALLEGRO, a Game Programming Library for C/C++. Its free, pretty Low level, flexible, has almost every feature you'll need for the 2D game, and Its Easy To Get Hold Of!

Another thing is that, the tutorial focuses on compilation on Windows Platform, Windows XP or Windows 7, will do . But if you have Mac/Linux Platform,this tutorial might give you mere pointers, as sole focus of the tutorial is "How to achieve this, this way.." (Sorry..)

No I repeat! Its not the only language you can program a Game in! In fact, its just one among the many. Recently there has been an surge of free Game Engines, which require you to only implement the Game Logic, through some easy Graphical Interface Eg. SCRATCH, Blender,Game Maker etc. But they are abstracting out the Details, and as such have low learning curve as pros but cons? Lots of inflexibility associated with them + Its like a magic box, and over-simplified. With some workable Lower Level API's, you can make descent Game Engines of your own!

What are Game Engines?

Basically Game Engines are bunch (huge one) of codes, which enable you to use the established template, to create similar Games. For eg. 'The Age Of Empire' engine, upon which the games in the series were built. Haven't you heard about about Quake Game Engine? There are Game Engines with Graphical Interface as well. And once you know how to design and implement GUI's, its just a matter of time, you've made a Game Engine of your own.

But again, you could mug your hands in Windows APIs (Which I've not courage'd much as of yet), low level Graphics, use DirectX/OpenGl, and do something awesome .

So Game programming can be done in every language that provides provisions to draw Graphics on screen! In a varied number of ways.

To our purpose..

As mentioned, our sole focus in 2D Game Programming in C++ under Windows. We'll use Allegro: A Game Programming Library, and its pretty low level. Let's see what we'll need.

Tools you'll need

First, You'll need a Compiler & preferably an IDE. We'll use DevC++ IDE, old, but simple, free, n open source and works good with the game programming library we'll use here (ALLEGRO). For Windows Users, you can download it from here

Install It, without hesitations :D

Second, you need the Programming Library itself, ALLEGRO.

ALLEGRO stands for Allegro Low LEvel Game ROutines. Yes, its another Recursive Acronym!

Why Do we need Allegro?

Because, C/C++, unlike JAVA or other languages, don't come with high level Graphics or Advanced Audio/Video or I/O required for Computer Games. It was written by Shawn Hargreaves in the early 1990s, as Wikipedia has it!

Now, it's a Giftware, and comes with lots of examples & good documentation.

It stands for Allegro Low LEvel Game ROutines. It doesn't come preinstalled. DevC++ IDE will minimize your effort in the installation part.

Getting Allegro:

Start DevC++. Go to Tools->Check for Updates/Packages. Select DevPak Server- Community Devpaks. Check For Updates.

After sometime, you'll see a list of DevPaks. From Groups, Select Allegro. Now mark the following:

  1. Allegro 4.2.2
  2. Allegro supplement
  3. AllegroFont (Because, By default Allegro supports PCX Fonts, but you would use TTF Fonts most of the time.)

These will get installed automatically.

You'll need a few more libraries, to make things easier for you.

1. (AlGif library)

2. (AlPng Library)

3. (JPGalleg Library)

The last 3 are required to work with Gif, png, and JPEG Images. ALLEGRO, by default supports BItmap Images.

Now install these. There shouldn't be any problem in this part.

Third , you need some Graphics Editing/ Picture Manipulation/Creation Suite. GIMP, is free & Opensource. If you've got Adobe Photoshop, that's great as well. Why?

Because, its why you play games so deep! Art! Game Characters, Scenarios, Textures, you love them, don't you? But right now, I'll suggest you, to focus less on this part, and more on the programming instead. Well I had no option, I'm bad at sketching/painting. So for me, I discovered that, there are large collections of Art in Public Domain, i.e Royalty Free & come without any copyrights.

These are a few websites:




you'll find lots of free resources on the Internet, which are good to give you a Head-Start!

Also, you might need a MIDI music editor, for composing some in-game music. Mp3 tracks can also be used. Just with some more downloads. We'll talk more on that later.

Update From Here. Then Select Allegro Packages listed.
Update From Here. Then Select Allegro Packages listed. | Source

The Action Plan

By now, you've got your system ready for some Game Programming, and you'll draw out some Imagination soon. But before that, Have we yet planned it Yet?

A Game is just another expression of art, in expression, in interaction, which makes it a unique form of art.

What do we need?

1. Story or Plot. Keep it Simple, and you might learn a lot, without getting dry & frustrated!

2. Game Logic- The Heart Of the Game.

3. Allegro Basics

4. Codes!!!!!

And finally, A Cup of Coffee (You, not Me)...

...and Lots of Patience!

So Where Shall we Start?

Simple, didn't we determine? Here we'll do some very simple things. Why? Ok you said 2D but Why Not a Mario Clone or Zelda Style Game?

Hold On, we're just beginning..we must start light! You can't expect to learn a new thing and doin' miracles with it at the same time. We must start very simple. Later you'll be creating better & more advanced games on yourself.

After we've learned Allegro basics, we'll make, say A Basketball bounce on your flicks. We'll start out simple, very simple, so that you can learn How to use the Graphics, and implement Game Logic, and later you can expand the Game, steadily. Here the journey begins, I'll show you "How to do this & that and create something good"...

Believe it or Not

Games are easy to make, once you've levelled up, and are comfortable with the Graphics & the Logic.

For instance, right now, I can create 2D Games, quite pretty and playable games. Its quite clear to me, using the ways I work. But I won't be making 3D games. Simply, because I've never attempted one. So once you learn simpler things, you'll be working at more difficult aspects, comfortably.

But one thing I'll assure, Game Logic, is what'll remain unchanged. In programming, this is the most vital step, developing 'Logic' for solving a particular problem. Second thing is playablility and presentation. The small Game like thing we'll create subsequently, in this tutorial series, won't be neither, because its simply there to share space with a Game programming tutorial. Its not a demo, its just a tutorial.

The First 2D Game I ever programmed ..
The First 2D Game I ever programmed .. | Source

Where To Go from here?

That was just the Introduction, and we'll visit the Game at last! Before that, we must learn 'Allegro Basics'. In the Next Tutorial, we'll see how to use Allegro Game Library to create the Game.

Next Tutorial: Allegro Basics


    0 of 8192 characters used
    Post Comment

    No comments yet.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)