(define WINDOW-WIDTH 150) (define WINDOW-HEIGHT 180) (define DIAMETER 10) (define DX 5) (define DY 5) ; A world is a posn. ; Its display is a blue ball at those coordinates ; show-world : world -> image (define (show-world where) (overlay/xy (empty-scene WINDOW-WIDTH WINDOW-HEIGHT) (posn-x where) (posn-y where) (circle DIAMETER "solid" "blue"))) "Example of show-world:" (show-world (make-posn 30 50)) "should be" (overlay/xy (empty-scene WINDOW-WIDTH WINDOW-HEIGHT) 30 50 (circle DIAMETER "solid" "blue")) ; move-right : posn -> posn (define (move-right p) (make-posn (+ (posn-x p) DX) (posn-y p))) "examples of move-right:" (move-right (make-posn 5 7)) "should be" (make-posn 10 7) ; move-left : posn -> posn (define (move-left p) (make-posn (- (posn-x p) DX) (posn-y p))) "example of move-left:" (move-left (make-posn 29 47)) "should be" (make-posn 24 47) ; move-up : posn -> posn (define (move-up p) (make-posn (posn-x p) (- (posn-y p) DY))) "example of move-up:" (move-up (make-posn 29 47)) "should be" (make-posn 29 42) ; move-down : posn -> posn (define (move-down p) (make-posn (posn-x p) (+ (posn-y p) DY))) "example of move-down:" (move-down (make-posn 29 47)) "should be" (make-posn 29 52) ; The next world is moved up, down, left, right, or nowhere depending on what key the user hit. ; next-world : world -> world (define (next-world key where) (cond [(not (symbol? key)) where] ; handle letters, numbers, etc. [(symbol=? key 'right) (move-right where)] [(symbol=? key 'left) (move-left where)] [(symbol=? key 'up) (move-up where)] [(symbol=? key 'down) (move-down where)] [else where])) "Examples of next-world:" (next-world 'right (make-posn 29 47)) "should be" (make-posn 34 47) (next-world 'left (make-posn 29 47)) "should be" (make-posn 24 47) (next-world 'up (make-posn 29 47)) "should be" (make-posn 29 42) (next-world 'down (make-posn 29 47)) "should be" (make-posn 29 52) (big-bang WINDOW-WIDTH WINDOW-HEIGHT 1 (make-posn 50 50)) (on-update-event show-world) (on-key-event next-world)