CS 1101 - A-term 08

Homework 5 - Structs that contain Lists

Due: Friday, September 19 at 11:59pm

Read the expectations on homework.

Acknowledgement

This assignment is a modification of an assignment designed by Kathi Fisler.

Assignment Goals


The Assignment

Your job is to write a simple interactive game in which the player drops water from a plane onto a fire on the ground; the goal of the game is to put out the fire by dropping enough water on it. A snapshot of the game window appears below:

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.

Overview

To write this game, you will need to provide at least the following: Once you have these functions, you will run your game using the commands:
(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.

Images

You may use the following images to represent the objects in your "world". Use the "insert image" option under the "insert" menu to load an image into your DrScheme file; you can use 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.

small fire medium fire large fire plane

These images are from school-clip-art.com and clipartguide.com.

Problems to turn in for HW5

  1. Develop a data definition for a fire, where a fire has a location (a posn), and an intensity level (a number). Provide examples of data.

    (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!)

  2. Develop a data definition for a list-of-drop, where a drop has a location. Provide examples of data.

  3. Develop a data definition for a world. A world should be a structure that consists of an x-coordinate for a plane (we'll assume that the plane always flies at the same height), a fire, and a list of water droplets. Provide examples of data.

  4. Write the templates for your data definitions.

  5. Write a function 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.)

  6. Write a function 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.
Does this part of the animation work? Run the animation you have designed so far by including the following statements at the bottom of the Definitions Window (make sure you have defined constants for WIDTH, HEIGHT, and INITWORLD, where your definition for INITWORLD will be an instance of (make-world...)):
(big-bang WIDTH HEIGHT (/ 1.0 28) INITWORLD)
(on-redraw draw-world)
(on-key-event process-keys)

What to Turn In

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.