Click here to Skip to main content
12,955,891 members (64,003 online)
Click here to Skip to main content
Add your own
alternative version


30 bookmarked
Posted 23 Feb 2007

A C++ Breakout Game Clone in Less than 64 Lines

, 23 Feb 2007 GPL3
Rate this:
Please Sign up or sign in to vote.
I propose a simple version of a Breakout (or Arkanoid) game in few C++ lines.
Screenshot - CImgBreakout.jpg


I propose here a cross-platform C++ version of the well known Breakout game (or Arkanoid if you prefer). The interesting thing here is that it is coded in less than 64 lines of C++ code. While the code is quite compact, it stays easily readable. The secret ? I use the CImg Library to perform all necessary operations on images. The CImg Library is an easy-to-use C++ template image processing library that has the particularity to entirely fit in one single header file. It means that with a single include, you are able to deal with images and perform many operations on it (display, filtering, drawing, ...).

This work follows my previous submission on "Tetris in less than 128 lines of code", already proposed on CodeProject.


The code is divided into two distinct parts. The first one creates games graphics (colored bricks, ball, racket and background image) from scratch, using the primitive drawing functions of the CImg Library.

The second part consists of the main event loop, catching the user's events and computing the ball/racket motion and the possible collisions. In fact, there's nothing specially difficult here, but all is coded in quite a compact way.

This is a good way to see how simple it is to code small animations using the CImg Library. It is also worth noticing that the source is cross-platform and you may compile it on Unix or Mac OS X without modifying a single line. I hope this may give some idea for people that are discouraged because of the relative code complexity needed when one wants to do basic image operations inside C++ source codes.

Proposed Archive

The proposed archive contains the small source code of the game (file 'breakout.cpp'), the CImg Library header file 'CImg.h' needed for the compilation, as well as the compiled executable (Win32) and the Visual Express 2005 solution used to compile. So, the archive should be self-contained.

Hope you'll enjoy it.


  • 23rd February, 2007: Initial post


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

France France
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
Destiny77712-May-13 14:59
memberDestiny77712-May-13 14:59 
SuggestionObviously the code works... But... Pin
Destiny77712-May-13 14:56
memberDestiny77712-May-13 14:56 
QuestionAny way to get ride of empty console window on this? Pin
Paul Reichow13-May-08 9:26
memberPaul Reichow13-May-08 9:26 
GeneralRe: Any way to get ride of empty console window on this? Pin
Member 803626723-Nov-11 4:01
memberMember 803626723-Nov-11 4:01 
QuestionUnder 64 lines ? I beg to differ. Pin
L.Denninger13-May-07 6:29
memberL.Denninger13-May-07 6:29 
AnswerRe: Under 64 lines ? I beg to differ. Pin
NevetsRetxab7-Jul-07 18:40
memberNevetsRetxab7-Jul-07 18:40 
GeneralProduction level Pin
Bjornar1-Mar-07 1:41
memberBjornar1-Mar-07 1:41 
GeneralRe: Production level Pin
MarkusS4-Mar-07 6:34
memberMarkusS4-Mar-07 6:34 
GeneralRe: Production level Pin
Ronounours11-Mar-07 12:39
memberRonounours11-Mar-07 12:39 
GeneralRe: Production level Pin
CoreyCooper5-Jun-07 11:14
memberCoreyCooper5-Jun-07 11:14 
GeneralRe: Production level Pin
cosmiKcosmiK11-Jan-09 16:26
membercosmiKcosmiK11-Jan-09 16:26 
GeneralRe: Production level Pin
xMYx4-Feb-10 2:50
memberxMYx4-Feb-10 2:50 
GeneralRe: Production level Pin
xComaWhitex8-Nov-10 19:42
memberxComaWhitex8-Nov-10 19:42 
GeneralAwesome! Pin
Ravi Bhavnani24-Feb-07 5:56
memberRavi Bhavnani24-Feb-07 5:56 
GeneralRe: Awesome! Pin
PJ Arends24-Feb-07 10:07
memberPJ Arends24-Feb-07 10:07 
GeneralRe: Awesome! Pin
Ronounours24-Feb-07 10:54
memberRonounours24-Feb-07 10:54 
GeneralRe: Awesome! Pin
PJ Arends24-Feb-07 11:17
memberPJ Arends24-Feb-07 11:17 
GeneralRe: Awesome! Pin
OscarTV26-Feb-07 21:02
memberOscarTV26-Feb-07 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 23 Feb 2007
Article Copyright 2007 by Ronounours
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid