[racket] ufo structure problem

From: Roelof Wobben (r.wobben at home.nl)
Date: Fri Mar 30 03:32:20 EDT 2012

Hello,

I try to make the ufo exercise work on this chapter :

So I have this :

; visual constants
(define MTS (empty-scene 100 100))
(define BLU (place-image (rectangle 25 25 "solid" "blue") 50 50 MTS))

(define-struct velocity (dx dy))
; A Velocity is a structure: (make-vel Number Number)
; interp. (make-vel d e) means that the object moves d steps
; along the horizontal and e steps along the vertical per tick


(define-struct ufo (loc vel))
; A UFO is a structure: (make-ufo Posn Velocity)
; interp. (make-ufo p v) is at location p
; moving at velocity v
(define v1 (make-velocity 8 -3))
(define v2 (make-velocity -5 -3))
(define p1 (make-posn 22 80))
(define p2 (make-posn 30 77))
(define u1 (make-ufo p1 v1))
(define u2 (make-ufo p1 v2))
(define u3 (make-ufo p2 v1))
(define u4 (make-ufo p2 v2))

; UFO -> UFO
; move the ufo u, i.e., compute its new location in one clock
; tick from now and leave the velocity as is

(define (ufo-move u)
   (make-ufo
     (posn+ (ufo-loc u) (ufo-vel u))
     (ufo-vel u)))

(define (posn+ p v)
   (make-posn (+ (posn-x p) (velocity-dx v))
              (+ (posn-y p) (velocity-dy v))))

(define (show-ufo ufo)
   (place-image BLU (ufo-loc u) MTS))

(define (game ufo)
   (big-bang ufo (on-tick ufo move u) (on-draw show-ufo)))


But still I can't get the show-ufo work.
I my opinion ufo loc represent the position on the screen so the x and y 
position.
Is this right ?

I find this a very confusing exercise and I hope someone can give me 
tips how to solve this without given the answer to the pogramm.

Roelof


Posted on the users mailing list.