RU beehive logo ITEC dept promo banner
ITEC 380
2011fall
ibarland

homelecturesexamshwsbreeze (snow day)

hw06
finishing asteroids
higher order functions

Due Oct.21 (Fri)23 (Sun)
In this assignment, we'll finish off the asteroids game (by adding bullets and detecting collisions), using higher-order functions like map, filter, and foldl as appropriate.

All non-drawing functions require at least two test cases! Good test cases and signature are worth about half the points for a function.

As mentioned on the discussion board:


  1. What is the signature for map?                 
    (that is, the version of map we wrote in class, and that is in the student languages).
  2. Read the documentation for foldl and foldr (in DrRacket, hit F1 while the cursor is on each of those words; look at the version provided by racket3).
    1. What is the difference between what each function does?
    2. What is a difference in the run-time resources used internally?
    3. (What term from lecture presumably accounts for the difference? )
    4. Which version should you prefer, if either will work?
  3. Consider the higher-order function non, which takes in any boolean predicate and returns a new predicate that behaves in the opposite4way: (non positive?) is a function that takes in a real number, and returns true if that number is negative or zero. Similarly, (non ship?) takes in any value, and returns true if it's not a ship structure.
    1. What is the signature of non?
      Remember, you can't just say its input is “function”; you have to give the signature of that function.
    2. Give two tests of calling the result returned from calling non.
    3. Write non.
  4. Copy your hw04 solution to a new directory. Make sure your language level is “Intermediate plus lambda”.
  5. Update move-asteroids so that it is a one-line call to map.
    Update draw-asteroids so that it is a one-line call to foldl.
  6. Write a structure to represent a bullet. Note that in the original game, bullets time out after a while; what does that require as far as the information needed to represent a bullet?
  7. Write move-bullet, which simply updates a bullet by one tick passing (but does not worry about collisions).
  8. Write move-bullets.
  9. Write a function representing the ship firing. It should return just one bullet. Include test cases.
  10. Write draw-bullet.
  11. Write draw-bullets.
  12. Update your world structure, as well as move-world, draw-world and handle-keypress (or whatever you called the functions that did these tasks), to handle bullets.
    First just update the code and test to handle the extra field; we'll worry about all of firing, collisions, and bullets timing out later.
  13. Now we will start to handle collisions.
  14. Update your move-world so that it removes bullets that have timed out. (Use filter and lambda. I recommend make a separate function for removing bullets, but you don't need to. Regardless, you should have a couple tests.)
  15. Update your move-world so that it removes asteroids that have been shot.

    This involves two steps: First write code that takes in a list of asteroids and a single bullet, and removes all the asteroids which overlap the bullet.
    Then write a function that takes in a list of bullets (You can use the list-processing template, or foldl.)

  16. Add a keypress-handler, to let a ship fire.
    It' be nice (but not required) to have a way to slow the rate at which bullets are released. You might have the ship require a “recharge time”, or just not allow new bullets while there are too many existing bullets.5
  17. Extra credit: Have large asteroids break into smaller asteroids.
  18. Extra credit: Have bullets disappear, after they blow up an asteroid.
  19. Extra credit: add sounds. See play-sound; credit all sound files used, and do not use sound files that you don't have the copyright to. The only time you are allowed to call begin is when calling play-sound.

1Or at the least, all code except for possibly one-to-two line snippets that are straightforward.      

3except that the intermediate-student version only folds a single list at a time, which is the only way we've seen it in class.      

2 The version functions are provided by the intermediate-language is actually the same3, but the documentation/explanation is better for the racket version.      

4 Well, that's not quite true, since the input function might loop forever or throw an exception, in which case non will do that. So perhaps we should say “(non f) returns a function which behaves as f, except that (non f) returns the boolean-negation of what f returns (if anything).”      

5 I was also going to mention just the simple hack of using on-release (rather than on-key) to slow the player's rate of firing. Alas, on-release isn't working; a bug report has been submitted, and this has been fixed in the experimental nightly-build.      

homelecturesexamshwsbreeze (snow day)


©2011, Ian Barland, Radford University
Last modified 2011.Nov.03 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme