This repository was archived by the owner on May 20, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 4040; ; TODO(bsvercl): Don't allow Left<->Right Up<->Down
4141(defun change-direction (snake direction)
4242 " Modify DIRECTION of SNAKE with NEW-DIRECTION."
43- (let ((new-direction (case direction
44- (:up (gamekit :vec2 0 1 ))
45- (:down (gamekit :vec2 0 -1 ))
46- (:left (gamekit :vec2 -1 0 ))
47- (:right (gamekit :vec2 1 0 ))
48- ; ; We don't know that this is supposed to be.
49- (t (gamekit :vec2)))))
50- (setf (direction-of snake) new-direction)))
43+ (setf (direction-of snake) direction))
5144
5245(defun advance (snake ate-food-p)
5346 " Moves the SNAKE according to it's DIRECTION."
5447 (with-slots (segments direction) snake
5548 (let* ((position (snake-position snake))
5649 ; ; The position of the next head.
57- (new-head (gamekit :add position direction))
50+ (new-head (gamekit :add position ( direction-vec direction) ))
5851 ; ; If we ate the food we do not chop off the end of the SEGMENTS.
5952 (which-segments (if ate-food-p segments (butlast segments)))
6053 (new-segments (push new-head which-segments)))
Original file line number Diff line number Diff line change 6060 (funcall end-callback)))))
6161
6262(defmethod draw ((this game-state))
63- ; ; TODO(bsvercl): Drop into CL-BODGE to speed this up.
63+ ; ; TODO(bsvercl): Drop into CL-BODGE to speed this up,
64+ ; ; or just remove this completely?
6465 (loop for x from 0 below +segments-across-width+
6566 do (loop for y from 0 below +segments-across-height+
6667 do (draw-segment (gamekit :vec2 x y)
Original file line number Diff line number Diff line change 2323 size size
2424 :fill-paint fill-paint
2525 :stroke-paint stroke-paint))
26+
27+ (defun direction-vec (direction)
28+ (case direction
29+ (:up (gamekit :vec2 0 1 ))
30+ (:down (gamekit :vec2 0 -1 ))
31+ (:left (gamekit :vec2 -1 0 ))
32+ (:right (gamekit :vec2 1 0 ))
33+ ; ; We don't know that this is supposed to be.
34+ (t (gamekit :vec2))))
You can’t perform that action at this time.
0 commit comments