Click here to Skip to main content
Licence GPL3
First Posted 23 Feb 2007
Views 43,609
Downloads 715
Bookmarked 30 times

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

By | 23 Feb 2007 | Article
I propose a simple version of a Breakout (or Arkanoid) game in few C++ lines.
Screenshot - CImgBreakout.jpg

Introduction

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.

Explanation

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.

History

  • 23rd February, 2007: Initial post

License

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

About the Author

Ronounours



France France

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionAny way to get ride of empty console window on this? PinmemberPaul Reichow9:26 13 May '08  
GeneralRe: Any way to get ride of empty console window on this? PinmemberMember 80362674:01 23 Nov '11  
QuestionUnder 64 lines ? I beg to differ. PinmemberL.Denninger6:29 13 May '07  
AnswerRe: Under 64 lines ? I beg to differ. PinmemberNevetsRetxab18:40 7 Jul '07  
GeneralProduction level PinmemberBjornar1:41 1 Mar '07  
GeneralRe: Production level PinmemberMarkusS6:34 4 Mar '07  
GeneralRe: Production level PinmemberRonounours12:39 11 Mar '07  
GeneralRe: Production level PinmemberCoreyCooper11:14 5 Jun '07  
GeneralRe: Production level PinmembercosmiKcosmiK16:26 11 Jan '09  
GeneralRe: Production level PinmemberxMYx2:50 4 Feb '10  
GeneralRe: Production level PinmemberxComaWhitex19:42 8 Nov '10  
GeneralAwesome! PinmemberRavi Bhavnani5:56 24 Feb '07  
GeneralRe: Awesome! PinmemberPJ Arends10:07 24 Feb '07  
GeneralRe: Awesome! PinmemberRonounours10:54 24 Feb '07  
GeneralRe: Awesome! PinmemberPJ Arends11:17 24 Feb '07  
GeneralRe: Awesome! PinmemberOscarTV21:02 26 Feb '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 23 Feb 2007
Article Copyright 2007 by Ronounours
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid