cursor overhaul.
This commit is contained in:
@@ -14,31 +14,39 @@
|
|||||||
(def +screen-width+ 320)
|
(def +screen-width+ 320)
|
||||||
(def +screen-height+ 240)
|
(def +screen-height+ 240)
|
||||||
(def +num-cursors+ 4)
|
(def +num-cursors+ 4)
|
||||||
(def +next-cursor+ (into {} (map vector (range +num-cursors+) (drop 1 (cycle (range +num-cursors+))))))
|
(def +next-cursor+ (into {} (map vector [:walk :touch :look :talk] (drop 1 (cycle [:walk :touch :look :talk])))))
|
||||||
|
(def +all-cursors+ [:walk :touch :look :talk :right :down :left :up])
|
||||||
|
|
||||||
(defn +next-cursor+ [x]
|
(def +cursor-defaults+ {:walk (fn [screen entities [x y]]
|
||||||
(first (drop 1 (drop-while #(not= x %) (cycle (range +num-cursors+))))))
|
(assoc-in entities [:ego :actions] (actions/from-path screen entities :ego [x y])))
|
||||||
|
:look (fn [screen entities _]
|
||||||
|
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||||
|
(actions/talk :ego "Looks pretty uninteresting to me.")]))
|
||||||
|
:touch (fn [screen entities _]
|
||||||
|
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||||
|
(actions/talk :ego "Can't do anything with it.")]))
|
||||||
|
:talk (fn [screen entities _]
|
||||||
|
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||||
|
(actions/talk :ego "It's not much of a conversationalist.")]))})
|
||||||
|
|
||||||
(defn cursor [filename index]
|
(defn cursor [filename which]
|
||||||
(let [scale 2
|
(let [scale 2
|
||||||
base-cursor (pixmap filename)
|
base-cursor (pixmap filename)
|
||||||
target-width (* 16 scale)
|
target-width (* 16 scale)
|
||||||
target-height (* 16 scale)
|
target-height (* 16 scale)
|
||||||
resized (Pixmap. target-width target-height (.getFormat base-cursor))]
|
resized (Pixmap. target-width target-height (.getFormat base-cursor))
|
||||||
|
index (.indexOf +all-cursors+ which)]
|
||||||
(Pixmap/setFilter Pixmap$Filter/NearestNeighbour)
|
(Pixmap/setFilter Pixmap$Filter/NearestNeighbour)
|
||||||
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
|
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
|
||||||
0 0 target-width target-height)
|
0 0 target-width target-height)
|
||||||
resized ))
|
resized ))
|
||||||
|
|
||||||
(defn right-click [screen entities]
|
(defn right-click [screen entities]
|
||||||
(let [entities (update-in entities [:cursor] #(assoc % :cursor-index (+next-cursor+ (:cursor-index %))))]
|
(let [entities (update-in entities [:cursor] #(assoc % :current (+next-cursor+ (:current %))))]
|
||||||
(input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0)
|
(input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :current])) 0 0)
|
||||||
entities))
|
entities))
|
||||||
|
|
||||||
|
|
||||||
(defn walk-click [screen entities [x y]]
|
|
||||||
(assoc-in entities [:ego :actions] (actions/from-path screen entities :ego [x y])))
|
|
||||||
|
|
||||||
(defn walk-override-click [screen entities [x y]]
|
(defn walk-override-click [screen entities [x y]]
|
||||||
(let [target-location (->> (get-in entities [:background :mouse-overrides])
|
(let [target-location (->> (get-in entities [:background :mouse-overrides])
|
||||||
(filter #((:mouse-in? %) x y))
|
(filter #((:mouse-in? %) x y))
|
||||||
@@ -48,11 +56,14 @@
|
|||||||
|
|
||||||
(defn left-click [screen entities]
|
(defn left-click [screen entities]
|
||||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
|
||||||
interaction (first (filter #((:mouse-in? %) x y) (get-in entities [:background :interactions])))]
|
interaction (first (filter #((:mouse-in? %) x y) (get-in entities [:background :interactions])))
|
||||||
|
current-cursor (get-in entities [:cursor :current])
|
||||||
|
interaction-fn (when interaction
|
||||||
|
(interaction current-cursor))]
|
||||||
(cond (get-in entities [:cursor :override]) (walk-override-click screen entities [x y])
|
(cond (get-in entities [:cursor :override]) (walk-override-click screen entities [x y])
|
||||||
interaction ((:click-fn interaction) screen entities [x y])
|
(and interaction interaction-fn) (interaction-fn screen entities [x y])
|
||||||
|
:else
|
||||||
:else (walk-click screen entities [x y]))))
|
((+cursor-defaults+ current-cursor) screen entities [x y]))))
|
||||||
|
|
||||||
(defn get-ego [screen]
|
(defn get-ego [screen]
|
||||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||||
@@ -92,7 +103,7 @@
|
|||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(update! screen :renderer (stage) :camera (orthographic))
|
(update! screen :renderer (stage) :camera (orthographic))
|
||||||
(let [
|
(let [
|
||||||
_ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0)
|
_ (input! :set-cursor-image (cursor "cursor.png" :walk) 0 0)
|
||||||
background (texture "bg5.png")
|
background (texture "bg5.png")
|
||||||
background-trees (texture "background-trees.png")
|
background-trees (texture "background-trees.png")
|
||||||
house (texture "house.png")
|
house (texture "house.png")
|
||||||
@@ -101,21 +112,21 @@
|
|||||||
;; _ (sound! music :loop)
|
;; _ (sound! music :loop)
|
||||||
]
|
]
|
||||||
{
|
{
|
||||||
:cursor {:id "cursor" :cursor-index 0 }
|
:cursor {:id "cursor" :current :walk }
|
||||||
:background (assoc {}
|
:background (assoc {}
|
||||||
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
||||||
:baseline 0
|
:baseline 0
|
||||||
:mouse-overrides [{:mouse-in? (zone/box 300 131 320 224)
|
:mouse-overrides [{:mouse-in? (zone/box 300 131 320 224)
|
||||||
:cursor-override 4
|
:cursor-override :right
|
||||||
:go-to [319 160]}
|
:go-to [319 160]}
|
||||||
{:mouse-in? (zone/box 60 180 224 240)
|
{:mouse-in? (zone/box 60 180 224 240)
|
||||||
:cursor-override 7
|
:cursor-override :up
|
||||||
:go-to [137 204]}
|
:go-to [137 204]}
|
||||||
{:mouse-in? (zone/box 0 40 20 140)
|
{:mouse-in? (zone/box 0 40 20 140)
|
||||||
:cursor-override 6
|
:cursor-override :left
|
||||||
:go-to [0 80]}]
|
:go-to [0 80]}]
|
||||||
:interactions [{:mouse-in? (zone/box 258 100 281 160)
|
:interactions [{:mouse-in? (zone/box 258 100 281 160)
|
||||||
:click-fn (fn [screen entities [x y]]
|
:look (fn [screen entities [x y]]
|
||||||
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||||
(actions/talk :ego (str "The last time I went through that door, Fangald turned me into a frog."))]))}]
|
(actions/talk :ego (str "The last time I went through that door, Fangald turned me into a frog."))]))}]
|
||||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
|
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
|
||||||
@@ -150,7 +161,7 @@
|
|||||||
(assoc-in entities [:cursor :override] true)))
|
(assoc-in entities [:cursor :override] true)))
|
||||||
|
|
||||||
(when (get-in entities [:cursor :override])
|
(when (get-in entities [:cursor :override])
|
||||||
(do (input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0)
|
(do (input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :current])) 0 0)
|
||||||
(assoc-in entities [:cursor :override] false))))))
|
(assoc-in entities [:cursor :override] false))))))
|
||||||
|
|
||||||
:on-touch-down (fn [screen [entities]]
|
:on-touch-down (fn [screen [entities]]
|
||||||
|
|||||||
Reference in New Issue
Block a user