Commits

Steve Losh committed ef03fb8

Add real hp, attack and defense.

  • Participants
  • Parent commits d18013e

Comments (0)

Files changed (9)

File src/caves/core.clj

                       (args ":text")  :text
                       :else           :auto)]
     (main screen-type true)))
+
+(comment
+  (main :swing false)
+  (main :swing true)
+  )

File src/caves/entities/aspects/attacker.clj

 (ns caves.entities.aspects.attacker
-  (:use [caves.entities.aspects.destructible :only [Destructible take-damage]]
+  (:use [caves.entities.aspects.destructible :only [Destructible take-damage
+                                                    defense-value]]
         [caves.entities.core :only [defaspect]]))
 
 
 (defaspect Attacker
   (attack [this world target]
     {:pre [(satisfies? Destructible target)]}
-    (let [damage 1]
-      (take-damage target world damage))))
+    (let [damage (inc (rand-int (max 0 (- (attack-value this world)
+                                          (defense-value target world)))))]
+      (take-damage target world damage)))
+  (attack-value [this world]
+    (get this :attack 1)))
 

File src/caves/entities/aspects/destructible.clj

     (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)))))
+        (assoc-in world [:entities id] damaged-this))))
+  (defense-value [this world]
+    (get this :defense 0)))

File src/caves/entities/bunny.clj

         [caves.world :only [find-empty-neighbor]]))
 
 
-(defrecord Bunny [id glyph color location hp])
+(defrecord Bunny [id glyph color location hp max-hp])
 
 (defn make-bunny [location]
-  (->Bunny (get-id) "v" :yellow location 1))
+  (map->Bunny {:id (get-id)
+               :glyph "v"
+               :color :yellow
+               :location location
+               :hp 4
+               :max-hp 4}))
 
 
 (extend-type Bunny Entity

File src/caves/entities/lichen.clj

         [caves.world :only [find-empty-neighbor]]))
 
 
-(defrecord Lichen [id glyph color location hp])
+(defrecord Lichen [id glyph color location hp max-hp])
 
 (defn make-lichen [location]
-  (->Lichen (get-id) "F" :green location 1))
+  (map->Lichen {:id (get-id)
+                :glyph "F"
+                :color :green
+                :location location
+                :hp 6
+                :max-hp 6}))
 
 (defn should-grow []
   (< (rand) (/ 1 500)))

File src/caves/entities/player.clj

         [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])
+(defrecord Player [id glyph color location hp max-hp attack])
 
 (extend-type Player Entity
   (tick [this world]
 (add-aspect Player Mobile)
 (add-aspect Player Digger)
 (add-aspect Player Attacker)
+(add-aspect Player Destructible)
 
 (defn make-player [location]
-  (->Player :player "@" :white 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])

File src/caves/entities/silverfish.clj

         [caves.coords :only [neighbors]]))
 
 
-(defrecord Silverfish [id glyph color location hp])
+(defrecord Silverfish [id glyph color location hp max-hp])
 
 (defn make-silverfish [location]
-  (->Silverfish (get-id) "~" :white location 1))
+  (map->Silverfish {:id (get-id)
+                    :glyph "~"
+                    :color :white
+                    :location location
+                    :hp 15
+                    :max-hp 15}))
 
 
 (extend-type Silverfish Entity

File src/caves/ui/drawing.clj

   (map - coords origin))
 
 
-(defn draw-hud [screen game [ox oy]]
+(defn draw-hud [screen game]
   (let [hud-row (dec (second (s/get-size screen)))
-        [x y] (get-in game [:world :entities :player :location])
-        info (str "player loc: [" x "-" y "]")
-        info (str info " viewport origin: [" ox "-" oy "]")]
+        player (get-in game [:world :entities :player])
+        {:keys [location hp max-hp]} player
+        [x y] location
+        info (str "hp [" hp "/" max-hp "]")
+        info (str info " loc: [" x "-" y "]")]
     (s/put-string screen 0 hud-row info)))
 
 
     (draw-world screen vrows vcols origin tiles)
     (doseq [entity (vals entities)]
       (draw-entity screen origin entity))
-    (draw-hud screen game origin)
+    (draw-hud screen game)
     (highlight-player screen origin player)))
 
 

File src/caves/ui/input.clj

     (-> world
       (add-creatures make-lichen 30)
       (add-creatures make-bunny 20)
-      (add-creatures make-silverfish 15))))
+      (add-creatures make-silverfish 4))))
 
 (defn reset-game [game]
   (let [fresh-world (random-world)]