The plane moves left and right across the screen, controlled by the player pressing the left and right arrow keys. The player can also drop water from the plane by pressing the down arrow key. The fire has an intensity level: when a drop of water hits the fire, the intensity of the fire decreases. If the fire burns without water hitting it, its intensity increases. The fire is extinguished (and disappears) when its intensity reaches zero. The game ends when the fire has been extinguished.
A more advanced version of the game might include multiple fires spontaneously erupting. We'll just concentrate on having one fire for now.
You'll build this game using the world.ss teachpack. Work
in the "Beginner with List Abbreviations" language level.
draw-world that consumes a world datum (from the
previous
item) and produces an image of that world (using place-image
and empty-scene
as shown in the world.ss documentation). The
place-image
function
produces a scene, so you can nest calls to place-image to put
multiple objects
into a single scene.
process-keys that consumes a world datum and a
key-event
(symbol) and produces a new world datum reflecting changes in the
world based on keys pressed.
update-world that consumes a world and produces a
world
reflecting what happens when no key is pressed (ie, the intensity of the
fire increases, the water droplets continue to fall, etc).
game-over? that consumes a world and produces a
boolean indicating whether the animation should stop.
(big-bang WIDTH HEIGHT (/ 1.0 28) INITWORLD) (on-redraw draw-world) (on-key-event process-keys) (on-tick-event update-world) (stop-when game-over?)where WIDTH, HEIGHT, and INITWORLD are constants you define for the size of the game window and the initial configuration of the game. You may omit any of these lines if you haven't yet written the corresponding functions (like
game-over?)
You should provide test cases for any functions that produce data. You do not need to provide test cases for a function that returns an image or a scene.
define
to give an image a name. The fire images will be used in HW6. You'll also
need an image to represent water droplets. You may use a circle
(see the circle operator in world.ss), or if you
find another image for water droplets that you like, go ahead and use that.
These images are from school-clip-art.com and clipartguide.com.
(Note that DrScheme provides a built-in define-struct for coordinates, called a posn:
(define-struct posn (x y))
Do not type this into your definitions window -- it is built in!)
draw-world that consumes a world
and draws a scene represented by that world. In this version of
draw-world (you'll be enhancing draw-world
later), just draw an image of the plane in the top middle area of the
scene;
ignore the water drops and fire for now. You may use the image of a
plane
shown above. When you test this function,
you may assume that
the list of water droplets is empty. You'll need to provide a
(make-fire...) in your test (but you won't be drawing the fire).
(You do not have to pass in a test case for this function, but you should
test it out on your own in the Interactions window.)
process-keys that consumes a world
and a symbol, and produces a world. The world produced reflects
changes based on the key that was pressed. If the key-event is 'left,
the position of the plane has moved to the left, if the key-event is
'right, the position of the plane has moved to the right.
(make-world...)):
(big-bang WIDTH HEIGHT (/ 1.0 28) INITWORLD) (on-redraw draw-world) (on-key-event process-keys)
Save a copy of your work - you will use it for Homework 6. Answers to Homework 5 will be made available on Saturday, Sept 20. Using web-based turnin, turn in a single file hw5.scm containing all code and documentation for this assignment. Make sure both partners names and wpi usernames appear in a comment at the beginning of the file.