Skip to content
Browse files

Add spreading for lichens.

  • Loading branch information...
1 parent 822a397 commit e218bc12b60e73d2244d152e3c6c8a1446933c7e @sjl committed Jul 12, 2012
Showing with 15 additions and 7 deletions.
  1. +13 −5 src/caves/entities/lichen.clj
  2. +2 −2 src/caves/entities/player.clj
View
18 src/caves/entities/lichen.clj
@@ -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))
View
4 src/caves/entities/player.clj
@@ -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]

0 comments on commit e218bc1

Please sign in to comment.
Something went wrong with that request. Please try again.