src/caves/entities/lichen.clj @ 180b5b981d92

use the black magic everywhere
author Steve Losh <steve@stevelosh.com>
date Sat, 14 Jul 2012 14:32:49 -0400
parents 2a668110bcf8
children 130e2fc7c495
(ns caves.entities.lichen
  (:use [caves.entities.core :only [Entity get-id add-aspect]]
        [caves.entities.aspects.destructible :only [Destructible take-damage]]
        [caves.world :only [find-empty-neighbor]]))


(defrecord Lichen [id glyph color location hp])

(defn make-lichen [location]
  (->Lichen (get-id) "F" :green location 1))

(defn should-grow []
  (< (rand) (/ 1 500)))

(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)))

(add-aspect Lichen Destructible)