# HG changeset patch # User Steve Losh # Date 1342134428 14400 # Node ID 0e7bdc5771b2255ca5c55871d02831a2ddb11791 # Parent a208f6298145f0df4ee645f2677b15eae062bbb6 Add spreading for lichens. diff -r a208f6298145 -r 0e7bdc5771b2 src/caves/entities/lichen.clj --- 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)) - diff -r a208f6298145 -r 0e7bdc5771b2 src/caves/entities/player.clj --- 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]