src/caves/entities/silverfish.clj @ 811f328099c6

Real attacking, and some refactoring.
author Steve Losh <steve@stevelosh.com>
date Tue, 17 Jul 2012 23:22:14 -0400
parents ef03fb8bb7e4
children ae4e6a9fa906
(ns caves.entities.silverfish
  (:use [caves.entities.core :only [Entity get-id add-aspect]]
        [caves.entities.aspects.destructible :only [Destructible]]
        [caves.entities.aspects.mobile :only [Mobile move can-move?]]
        [caves.world :only [get-entity-at]]
        [caves.coords :only [neighbors]]))


(defrecord Silverfish [id glyph color location hp max-hp])

(defn make-silverfish [location]
  (map->Silverfish {:id (get-id)
                    :glyph "~"
                    :color :white
                    :location location
                    :hp 15
                    :max-hp 15}))


(extend-type Silverfish Entity
  (tick [this world]
    (let [target (rand-nth (neighbors (:location this)))]
      (if (get-entity-at world target)
        world
        (move this target world)))))

(add-aspect Silverfish Mobile
  (can-move? [this dest world]
    (not (get-entity-at world dest))))

(add-aspect Silverfish Destructible)