aboutsummaryrefslogtreecommitdiff
path: root/server/game.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'server/game.lisp')
-rw-r--r--server/game.lisp11
1 files changed, 11 insertions, 0 deletions
diff --git a/server/game.lisp b/server/game.lisp
index 5658c5a..207b669 100644
--- a/server/game.lisp
+++ b/server/game.lisp
@@ -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
(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))
;; First, update direction
(with-slots ((active-dir dir)) g