Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move creature creation into generation.clj.

Suggested by Gery Debongnie.
  • Loading branch information...
commit 8c8a1770dec46acc287e45a2619843d2657db674 1 parent b7278ef
@sjl authored
Showing with 30 additions and 26 deletions.
  1. +2 −24 src/caves/ui/input.clj
  2. +28 −2 src/caves/world/generation.clj
View
26 src/caves/ui/input.clj
@@ -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)]))))
View
30 src/caves/world/generation.clj
@@ -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)))))
Please sign in to comment.
Something went wrong with that request. Please try again.