Permalink
Browse files

Fix entity drawing bounds.

  • Loading branch information...
1 parent bdd67fd commit c6abbcb4ec6ffccf1973b90a3bab6376ce4c65a8 @sjl committed Jul 18, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/caves/ui/drawing.clj
View
@@ -89,9 +89,13 @@
(s/put-string screen 0 hud-row info)))
-(defn draw-entity [screen origin {:keys [location glyph color]}]
- (let [[x y] (get-viewport-coords-of origin location)]
- (s/put-string screen x y glyph {:fg color})))
+(defn draw-entity [screen origin vrows vcols {:keys [location glyph color]}]
+ (let [[x y] (get-viewport-coords-of origin location)
+ max-x (dec vcols)
+ max-y (dec vrows)]
+ (when (and (<= 0 x max-x)
+ (<= 0 y max-y))
+ (s/put-string screen x y glyph {:fg color}))))
(defn draw-world [screen vrows vcols [ox oy] tiles]
@@ -122,7 +126,7 @@
origin (get-viewport-coords game (:location player) vcols vrows)]
(draw-world screen vrows vcols origin tiles)
(doseq [entity (vals entities)]
- (draw-entity screen origin entity))
+ (draw-entity screen origin vrows vcols entity))
(draw-hud screen game)
(draw-messages screen (:messages player))
(highlight-player screen origin player)))

0 comments on commit c6abbcb

Please sign in to comment.