Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define ANCHO 600)
- (define ALTO 600)
- (define DELTA 12)
- (define Inicio (make-posn (/ ANCHO 2) (/ ALTO 2)))
- (define radiomosca 2)
- (define GAMMA radiomosca)
- (define mosca (circle radiomosca "solid" "black"))
- (define ESTADO-FINAL (make-posn -100 -100))
- (define (pantalla p) (if (end? p) (text "MOSCA ATRAPADA" 56 "Green") (place-image mosca (posn-x p) (posn-y p) (empty-scene ANCHO ALTO)) ) )
- (define (dist-origen M) (sqrt (+ (* (posn-x M) (posn-x M)) (* (posn-y M) (posn-y M)))))
- (define (elegir-random a b) (if (= (random 2) 0) a b))
- (define (checkY y d) (if (and (>= (- y d) 0) (<= (+ y d) ALTO) ) #t #f))
- (define (checkX x d) (if (and (>= (- x d) 0) (<= (+ x d) ANCHO) ) #t #f))
- (define (tecla I k) (cond ((key=? k "left") (make-posn (- (posn-x I) DELTA) (posn-y I)))
- ((key=? k "right") (make-posn (+ (posn-x I) DELTA) (posn-y I)))
- ((key=? k "up") (make-posn (posn-x I) (- (posn-y I) DELTA)))
- ((key=? k "down") (make-posn (posn-x I) (+ (posn-y I) DELTA)))
- (else I)
- ))
- (define (mousehandler I x y event) (cond ((string=? event "button-down") (if (or (<= (abs (- (posn-x I) x)) GAMMA) (<= (abs (- (posn-y I) y)) GAMMA)) ESTADO-FINAL I ))
- (else I)
- ))
- (define (randmov I) (if (elegir-random #t #f) I ;#t -> stay, #f -> move
- (if (elegir-random #t #f) ;#t -> vert, #f -> horiz
- (if (elegir-random #t #f) ;#t -> up, #f -> down
- (make-posn (posn-x I) (- (posn-y I) DELTA )) (make-posn (posn-x I) (+ (posn-y I) DELTA )) )
- (if (elegir-random #t #f) ;#t -> left, #f -> r8
- (make-posn (- (posn-x I) DELTA) (posn-y I)) (make-posn (+ (posn-x I) DELTA) (posn-y I) )))))
- (define (end? I) (if (= (posn-x I) -100) #t #f))
- (big-bang Inicio
- (to-draw pantalla)
- (on-tick randmov)
- (on-mouse mousehandler)
- (on-key tecla)
- (stop-when end?)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement