[[ Please, please break up your big function into small ones. 
A function per handler would be a good start. -- Matthias ]]



On Dec 26, 2015, at 9:52 AM, Taro Annual <[email protected]> wrote:

> 2015年12月26日土曜日 21時54分52秒 UTC+9 Matthew Flatt:
>> At Fri, 25 Dec 2015 22:17:21 -0800 (PST), Taro Annual wrote:
>>> I make "pong" game in big-bang(2hdp/universe).
>>> But, moving a racket(not language!) by keyboard("up", "down", ...), the 
>>> racket 
>>> freezes in 0.3~0.5s sometimes.
>>> 
>>> I think it is due to the beginner's platform.
>>> What modules/syntaxes are used in action games in Racket language.
>> 
>> It sounds like you're seeing pauses related to garbage collection. The
>> current pre-release version of Racket includes improvements aimed
>> specifically at this problem.
>> 
>> Can you try a current snapshot to see whether it eliminates pauses?:
>> 
>>  http://pre.racket-lang.org/
>> 
>> The program should run better within DrRacket. For best results,
>> though, you may need to run outside of DrRacket (either by starting the
>> program with `racket` on the command line or by choosing "Create
>> Executable" in DrRacket's "Racket" menu).
>> 
>> If the pauses are still not eliminated in the current snapshot, I'm
>> interested to take a closer look at your program.
>> 
>> Thanks,
>> Matthew
> 
> Matthew,
> 
> Sorry, it doesn't work well. Try the follows:
> 
> ---source code---
> 
> #lang racket
> (require 2htdp/universe 2htdp/image point-free)
> ;(require lux mode-lambda)
> 
> ; Tennis for two
> ;
> ; [Original Version]
> ; https://kyorohiro.gitbooks.io/doc_scratch/content/tennis_of_two/index.html
> 
> (struct world (player1 player2 ball) #:transparent)
> (struct ball (x y dx dy) #:transparent)
> (struct player (y keycnt) #:transparent)
> 
> (define BALL-IMAGE (circle 10 "solid" "orange"))
> (define RACKET1-IMAGE (rectangle 5 100 "solid" "red"))
> (define RACKET2-IMAGE (rectangle 5 100 "solid" "blue"))
> 
> (define (direction x)
>  (cond ((= x 0) 0)
>        ((> x 0) 1)
>        (else -1)))
> (define (saturate x a b) (max a (min b x)))
> (define (from-to? x a b) (and (>= x a) (<= x b)))
> 
> (define (on-tick-func w)
>  (let ((player1 (world-player1 w)) (player2 (world-player2 w))
>        (ball1 (world-ball w)))
>    (let ((y1 (player-y player1)) (keycnt1 (player-keycnt player1))
>          (y2 (player-y player2)) (keycnt2 (player-keycnt player2))
>          (x (ball-x ball1)) (y (ball-y ball1))
>          (dx (ball-dx ball1)) (dy (ball-dy ball1)))
>      (let* ((n?x (+ x dx)) (n?y (+ y dy))
>             (top1 (- y1 50)) (btm1 (+ y1 50))
>             (top2 (- y2 50)) (btm2 (+ y2 50))
>             (collision1 (and (from-to? 50 n?x x)
>                              (or (from-to? y top1 btm1)
>                                  (from-to? n?y top1 btm1))))
>             (collision2 (and (from-to? 550 x n?x)
>                              (or (from-to? y top2 btm2)
>                                  (from-to? n?y top2 btm2))))
>             (nx (cond (collision1 (max n?x 50))
>                       (collision2 (min n?x 550))
>                       (else n?x)))
>             (ny (saturate n?y 0 400))
>             (ndx (cond (collision1 (abs dx))
>                        (collision2 (- (abs dx)))
>                        (else dx)))
>             (ndy (cond ((<= y 0) (abs dy))
>                        ((>= y 400) (- (abs dy)))
>                        (else dy)))
>             (next-player1
>              (player
>               (saturate (+ y1 (* (direction keycnt1) 10)) 50 350)
>               (- keycnt1 (direction keycnt1))))
>             (next-player2
>              (player
>               (saturate (+ y2 (* (direction keycnt2) 10)) 50 350)
>               (- keycnt2 (direction keycnt2))))
>             (next-ball (ball nx ny ndx ndy)))
>        (when collision1 (display "collision1"))
>        (when collision2 (display "collision2"))
>        (world next-player1 next-player2 next-ball)))))
> 
> (big-bang
>  (world (player 200 0) (player 200 0) (ball 300 200 -5.1111 2.51111))
> 
>  {on-key
>   (lambda (w key)
>     (case key
>       [("up")   (world (world-player1 w)
>                        (player (player-y (world-player2 w)) -10)
>                        (world-ball w))]
>       [("down") (world (world-player1 w)
>                        (player (player-y (world-player2 w)) 10)
>                        (world-ball w))]
>       [("a")    (world (player (player-y (world-player1 w)) -10)
>                        (world-player2 w)
>                        (world-ball w))]
>       [("z")    (world (player (player-y (world-player1 w)) 10)
>                        (world-player2 w)
>                        (world-ball w))]
>       [("b")    (display w)
>                 w]
>       [else w]))}
> 
>  {on-release
>   (lambda (w key)
>     (world (player (player-y (world-player1 w)) 0)
>            (player (player-y (world-player2 w)) 0)
>            (world-ball w)))}
> 
>  {on-tick on-tick-func}
> 
>  {on-draw
>   (lambda (w)
>     (~> (empty-scene 600 400)
>         (curry place-image/align
>           RACKET1-IMAGE 50 (player-y (world-player1 w))
>           "right" "center")
>         (curry place-image/align
>           RACKET2-IMAGE 550 (player-y (world-player2 w))
>           "left" "center")
>         (curry place-image/align
>           BALL-IMAGE (ball-x (world-ball w)) (ball-y (world-ball w))
>           "center" "center")))})
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to