Commits

Steve Losh committed 5724045

Move creature creation into generation.clj.

Suggested by Gery Debongnie.

Comments (0)

Files changed (2)

src/caves/ui/input.clj

 (ns caves.ui.input
   (:use [caves.world.generation :only [random-world smooth-world]]
-        [caves.world.core :only [find-empty-tile]]
-        [caves.ui.core :only [->UI]]
-        [caves.entities.player :only [move-player make-player]]
-        [caves.entities.lichen :only [make-lichen]]
-        [caves.entities.bunny :only [make-bunny]]
-        [caves.entities.silverfish :only [make-silverfish]])
+        [caves.entities.player :only [move-player]]
+        [caves.ui.core :only [->UI]])
   (:require [lanterna.screen :as s]))
 
 
-(defn add-creature [world make-creature]
-  (let [creature (make-creature (find-empty-tile world))]
-    (assoc-in world [:entities (:id creature)] creature)))
-
-(defn add-creatures [world make-creature n]
-  (nth (iterate #(add-creature % make-creature)
-                world)
-       n))
-
-(defn populate-world [world]
-  (let [world (assoc-in world [:entities :player]
-                        (make-player (find-empty-tile world)))]
-    (-> world
-      (add-creatures make-lichen 30)
-      (add-creatures make-bunny 20)
-      (add-creatures make-silverfish 4))))
-
 (defn reset-game [game]
   (let [fresh-world (random-world)]
     (-> game
       (assoc :world fresh-world)
-      (update-in [:world] populate-world)
       (assoc :uis [(->UI :play)]))))
 
 

src/caves/world/generation.clj

 (ns caves.world.generation
   (:use [clojure.set :only (union difference)]
+        [caves.entities.player :only [make-player]]
+        [caves.entities.lichen :only [make-lichen]]
+        [caves.entities.bunny :only [make-bunny]]
+        [caves.entities.silverfish :only [make-silverfish]]
         [caves.world.core :only [tiles get-tile-from-tiles random-coordinate
-                                 world-size ->World tile-walkable?]]
+                                 world-size ->World tile-walkable?
+                                 find-empty-tile]]
         [caves.coords :only [neighbors]]))
 
 
   (assoc world :tiles (get-smoothed-tiles tiles)))
 
 
+; Creatures -------------------------------------------------------------------
+(defn add-creature [world make-creature]
+  (let [creature (make-creature (find-empty-tile world))]
+    (assoc-in world [:entities (:id creature)] creature)))
+
+(defn add-creatures [world make-creature n]
+  (nth (iterate #(add-creature % make-creature)
+                world)
+       n))
+
+(defn populate-world [world]
+  (let [world (assoc-in world [:entities :player]
+                        (make-player (find-empty-tile world)))]
+    (-> world
+      (add-creatures make-lichen 30)
+      (add-creatures make-bunny 20)
+      (add-creatures make-silverfish 4))))
+
+
+; Actual World Creation -------------------------------------------------------
 (defn random-world []
   (let [world (->World (random-tiles) {})
-        world (nth (iterate smooth-world world) 3)]
+        world (nth (iterate smooth-world world) 3)
+        world (populate-world world)]
     (assoc world :regions (get-region-map (:tiles world)))))