mouse areas.

This commit is contained in:
=
2014-09-04 10:10:45 -07:00
parent 1b54f404d2
commit c8c359362d
3 changed files with 28 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -7,7 +7,7 @@
[advent.pathfind])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter]))
(def scale 4)
(def scale 2)
(def +screen-width+ 320)
(def +screen-height+ 240)
(def +num-cursors+ 4)
@@ -91,6 +91,12 @@
range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)]
range)))))
(defn box-maker-fn [x1 y1 x2 y2]
(fn [x y]
(and
(< x1 x x2)
(< y1 y y2))))
(defscreen main-screen
:on-show
(fn [screen entities]
@@ -101,13 +107,20 @@
house (texture "house.png")
overdirt (texture "overdirt.png")
music (sound "outside-house.mp3")
_ (sound! music :loop)]
;; _ (sound! music :loop)
]
{
:cursor {:id "cursor" :cursor-index 0 }
:background (assoc background
:id "background" :x 0 :y 0
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
:baseline 0
:mouse-overrides [{:mouse-in? (box-maker-fn 290 131 320 224)
:cursor-override 4}
{:mouse-in? (box-maker-fn 60 180 224 240)
:cursor-override 7}
{:mouse-in? (box-maker-fn 0 40 30 140)
:cursor-override 6}]
:scale-fn (scaler-fn-with-baseline 110 0.10 1.10))
:house (assoc house
:x 0 :y 0
@@ -128,6 +141,19 @@
:on-resize (fn [screen entities]
(size! screen 320 240))
:on-mouse-moved
(fn [screen [entities]]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(if-let [mouse-override (first (filter #((:mouse-in? %) x y) (get-in entities [:background :mouse-overrides])))]
(when (not (get-in entities [:cursor :override]))
(do (input! :set-cursor-image (cursor "cursor.png" (:cursor-override mouse-override)) 0 0)
(assoc-in entities [:cursor :override] true)))
(when (get-in entities [:cursor :override])
(do (input! :set-cursor-image (cursor "cursor.png" (get-in entities [:cursor :cursor-index])) 0 0)
(assoc-in entities [:cursor :override] false))))
))
:on-touch-down (fn [screen [entities]]
(if (= (button-code :right) (:button screen))