src/caves/entities/lichen.clj @ 0e7bdc5771b2
Add spreading for lichens.
author |
Steve Losh <steve@stevelosh.com> |
date |
Thu, 12 Jul 2012 19:07:08 -0400 |
parents |
a208f6298145 |
children |
716b6b7e09f1 |
(ns caves.entities.lichen
(: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]
(if (should-grow)
(grow this world)
world)))