Add sounds to demo

This commit is contained in:
David Botton 2021-01-24 20:54:46 -05:00
parent 7307ebabd0
commit 4cc510b2c1
4 changed files with 10 additions and 4 deletions

View file

@ -55,7 +55,7 @@
(sleep .1))
(setf (hiddenp splash) t)))
(defun paint (cx app)
(defun paint (body cx app)
(let ((game-over nil)
(head-cell (car (snake app))))
@ -94,6 +94,7 @@
(fill-style cx :red)
(font-style cx "bold 20px sans-serif")
(fill-text cx "GAME OVER" 30 30)
(play-media (create-audio body :source "/demo/game-over.wav" :controls nil))
(setf game-over t))
(t
(fill-style cx :purple)
@ -113,6 +114,8 @@
(fill-text cx (format nil "Score: ~A" (score app))
5 (- display-height 15))
(play-media (create-audio body :source "/demo/eat.wav" :controls nil))
(setf (food app) (new-food)))
(t
(draw-segment (car (last (snake app))))
@ -179,10 +182,12 @@
(set-on-click up-btn #'on-click)
(set-on-click down-btn #'on-click)
(play-media (create-audio body :source "/demo/start.wav" :controls nil))
;; Game loop
(loop
(unless (validp body) (return))
(when (paint context app) (return))
(when (paint body context app) (return))
(sleep .1))))
(defun on-new-window (body)
@ -190,7 +195,8 @@
(setf (connection-data-item body "app-data") app))
(display-splash body)
(start-game body))
(start-game body)
(run body))
(defun start-demo ()
"Start demo."

BIN
static-files/demo/eat.wav Normal file

Binary file not shown.

Binary file not shown.

BIN
static-files/demo/start.wav Normal file

Binary file not shown.