Tags: %TAGME{ tpaction="" web="SCMP118/Fall2016" tag="" }% view all tags

Graphics with Allegro

An alternate lab 8

Due November 2



Your goal is to make a graphic simulation of 2 or more balls interacting in a box. See an example here: InteractingBalls.

For a really cool example try this.

Sample Code

A simple program using Allegro here.

The Allegro Manual is here: Allegro.


1. Install Allegro
On Mac

a. Paste the following in a terminal to install homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

b. Install Allegro:

Type "brew install allegro" on the terminal to install Allegro 5.2.x, the stable version.

c. Test out the install

  • Create a new c++ progect.
  • Paste the sample code into the main.
  • Right click on the project, select "properties"
  • Select "Linker"
  • Select the "..." after "Additional Options"
  • Paste in "-lallegro_image -lallegro -lallegro_primitives -lallegro_main".
  • Build and run the program.
On Windows

Follow these instructions (this is untested): Windows Instructions

or This

or http://liballeg.org/stabledocs/en/build/mingw32.html

2. Build a program with two (or more) bounching balls.
  • Review the example
  • The program basically sets up a timer loop. You really don't need to understand this fully to do the project. What you need to understand is the code in the "while () { ... }" loop. This code loops 60 times a second (the "al_wait_for_event(event_queue, &ev);" causes it to wait 1/60 of second between iterations. The rest of the code is pretty basic. The code maintains the X and Y position of an circle and draws it. It also uses the x and y to draw a line. Each time throug the loop the position is updated, and when it hits the side, it's direction is reversed.
  • You can learn about simulating the collisons of balls here: When Worlds Collide: Simulating Circle-Circle Collisions

Grading Table

RequirementGrading CommentsPointsScore
C++ code includes comments, with project information at top, pre and post conditions for each functions and other cmments as needed. 10
The C++ code has good formatting, indentation, and organization. 10
Good variable and function names, appropriate use of constants rather then literal numbers. 10
Functions: Logic divided up into cohesive functions with a single purpose 20
Runs: the program runs. You will need demonstrate it to the instructor 50
Total 100

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2017-10-26 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback