Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add real hp, attack and defense.

  • Loading branch information...
commit 8de2ef38b96fbd558092e67593162a7606fb208c 1 parent dd6942f
@sjl authored
View
5 src/caves/core.clj
@@ -48,3 +48,8 @@
(args ":text") :text
:else :auto)]
(main screen-type true)))
+
+(comment
+ (main :swing false)
+ (main :swing true)
+ )
View
10 src/caves/entities/aspects/attacker.clj
@@ -1,11 +1,15 @@
(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)))
View
4 src/caves/entities/aspects/destructible.clj
@@ -7,4 +7,6 @@
(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)))
View
9 src/caves/entities/bunny.clj
@@ -5,10 +5,15 @@
[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
View
9 src/caves/entities/lichen.clj
@@ -4,10 +4,15 @@
[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)))
View
12 src/caves/entities/player.clj
@@ -3,11 +3,12 @@
[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]
@@ -16,9 +17,16 @@
(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])
View
9 src/caves/entities/silverfish.clj
@@ -6,10 +6,15 @@
[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
View
12 src/caves/ui/drawing.clj
@@ -79,11 +79,13 @@
(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)))
@@ -116,7 +118,7 @@
(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)))
View
2  src/caves/ui/input.clj
@@ -23,7 +23,7 @@
(-> 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)]
Please sign in to comment.
Something went wrong with that request. Please try again.