6495891e4c59

Variable tick delay
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 13 Dec 2015 14:40:04 +0000
parents 9f53475e55c2
children c6977b636ae8
branches/tags (none)
files src/silt/core.clj

Changes

--- a/src/silt/core.clj	Sun Dec 13 14:34:05 2015 +0000
+++ b/src/silt/core.clj	Sun Dec 13 14:40:04 2015 +0000
@@ -11,6 +11,7 @@
 (def day (ref 0))
 (def world-width 600)
 (def world-height 400)
+(def tick-delay (atom 500))
 
 (def pond-count 100)
 (def pond-size 3)
@@ -313,6 +314,9 @@
 (defn reset-day! []
   (dosync (ref-set day 0)))
 
+(defn reset-tick-delay! []
+  (reset! tick-delay 500))
+
 
 (defn update-animals! []
   (alter animals tick-animals))
@@ -345,6 +349,7 @@
   (mark-dirty!))
 
 (defn reset-world! []
+  (reset-tick-delay!)
   (reset-day!)
   (reset-window!)
   (reset-terrain!)
@@ -354,6 +359,9 @@
 (defn toggle-pause! []
   (swap! paused not))
 
+(defn update-tick-delay! [amt]
+  (swap! tick-delay + amt))
+
 (defn handle-input! [screen]
   (while-let [key (s/get-key screen)]
     (case key
@@ -372,6 +380,12 @@
       (\1 \2 \3 \4 \5 \6 \7 \8 \9)
       (update-world! key)
 
+      \[
+      (update-tick-delay! -50)
+
+      \]
+      (update-tick-delay! 50)
+
       (\+ \=)
       (update-temperature! 1)
 
@@ -395,7 +409,7 @@
       (Thread/sleep wait))))
 
 (defn tick []
-  (Thread/sleep 500)
+  (Thread/sleep @tick-delay)
   (when (not @paused)
     (update-world! \1)))