Function: snake-update-game
snake-update-game is a byte-compiled function defined in snake.el.gz.
Signature
(snake-update-game SNAKE-BUFFER)
Documentation
Called on each clock tick.
Advances the snake one square, testing for collision. Argument SNAKE-BUFFER is the name of the buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/play/snake.el.gz
(defun snake-update-game (snake-buffer)
"Called on each clock tick.
Advances the snake one square, testing for collision.
Argument SNAKE-BUFFER is the name of the buffer."
(when (and (not snake-paused)
(eq (current-buffer) snake-buffer))
(snake-update-velocity)
(let* ((pos (car snake-positions))
(x (+ (aref pos 0) snake-velocity-x))
(y (+ (aref pos 1) snake-velocity-y))
(c (gamegrid-get-cell x y)))
(if (or (= c snake-border)
(= c snake-snake))
(snake-end-game)
(cond ((= c snake-dot)
(incf snake-length)
(incf snake-score)
(snake-update-score)
(snake-set-dot))
(t
(let* ((last-cons (nthcdr (- snake-length 2)
snake-positions))
(tail-pos (cadr last-cons))
(x0 (aref tail-pos 0))
(y0 (aref tail-pos 1)))
(gamegrid-set-cell x0 y0 snake-blank)
(setcdr last-cons nil))))
(gamegrid-set-cell x y snake-snake)
(setq snake-positions
(cons (vector x y) snake-positions))
(setq snake-moved-p nil)))))