summary history branches tags files
commit:f2029bf73ce3214404a8d4bca819f0dc9cb34a71
author:mrmekon
committer:mrmekon
date:Tue Apr 10 17:59:44 2012 -0400
parents:477e4f05f1c95534f4ede1c8efdd282551d976fa
Spikes are drawn, but don't interact yet.
diff --git a/tempest/tempest/core.cljs b/tempest/tempest/core.cljs
line changes: +23/-1
index f22f42c..1eb456c
--- a/tempest/tempest/core.cljs
+++ b/tempest/tempest/core.cljs
@@ -66,6 +66,7 @@ after passing through all the other functions.  This implements the game loop.
                  handle-exiting-spikers
                  maybe-enemies-shoot)
         gs3 (->> gs2
+                 handle-spike-laying
                  maybe-make-enemy
                  check-if-player-captured
                  update-player-if-shot
@@ -97,6 +98,7 @@ after passing through all the other functions.  This implements the game loop.
   {:enemy-list '()
    :projectile-list '()
    :player '()
+   :spikes []
    :context nil
    :bgcontext nil
    :anim-fn identity
@@ -136,7 +138,8 @@ after passing through all the other functions.  This implements the game loop.
       :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
@@ -669,6 +672,24 @@ flipper appears to flip 'inside' the level:
     (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]
@@ -954,6 +975,7 @@ The setTimeout fail-over is hard-coded to attempt 30fps.
         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})

diff --git a/tempest/tempest/draw.cljs b/tempest/tempest/draw.cljs
line changes: +24/-0
index 2f9a6e5..c2f8eff
--- a/tempest/tempest/draw.cljs
+++ b/tempest/tempest/draw.cljs
@@ -128,6 +128,30 @@ level functions to draw complete game entities using the primitives.
                          (: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."

diff --git a/tempest/tempest/levels.cljs b/tempest/tempest/levels.cljs
line changes: +2/-2
index 203b974..8b1e041
--- a/tempest/tempest/levels.cljs
+++ b/tempest/tempest/levels.cljs
@@ -291,8 +291,8 @@ Functions related to generating paths representing levels.
 
 (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}