## CS 115 Program 2 Angry Birds Fall 2017

Due Dates:
Individual Design: Friday, October 27, midnight
Phase I, Text version source: Friday, October 27, midnight
Phase II, Graphical version source: Sunday November 5, midnight

Assignment total points = Design (20 points) + Runs test cases (20 points) + Implementation Phase I (40 points) + Implementation Phase II (30 points) + Style and documentation (15 points) = 125 points

#### Submit all program materials (.py files) with the link here.

Educational Goals: The goals of this program are that the student should use the concepts of

• design using pseudocode
• output of prompts and labels to match specified output
• input of values from the graphics screen
• using random library functions
• using math library functions
• calculations in assignment statements
• accumulators
• Zelle graphics
• if/else statements
• definite loop
• documentation

You are going to write a program that will play a (simplified) game of Angry Birds. The red bird is flung across the screen to try to hit the green pig on the other side. The pig is either hit or he is not. You get a point for every pig that you hit.

This program will be done in TWO stages. Design and implementation will be done with console (Shell) output first. Then the graphics elements will be added.

You will need these formulas:

• distance traveled by a projectile (neglects air resistance)
vel is the initial velocity, angle is the angle of launch (in RADIANS), sin is a mathematical (trigonometric) function. The notation in the distance formula means that the angle is multiplied by 2 then sent to the sine function as the argument.
• maximum height reached by a projectile
height is the maximum height, vel is the initial velocity, angle is the degree of launch (in RADIANS), sin is a mathematical function. Note that this notation means that the sine of the angle is taken first, then the result is squared.

It is assumed that the pig is "near" the right side of the screen. It does not stay in the same place all the time; in fact, it moves a random (but small) amount for every round. Note how the distance to the pig changes with every round in the runs below.

Sample Run WITHOUT the graphics:

Angry Birds!
Bird is at left edge of screen.
Pig is at right edge of screen.
Enter angle and velocity to catapult the bird to make it land on the pig

How many rounds do you want to play? 3
Level of difficulty? (smaller is harder) 10

Round # 1
The pig is 124 meters away
What angle? 45
Initial velocity? 40

The bird flew 163 meters
and reached a height of 41 meters
you missed

Round # 2
The pig is 149 meters away
What angle? 45
Initial velocity? 35

The bird flew 125 meters
and reached a height of 31 meters
you missed

Round # 3
The pig is 100 meters away
What angle? 45
Initial velocity? 37

The bird flew 140 meters
and reached a height of 35 meters
you missed
You got NO pigs!

Another sample:

Angry Birds!
Bird is at left edge of screen.
Pig is at right edge of screen.
Enter velocity and angle to catapult the bird to make it land on the pig

How many rounds do you want to play? 3
Level of difficulty? (smaller is harder) 40

Round # 1
The pig is 124 meters away
What angle? 35
Initial velocity? 40

The bird flew 153 meters
and reached a height of 27 meters
you got the pig!

Round # 2
The pig is 149 meters away
What angle? 45
Initial velocity? 35

The bird flew 125 meters
and reached a height of 31 meters
you got the pig!

Round # 3
The pig is 100 meters away
What angle? 45
Initial velocity? 25

The bird flew 64 meters
and reached a height of 16 meters
you got the pig!
you got the pig 3 times

## Testing

Link to the tables of test cases.

## Design

Decide on what steps you will need to perform to solve this problem. Put it in Python form as comments. Save this Python file as "design2.py". See this page about how to write control structures in a design. You are expected to use a loop and an if/else statement. Note that you should NOT consider the graphics part of the problem when you are doing the individual design.

There are some specifications that your design and program MUST meet.

• Details about the bird's and the pig's location: The bird should be assumed at 0, 0 or something close to the left edge of the screen. The pig is assumed to be close to the right edge of the screen. The pig should not be in a fixed location, through the whole program. Use the random numbers to move the pig for each round, closer or farther away from the bird's location. For Phase I, use random numbers between 100 and 150. For Phase II, use the size of the window to determine the pig's distance. The "angle" that is input is relative to the ground. Horizontal would be zero degrees, straight up would be 90 degrees and so on. The user gives the angle in degrees, the sine function requires the argument in radians. There is a nice function called radians in the math library that will take one argument, a number in degrees and returns a float answer in radians.
• Your code must use the control structures: loop(s) and if statement(s).
• Note that the formulas give float answers; they are rounded to integers in display.
• Do not use anything we have not done in class.
• At the end of the game, your program must report the resulting number of pigs (points) that the player hit. If they did not get any, there should be a different message (like "You got none!") instead of just "You got 0 pigs". If they only got one, it should say "You got 1 pig".
• The level of difficulty can be any integer. Think of the difficulty as how close you have to get the bird to the pig to count it as a 'hit'. A difficulty of zero would be nearly impossible! A difficulty of 10 would be a little easier. A difficulty of 50 would be pretty easy. A difficulty of 100 would be ridiculously easy. The larger the level is, the easier the game is. The abs function is useful here.
• You MUST have a main function.
• You may NOT use any global variables. All code (except import statements) must be inside the main function. Submit this design .py file with the link. Choose the menu choices of "Design" and "Program 2". This is due by Friday October 27, midnight.

## Phase I

### Implement the design with SHELL output (Text), NOT graphics

Write a Python program to implement your design. You may have the help of ONE student, as well as of Dr. Keen and ALL the TAs. Start with a copy of the Python file you have that has the design in it and write your Python code between the commented lines of the design. Make sure you eliminate any syntax and semantics errors. Verify that the program provides the correct behavior.

## PLEASE put in the line "seed(25)" at the top of your main function when you turn it in.

This makes it easier for us to run the test cases. Submit your individual source code (.py file) with the link above. Choose the menu choices of "Code" and "Program 2". This is ALSO due by Friday, October 27, midnight.

# Phase II

Now that you have your logic working correctly. implement the program again as a graphics program. Use the gifs at the top of the assignment page or get others, if you like. They must be called bird.gif and pig.gif. Submit this program by Sunday, November 5, midnight, using the link above.

The description of the graphics part is here.