Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. (require 'lispbuilder-sdl)
  2.  
  3. (defun game (&optional (width 320) (height 240) (speed 1))
  4. (let ((v-coord (/ height 2)))
  5. (sdl:with-init ()
  6. (sdl:window width height :title-caption "My game")
  7. (setf (sdl:frame-rate) 60)
  8. (sdl:with-events ()
  9. (:quit-event () t)
  10. (:idle ()
  11. (sdl:clear-display sdl:*white*)
  12. (setf speed (if (or (< v-coord 10) (> v-coord (- height 10)))
  13. (- speed)
  14. speed))
  15. (sdl:draw-box (sdl:rectangle-from-midpoint-*
  16. (/ width 2) (incf v-coord speed) 20 20) :color sdl:*red*)
  17. (sdl:update-display))))))
  18.  
  19. (defparameter *decoy* (pairlis '(h-coord v-coord h-speed v-speed) '(120 160 2 2)))
  20.  
  21. (:idle ()
  22. (acons 'h-coord (+ (cdr (assoc 'h-coord *decoy*)) (cdr (assoc 'h-speed *decoy*))) *decoy*)
  23. (acons 'v-coord (+ (cdr (assoc 'v-coord *decoy*)) (cdr (assoc 'v-speed *decoy*))) *decoy*)
  24. (sdl:draw-box (sdl:rectangle-from-midpoint-*
  25. (cdr (assoc 'h-coord *decoy*)) (cdr (assoc 'v-coord *decoy*)) 20 20)
  26. :color sdl:*red*)
  27.  
  28. (defun game (&optional (width 320) (height 240) (speed 2))
  29. (let ((decoy (pairlis '(h-coord v-coord h-speed v-speed)
  30. '((/ width 2) (/ height 2) speed speed))))
  31. (sdl:with-init ()
  32. (sdl:window width height :title-caption "My game")
  33. (setf (sdl:frame-rate) 60)
  34. (sdl:with-events ()
  35. (:quit-event () t)
  36. (:key-down-event (:key key)
  37. (when (sdl:key= key :sdl-key-escape) (sdl:push-quit-event)))
  38. (:idle ()
  39. (acons 'h-coord (+ (cdr (assoc 'h-coord decoy))
  40. (cdr (assoc 'h-speed decoy))) decoy)
  41. (acons 'v-coord (+ (cdr (assoc 'v-coord *decoy*))
  42. (cdr (assoc 'v-speed decoy))) decoy)
  43. (sdl:clear-display sdl:*white*
  44. :surface (sdl:draw-surface (sdl:load-image *bg*)))
  45. (sdl:draw-box (sdl:rectangle-from-midpoint-*
  46. (cdr (assoc 'h-coord decoy)) (cdr (assoc 'v-coord decoy)) 20 20)
  47. :color sdl:*red*)
  48. (sdl:update-display))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement