# Computer Science 1 Homework 8 Classes A Bird in the Hand

\$30.00

## Description

Part 1: CS 1 Birds
Computer games such as Angry Birds are based on simulating the basic rules of physics, or at least
some rough approximation to these rules. These simulations involve a simple basic loop where in
each iteration
1. The positions and sometimes the velocities (not here) of moving objects are both updated by
a small amount.
2. Objects are checked for collisions, and changes are made to the simulation based on these
collisions.
While never 100% accurate, realistic looking results and physically useful predictions (for scientific
simulations) can be obtained by making sure the changes in each loop iteration are small.
We will apply this idea to a simple version of angry birds called CS 1 Birds. Along the way you
will get practice writing classes.
The simulation occurs over a rectangular region whose lower left and upper right corners are
locations (0, 0) and (1000, 1000). Take note of the playing field. This is different than we
used for the wandering trainer. It now corresponds to the upper right quadrant of a graph. The
simulation will include birds, pigs, and barriers all represented by circles. Bird, pig and barrier
positions are in floats and correspond to points in cartesian or (x,y) coordinates. The pigs and
barriers are stationary, but the birds will move along a line (no gravity!). Each bird will move in
turn, slowing down or stopping when it strikes a pig or a barrier, and stopping when it becomes
too slow or when any part of it goes outside the game rectangle. When a bird strikes a pig, the
pig will “pop” and disappear from the simulation. When it strikes a barrier, the barrier will take
damage, but may or may not disappear depending on its initial strength and how many times it
has been hit. The simulation ends when either all pigs have been “popped” or when all birds have
stopped, whichever occurs first.
We can summarize the possible behaviors as follows:
 Bird
1. fly – Update the current position by dx and dy
2. collide with a pig – Decrease x velocity by a factor of 2
3. collide with a barrier – Total velocity becomes 0