caves / src / caves / entities / silverfish.clj

(ns caves.entities.silverfish
  (:use [caves.entities.core :only [Entity get-id add-aspect]]
        [caves.entities.aspects.destructible :only [Destructible]]
        [ :only [Mobile move can-move?]]
        [ :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)

(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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.