src/caves/entities/aspects/destructible.clj @ ef03fb8bb7e4

Add real hp, attack and defense.
author Steve Losh <steve@stevelosh.com>
date Sun, 15 Jul 2012 15:24:14 -0400
parents c1fba0f3ec5f
children 811f328099c6
(ns caves.entities.aspects.destructible
  (:use [caves.entities.core :only [defaspect]]))


(defaspect Destructible
  (take-damage [{:keys [id] :as this} world damage]
    (let [damaged-this (update-in this [:hp] - damage)]
      (if-not (pos? (:hp damaged-this))
        (update-in world [:entities] dissoc id)
        (assoc-in world [:entities id] damaged-this))))
  (defense-value [this world]
    (get this :defense 0)))