Permalink
Browse files

Fix Silverfish walking out of the world.

  • Loading branch information...
1 parent c6abbcb commit e8f35770cdc63fd8b4a4d528b391af5fdd49f42e @sjl committed Jul 18, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/caves/entities/silverfish.clj
@@ -2,7 +2,7 @@
(: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.world :only [get-entity-at]]
+ [caves.world :only [get-entity-at get-tile-kind]]
[caves.coords :only [neighbors]]))
@@ -20,12 +20,13 @@
(extend-type Silverfish Entity
(tick [this world]
(let [target (rand-nth (neighbors (:location this)))]
- (if (get-entity-at world target)
- world
- (move this target world)))))
+ (if (can-move? this target world)
+ (move this target world)
+ world))))
(add-aspect Silverfish Mobile
(can-move? [this dest world]
- (not (get-entity-at world dest))))
+ (and (#{:floor :wall} (get-tile-kind world dest))
+ (not (get-entity-at world dest)))))
(add-aspect Silverfish Destructible)

0 comments on commit e8f3577

Please sign in to comment.