mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-05 18:20:36 -08:00
added condition handling, regrestion in snake from key-code changes
This commit is contained in:
parent
8edd6e8c84
commit
516cdd5eef
2 changed files with 107 additions and 81 deletions
|
|
@ -109,11 +109,15 @@
|
|||
|
||||
(defun on-key-down (obj event)
|
||||
(let ((app (connection-data-item obj "app-data"))
|
||||
(key-code (getf event :key-code)))
|
||||
(cond ((or (eql key-code 65) (eql key-code 37)) (setf (snake-direction app) :left))
|
||||
((or (eql key-code 87) (eql key-code 38)) (setf (snake-direction app) :up))
|
||||
((or (eql key-code 83) (eql key-code 40)) (setf (snake-direction app) :down))
|
||||
((or (eql key-code 68) (eql key-code 39)) (setf (snake-direction app) :right)))))
|
||||
(key (getf event :key)))
|
||||
(cond ((or (equalp key "ArrowLeft") (equalp key "a"))
|
||||
(setf (snake-direction app) :left))
|
||||
((or (equalp key "ArrowUp") (equalp key "w"))
|
||||
(setf (snake-direction app) :up))
|
||||
((or (equalp key "ArrowDown") (equalp key "s"))
|
||||
(setf (snake-direction app) :down))
|
||||
((or (equalp key "ArrowRight") (equalp key "d"))
|
||||
(setf (snake-direction app) :right)))))
|
||||
|
||||
(defun on-click (obj)
|
||||
(let ((app (connection-data-item obj "app-data"))
|
||||
|
|
@ -152,7 +156,7 @@
|
|||
(fill-style context :green)
|
||||
(fill-text context (format nil "Score: ~A" (score app))
|
||||
5 (- display-height 15))
|
||||
(set-on-key-down body #'on-key-down)
|
||||
(set-on-key-down body #'on-key-down :disable-default t)
|
||||
(set-on-click left-btn #'on-click)
|
||||
(set-on-click right-btn #'on-click)
|
||||
(set-on-click up-btn #'on-click)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue