src/caves/entities/player.clj @ ef03fb8bb7e4
Add real hp, attack and defense.
| author | Steve Losh <steve@stevelosh.com> |
|---|---|
| date | Sun, 15 Jul 2012 15:24:14 -0400 |
| parents | 180b5b981d92 |
| children | 811f328099c6 |
(ns caves.entities.player (:use [caves.entities.core :only [Entity add-aspect]] [caves.entities.aspects.mobile :only [Mobile move can-move?]] [caves.entities.aspects.digger :only [Digger dig can-dig?]] [caves.entities.aspects.attacker :only [Attacker attack]] [caves.entities.aspects.destructible :only [Destructible]] [caves.coords :only [destination-coords]] [caves.world :only [get-entity-at]])) (defrecord Player [id glyph color location hp max-hp attack]) (extend-type Player Entity (tick [this world] world)) (add-aspect Player Mobile) (add-aspect Player Digger) (add-aspect Player Attacker) (add-aspect Player Destructible) (defn make-player [location] (map->Player {:id :player :glyph "@" :color :white :location location :hp 40 :max-hp 40 :attack 10})) (defn move-player [world dir] (let [player (get-in world [:entities :player]) target (destination-coords (:location player) dir) entity-at-target (get-entity-at world target)] (cond entity-at-target (attack player world entity-at-target) (can-move? player world target) (move player world target) (can-dig? player world target) (dig player world target) :else world)))