This homework continues using the graphics framework introduced in Lab 1.
Remember to follow the Expectations on Homework when preparing your solutions, including the academic honesty policy.
Your job is to write a simple interactive game in which the player drops water from a plane onto fires on the ground; the goal of the game is to put out all of the fires by dropping enough water on them. A sample appears to the right. The plane flies continuously back and forth across the screen (i.e., the plane is always moving, regardless of what the player does). The player can change the direction of the plane by pressing the left and right arrow keys. The player can also drop water from the plane by pressing the down arrow key. Each fire has an intensity: when a drop of water hits a fire, the intensity decreases. As a fire burns without water hitting it, its intensity increases. A fire is extinguished when its intensity reaches zero. You will build this game using the same Work in the Beginning Student with List Abbreviations language level. To enable this language level, select Choose Language from the Language menu in the top toolbar, and then under Teaching Languages select Beginning Studentwith List Abbrevations. NB: Before clicking Ok in this menu, click on Show Details (lower left corner) and change the Constant Style to "true false empty". Finally, press Run button (top right corner) to make this change take effect. | |
A data definition for a "world", which is a single data structure containing all of the logical information that makes up the current configuration of the game (including the plane, fires, water drops and their component information).
Do not assume the same number of fires for every playing
of the game. You should be able to change the number of fires simply
by changing the definition of INITWORLD
(see below). You do not, however, need to write
code to automatically generate a random number or placement of fires for each game play (as this will make writing test cases difficult).
Include all data definitions needed to write your overall world data definition. Function templates are required for all data definitions.
A function draw-world
that consumes a world
and produces a graphical scene of that world, using
place-image
and empty-scene
as you did in
lab. (Hint: Notice that the place-image
function produces a scene, so you
can nest calls to place-image
to put multiple objects
into a single scene.)
A function update-world
that consumes a world and
produces a world reflecting what happens when no key is pressed (i.e.,
the plane continues to move, the water continues to fall, etc.).
A function process-keys
that consumes a world
and a key-event (symbol) and produces a new world with
changes based which key has been pressed.
Once you have these functions, you will run your game using these built-in functions (as you did in lab):
(big-bang INITWORLD (on-draw draw-world) (on-tick update-world) (on-key process-keys))where
INITWORLD
is an instance of the world datatype.
You must decide what other functions to implement as part of
writing the required functions listed above. However, we expect
you to follow the design-recipe strategy used in class in which one
function uses one template to operate on one data definition.
You may bend this rule for posn
's nested within
other structures (i.e., you don't need a separate function just to
process the posn
), but not for other data types you define.
Also, if a function consumes two defined data types, pass one
one argument directly to a helper function that uses that type's template to
operate on it. If you don't follow this design recipe, this assignment
will take you far longer than necessary. You'll also lose substantial
points in the grading.
If you and your partner prefer to work separately, work out and agree on the data definitions first, then proceed to work on the rest of the code (together or independently).
Implement the game in stages, not all at once. Start with a simple version that lets the user change the direction of the plane's movement, but has no fires or water. Once you have that working, add the water drops and get them to fall. Once that is working, add the fires. Get the fires to decrease in intensity when water hits them, then get them to increase in intensity when no water falls on them.
You will get more credit for a fully-working solution to part of the game than for a non-working solution to the whole game. You should have the game working at least through water drops falling for a passing grade on this assignment.
You will be graded primarily on the structure of your code, not on efficiency. Don't worry about efficiency. Your computations to check whether a water drop has hit a fire need to be reasonable, but do not need to be exact (i.e., don't waste time on getting these expressions correct down to the pixel). If the resulting game play looks plausible, we won't care about the precise formula you used.
You may simply specify a stop-when
(see lab)
function to stop the game when all fires are extinguished. You do not
need to add fancy screen graphics with the result of the game; you
will not get extra points for doing so (though you are
welcome to do this if you want).
You may use whatever images you wish for the pieces of the game
(the ones we used are below; feel free to use them or plain circles
and rectangles if you prefer). We used the circle
function provided in the teachpacks to draw the water drops, e.g.,
(circle 5 "solid" "blue")and the different sized fire images for different ranges of intensity of fires.
You do not need to reverse the image of the plane when it reverses direction or do anything fancy with the graphics. No extra points for fancy graphics work!
You do not need test cases for functions that return scenes, but you do need test cases for all other functions.
Remove extinguished fires from the world: certain aspects of the game will be much easier to program if you do this.
Increase the intensity of the fire at a much lower rate than you decrease it (or the game becomes unplayable). Our prototype increased intensity at 1/100 the rate of lowering it, for example. You will want to use numbers with decimal points, rather than just integers for this.
Grade your own homework according to General Grading Guidelines before you hand it in!
Turn in a single file hwk2.rkt containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.