![]() |
![]() |
|
home—info—lectures—exams—hws—archive
Due Sep.28 (Mon) (hardcopy, and on WebCT) Your name and the assignment-number must be in a comment at the start of the file.
The following problems deal with frogger. Follow all steps of the design recipe (from lect02c—design recipe; functions returning structs and/or How to Design Programs. However, you do not need to provide test cases for functions which return images/scenes.
Write the method
(It goes without saying1,
that you'll lose points if you don't call
the
Note that updating the world structure has nothing to do with drawing it.
Write the method
; draw-truck : truck, scene -> scene ; Return a scene just like the one given, ; except with the truck overlayed onto it. |
; overlay/xy:nw : image number number image -> scene
; Overlay `pic` onto `bg`,
; where `pic`s northwest corner is offset by `x`,`y`.
; The result is clipped to `bg`s dimensions.
;
; (This function is just like overlay/xy, except that all images
; use their northwest corner as their reference point ("pinhole").
; The result also has its pinhole in the nw corner (i.e., it's a 'scene').)
;
(define (overlay/xy:nw bg x y pic)
(place-image (put-pinhole pic 0 0) x y (put-pinhole bg 0 0)))
|
No check-expects are needed for the drawing-functions (since it's hard to create the result-images before you write your function). To make sure your function works, test your function, you can try drawing a particular truck onto an empty scene, or a non-empty scene:
; evaluates to a scene of a lone truck: (draw-truck (make-truck …) (empty-scene 200 300)) ; evaluates to a scene of a truck and an orange circle: (draw-truck (make-truck …) (overlay/xy:nw (circle 40 'solid 'orange) 100 120 (empty-scene 200 300))) |
A note on images:
(big-bang w0
[on-tick update-world]
[on-draw draw-world])
|
Write the method
truck-handle-key : truck key-event -> truck |
Note that a
(Don't forget to follow the design recipe; create test cases before you write the code! You should be clear before you start writing code, that this method doesn't change the truck's location at all.)
cool hint, from robotics:: We can reduce this problem to a simpler one: checking if an expanded version of the first rectangle merely contains one particular point: the southeast corner of the second rectangle.Some test cases are given here, but you must make at least two more which test different situations.
For example: consider a 20x30 rectangle whose northwest corner is at (500,400) and a second rectangle which is 80x60. These two rectangles overlap exactly when the second rectangle's southeast corner is inside the (20+80)×(30+60) rectangle rooted at (500,400).
; The eight inputs are: x,y,width,height of two rectangles. (check-expect (overlap? 0 0 10 10 5 5 2 2) true) (check-expect (overlap? 0 0 10 10 5 5 20 2) true) (check-expect (overlap? 0 0 10 10 15 15 2 2) false) |
<assign> → <id> = <expr> <id> → A | B | C <expr> → <expr> + <term> | <term> <term> → <term> * <factor> | <factor> <factor> → ( <expr> ) | <id> |
1Don't you hate it, when people say that? ↩
2
Alternately, you might have
have
3Although you could also use
home—info—lectures—exams—hws—archive
| ©2009, Ian Barland, Radford University Last modified 2009.Oct.17 (Sat) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |