Handle snake grow
This commit is contained in:
parent
6d3e1f82bc
commit
8ca0bf8b42
1 changed files with 11 additions and 0 deletions
|
@ -42,6 +42,17 @@
|
||||||
(and (or (eq dir :left) (eq dir :right)) ; Goto left or right only if the snake is on the up or down direction
|
(and (or (eq dir :left) (eq dir :right)) ; Goto left or right only if the snake is on the up or down direction
|
||||||
(or (eq active-dir :up) (eq active-dir :down)))))
|
(or (eq active-dir :up) (eq active-dir :down)))))
|
||||||
|
|
||||||
|
;;; Grow snake of grow-size amount (snake is growing by the tail)
|
||||||
|
(defun grow-snake (snake grow-size)
|
||||||
|
(let* ((old-size (first (array-dimensions snake)))
|
||||||
|
(new-size (+ old-size grow-size))
|
||||||
|
(tail (aref snake (- old-size 1)))
|
||||||
|
(new-tail (coerce (make-array grow-size :initial-element tail) 'list))
|
||||||
|
(new-snake (make-array new-size :initial-contents `(,@(coerce snake 'list) ,@new-tail))))
|
||||||
|
new-snake))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defmethod refresh ((g game) &key (dir nil dir-supplied-p))
|
(defmethod refresh ((g game) &key (dir nil dir-supplied-p))
|
||||||
;; First, update direction
|
;; First, update direction
|
||||||
(with-slots ((active-dir dir)) g
|
(with-slots ((active-dir dir)) g
|
||||||
|
|
Loading…
Add table
Reference in a new issue