Permalink
Browse files

Real attacking, and some refactoring.

  • Loading branch information...
1 parent 8de2ef3 commit fff4e1e939b2004cdfa4e811dd3343ad3bd2e194 @sjl committed Jul 18, 2012
View
@@ -8,6 +8,6 @@
]
; :repositories {"sonatype-snapshots" "https://oss.sonatype.org/content/repositories/snapshots"}
- ; :main caves.core
+ :main ^{:skip-aot true} caves.core
)
View
@@ -49,6 +49,7 @@
:else :auto)]
(main screen-type true)))
+
(comment
(main :swing false)
(main :swing true)
@@ -4,12 +4,19 @@
[caves.entities.core :only [defaspect]]))
+(declare get-damage)
+
(defaspect Attacker
- (attack [this world target]
+ (attack [this target world]
{:pre [(satisfies? Destructible target)]}
- (let [damage (inc (rand-int (max 0 (- (attack-value this world)
- (defense-value target world)))))]
- (take-damage target world damage)))
+ (take-damage target (get-damage this target world) world))
(attack-value [this world]
(get this :attack 1)))
+
+(defn get-damage [attacker target world]
+ (let [attack (attack-value attacker world)
+ defense (defense-value target world)
+ max-damage (max 0 (- attack defense))
+ damage (inc (rand-int max-damage))]
+ damage))
@@ -3,7 +3,7 @@
(defaspect Destructible
- (take-damage [{:keys [id] :as this} world damage]
+ (take-damage [{:keys [id] :as this} damage world]
(let [damaged-this (update-in this [:hp] - damage)]
(if-not (pos? (:hp damaged-this))
(update-in world [:entities] dissoc id)
@@ -4,8 +4,8 @@
(defaspect Digger
- (dig [this world dest]
- {:pre [(can-dig? this world dest)]}
+ (dig [this dest world]
+ {:pre [(can-dig? this dest world)]}
(set-tile-floor world dest))
- (can-dig? [this world dest]
+ (can-dig? [this dest world]
(check-tile world dest #{:wall})))
@@ -4,9 +4,9 @@
(defaspect Mobile
- (move [this world dest]
- {:pre [(can-move? this world dest)]}
+ (move [this dest world]
+ {:pre [(can-move? this dest world)]}
(assoc-in world [:entities (:id this) :location] dest))
- (can-move? [this world dest]
+ (can-move? [this dest world]
(is-empty? world dest)))
@@ -1,7 +1,7 @@
(ns caves.entities.bunny
(:use [caves.entities.core :only [Entity get-id add-aspect]]
[caves.entities.aspects.destructible :only [Destructible]]
- [caves.entities.aspects.mobile :only [Mobile move can-move?]]
+ [caves.entities.aspects.mobile :only [Mobile move]]
[caves.world :only [find-empty-neighbor]]))
@@ -19,7 +19,7 @@
(extend-type Bunny Entity
(tick [this world]
(if-let [target (find-empty-neighbor world (:location this))]
- (move this world target)
+ (move this target world)
world)))
(add-aspect Bunny Mobile)
@@ -33,7 +33,7 @@
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)
+ 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)))
@@ -22,10 +22,10 @@
(let [target (rand-nth (neighbors (:location this)))]
(if (get-entity-at world target)
world
- (move this world target)))))
+ (move this target world)))))
(add-aspect Silverfish Mobile
- (can-move? [this world dest]
+ (can-move? [this dest world]
(not (get-entity-at world dest))))
(add-aspect Silverfish Destructible)

0 comments on commit fff4e1e

Please sign in to comment.