[racket] ufo structure problem
Sorry, I forget to give you the chapter and the book.
Im talking about this chapter
2.5.2Programming with Structures Which can be found at this
url:
http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part1.html#%28part._structure%29
Roelof
Op 30-3-2012 9:32, Roelof Wobben schreef:
> 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
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120330/132209f0/attachment.html>