Guest User

Ball bouncing on edges

a guest
Sep 8th, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.73 KB | None | 0 0
  1. (seed (time))
  2.  
  3. (class +Ball)
  4.  
  5. (dm T (X Y)
  6.    (=: x X)
  7.    (=: y Y)
  8.    (=: dx (rand -3 3))
  9.    (=: dy (rand -3 3))
  10.    (=: xMax 100)
  11.    (=: yMax 35))
  12.  
  13. (dm draw> ()
  14.    (prinl "(" (: x) " , " (: y) ")"))
  15.  
  16. (dm constrain> ()
  17.    (cond
  18.       ( (<= (: x) 0) (set (:: x) 0  (:: dx) (- (: dx))) )
  19.       ( (<= (: y) 0) (set (:: y) 0  (:: dy) (- (: dy))) )
  20.       ( (>= (: x) (: xMax)) (set (:: x) (: xMax)  (:: dx) (- (: dx))) )
  21.       ( (>= (: y) (: yMax)) (set (:: y) (: yMax)  (:: dy) (- (: dy))) ) ) )
  22.  
  23. (dm update> ()
  24.    (inc (:: x) (: dx))
  25.    (inc (:: y) (: dy)))
  26.  
  27. (setq myBall (new '(+Ball) 5 5))
  28.  
  29. (with myBall
  30.  (call 'clear)
  31.  (until (key 25)
  32.   (call 'tput "cup" (: y) (: x))
  33.   (update> myBall)
  34.   (constrain> myBall)
  35.  )
  36. )
Advertisement
Add Comment
Please, Sign In to add comment