src/caves/entities/player.clj @ 811f328099c6
Real attacking, and some refactoring.
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 17 Jul 2012 23:22:14 -0400 |
parents |
ef03fb8bb7e4 |
children |
88091919d482 |
(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 entity-at-target world)
(can-move? player target world) (move player target world)
(can-dig? player target world) (dig player target world)
:else world)))