Spikes are drawn, but don't interact yet.
handle-exiting-spikers
maybe-enemies-shoot)
gs3 (->> gs2
+ handle-spike-laying
maybe-make-enemy
check-if-player-captured
update-player-if-shot
{:enemy-list '()
:projectile-list '()
:player '()
+ :spikes []
:context nil
:bgcontext nil
:anim-fn identity
:is-zooming? true
:level-done? false
:projectile-list '()
- :enemy-list '())))
+ :enemy-list '()
+ :spikes (vec (take (count (:segments level)) (repeat 0))))))
(defn maybe-change-level
"Reloads or moves to the next level if player is dead, or if all enemies are
(assoc game-state
:enemy-list (enemy-list-after-exiting-spikers enemy-list))))
+(defn spikes-after-spike-laying
+ [enemy-list spikes]
+ (loop [[enemy & enemies] enemy-list
+ spikes-out spikes]
+ (let [{:keys [step segment]} enemy
+ spike-step (nth spikes-out segment)]
+ (cond
+ (nil? enemy) spikes-out
+ (>= step spike-step) (recur enemies (assoc spikes-out segment step))
+ :else (recur enemies spikes-out)))))
+
+(defn handle-spike-laying
+ [game-state]
+ (let [enemy-list (:enemy-list game-state)
+ spikes (:spikes game-state)
+ spiker-list (filter #(= (:type %) (EnemyEnum "SPIKER")) enemy-list)]
+ (assoc game-state :spikes (spikes-after-spike-laying spiker-list spikes))))
+
(defn kill-tanker-at-top
"If the given tanker is at the top of a level, mark it as dead."
[tanker]
game-state
{enemy-shots true player-shots false}
(group-by :from-enemy? projectile-list)]
+ (draw/draw-all-spikes game-state)
(if (not (:is-dead? player))
(draw/draw-player context dims level player))
(draw/draw-entities context dims level enemy-list {:r 150 :g 10 :b 10})
(:flip-cur-angle entity))
(.closePath context))))
+(defn draw-spike
+ [{:keys [dims context level]} seg-idx length]
+ (.beginPath context)
+ (set! (. context -strokeStyle) (str "rgb(10, 150, 10)"))
+ (draw-line context
+ (path/polar-to-cartesian-centered
+ (path/segment-midpoint level seg-idx false) dims)
+ (path/polar-to-cartesian-centered
+ (path/polar-segment-midpoint level seg-idx length) dims))
+ (.closePath context))
+
+(defn draw-all-spikes
+ [game-state]
+ (let [spikes (:spikes game-state) spike-count (count spikes)]
+ (doseq [idx (range spike-count)]
+ (let [length (nth spikes idx)]
+ (if (pos? length)
+ (draw-spike game-state idx length))))))
+
+;;(for [idx (range spike-count)
+;; spike (nth spikes idx)
+;; :when (pos? spike)]
+;; #(draw-spike game-state idx spike))
+
(defn draw-player-segment
"Draws just the segment of the board that the player is on, with the given
color."
(def *levels*
[ (make-level-entry *level1_lines* false
- {:flipper 0 :tanker 0 :spiker 4}
- {:flipper 0.01 :tanker 0 :spiker 1})
+ {:flipper 5 :tanker 0 :spiker 4}
+ {:flipper 0.01 :tanker 0 :spiker 0.01})
(make-level-entry *level2_lines* true
{:flipper 20}
{:flipper 0.01}