Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moar

  • Loading branch information...
commit 76dce3418c663473a62d0ba449caeb17c7f56d59 1 parent e95a001
@sjl authored
View
8 src/caves/entities/player.clj
@@ -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)
View
19 src/caves/ui/drawing.clj
@@ -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)))
View
14 src/caves/ui/input.clj
@@ -5,11 +5,7 @@
(:require [lanterna.screen :as s]))
-(defmulti process-input
- (fn [game input]
- (:kind (last (:uis game)))))
-
-(defmethod process-input :start [game input]
+(defn reset-game [game]
(let [fresh-world (random-world)]
(-> game
(assoc :world fresh-world)
@@ -17,6 +13,14 @@
(assoc :uis [(->UI :play)]))))
+(defmulti process-input
+ (fn [game input]
+ (:kind (last (:uis game)))))
+
+(defmethod process-input :start [game input]
+ (reset-game game))
+
+
(defmethod process-input :play [game input]
(case input
:enter (assoc game :uis [(->UI :win)])
View
15 src/caves/world.clj
@@ -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)))))
Please sign in to comment.
Something went wrong with that request. Please try again.