Fix Silverfish walking out of the world.
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 18 Jul 2012 17:37:46 -0400 |
parents |
16038f1308d8
|
children |
f57db9d7ccff
|
branches/tags |
(none) |
files |
src/caves/entities/silverfish.clj |
Changes
--- a/src/caves/entities/silverfish.clj Wed Jul 18 17:32:49 2012 -0400
+++ b/src/caves/entities/silverfish.clj Wed Jul 18 17:37:46 2012 -0400
@@ -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)