572404588054

Move creature creation into generation.clj.

Suggested by Gery Debongnie.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 13 Oct 2012 15:15:48 -0400
parents 3152de9c4d38
children b7c4387ab701
branches/tags (none)
files src/caves/ui/input.clj src/caves/world/generation.clj

Changes

--- a/src/caves/ui/input.clj	Sat Oct 13 14:55:32 2012 -0400
+++ b/src/caves/ui/input.clj	Sat Oct 13 15:15:48 2012 -0400
@@ -1,36 +1,14 @@
 (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)]))))
 
 
--- a/src/caves/world/generation.clj	Sat Oct 13 14:55:32 2012 -0400
+++ b/src/caves/world/generation.clj	Sat Oct 13 15:15:48 2012 -0400
@@ -1,7 +1,12 @@
 (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]]))
 
 
@@ -118,7 +123,28 @@
   (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)))))