[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another error in my tiny test program



Thanks for spend time with my tiny program.
Some blocks was added. The moving ball is reflected while hitting object.

One thing bothers me is that the method I use to make a animated ball is
not neat. I draw first and erase by using background color. I wonder if
this happen because MCL is not good in drawing.

This program is OK and no runtime error. But I still got questions :
Which method of drawing is better : Qucikdraw, traps, or even import FF from
another programming language?
Dose any trap descripted on Inside Macintosh can work directly in MCL ?

Sorry about these trivial question. Please set comments, any expert?



;;; "Drop a ball" *finished 7/26/92 1:05, ReEdit by 7/31 2nd Edit by 8/2
;;; -*- package: ccl -*-
(defun Reflected-ball(ballsize)

       (let (
             (b-top 0)     ;list buffer for checking and drawing
             (my-right 0)  ;
             (b-bottom 0)  ;
             (b-left 0)    ;
             (h 240)       ;initial horizental position of ball
             (v 240)       ;initial vertical position of ball
             (v-ref 1)     ;moving rates
             (h-ref 1)     ;
             (w (make-instance 'window 
                          :view-size #@(400 300))))

         (flet ( (visible(w) 
                         (set-fore-color w *red-color*))
                 (invisible(w) 
                           (set-fore-color w *white-color*)))



           (defmacro toggle (x)  ;fuction to reverse the direction 
             `(setf ,x (- ,x)))  ;of the moving ball


           ;;(set-back-color w *black-Color*) ;optional to set background color

           ;; when hits anything reverse direction and beep!
           (while (< v 1120)
             (when (= (point-h(view-size w)) (+ ballsize h)) 
               (toggle h-ref)(beep))                          ;right
             (when (= (point-v(view-size w)) (+ ballsize v)) 
               (toggle v-ref)(beep))                          ;bottom
             (when (= (point-h(view-position w)) h) 
               (toggle h-ref)(beep))                          ;left
             (when (= (point-v(view-position w)) (+ v 40)) 
               (toggle v-ref)(beep))                          ;top

             (let (
                   (b-list-left '(40 60 10 10))            ;list of block positions
                   (b-list-right '(200 300 200 250))       ;there are four blocks
                   (b-list-top '(50 150 200 90))
                   (b-list-bottom '(70 180 240 100)))

               (while (not(and (null b-list-left)          ;***loop for checking*** 
                               (null b-list-right)         ;and drawing
                               (null b-list-top)
                               (null b-list-bottom)))

                 (setf my-right (car b-list-right)         ;consist block from lists
                       b-top (car b-list-top)
                       b-bottom (car b-list-bottom)
                       b-left (car b-list-left))

                 ;Detect when the ball hits block
                 (when (and (= h my-right) (>= v b-top) (<= v b-bottom)) 
                   (toggle h-ref)(beep)) ;when left side hits block
                 (when (and (= v b-bottom) (>= h b-left) (<= h my-right)) 
                   (toggle v-ref)(beep)) ;when top side hits
                 (when (and (= (+ ballsize h) b-left) (>= v b-top) (<= v b-bottom)) 
                   (toggle h-ref)(beep));right side
                 (when (and (= (+ ballsize v) b-top) (>= h b-left) (<= h my-right))
                   (toggle v-ref)(beep))


                 (set-fore-color w *blue-color*)            ; draw blocks
                 (rlet((r :rect 
                      :top  b-top
                      :left b-left
                      :bottom b-bottom
                      :right my-right))

                      (with-focused-view w
                        (#_paintroundrect r 0 0)))

                 (setf b-list-left (cdr b-list-left)        ; get next block
                       b-list-right (cdr b-list-right) 
                       b-list-top (cdr b-list-top) 
                       b-list-bottom (cdr b-list-bottom)))) ;***end of loop****
  


             (rlet((r :rect 
                      :top  V
                      :left h
                      :bottom (+ ballsize V)
                      :right (+ ballsize h)))

                  (visible w)
                  (with-focused-view w
                    (#_paintroundrect r 500 500))
                  
                  (invisible w)
                  (with-focused-view w
                    (#_paintroundrect r 500 500)))

 
             (setf v (+ v v-ref) h (+ h h-ref))))))

-Chien