Simple Breakout Game Source (C, Allegro)

Aug 24, 2009

Download the Breakout Example Source Code

To play, move your mouse to position the paddle, and click to reset the ball when it is off the screen. Press the Escape key to quit. The zip file includes pre-compiled binaries for both Mac (breakout-mac) and PC/Windows (breakout.exe) – just double click those to play. The instructions to recompile these programs on your own are below – so that you can experiment making changes to the code to see how it works.

Compiling on PC/Windows

Download Dev-C++ 5.0 beta 9.2 ( (9.0 MB) with Mingw/GCC 3.4.2. After it’s installed, inside Dev-C++ go to “Tools” then “Check for Updates/Packages”, then under “Select devpak server” choose “ Community Devpaks”. Press the “Check for Updates” button, then check the boxes to install Allegro (the library for audio, input, and graphical functions) and Allegro Supplement (documentation and sample files). After that, open up the file I’ve included, which already has the Allegro library added to the Parameters section of Linker under Project Options (as “-lalleg”). Then use the menus to go to Execute, Compile & Run. Any time you make changes to the program source, you can update the game itself by repeating that last step to Compile & Run.

Compiling on a Mac

Download Xcode for Mac-only Development from Apple’s website to get all developer’s tools installed. Also download the Allegro source for Linux (I found that here). Double click that downloaded allegro tar.gz to turn it into a folder, then use the Terminal to ‘cd’ command your way into that new allegro-4.2.2 folder (need to learn the Basic Terminal Commands?), then type the following lines into the terminal to install Allegro:

chmod +x
./ macosx
sudo make install
sudo make install-man
sudo make install-applehelp
sudo make install-framework
sudo make install

Followed by using the Terminal to navigate into the folder containing the Breakout game sample source. Then type in this command:

g++ main.cpp core.cpp -o breakout-mac `allegro-config --libs`

NOTE that the ` is a BACKTICK on the same key as tilde (~), NOT a single quote/apostrophe from the same key as the parenthesis (“).

To edit the code, open main.cpp using any plain text editor (TextEdit, TextWrangler, DashCode…). To recompile the program to reflect changes made to main.cpp, repeat the step above for typing “g++ main.cpp…[and the rest]” in the Terminal.

Compiling on Linux

If you’re using Linux, I think you can figure this out.

Pro Tip Hint: check out the instructions for the Mac section.

(Originally posted as part of Vol. 5 Sec. 1)

Este artículo está disponible en español. Traducción por cortesía de Andrés de Pedro.

Learn and practice team game development with Gamkedo Club.
Membership worldwide. Professional support. Proven process.

Subscribe by e-mail to receive weekly updates with Gamkedo.Community interviews and YouTube training videos for game developers!


  1. […] simple brick game examples using Tile Arithmetic to track brick states via 2D array: check out my C++/Allegro Breakout Source from Vol. 5 or the ActionScript 3 Breakout Source from Vol. […]

  2. […] you’re ready to make the jump from text to graphics, check out this basic example of Breakout code programmed in C/C++, using the Allegro library for […]

All contents Copyright ©2017 Chris DeLeon.

Site production by Ryan Burrell.