A few logic changes that might have been able to cause bugs, and one that might run a tiny bit faster.
gs3 (->> gs2
handle-spike-laying
maybe-make-enemy
+ check-if-enemies-remain
check-if-player-captured
update-player-if-shot
- check-if-enemies-remain
update-entity-is-flipping
update-entity-flippyness
animate-player-capture
(defn build-enemy
"Returns a dictionary describing an enemy on the given level and segment,
and starting on the given step. Step defaults to 0 (innermost step of
- level) if not specified. TODO: Only makes flippers."
+ level) if not specified."
[level seg-idx & {:keys [step] :or {step 0}}]
{:step step
:stride 1
level."
[game-state]
(let [{:keys [spikes player]} game-state step (:step player)
+ ;; TODO: (nth) caused an error here once, spikes was length 0.
segment (:segment player) spike-len (nth spikes segment)]
(cond
(zero? spike-len) game-state
(assoc game-state :zoom target)
(assoc game-state :zoom newzoom)))))
+
(defn clear-player-segment
"Returns game-state unchanged, and as a side affect clears the player's
current segment back to blue. To avoid weird color mixing, it is cleared
(assoc (clear-level-entities game-state)
:player (assoc player :is-dead? true)
:is-zooming? true
+ :player-zooming? false
:zoom-in? false)
game-state)))
(defn draw-rectangle
"Draws a rectangle (4 cartesian coordinates in a vector) on the 2D context
of an HTML5 canvas."
- [context [p0 & points]]
- (.moveTo context (first p0) (peek p0))
- (doseq [p points]
- (.lineTo context (first p) (peek p)))
- (.lineTo context (first p0) (peek p0))
+ [context [[x0 y0] [x1 y1] [x2 y2] [x3 y3]]]
+ (.moveTo context x0 y0)
+ (.lineTo context x1 y1)
+ (.lineTo context x2 y2)
+ (.lineTo context x3 y3)
+ (.lineTo context x0 y0)
(.stroke context)
)