Click here to Skip to main content
Click here to Skip to main content

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

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)

Share

About the Author

Ronounours

France France
No Biography provided

Comments and Discussions

 
GeneralMy vote of 2 PinmemberDestiny77712-May-13 15:59 
SuggestionObviously the code works... But... PinmemberDestiny77712-May-13 15:56 
QuestionAny way to get ride of empty console window on this? PinmemberPaul Reichow13-May-08 10:26 
GeneralRe: Any way to get ride of empty console window on this? PinmemberMember 803626723-Nov-11 5:01 
QuestionUnder 64 lines ? I beg to differ. PinmemberL.Denninger13-May-07 7:29 
AnswerRe: Under 64 lines ? I beg to differ. PinmemberNevetsRetxab7-Jul-07 19:40 
GeneralProduction level PinmemberBjornar1-Mar-07 2:41 
GeneralRe: Production level PinmemberMarkusS4-Mar-07 7:34 
GeneralRe: Production level PinmemberRonounours11-Mar-07 13:39 
GeneralRe: Production level PinmemberCoreyCooper5-Jun-07 12:14 
GeneralRe: Production level PinmembercosmiKcosmiK11-Jan-09 17:26 
GeneralRe: Production level PinmemberxMYx4-Feb-10 3:50 
GeneralRe: Production level PinmemberxComaWhitex8-Nov-10 20:42 
GeneralAwesome! PinmemberRavi Bhavnani24-Feb-07 6:56 
GeneralRe: Awesome! PinmemberPJ Arends24-Feb-07 11:07 
GeneralRe: Awesome! PinmemberRonounours24-Feb-07 11:54 
GeneralRe: Awesome! PinmemberPJ Arends24-Feb-07 12:17 
GeneralRe: Awesome! PinmemberOscarTV26-Feb-07 22:02 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 23 Feb 2007
Article Copyright 2007 by Ronounours
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid