Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require 'lispbuilder-sdl)
- (defun game (&optional (width 320) (height 240) (speed 1))
- (let ((v-coord (/ height 2)))
- (sdl:with-init ()
- (sdl:window width height :title-caption "My game")
- (setf (sdl:frame-rate) 60)
- (sdl:with-events ()
- (:quit-event () t)
- (:idle ()
- (sdl:clear-display sdl:*white*)
- (setf speed (if (or (< v-coord 10) (> v-coord (- height 10)))
- (- speed)
- speed))
- (sdl:draw-box (sdl:rectangle-from-midpoint-*
- (/ width 2) (incf v-coord speed) 20 20) :color sdl:*red*)
- (sdl:update-display))))))
- (defparameter *decoy* (pairlis '(h-coord v-coord h-speed v-speed) '(120 160 2 2)))
- (:idle ()
- (acons 'h-coord (+ (cdr (assoc 'h-coord *decoy*)) (cdr (assoc 'h-speed *decoy*))) *decoy*)
- (acons 'v-coord (+ (cdr (assoc 'v-coord *decoy*)) (cdr (assoc 'v-speed *decoy*))) *decoy*)
- (sdl:draw-box (sdl:rectangle-from-midpoint-*
- (cdr (assoc 'h-coord *decoy*)) (cdr (assoc 'v-coord *decoy*)) 20 20)
- :color sdl:*red*)
- (defun game (&optional (width 320) (height 240) (speed 2))
- (let ((decoy (pairlis '(h-coord v-coord h-speed v-speed)
- '((/ width 2) (/ height 2) speed speed))))
- (sdl:with-init ()
- (sdl:window width height :title-caption "My game")
- (setf (sdl:frame-rate) 60)
- (sdl:with-events ()
- (:quit-event () t)
- (:key-down-event (:key key)
- (when (sdl:key= key :sdl-key-escape) (sdl:push-quit-event)))
- (:idle ()
- (acons 'h-coord (+ (cdr (assoc 'h-coord decoy))
- (cdr (assoc 'h-speed decoy))) decoy)
- (acons 'v-coord (+ (cdr (assoc 'v-coord *decoy*))
- (cdr (assoc 'v-speed decoy))) decoy)
- (sdl:clear-display sdl:*white*
- :surface (sdl:draw-surface (sdl:load-image *bg*)))
- (sdl:draw-box (sdl:rectangle-from-midpoint-*
- (cdr (assoc 'h-coord decoy)) (cdr (assoc 'v-coord decoy)) 20 20)
- :color sdl:*red*)
- (sdl:update-display))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement