update snake demo for api changes

This commit is contained in:
David Botton 2022-08-23 12:06:43 -04:00
parent 20d8e4a6d6
commit cc1b306e75

View file

@ -80,22 +80,22 @@
(>= (* (car head-cell) segment-size) display-width) (>= (* (car head-cell) segment-size) display-width)
(>= (* (cadr head-cell) segment-size) display-height) (>= (* (cadr head-cell) segment-size) display-height)
(self-collision)) (self-collision))
(fill-style cx :red) (setf (fill-style cx) :red
(font-style cx "bold 20px sans-serif") (font-style cx) "bold 20px sans-serif")
(fill-text cx "GAME OVER" 30 30) (fill-text cx "GAME OVER" 30 30)
(play-media (create-audio body :source "/demo/game-over.wav" :controls nil)) (play-media (create-audio body :source "/demo/game-over.wav" :controls nil))
(setf game-over t)) (setf game-over t))
(t (t
(fill-style cx :purple) (setf (fill-style cx) :purple)
(push head-cell (snake app)) (push head-cell (snake app))
(dolist (cell (snake app)) (dolist (cell (snake app))
(draw-segment cell)) (draw-segment cell))
(fill-style cx :white) (setf (fill-style cx) :white)
(cond ((equal head-cell (food app)) (cond ((equal head-cell (food app))
(fill-text cx (format nil "Score: ~A" (score app)) (fill-text cx (format nil "Score: ~A" (score app))
5 (- display-height 15)) 5 (- display-height 15))
(setf (score app) (+ (score app) 10)) (setf (score app) (+ (score app) 10))
(fill-style cx :green) (setf (fill-style cx) :green)
(fill-text cx (format nil "Score: ~A" (score app)) (fill-text cx (format nil "Score: ~A" (score app))
5 (- display-height 15)) 5 (- display-height 15))
(play-media (create-audio body :source "/demo/eat.wav" :controls nil)) (play-media (create-audio body :source "/demo/eat.wav" :controls nil))
@ -103,7 +103,7 @@
(t (t
(draw-segment (car (last (snake app)))) (draw-segment (car (last (snake app))))
(setf (snake app) (butlast (snake app))))) (setf (snake app) (butlast (snake app)))))
(fill-style cx :brown) (setf (fill-style cx) :brown)
(draw-segment (food app)))) (draw-segment (food app))))
game-over))) game-over)))
@ -152,8 +152,8 @@
(dotimes (n initial-length) (dotimes (n initial-length)
(push (list n 0) (snake app))) (push (list n 0) (snake app)))
(setf context (create-context2d disp)) (setf context (create-context2d disp))
(font-style context "normal 20px sans-serif") (setf (font-style context) "normal 20px sans-serif"
(fill-style context :green) (fill-style context) :green)
(fill-text context (format nil "Score: ~A" (score app)) (fill-text context (format nil "Score: ~A" (score app))
5 (- display-height 15)) 5 (- display-height 15))
(set-on-key-down body #'on-key-down :disable-default t) (set-on-key-down body #'on-key-down :disable-default t)