Commits

Steve Losh  committed ed404f9

Refactor a bit, add better scrolling.

  • Participants
  • Parent commits acdb58b

Comments (0)

Files changed (3)

File src/ruin/drawing.clj

 
 (defn draw-entities []
   (let [[ox oy] (:viewport-origin @game)
-        screen (:screen @game)]
-  (doseq [entity (vals @(:entities @game))]
-    (let [{:keys [location glyph]} @entity
-          [x y] location
-          vx (- x ox)
-          vy (- y oy)]
-      (when (and (<= 0 vx)
-                 (<= 0 vy)))
-      (s/put-string screen vx vy glyph)))))
+        screen (:screen @game)
+        [cols rows] (s/get-size screen)
+        map-height rows
+        map-width (- cols (inc SIDEBAR-WIDTH))]
+    (doseq [entity (vals @(:entities @game))]
+      (let [{:keys [location glyph]} @entity
+            [x y] location
+            vx (- x ox)
+            vy (- y oy)]
+        (when (and (<= 0 vy (dec map-height))
+                   (<= 0 vx (dec map-width)))
+          (s/put-string screen vx vy glyph))))))
 
 (defn draw-map []
   (let [screen (:screen @game)
         y (inc STATUS-HEIGHT)]
     (s/put-sheet screen x y
                  ["MENU"
-                  "hjkl: move view"
-                  "Q:    quit game"]))
-  )
+                  "hjklyubn: move view"
+                  "HJKLYUBN: move view faster"
+                  "Q:        quit game"])))
+
 (defn draw-sidebar []
   (draw-status)
   (draw-main-menu))

File src/ruin/input.clj

 (ns ruin.input
-  (:use [ruin.state :only [game]]
+  (:use [ruin.util :only [dir-to-offset]]
+        [ruin.state :only [game]]
         [ruin.ui :only [push-ui pop-ui ->UI]])
   (:require [lanterna.screen :as s]))
 
 
+(defn quit-game []
+  (do
+    (dosync (alter game dissoc :state))
+    (s/stop (:screen @game))))
+
+
 (defmulti process-input
   "Handle input from the console."
   (fn [ui input]
     (:kind ui)))
 
-(defn quit-game []
-  (do
-    (dosync (alter game dissoc :state))
-    (s/stop (:screen @game))))
 
 (defmethod process-input :start [ui input]
   (cond
     (push-ui (->UI :start))))
 
 
-(defn scroll-map [dir]
-  (let [offset (case dir
-                 :w [-1 0]
-                 :e [1 0]
-                 :s [0 1]
-                 :n [0 -1])]
-    (dosync (alter game update-in [:viewport-origin] #(map + offset %)))))
+(defn scroll-map
+  ([dir] (scroll-map dir 1))
+  ([dir amount]
+   (dosync
+     (alter game update-in [:viewport-origin]
+            #(map + (map (partial * amount)
+                         (dir-to-offset dir))
+                  %)))))
+
 
 (defmethod process-input :play [ui input]
   (case input
     \j (scroll-map :s)
     \k (scroll-map :n)
     \l (scroll-map :e)
+    \y (scroll-map :nw)
+    \u (scroll-map :ne)
+    \b (scroll-map :sw)
+    \n (scroll-map :se)
+    \H (scroll-map :w 6)
+    \J (scroll-map :s 6)
+    \K (scroll-map :n 6)
+    \L (scroll-map :e 6)
+    \Y (scroll-map :nw 6)
+    \U (scroll-map :ne 6)
+    \B (scroll-map :sw 6)
+    \N (scroll-map :se 6)
     :enter (dosync
              (pop-ui)
              (push-ui (->UI :win)))

File src/ruin/util.clj

+(ns ruin.util)
+
+(defn dir-to-offset [dir]
+  (case dir
+    :w [-1 0]
+    :e [1 0]
+    :s [0 1]
+    :n [0 -1]
+    :nw [-1 -1]
+    :ne [1 -1]
+    :sw [-1 1]
+    :se [1 1]))