A1: Event Loops and Drawing (C++/Xlib) -- Breakout!

Due Fri Sept 28 at 5:00 PM


Implement a "breakout" game in C or C++ and Xlib.

Breakout is a simple 2D video game, originally published by Atari in 1976. "In the game, a layer of bricks lines the top third of the screen. A ball travels across the screen, bouncing off the top and side walls of the screen. When a brick is hit, the ball bounces away and the brick is destroyed. The player loses a turn when the ball touches the bottom of the screen. To prevent this from happening, the player has a movable paddle to bounce the ball upward, keeping it in play." (see Wikipedia.)


Learning Goals

Game Requirements

There are many versions of Breakout playable on the web (here or here). You need to implement a simple version that includes the following features:

Technical Requirements

  1. Implement a breakout game of your own design using C++ 14 and Xlib, meeting the game requirements described above.
  2. Your assignment must compile and run on one of the linux.student.cs computers, since this is where they will be graded. Your makefile should include correct command-line arguments for g++ and C++ 14 features in that environment (e.g. g++-5 -std=c++14 program.cc -o program)
  3. Your game must accept two command-line parameters: (1) "frame-rate", measured in frames per second, which controls how often the screen is painted or redrawn, and (2) the "speed" of the ball in-game. Acceptable values are: 10 to 60 for frame-rate, and 1 to 10 for ball speed. Changing the frame-rate should NOT change the speed of the ball.
  4. Your game should open with a splash screen that includes your name, userid, and a description of how to play the game (including a description of which keys to use).
  5. Your game must use the keyboard to move the paddle. In-game actions should include the ability to move the paddle left and right, and quit the game.
  6. Gameplay should progress as described above.
  7. Assume that the TA marking your game is a terrible gamer. You'll want to tune the game so that it provides an enjoyable experience for novice gamers.
  8. You're encouraged to be creative in this assignment! Some portion of your grade is based on building an enjoyable and exciting game.
  9. Your window should run in a fixed-size (non-resizable) window, sized to be 1280x800 pixels. You should prevent the user from resizing the window.
  10. Your game should use double-buffering to eliminate any "stuttering" in gameplay.
  11. Your game should be single-threaded.
  12. Your event loop must:
    • Not consume all of the CPU cycles (test: Run the "top" command in one terminal while running the game in another. Your game plus the X server should consume less than 25% of the CPU -- and even 25% is high).
    • Repaint on a regular basis (i.e. repaint using the values from the command-line parameters)
    • Respond to events on a timely basis (i.e. can handle many events coming all at once, such as resizing the window, without lag.)
    • Be easy to understand (i.e. few nested loops, appropriate use of helper functions, etc.)
  13. Submit a makefile such that the default target will compile and execute your program.


Submit the following to your personal Git repository, in the assignments/a1 subdirectory:


Late assignments will not be accepted. Your submission will be assessed roughly as follows:

Working game that meets the basic gameplay requirements described above.
Technical requirements met, including command-line parameters, proper handling of the event loop. There is no lag, and the screen resizes and repaints properly.
Screen design, aesthetics, enjoyable gameplay.


Versions that have been released: