src/caves/entities/silverfish.clj @ 1a3a4f8d5d85
Refactor the world code into separate files.
This pulls out the world generation code into its own file. It was
getting a bit crowded in there.
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 01 Aug 2012 21:13:37 -0400 |
parents |
f57db9d7ccff |
children |
(none) |
(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.core :only [get-entity-at get-tile-kind]]
[caves.coords :only [neighbors]]))
(defrecord Silverfish [id glyph color location hp max-hp name])
(defn make-silverfish [location]
(map->Silverfish {:id (get-id)
:name "silverfish"
: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 (can-move? this target world)
(move this target world)
world))))
(add-aspect Silverfish Mobile
(can-move? [this dest world]
(and (#{:floor :wall} (get-tile-kind world dest))
(not (get-entity-at world dest)))))
(add-aspect Silverfish Destructible)