Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Commit db7d8a0

Browse files
committed
Don't store direction as a VEC2
1 parent 9fff017 commit db7d8a0

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

snake.lisp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,14 @@
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)))

state.lisp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
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)

util.lisp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@
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))))

0 commit comments

Comments
 (0)