Add spreading for lichens.
author |
Steve Losh <steve@stevelosh.com> |
date |
Thu, 12 Jul 2012 19:07:08 -0400 |
parents |
a208f6298145
|
children |
716b6b7e09f1
|
branches/tags |
(none) |
files |
src/caves/entities/lichen.clj src/caves/entities/player.clj |
Changes
--- a/src/caves/entities/lichen.clj Thu Jul 12 18:52:17 2012 -0400
+++ b/src/caves/entities/lichen.clj Thu Jul 12 19:07:08 2012 -0400
@@ -1,19 +1,27 @@
(ns caves.entities.lichen
- (:use [caves.entities.core :only [Entity get-id]]))
+ (:use [caves.entities.core :only [Entity get-id]]
+ [caves.world :only [find-empty-neighbor]]))
(defrecord Lichen [id glyph color location])
+(defn make-lichen [location]
+ (->Lichen (get-id) "F" :green location))
+
(defn should-grow []
(< (rand) 0.01))
+(defn grow [lichen world]
+ (if-let [target (find-empty-neighbor world (:location lichen))]
+ (let [new-lichen (make-lichen target)]
+ (assoc-in world [:entities (:id new-lichen)] new-lichen))
+ world))
(extend-type Lichen Entity
(tick [this world]
- world))
+ (if (should-grow)
+ (grow this world)
+ world)))
-(defn make-lichen [location]
- (->Lichen (get-id) "F" :green location))
-
--- a/src/caves/entities/player.clj Thu Jul 12 18:52:17 2012 -0400
+++ b/src/caves/entities/player.clj Thu Jul 12 19:07:08 2012 -0400
@@ -3,7 +3,7 @@
[caves.entities.aspects.mobile :only [Mobile move can-move?]]
[caves.entities.aspects.digger :only [Digger dig can-dig?]]
[caves.coords :only [destination-coords]]
- [caves.world :only [get-tile-kind set-tile-floor]]))
+ [caves.world :only [is-empty? get-tile-kind set-tile-floor]]))
(defrecord Player [id glyph color location])
@@ -23,7 +23,7 @@
{:pre [(can-move? this world dest)]}
(assoc-in world [:entities :player :location] dest))
(can-move? [this world dest]
- (check-tile world dest #{:floor})))
+ (is-empty? world dest)))
(extend-type Player Digger
(dig [this world dest]