Skip to content

Commit

Permalink
Move creature creation into generation.clj.
Browse files Browse the repository at this point in the history
Suggested by Gery Debongnie.
  • Loading branch information
sjl committed Oct 13, 2012
1 parent b7278ef commit 8c8a177
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
26 changes: 2 additions & 24 deletions src/caves/ui/input.clj
@@ -1,36 +1,14 @@
(ns caves.ui.input (ns caves.ui.input
(:use [caves.world.generation :only [random-world smooth-world]] (:use [caves.world.generation :only [random-world smooth-world]]
[caves.world.core :only [find-empty-tile]] [caves.entities.player :only [move-player]]
[caves.ui.core :only [->UI]] [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]])
(:require [lanterna.screen :as s])) (: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] (defn reset-game [game]
(let [fresh-world (random-world)] (let [fresh-world (random-world)]
(-> game (-> game
(assoc :world fresh-world) (assoc :world fresh-world)
(update-in [:world] populate-world)
(assoc :uis [(->UI :play)])))) (assoc :uis [(->UI :play)]))))




Expand Down
30 changes: 28 additions & 2 deletions src/caves/world/generation.clj
@@ -1,7 +1,12 @@
(ns caves.world.generation (ns caves.world.generation
(:use [clojure.set :only (union difference)] (: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 [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]])) [caves.coords :only [neighbors]]))




Expand Down Expand Up @@ -118,7 +123,28 @@
(assoc world :tiles (get-smoothed-tiles tiles))) (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 [] (defn random-world []
(let [world (->World (random-tiles) {}) (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))))) (assoc world :regions (get-region-map (:tiles world)))))

0 comments on commit 8c8a177

Please sign in to comment.