--- a/src/caves/entities/player.clj Wed Jul 11 12:43:30 2012 -0400
+++ b/src/caves/entities/player.clj Wed Jul 11 20:32:47 2012 -0400
@@ -6,7 +6,7 @@
[caves.world :only [find-empty-tile get-tile-kind set-tile-floor]]))
-(defrecord Player [id loc])
+(defrecord Player [id glyph location])
(defn check-tile
"Check that the tile at the destination passes the given predicate."
@@ -21,7 +21,7 @@
(extend-type Player Mobile
(move [this world dest]
{:pre [(can-move? this world dest)]}
- (assoc-in world [:player :loc] dest))
+ (assoc-in world [:player :location] dest))
(can-move? [this world dest]
(check-tile world dest #{:floor})))
@@ -34,11 +34,11 @@
(defn make-player [world]
- (->Player :player (find-empty-tile world)))
+ (->Player :player "@" (find-empty-tile world)))
(defn move-player [world dir]
(let [player (:player world)
- target (destination-coords (:loc player) dir)]
+ target (destination-coords (:location player) dir)]
(cond
(can-move? player world target) (move player world target)
(can-dig? player world target) (dig player world target)
--- a/src/caves/ui/drawing.clj Wed Jul 11 12:43:30 2012 -0400
+++ b/src/caves/ui/drawing.clj Wed Jul 11 20:32:47 2012 -0400
@@ -60,16 +60,16 @@
(defn draw-hud [screen game start-x start-y]
(let [hud-row (dec (second screen-size))
- [x y] (get-in game [:world :player :loc])
+ [x y] (get-in game [:world :player :location])
info (str "loc: [" x "-" y "]")
- info (str info " start: [" start-x " " start-y "]")
- ]
+ info (str info " start: [" start-x "-" start-y "]")]
(s/put-string screen 0 hud-row info)))
-(defn draw-player [screen start-x start-y [player-x player-y]]
- (let [x (- player-x start-x)
+(defn draw-player [screen start-x start-y player]
+ (let [[player-x player-y] (:location player)
+ x (- player-x start-x)
y (- player-y start-y)]
- (s/put-string screen x y "@" {:fg :white})
+ (s/put-string screen x y (:glyph player) {:fg :white})
(s/move-cursor screen x y)))
(defn draw-world [screen vrows vcols start-x start-y end-x end-y tiles]
@@ -83,14 +83,13 @@
(defmethod draw-ui :play [ui game screen]
(let [world (:world game)
- tiles (:tiles world)
- player-location (get-in world [:player :loc])
+ {:keys [tiles player]} world
[cols rows] screen-size
vcols cols
vrows (dec rows)
- [start-x start-y end-x end-y] (get-viewport-coords game player-location vcols vrows)]
+ [start-x start-y end-x end-y] (get-viewport-coords game (:location player) vcols vrows)]
(draw-world screen vrows vcols start-x start-y end-x end-y tiles)
- (draw-player screen start-x start-y player-location)
+ (draw-player screen start-x start-y player)
(draw-hud screen game start-x start-y)))
--- a/src/caves/ui/input.clj Wed Jul 11 12:43:30 2012 -0400
+++ b/src/caves/ui/input.clj Wed Jul 11 20:32:47 2012 -0400
@@ -5,16 +5,20 @@
(:require [lanterna.screen :as s]))
+(defn reset-game [game]
+ (let [fresh-world (random-world)]
+ (-> game
+ (assoc :world fresh-world)
+ (assoc-in [:world :player] (make-player fresh-world))
+ (assoc :uis [(->UI :play)]))))
+
+
(defmulti process-input
(fn [game input]
(:kind (last (:uis game)))))
(defmethod process-input :start [game input]
- (let [fresh-world (random-world)]
- (-> game
- (assoc :world fresh-world)
- (assoc-in [:world :player] (make-player fresh-world))
- (assoc :uis [(->UI :play)]))))
+ (reset-game game))
(defmethod process-input :play [game input]
--- a/src/caves/world.clj Wed Jul 11 12:43:30 2012 -0400
+++ b/src/caves/world.clj Wed Jul 11 20:32:47 2012 -0400
@@ -23,14 +23,6 @@
[(rand-int cols) (rand-int rows)]))
-; Debugging -------------------------------------------------------------------
-(defn print-row [row]
- (println (apply str (map :glyph row))))
-
-(defn print-world [world]
- (dorun (map print-row (:tiles world))))
-
-
; World generation ------------------------------------------------------------
(defn random-tiles []
(let [[cols rows] world-size]
@@ -95,8 +87,7 @@
(defn find-empty-tile [world]
(loop [coord (random-coordinate)]
- (let [{:keys [kind]} (get-tile world coord)]
- (if (#{:floor} kind)
- coord
- (recur (random-coordinate))))))
+ (if (#{:floor} (get-tile-kind world coord))
+ coord
+ (recur (random-coordinate)))))