summary history branches tags files
commit:e742a213df9f665797a2119ae67ca5bd34538be6
author:mrmekon
committer:mrmekon
date:Thu Mar 22 18:16:43 2012 -0400
parents:f7194072c6a0688872d44c88ba88cb77f4f4cf2e
Projectiles removed when they hit an extremity, instead of piling up at the edges.
diff --git a/tempest/tempest.cljs b/tempest/tempest.cljs
line changes: +20/-11
index 6c6a6ab..7ccb2d3
--- a/tempest/tempest.cljs
+++ b/tempest/tempest.cljs
@@ -443,6 +443,12 @@
         dims (rectangle-for-segment level idx))))
     (.closePath context)))
 
+(defn projectile-off-level? [projectile]
+  (cond
+   (zero? (:step projectile)) true
+   (>= (:step projectile) (:steps (:level projectile))) true
+   :else false))
+
 (defn draw-world [context dims level]
   (doseq []
    (.clearRect context 0 0 (:width dims) (:height dims))
@@ -451,18 +457,17 @@
    (comment (draw-enemies context dims level))
    (draw-entities context dims level *enemy-list*)
    (draw-entities context dims level @*projectile-list*)
-   (def *enemy-list* (update-entity-list *enemy-list*))
-   (def *projectile-list* (atom (update-entity-list @*projectile-list*)))))
+   (when (not @*paused*)
+     (def *enemy-list* (update-entity-list *enemy-list*))
+     (def *projectile-list* (atom (update-entity-list @*projectile-list*)))
+     (def *projectile-list* (atom (vec (remove projectile-off-level? @*projectile-list*))))
+     )))
 
 (defn add-projectile [level seg-idx stride step]
-  (do
-    (.log js/console (str "Proj: " (pr-str seg-idx) " "
-                          (pr-str stride) " "
-                          (pr-str step) " "))
-    (def *projectile-list*
-      (atom (vec (conj @*projectile-list*
-             (build-projectile level seg-idx stride :step step)))))))
-
+  (def *projectile-list*
+    (atom
+     (vec (conj @*projectile-list*
+                (build-projectile level seg-idx stride :step step))))))
 
 (defn keypress [event]
   (let [player @*player*
@@ -481,9 +486,12 @@
                                    (mod (+ (- segment 1) seg-count)
                                         seg-count))))
           key-codes/SPACE (add-projectile level segment -5 (:steps level))
+          key-codes/ESC (def *paused* (atom (not @*paused*)))
           nil
           )))
 
+(def *paused* (atom false))
+
 (defn ^:export canvasDraw [level]
   (let [document (dom/getDocument)
         timer (goog.Timer. 50)
@@ -503,7 +511,8 @@
       (atom (doall (build-player level 7))))
     (def *projectile-list*
       (atom [(build-projectile level 0 4)
-             (build-projectile level 8 -4 :step 100)]))
+             (build-projectile level 8 -4 :step 100)
+             (build-projectile level 5 4 :step 100)]))
 
     (events/listen timer goog.Timer/TICK #(draw-world context dims level))
     (events/listen handler "key" (fn [e] (keypress e)))