# HG changeset patch # User Steve Losh # Date 1350155748 14400 # Node ID 572404588054dd5c2d436ad4b0d13b71e3f8b9db # Parent 3152de9c4d387228c36fdd4a63a9e0ea36ac84f8 Move creature creation into generation.clj. Suggested by Gery Debongnie. diff -r 3152de9c4d38 -r 572404588054 src/caves/ui/input.clj --- 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)])))) diff -r 3152de9c4d38 -r 572404588054 src/caves/world/generation.clj --- 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)))))