TASK:
What is Density?
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #1
- Create an intro screen and game loop.
TASK:
What is the Sprite class?
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Add comments to your code that outlines the general control.
HINT:
You will add comments that will break up your program into the following logical sections:
initialize variables, create game objects, create groups, update groups, and blit groups.
HINT:
Watch the video below to check that you completed the task.
TASK:
Create the Ship class.
HINT:
You will need to create a class as you have previously in Pong, however, this time, the Ship class
will need to inherit from the Sprite class so that objects of type Ship can create groups and be controlled using a single command.
HINT:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #2
- Create two ship objects.
TASK:
Create a ship group and add the two ships to the group.
HINT:
You will need to invoke the Group() constructor and save the object in a variable called ship_group. Then, you can add the ship
objects by invoking the group object's add method.
HINT #2:
Watch the video below to check that you completed the task.
TASK:
Blit the two ships.
HINT:
You will need to invoke the draw method and give the screen as an argument. Remember that the draw method runs blit on every object in the group
using the object's image and rect instance variables.
HINT #2:
Watch the video below to check that you completed the task.
TASK:
Add upward movement using the get_pressed method.
HINT:
You will need to run the ship group's update method. In the
update method, you will need to invoke get_pressed() to read in the keystrokes and act accordingly.
HINT #2:
Watch the video below to check that you completed the task.
TASK:
Have the left and right ship move independently.
HINT:
You will need to add an additional instance variable to
each ship that distinguishes each ship from one another. Then the update method will run different
branch statements based on that instance variable, with the left ship reading 'wasd' and the right
ship reading 'up/down/left/right' then acting accordingly.
HINT #2:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #3
- Complete the movement algorithm.
TASK:
Create a vertical line surface that will act as a division and blit it to the screen.
HINT:
You will need to create a surface that is one pixel wide and a little bit less than screen height pixels tall.
Then you will need to blit it to the screen at the center.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #4
- Create an add a horizontal partition to complete the HUD(Head's Up Display) space.
TASK:
Stop the left ship from passing through the middle of the screen.
HINT:
To accomplish this task, you will need to add a branch statement to
your update method that will check if the ship has gone past the vertical partition and if it has, to set the
ship's x position to just left of the vertical partition.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #5
- Add the additional boundary conditions for the left ship.
- Add similar boundaries for the right ship.
TASK:
Create the Pill class.
HINT:
You will need to create a class as you have previously in Ship, however, this time, the Pill class will need a different set of instance variables such as one to hold it's density value.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Define the update method so that the pills fall from the top of the screen.
HINT:
Since the pills aren't moving on the x axis, you must define an update method that will change the object's rect's y position so that
it moves downward. Remember that you must remove the pills from the group if they fall past the bottom of the screen.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Start adding pills by printing the word “pill” to the console 6 times a second.
HINT:
Add a branch statement that will execute 6 times a second and print "pill". To
create a conditional expression that is true 6 times a second, you will need to create a counter and use the % operator.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Create instances of Pill.
HINT:
You will need to create objects of type Pill in the if
statement that we just created. Remember that the Pill constructor takes in a value for the x position
and a value for the density. We want the x position to be random and we want the density value to be between
1-4 with 1's appearing more often than 4's. CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Run pill_group update and draw.
HINT:
To get the pills you created to appear on the screen,
you will need to create a pill group, add the pills to the group and run the draw method on the
group.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Delete the pills after they go off the screen.
HINT:
To delete the pills, you will need to check their y positions
in the class' update method. If their y positions are below the bottom of the screen, you can remove the
pill object from the group.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #6
- Create pills for the right ship.
TASK:
Set the color of a pill to yellow, red, blue or black depending on it's density value.
HINT:
You will need to create a method that will set the color of the pill's surface
to yellow, red, blue or black based on the density value of the pill.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Cause the pills to disappear when the ships touch them.
HINT:
To get the pills to get eaten by the ship, you will need
to invoke the "spritecollide" method. Please take a look at the documentation and examples provided
on the Pygame website for more information.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Make the ship’s height and width a function of its density.
HINT:
We will be having the ship's dimensions grow based on its
density value. In order for this to happen, the ship's height and width must be a function of it's
density value.
CHECK UP:
Watch the video below to check that you completed the task.
TASK:
Make the ship grow based on it's density value.
HINT:
You will need to set the rect's width and height to
the square root of the ship's density value. Following that, you will need the surface's dimensions
to be affected based on those values.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #7
- Update the image for the right ship as well.
- Create Text objects that will display each ship's score.
- Create a density limit that will end the game.
- Add an outro loop that will state the winner of the game.
Congratulations!
You have completed the Density project!
You have completed the Density project!