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

homelecturesexamshwsbreeze (snow day)

hw04
assembling asteroids
let the game begin

Grading note-to-self:

For the local section: Due Sep.28 (Wed)29 (Thu)32 (Sun)1 23:59 (D2L; bring hardcopy next class) Your name and the assignment-number must be in a comment at the start of the file.

Implement the functions below. Following those requirements is a discussion of ways our game can differ from the original game.

    All non-drawing functions require at least two test cases! (Point-values are subject to slight tweaking.)
  1. (3pts) Write a function draw-ship which takes in a ship and an image (the screen / background), and returns a new image which contains [a picture of] the ship overlayed on the given background.
    See the racket documentation for helpful image-drawing functions. (Either search directly, or take a function you know about (like circle), put the caret over it, and hit F1 to call up the documentation.)
  2. (3pts) Write draw-astr : astr, image -> image.
  3. (3pts) Write draw-astrs : (list-of astr), image -> image.
  4. (3pts) Design a world structure, to represent the entire asteroids game. Construct some examples.
  5. (6pts) Write move-world : world -> world and draw-world : world -> image.
  6. (3pts) Have your code call big-bang, providing it on-tick and on-draw handlers.
    You can look over the file big-bang-example.rkt dicussed in class, for a medium-length example of using big-bang (followed by a short example). And/or, racket-lang.org's splash page “Start Quickly” examples include a balloon-inflating example.
  7. (9pts) Implement controls: Rotate the ship when the user presses the right or left arrows, and apply thrust when the user presses the up-arrow. (As in the classic game, applying thrust will accelerate the ship but only in the direction it's facing.)
    You'll of course want a helper functions accelerate-ship and rotate-ship, along with test cases for those functions.
  8. We will approximate collision-detection by treating all our objects (ships, asteroids, and later bullets) as circles2. Half the points are for test cases.
    1. (3pts) Write overlap?, which takes info about two circles (two (x,y) centers and two radii), and returns whether they overlap.
    2. (3pts) Write collide-ship-astr?, which takes in a ship and an asteroid, and returns whether or not they are colliding. (You can approximate collision by whether their "bounding circles" overlap.)
    3. (3pts) Write collide-ship-astrs?, which takes in a ship and a list of asteroids, and returns whether or not the ship collides with any of them.
    4. (1pt) Provide a stop-when handler to big-bang.

All that remains is adding bullets and effects of their collisons! You can think about, and perhaps start coding, those functions3.

We're looking for a asteroids-like game, but we don't need to implement every feature of the original. In particular, it's acceptable to punt on the following issues.

Post/ask on discussion boards if you have other questions/suggestions. The ultimate point of the exercise is to

Opportunities are rife for extra-credit, by adding additional features. Don't do this until you get the above functionality working, though!


1Sep.32 being a non-normalized representation for Oct.02      

2 If you prefer to use rectangles for bounding-boxes, see me for advice. If you want to use some other collision-detection approach, I encourage you to run it by me first.      

3 One can use strutures with inheritance, although you have to abandon the student languages for that.

#lang racket
;; Be sure to have selected 'Language > Determine language from source'
#lang racket
(define-struct foo (a b) #:transparent)
(define-struct (goo foo) (c d e) #:transparent)

(define f (make-foo 98 99))
(define g (make-goo 1 2 3 4 5))

(foo-a f)  ; 98
(foo-a g)  ; 1
(goo-c g)  ; 3
  
     

4 If you did want to go the extra mile and handle both key-release events (in addition to key-press events), it would presumably requires adding state to the ship representing whether or not it is currently in the middle of acceleration.      

homelecturesexamshwsbreeze (snow day)


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