# HG changeset patch # User Steve Losh # Date 1342581734 14400 # Node ID 811f328099c66446b8e6a14bf1878dd9b71e1601 # Parent ef03fb8bb7e48c5c5c90ba5d852d292869655cb0 Real attacking, and some refactoring. diff -r ef03fb8bb7e4 -r 811f328099c6 project.clj --- a/project.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/project.clj Tue Jul 17 23:22:14 2012 -0400 @@ -8,6 +8,6 @@ ] ; :repositories {"sonatype-snapshots" "https://oss.sonatype.org/content/repositories/snapshots"} - ; :main caves.core + :main ^{:skip-aot true} caves.core ) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/core.clj --- a/src/caves/core.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/core.clj Tue Jul 17 23:22:14 2012 -0400 @@ -49,6 +49,7 @@ :else :auto)] (main screen-type true))) + (comment (main :swing false) (main :swing true) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/aspects/attacker.clj --- a/src/caves/entities/aspects/attacker.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/aspects/attacker.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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)) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/aspects/destructible.clj --- a/src/caves/entities/aspects/destructible.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/aspects/destructible.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/aspects/digger.clj --- a/src/caves/entities/aspects/digger.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/aspects/digger.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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}))) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/aspects/mobile.clj --- a/src/caves/entities/aspects/mobile.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/aspects/mobile.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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))) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/bunny.clj --- a/src/caves/entities/bunny.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/bunny.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/player.clj --- a/src/caves/entities/player.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/player.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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))) diff -r ef03fb8bb7e4 -r 811f328099c6 src/caves/entities/silverfish.clj --- a/src/caves/entities/silverfish.clj Sun Jul 15 15:24:14 2012 -0400 +++ b/src/caves/entities/silverfish.clj Tue Jul 17 23:22:14 2012 -0400 @@ -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)