summary history branches tags files
commit:2bae658dc327b7aa444e0dd6e80bf9cf6cdc07ff
author:Trevor Bentley
committer:Trevor Bentley
date:Fri Mar 16 14:28:41 2012 -0400
parents:e30495d33f4cf2c97485a07b2ddc8b8b6b3c823a
Flat leves of arbitrary segment count can be generated.  Segment width is equal length at the player's end.
diff --git a/tempest/levels.cljs b/tempest/levels.cljs
line changes: +45/-13
index 37634bd..f685924
--- a/tempest/levels.cljs
+++ b/tempest/levels.cljs
@@ -23,20 +23,37 @@
     )
   )
 
+(defn rad-to-deg [rad]
+  (/ (* rad 180) 3.14159265358979))
+
+(defn deg-to-rad [deg]
+  (/ (* deg 3.14159265358979) 180))
+
+(defn theta0 [width depth]
+  "Return theta0 in degrees."
+  (rad-to-deg (js/Math.atan (/ width depth))))
+
+(defn nth-theta [n width depth]
+  (js/Math.round (rad-to-deg (js/Math.atan (/ (* (+ n 1) width) depth)))))
+
+(defn r-for-nth-theta [nth-theta depth]
+  (js/Math.round (/ depth (js/Math.cos (deg-to-rad nth-theta)))))
+
+(defn nth-straight-line [n width depth angle-center angle-multiplier]
+  "Returns [r theta] for straight line segment n."
+  (let [th (nth-theta n width depth)]
+    [(r-for-nth-theta th depth) (+ angle-center (* th angle-multiplier))]))
+
+(defn flat-level [segment-count segment-width segment-depth]
+  (concat (reverse (map #(nth-straight-line % segment-width segment-depth 270 -1) (range segment-count)))
+          [[80 270]]
+          (map #(nth-straight-line % segment-width segment-depth 270 1) (range segment-count))))
+
+
 ;; short radius, angle in degrees
 ;; straight lines: r = *default-line-length*/abs(cos(270-angle))
-(def *level1_lines*
-  [[113 225]
-   [99 234]
-   [90 243]
-   [84 252]
-   [81 261]
-   [*default-line-length* 270]
-   [81 279]
-   [84 288]
-   [90 297]
-   [99 306]
-   [113 315]])
+
+(def *level1_lines* (vec (flat-level 4 15 80)))
 
 (def *level2_lines*
   [[*default-line-length* 0]
@@ -61,6 +78,17 @@
    [*default-line-length* 342]
    ])
 
+(def *level3_lines* (vec (flat-level 7 15 80)))
+
+(comment (def *level3_lines*
+  [[111 (- 270 44)]
+   [95 (- 270 33)]
+   [84 (- 270 18)]
+   [80 270]
+   [84 (+ 270 18)]
+   [95 (+ 270 33)]
+   [111 (+ 270 44)]
+   ]))
 
 (def *levels*
   [
@@ -71,4 +99,8 @@
    {:lines *level2_lines*
     :segments (build-segment-list (- (count *level2_lines*) 1) true)
     :length-fn *default-length-fn*}
-   ])
+
+   {:lines *level3_lines*
+    :segments (build-segment-list (- (count *level3_lines*) 1) false)
+    :length-fn *default-length-fn*}
+])