src/caves/entities/silverfish.clj @ ef03fb8bb7e4
Add real hp, attack and defense.
author |
Steve Losh <steve@stevelosh.com> |
date |
Sun, 15 Jul 2012 15:24:14 -0400 |
parents |
130e2fc7c495 |
children |
811f328099c6 |
(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 world target)))))
(add-aspect Silverfish Mobile
(can-move? [this world dest]
(not (get-entity-at world dest))))
(add-aspect Silverfish Destructible)