Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. (defun game (&optional (width 320) (height 240) (speed 1))
  2. (let ((altitude (/ height 2)))
  3. (sdl:with-init ()
  4. (sdl:window width height :title-caption "My game")
  5. (setf (sdl:frame-rate) 60)
  6. (sdl:with-events ()
  7. (:quit-event () t)
  8. (:idle ()
  9. (sdl:clear-display sdl:*white*)
  10. (setf speed (if (or (< altitude 10) (> altitude (- height 10)))
  11. (- speed)
  12. speed))
  13. (sdl:draw-box (sdl:rectangle-from-midpoint-*
  14. (/ width 2) (incf altitude speed) 20 20) :color sdl:*red*)
  15. (sdl:update-display))))))
  16.  
  17. (defun calculate-speed (speed altitude height)
  18. (if (or (< altitude 10) (> altitude (- height 10)))
  19. (- speed)
  20. speed))
  21.  
  22. (defun update-altitude (speed altitude height)
  23. (+ altitude (calculate-speed speed altitude height)))
  24.  
  25. (defun game (&optional (width 320) (height 240) (speed 1))
  26. (let ((altitude (/ height 2)))
  27. (sdl:with-init ()
  28. (sdl:window width height :title-caption "My game")
  29. (setf (sdl:frame-rate) 60)
  30. (sdl:with-events ()
  31. (:quit-event () t)
  32. (:idle ()
  33. (sdl:clear-display sdl:*white*)
  34. (setf altitude (update-altitude speed altitude height))
  35. (sdl:draw-box (sdl:rectangle-from-midpoint-*
  36. 150 altitude 20 20)
  37. :color sdl:*red*)
  38. (sdl:update-display))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement