COMP 141: Project 8
Angry Birds with Graphics
You may work with a partner for this project. If you choose to do so, only turn in
one copy of the project with both of your names in the comments at the beginning of the code.
If Angry Birds doesn't particularly interest you, you may do one of the challenge
problems at the end of this description, or propose a different
project to me of comparable difficulty. You must get my approval before starting work on it.
For this project, you will write an Angry Birds program in two parts. The first part is
similar to the lab we did in class to write a text-based Angry Birds program. The second
part is to add graphics. Get Part A working before you begin Part B.
Part A
Your program should do the following (very similar to the in-class lab):
- Read in an angry birds file stating the types and locations of the birds.
(sample here) This file contains a description of the starting configuration
of the pigs, only the pigs are named by type.
- The types of pigs you must
support are are "regular,"
"helmet", "moustache", and "king." (That link is for fun, not because you actually
need to read any of that information.) In your program, each type of pig starts
with a certain number of points. Regular pigs start with 1 point, helmet pigs with
2, moustache with 3, and kings with 5.
- A pig disappears when its energy drops
to zero or below.
- When a pig disappears, it leaves a gap where it used to be; the other
pigs do not "slide over" to fill the gap. In other words, the list of pigs always
stays the same length; it does not get smaller and smaller as the pigs are defeated.
- You may not assume that there will always be five pigs at the beginning; there could be more or fewer.
- Let the user launch different types of birds at the pigs. You must support
at least the red, blue, purple, and orange birds, though I encourage you to be creative
and add your own types.
- Print, after each bird launch, the energy of each pig remaining. You should
not leave out any pig with zero energies; make sure all pig energies are printed.
- When the pigs have all been defeated, end the program.
How to do it:
Read in your angry birds file and make a list containing the energy levels (points)
for all the pigs. For instance, if your angry birds starting file contains the lines
regular, regular, helmet, moustache, regular, then you'd make a list containing
[1, 1, 2, 3, 1]. (The point of reading from a file is so you can have
different files with different levels of difficulty.)
Then enter a loop that lets the user choose a bird type and launch it. Some bird types
will need to ask the user where they want to launch the bird. Print the list of
pig energies after each launch.
Bird types you must include:
- A red bird is the simplest bird. It is launched at a specific pig,
and always decreases that pig's energy by 1 point.
- A blue bird zooms over all the pigs and decreases all their energies by 1 point.
- A purple bird seeks out the pig with the highest energy still remaining and
eliminates that pig (sets its energy to zero).
- An orange bird seeks out the pig with the lowest energy (but still greater than zero)
remaining and eliminates it.
Part B
After Part A works completely, you will add graphics to your program as follows:
- At the beginning of your program, open a graphics canvas and draw, using the graphics
commands, visual depiction of the row of pigs. The visual depiction should display the pig
(a circle is fine) with the energy of the pig inside the circle (use draw_string from the graphics library).
You may make your pictures more sophisticated, but this is the minimum (you are not graded on artistic ability).
- After each bird is launched, update the pictures of the pigs to reflect their new energies.
I suggest using the clear_canvas() function to erase the canvas after each bird launch so you can
re-draw the pigs from scratch (rather than re-opening and re-closing the canvas after every launch).
- The graphics do not have to be animated. You just have to show what the row of pigs looks like after each bird has been launched and the pigs' energies have been updated.
Hints
- I'm going to leave program design completely up to you. Use whatever functions
you deem appropriate or necessary (there's no "right way" to do this). However,
that doesn't mean you can forget or ignore all of the good coding practices you have learned.
Possible enhancements
- Add more bird types. Ideas:
- A bird that is targeted at a specific pig,
but also damages the pigs to the immediate left and right as well.
- A bird
that is launched at a specific pig, but then bounces to a neighboring pig and eliminates
it (similar to this bird).
- A magnetic bird that is launched at a target and draws all the other pigs around it
to that target (moves them as close as possible, removing any gaps). This way
you can then launch a bird that damages surrounding pigs next.
- Add more pig types. Change their visual depictions to distinguish between
them. Make it so as they lose energy, they change color or are drawn differently.
- Add barriers that can be destroyed, like in the real angry birds game. For instance,
every pig might be guarded by a certain type of material (e.g., wood, plastic, metal)
that has to be destroyed as well. Different types of birds react differently to different
materials. You can do this by using a second list that is the same length as the pigs
list, that stores the material that guards that pig.
- Store the pigs in a grid (2-d list) rather than a list, and let the pigs be stacked
on top of each other. You can choose how the birds will target the pigs (maybe they
can only destroy the top-most pig in each column first, or maybe they can
target any pig in any row/column, and surrounding pigs will drop down by gravity).
- Use the mouse to let the user pick bird types or launch locations.
- Something else!
What to turn in
Through Moodle, turn in your code as a file called angrybirds_yourLastName_yourFirstName.py.
Alternate challenge programs
Here are some alternate games with graphics you could create.
These are all significantly more difficult as they involve a 2-d grid.
You should feel very comfortable with your programming skills in order to attempt these.
- Angry Birds with a 2-d list instead of a 1-d list.
- Candy Crush Saga
- Minesweeper
- Diamond Dash
- Bubble Safari