summary history branches tags files
commit:fdac1f7e6641af02c34baf6ba14948b8e8d639a2
author:mrmekon
committer:mrmekon
date:Fri Apr 6 22:23:37 2012 -0400
parents:c8d837acf4551cecb8c45f653ecb6e7b08ddb647
Restart level if player dies, move to next level if player defeats all enemies.  Canvas widened and background color of page set to black.
diff --git a/src/tempest_cljs/views/common.clj b/src/tempest_cljs/views/common.clj
line changes: +1/-1
index 1fa2127..7e5e22f
--- a/src/tempest_cljs/views/common.clj
+++ b/src/tempest_cljs/views/common.clj
@@ -15,5 +15,5 @@
   (html5
    [:head
     [:title "Tempest in ClojureScript"]]
-   [:body
+   [:body {:style "background-color: #000000;"}
     [:div#wrapper content]]))

diff --git a/src/tempest_cljs/views/welcome.clj b/src/tempest_cljs/views/welcome.clj
line changes: +2/-2
index 7aefbf9..7c2d0e5
--- a/src/tempest_cljs/views/welcome.clj
+++ b/src/tempest_cljs/views/welcome.clj
@@ -11,10 +11,10 @@
 (defpage "/tempest/:level" {:keys [level]}
   (common/site-layout
    (include-js "/tempest.js")
-   [:canvas#canv-bg {:width "900" :height "900"
+   [:canvas#canv-bg {:width "1000" :height "900"
                      :style (str "position: absolute; z-index: 0;"
                                  "background-color: #000000;")}]
-   [:canvas#canv-fg {:width "900" :height "900"
+   [:canvas#canv-fg {:width "1000" :height "900"
                      :style (str "position: absolute; z-index: 1;")}]
    [:p#fps "FPS 0.0"]
    (javascript-tag (str "tempest.canvasDraw(" (pr-str level) ");"))

diff --git a/tempest/tempest/core.cljs b/tempest/tempest/core.cljs
line changes: +38/-3
index 79b2254..7aa9403
--- a/tempest/tempest/core.cljs
+++ b/tempest/tempest/core.cljs
@@ -48,6 +48,7 @@ after passing through all the other functions.  This implements the game loop.
   [game-state]
   (->> game-state
        dequeue-keypresses
+       maybe-change-level
        clear-frame
        draw-board
        render-frame
@@ -56,6 +57,7 @@ after passing through all the other functions.  This implements the game loop.
        update-enemy-locations
        maybe-make-enemy
        check-if-player-captured
+       check-if-enemies-remain
        update-entity-is-flipping
        update-entity-flippyness
        animate-player-capture
@@ -95,8 +97,20 @@ after passing through all the other functions.  This implements the game loop.
    :is-zooming? true
    :zoom-in? true
    :zoom 0.0
+   :level-done? false
    })
 
+(defn check-if-enemies-remain
+  [game-state]
+  (let [level (:level game-state)
+        player (:player game-state)
+        on-board (count (:enemy-list game-state))
+        unlaunched (apply + (vals (:remaining level)))
+        remaining (+ on-board unlaunched)]
+    (if (zero? remaining)
+      (assoc game-state :is-zooming? true :zoom-in? false)
+      game-state)))
+
 (defn change-level
   "Changes current level of game."
   [game-state level-idx]
@@ -104,7 +118,25 @@ after passing through all the other functions.  This implements the game loop.
     (assoc game-state
       :level-idx level-idx
       :level level
-      :player (build-player level 0))))
+      :player (build-player level 0)
+      :zoom 0.0
+      :zoom-in? true
+      :is-zooming? true
+      :level-done? false
+      :projectile-list '()
+      :enemy-list '())))
+
+(defn maybe-change-level
+  [game-state]
+  (let [player (:player game-state)
+        level (:level game-state)]
+    (cond
+     (and (:is-dead? player) (:level-done? game-state))
+     (change-level game-state (:level-idx game-state))
+     (and (not (:is-dead? player)) (:level-done? game-state))
+     (change-level game-state (inc (:level-idx game-state)))
+     :else game-state)))
+             
 
 (defn build-projectile
   "Returns a dictionary describing a projectile (bullet) on the given level,
@@ -585,7 +617,8 @@ flipper appears to flip 'inside' the level:
 (defn update-zoom
   "Updates current zoom value of the level, based on direction of :zoom-in?
    in the global-state.  This is used to animate the board zooming in or
-   zooming out at the start or end of a round."
+   zooming out at the start or end of a round.  If this was a zoom out, and
+   it's finished, mark the level as done so it can restart."
   [global-state]
   (let [zoom (:zoom global-state)
         zoom-in? (:zoom-in? global-state)
@@ -593,7 +626,9 @@ flipper appears to flip 'inside' the level:
         newzoom (if zoom-in? (+ zoom zoom-step) (- zoom zoom-step))
         target (if zoom-in? 1.0 0.0)
         cmp (if zoom-in? >= <=)]
-    (if (cmp zoom target) (assoc global-state :is-zooming? false)
+    (if (cmp zoom target) (assoc global-state
+                            :is-zooming? false
+                            :level-done? (not zoom-in?))
         (if (cmp newzoom target)
           (assoc global-state :zoom target)
           (assoc global-state :zoom newzoom)))))

diff --git a/tempest/tempest/draw.cljs b/tempest/tempest/draw.cljs
line changes: +0/-1
index b28d4a4..d36ca3b
--- a/tempest/tempest/draw.cljs
+++ b/tempest/tempest/draw.cljs
@@ -117,7 +117,6 @@ level functions to draw complete game entities using the primitives.
         color-str (str "rgb(" r "," g "," b ")")]
     (doseq [entity entity-list]
       (.beginPath context)
-      (.log js/console color-str)
       (set! (. context -strokeStyle) color-str)
       (draw-path-rotated context
                          (path/polar-to-cartesian-centered

diff --git a/tempest/tempest/levels.cljs b/tempest/tempest/levels.cljs
line changes: +1/-1
index d949b25..3af6e6b
--- a/tempest/tempest/levels.cljs
+++ b/tempest/tempest/levels.cljs
@@ -263,7 +263,7 @@ Functions related to generating paths representing levels.
 
 (def *levels*
   [ (make-level-entry *level1_lines* false
-                      {:flipper 20}
+                      {:flipper 5}
                       {:flipper 0.01})
     (make-level-entry *level2_lines* true
                       {:flipper 20}