diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png
index b1f3bfa5..92337a73 100644
Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ
diff --git a/desktop/resources/inside-house/background.png b/desktop/resources/inside-house/background.png
index e19da54e..b92cc869 100644
Binary files a/desktop/resources/inside-house/background.png and b/desktop/resources/inside-house/background.png differ
diff --git a/desktop/resources/outside-castle/collision.png b/desktop/resources/outside-castle/collision.png
index 52b610dc..41878696 100644
Binary files a/desktop/resources/outside-castle/collision.png and b/desktop/resources/outside-castle/collision.png differ
diff --git a/desktop/resources/outsidehouse/collision.png b/desktop/resources/outsidehouse/collision.png
index c2c63c56..e1397b3e 100644
Binary files a/desktop/resources/outsidehouse/collision.png and b/desktop/resources/outsidehouse/collision.png differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.png b/desktop/resources/outsidehouse/sheep-walk.png
new file mode 100644
index 00000000..16f136b5
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.png differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/0.pxi b/desktop/resources/outsidehouse/sheep-walk.pxa/0.pxi
new file mode 100644
index 00000000..2499d6a4
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.pxa/0.pxi differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/1.pxi b/desktop/resources/outsidehouse/sheep-walk.pxa/1.pxi
new file mode 100644
index 00000000..66a3bad5
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.pxa/1.pxi differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/2.pxi b/desktop/resources/outsidehouse/sheep-walk.pxa/2.pxi
new file mode 100644
index 00000000..7ee184c1
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.pxa/2.pxi differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/3.pxi b/desktop/resources/outsidehouse/sheep-walk.pxa/3.pxi
new file mode 100644
index 00000000..c050aaf5
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.pxa/3.pxi differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/4.pxi b/desktop/resources/outsidehouse/sheep-walk.pxa/4.pxi
new file mode 100644
index 00000000..d3f24b84
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.pxa/4.pxi differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/5.pxi b/desktop/resources/outsidehouse/sheep-walk.pxa/5.pxi
new file mode 100644
index 00000000..80255ecb
Binary files /dev/null and b/desktop/resources/outsidehouse/sheep-walk.pxa/5.pxi differ
diff --git a/desktop/resources/outsidehouse/sheep-walk.pxa/CelData.plist b/desktop/resources/outsidehouse/sheep-walk.pxa/CelData.plist
new file mode 100644
index 00000000..596e40e1
--- /dev/null
+++ b/desktop/resources/outsidehouse/sheep-walk.pxa/CelData.plist
@@ -0,0 +1,30 @@
+
+
+
+
+
+ duration
+ 0.10000000149011612
+
+
+ duration
+ 0.10000000149011612
+
+
+ duration
+ 0.10000000149011612
+
+
+ duration
+ 0.10000000149011612
+
+
+ duration
+ 0.10000000149011612
+
+
+ duration
+ 0.10000000149011612
+
+
+
diff --git a/desktop/resources/wizard/stand.png b/desktop/resources/wizard/stand.png
new file mode 100644
index 00000000..ce64fc19
Binary files /dev/null and b/desktop/resources/wizard/stand.png differ
diff --git a/desktop/resources/wizard/talk.png b/desktop/resources/wizard/talk.png
new file mode 100644
index 00000000..f3c1169a
Binary files /dev/null and b/desktop/resources/wizard/talk.png differ
diff --git a/desktop/resources/wizard/talk.pxa/0.pxi b/desktop/resources/wizard/talk.pxa/0.pxi
new file mode 100644
index 00000000..44daed7f
Binary files /dev/null and b/desktop/resources/wizard/talk.pxa/0.pxi differ
diff --git a/desktop/resources/wizard/talk.pxa/1.pxi b/desktop/resources/wizard/talk.pxa/1.pxi
new file mode 100644
index 00000000..a47f307a
Binary files /dev/null and b/desktop/resources/wizard/talk.pxa/1.pxi differ
diff --git a/desktop/resources/wizard/talk.pxa/2.pxi b/desktop/resources/wizard/talk.pxa/2.pxi
new file mode 100644
index 00000000..ad4e4cbc
Binary files /dev/null and b/desktop/resources/wizard/talk.pxa/2.pxi differ
diff --git a/desktop/resources/wizard/talk.pxa/3.pxi b/desktop/resources/wizard/talk.pxa/3.pxi
new file mode 100644
index 00000000..1a6bdecd
Binary files /dev/null and b/desktop/resources/wizard/talk.pxa/3.pxi differ
diff --git a/desktop/resources/wizard/talk.pxa/CelData.plist b/desktop/resources/wizard/talk.pxa/CelData.plist
new file mode 100644
index 00000000..f6263f12
--- /dev/null
+++ b/desktop/resources/wizard/talk.pxa/CelData.plist
@@ -0,0 +1,22 @@
+
+
+
+
+
+ duration
+ 0.20000000298023224
+
+
+ duration
+ 0.20000000298023224
+
+
+ duration
+ 0.20000000298023224
+
+
+ duration
+ 0.20000000298023224
+
+
+
diff --git a/desktop/src-common/advent/action_test.clj b/desktop/src-common/advent/action_test.clj
deleted file mode 100644
index 0abf0427..00000000
--- a/desktop/src-common/advent/action_test.clj
+++ /dev/null
@@ -1,93 +0,0 @@
-(ns advent.action-test)
-
-(defprotocol IAction
- (begin [this state])
- (done? [this state])
- (continue [this state]))
-
-
-(defmacro do-actions [name & forms]
- `(vector ~@(for [form forms]
- `(fn [~name]
- ~form))))
-
-(defn walk-to [who & targets ]
- (for [[target-x target-y] targets]
- (fn [state]
- (reify
- IAction
- (begin [this state] (println "Starting Walking") state)
- (continue [this {:keys [x y] :as state}]
- (println "Continue Walking from" x y)
- (Thread/sleep 500)
- (assoc state :x (inc x) :y (inc y)))
- (done? [this {:keys [x y]} ]
- (and (= x target-x)
- (= y target-y)))))))
-
-(defn talk [who text]
- (reify
- IAction
- (begin [this state]
- (println "Speaking:" text)
- (assoc state :time 0))
- (continue [this state]
- (Thread/sleep 200)
- (assoc state :time (inc (:time state))))
- (done? [this {:keys [time]}]
- (< 3 time))))
-
-(defn give-item [item]
- (reify
- IAction
- (begin [this state]
- (println "Receiving item:" item)
- (update-in state [:items] #(conj % item)))
- (continue [this state]
- state)
- (done? [this state]
- true)))
-
-
-(defn walk-to [who & targets ]
- (for [[target-x target-y] targets]
- (fn [state]
- (reify
- IAction
- (begin [this state] (println "Starting Walking to" target-x target-y) state)
- (continue [this {:keys [x y] :as state}]
- (println "Continue Walking from" x y)
- (Thread/sleep 500)
- (assoc state :x (inc x) :y (inc y)))
- (done? [this {:keys [x y]} ]
- (and (>= x target-x)
- (>= y target-y)))))))
-
-(defn get-script []
- (let [random-loc (+ 3 (rand-int 10))]
- (do-actions state
- (if (= 1 (rand-int 2))
- (give-item :gold)
- (give-item :candy))
- (walk-to :ego [3 3] [random-loc random-loc] )
- (if ((:items state) :gold)
- (talk :ego "I have enough money to buy something")
- (talk :ego "I'm broke.")))))
-
-(defn test-run []
- (let [state {:x 0 :y 0 :time 0 :items #{}}
- actions (get-script)]
- (loop [actions actions
- state state
- started? false]
- (when (seq actions)
- (let [step ((first actions) state)]
- (if (sequential? step)
- (recur (concat step (rest actions)) state false)
- (let [state (if started?
- state
- (begin step state))
- state (continue step state)]
- (if (done? step state)
- (recur (rest actions) state false)
- (recur actions state true)))))))))
diff --git a/desktop/src-common/advent/action_test2.clj b/desktop/src-common/advent/action_test2.clj
deleted file mode 100644
index 4fc7514b..00000000
--- a/desktop/src-common/advent/action_test2.clj
+++ /dev/null
@@ -1,99 +0,0 @@
-(ns advent.action-test2
- (:require [clojure.core.async :refer [put! ! chan go thread take! alts!!]]))
-
-(defprotocol IAction
- (begin [this state])
- (done? [this state])
- (continue [this state])
- (terminate [this state]))
-
-
-
-(defn talk [action-channel who text]
- (let [c (chan)]
- (put! action-channel
- (reify
- IAction
- (begin [this state]
- (println "Speaking:" text)
- (assoc state :time 0))
- (continue [this state]
- (Thread/sleep 200)
- (assoc state :time (inc (:time state))))
- (done? [this {:keys [time]}]
- (< 3 time))
- (terminate [this state]
- (put! c state)
- state)))
- (= x target-x)
- (>= y target-y)))
- (terminate [this state]
- (put! c state)
- state))))
- (! >!! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
- [com.badlogic.gdx.graphics.g2d TextureRegion]))
+ [com.badlogic.gdx.graphics.g2d TextureRegion]
+ [com.badlogic.gdx Screen]))
(defprotocol IAction
(begin [this screen entities])
(done? [this screen entities])
(continue [this screen entities])
(terminate [this screen entities])
+ (can-skip? [this screen entities])
(get-channel [this]))
+
(defmacro get-script [entities & forms]
`(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
@@ -26,7 +30,7 @@
(defn jump-to [screen entities entity [x y]]
- (let [scale-fn (-> entities :background :scale-fn)
+ (let [scale-fn (-> entities :room :scale-fn)
entity (assoc entity :x x
:y y
:baseline (- 240 y))]
@@ -46,7 +50,7 @@
entity)))
(defn stop [screen entities target-id]
- (update-in entities [:background :entities target-id] #(start-animation screen % :stand)))
+ (update-in entities [:room :entities target-id] #(start-animation screen % :stand)))
(defn dist [x1 y1 x2 y2]
@@ -63,12 +67,54 @@
~@forms))
(reset! ~entities ( entities
+ (assoc-in [:room :entities target-id :x] final-x)
+ (assoc-in [:room :entities target-id :y] final-y))
+ (update-in entities [:room :entities target-id]
+ #(start-animation screen
+ (assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
+ :facing (cond (< delta-x 0) :left
+ (> delta-x 0) :right
+ :else (:facing %)))
+ :walk
+ ))))))
+
+ (done? [this screen entities]
+ (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])]
+ (< (dist final-x final-y from-x from-y) 1)))
+
+ (terminate [this screen entities]
+ (stop screen entities target-id))
+ (can-skip? [this screen entities]
+ false))))
+
+(defn walk-to [entities target-id [final-x final-y] & [can-skip?]]
+ (let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
final-x (int final-x)
final-y (int final-y)
path (vec (take-nth 5 (advent.pathfind/visit-all
- (:collision (:background @entities))
+ (:collision (:room @entities))
[(int start-x) (int start-y)]
[final-x final-y])))
path (if (seq path)
@@ -81,7 +127,7 @@
entities)
(continue [this screen entities]
- (let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:background :entities target-id])
+ (let [{from-x :x from-y :y :keys [left right scale-x] :as target-entity} (get-in entities [:room :entities target-id])
[[target-x target-y] remainder] @targets-left]
(let [delta-x (- target-x from-x)
delta-y (- target-y from-y)
@@ -96,9 +142,9 @@
(if (< distance speed)
(do (swap! targets-left rest)
(-> entities
- (assoc-in [:background :entities target-id :x] target-x)
- (assoc-in [:background :entities target-id :y] target-y)))
- (update-in entities [:background :entities target-id]
+ (assoc-in [:room :entities target-id :x] target-x)
+ (assoc-in [:room :entities target-id :y] target-y)))
+ (update-in entities [:room :entities target-id]
#(start-animation screen
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
:facing (cond (< delta-x 0) :left
@@ -108,11 +154,13 @@
))))))
(done? [this screen entities]
- (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:background :entities target-id])]
+ (let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:room :entities target-id])]
(< (dist final-x final-y from-x from-y) 1)))
(terminate [this screen entities]
- (stop screen entities target-id)))
+ (stop screen entities target-id))
+ (can-skip? [this screen entities]
+ (or can-skip? false)))
@entities)))
(defn get-text-duration [text]
@@ -124,15 +172,15 @@
(run-action entities
(begin [this screen entities]
(let [_ (swap! initial-time #(or % (:total-time screen)))
- target-y (get-in entities [:background :entities target-id :y])
- scale-fn (get-in entities [:background :scale-fn])
+ target-y (get-in entities [:room :entities target-id :y])
+ scale-fn (get-in entities [:room :scale-fn])
scale (scale-fn target-y)
height (* scale 36)]
(run! dialogue/talking-screen :on-talk :text text
- :x (get-in entities [:background :entities target-id :x]) :y (+ (get-in entities [:background :entities target-id :y]) height)
+ :x (get-in entities [:room :entities target-id :x]) :y (+ (get-in entities [:room :entities target-id :y]) height)
:target-id target-id
:scale scale)
- (update-in entities [:background :entities target-id ] #(start-animation screen % :talk))))
+ (update-in entities [:room :entities target-id ] #(start-animation screen % :talk))))
(continue [this screen entities] entities)
@@ -145,15 +193,76 @@
(run! dialogue/talking-screen :stop-talk :target-id target-id)
(if stop?
(stop screen entities target-id)
- entities)))))
+ entities))
+ (can-skip? [this screen entities]
+ true))))
-(defn give [entities target-id item]
+(defn something-else [zipper]
+ (-> zipper zip/up zip/up))
+
+(defn previous-choices [zipper]
+ (-> zipper zip/up))
+
+(defn nth-child [zipper i]
+ (loop [so-far 0
+ zipper (zip/down zipper)]
+ (if (= so-far i)
+ zipper
+ (recur (inc so-far) (zip/right zipper)))))
+
+(defn make-zipper [tree]
+ (zip/zipper map? (comp #(map second %) #(partition 2 %) :choices) (fn [n c] nil) tree))
+
+(defn present-choices [entities choices]
+ (loop [zipper (make-zipper choices)]
+ (let [selected-index (atom nil)
+ node (zip/node zipper)
+ dialogue-choices (partition 2 (:choices node))]
+ (run-action entities
+ (begin [this screen entities]
+ (run! dialogue/choice-screen :on-present-choices :choices dialogue-choices :callback #(reset! selected-index %))
+ (run! @(resolve 'advent.screens.scene/scene) :on-deactivate)
+ entities)
+
+ (continue [this screen entities] entities)
+
+ (done? [this screen entities] (not (nil? @selected-index)))
+
+ (terminate [this screen entities]
+ (run! @(resolve 'advent.screens.scene/scene) :on-reactivate)
+ entities)
+ (can-skip? [this screen entities]
+ false))
+
+ (let [zipper (nth-child zipper @selected-index)
+ node (zip/node zipper)]
+ (when-let [run (:run node)]
+ (run (-> dialogue-choices
+ (nth @selected-index)
+ first)))
+ (when-let [next-choices (:choices node)]
+ (if (fn? next-choices)
+ (recur (next-choices zipper))
+ (recur zipper)))))))
+
+(defn update-state [entities f]
+ (run-action entities
+ (begin [this screen entities]
+ (update-in entities [:state] f ))
+ (continue [this screen entities] entities)
+ (done? [this screen entities] true)
+ (terminate [this screen entities]
+ entities)
+ (can-skip? [this screen entities]
+ false)))
+
+(defn give [entities item]
(run-action entities
(begin [this screen entities]
(sound! (sound "pickup.mp3") :play)
(-> entities
- (update-in [:background :entities target-id :inventory] #(conj % item))
+ (update-in [:state :inventory] #(conj % item))
(assoc-in [:cursor :current] item)))
(continue [this screen entities] entities)
@@ -161,7 +270,9 @@
(done? [this screen entities] true)
(terminate [this screen entities]
- entities)))
+ entities)
+ (can-skip? [this screen entities]
+ false)))
(defn transition-background [entities new-background [x y]]
(run-action entities
@@ -182,15 +293,17 @@
(>= (get-in entities [:transition :opacity]) 1.0))
(terminate [this screen entities]
- entities))
+ entities)
+ (can-skip? [this screen entities]
+ false))
(run-action entities
(begin [this screen entities]
- (let [ego (get-in entities [:background :entities :ego])
+ (let [ego (get-in entities [:room :entities :ego])
entities (-> entities
- (assoc-in [:background] (get-in entities [:backgrounds new-background]))
- (assoc-in [:background :entities :ego] ego))]
+ (assoc-in [:room] (get-in entities [:rooms new-background]))
+ (assoc-in [:room :entities :ego] ego))]
(-> entities
- (update-in [:background :entities :ego] #(jump-to screen entities % [x y])))))
+ (update-in [:room :entities :ego] #(jump-to screen entities % [x y])))))
(continue [this screen entities]
(update-in entities [:transition :opacity] - 0.075))
@@ -199,4 +312,19 @@
(<= (get-in entities [:transition :opacity]) 0.0))
(terminate [this screen entities]
- (dissoc entities :transition))))
+ (dissoc entities :transition))
+
+ (can-skip? [this screen entities]
+ false)))
+
+(defn do-dialogue [entities & pairs]
+ (loop [pairs (partition 2 pairs)]
+ (let [[[target line]] pairs
+ next-speaker-is-different (not= target (ffirst (next pairs)))
+ result (talk entities target line :stop? next-speaker-is-different)]
+ (if (seq (rest pairs))
+ (recur (rest pairs))
+ result))))
+
+(defn respond [entities line & more]
+ (apply do-dialogue entities :ego line more))
diff --git a/desktop/src-common/advent/core.clj b/desktop/src-common/advent/core.clj
index 7bf4d4f2..21acaf89 100644
--- a/desktop/src-common/advent/core.clj
+++ b/desktop/src-common/advent/core.clj
@@ -16,4 +16,4 @@
(defgame advent
:on-create
(fn [this]
- (set-screen! this scene/scene dialogue/talking-screen inventory/inventory-screen)))
+ (set-screen! this scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen)))
diff --git a/desktop/src-common/advent/screens/dialogue.clj b/desktop/src-common/advent/screens/dialogue.clj
index dcdd69ef..b0bfe9ad 100644
--- a/desktop/src-common/advent/screens/dialogue.clj
+++ b/desktop/src-common/advent/screens/dialogue.clj
@@ -4,10 +4,13 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
- [advent.pathfind])
+ [advent.pathfind]
+ [clojure.core.async :refer [put! ! >!! chan go thread take! alts!!]]
+ #_[advent.screens.scene :as scene])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
- [com.badlogic.gdx.scenes.scene2d.utils Align]))
+ [com.badlogic.gdx.scenes.scene2d.utils Align]
+ [com.badlogic.gdx Screen]))
(defn ensure-on-screen [talk]
(let [margin-width (* 0.05 (game :width))
@@ -33,7 +36,7 @@
(fn [{:keys [create-talk target-id text x y scale]} [entities]]
(let [font (bitmap-font "ego/font.fnt" )
tr (bitmap-font! font :get-region)
- scale (or (max scale 0.75) 1)
+ scale (or (min (max scale 0.75) 1) 1)
width (/ (game :width) 1.5)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
@@ -52,3 +55,45 @@
:on-resize (fn [screen entities]
(size! screen 1280 960)))
+
+(defscreen choice-screen
+ :on-show
+ (fn [screen entities]
+ (update! screen :renderer (stage) :camera (orthographic))
+ {})
+
+ :on-render
+ (fn [screen [entities]]
+ (render! screen (vals entities))
+ entities)
+
+ :on-present-choices
+ (fn [{:keys [choices callback]} [entities]]
+ (let [font (bitmap-font "ego/font.fnt" )
+ tr (bitmap-font! font :get-region)
+ scale 1
+ tx (.getTexture tr)
+ _ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)]
+ (-> entities
+ (into (for [[[text] i] (map vector choices (range))]
+ [i (assoc (label text (style :label font (color :white))) :x 30 :y (* 30 i))]))
+ (assoc :state {:object nil :callback callback :choices choices}))))
+
+ :on-touch-down (fn [screen [entities]]
+ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
+ (when (seq entities)
+ (when (< y (* 30 (dec (count entities))))
+ ((get-in entities [:state :callback]) (int (/ y 30)))
+ {}))))
+
+ :on-mouse-moved (fn [screen [entities]]
+ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
+ font (bitmap-font "ego/font.fnt" )]
+ (when (seq entities)
+ (doseq [index (range (dec (count entities)))]
+ (if (< (* index 30) y (* (inc index) 30))
+ (label! (entities index) :set-style (style :label font (color :yellow)))
+ (label! (entities index) :set-style (style :label font (color :white))))))))
+
+ :on-resize (fn [screen entities]
+ (size! screen 1280 960)))
diff --git a/desktop/src-common/advent/screens/inventory.clj b/desktop/src-common/advent/screens/inventory.clj
index f1b14a4c..bc04b0fc 100644
--- a/desktop/src-common/advent/screens/inventory.clj
+++ b/desktop/src-common/advent/screens/inventory.clj
@@ -4,7 +4,9 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
- [advent.pathfind])
+ [advent.pathfind]
+ [advent.zone :as zone]
+ [advent.utils :as utils])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.scenes.scene2d.utils Align]
@@ -12,17 +14,24 @@
InputMultiplexer InputProcessor Net Preferences Screen]))
+
(defscreen inventory-screen
:on-show
(fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic))
- {:overlay (assoc (texture "inventory-overlay.png" ) :x 0 :y 0)
- :fade (assoc (texture "black.png")
- :scale-x 20
- :scale-y 20
- :opacity 0.7)
- :shown? false
- :start-showing? false})
+ (let [highlighted-text (assoc (label "Hello" (style :label (utils/get-font "ego/font.fnt") (color :white))) :x 0 :y 850 :width 1280)]
+ (label! highlighted-text :set-alignment Align/center)
+ {:overlay (assoc (texture "inventory-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
+ :fade (assoc (texture "black.png")
+ :scale-x 80
+ :scale-y 80
+ :opacity 0.7)
+ :all-items (texture! (texture "cursor.png") :split 16 16)
+ :items []
+ :shown? false
+ :start-showing? false
+ :highlighted-item nil
+ :highlighted-text highlighted-text}))
:on-render
(fn [screen [entities]]
@@ -33,18 +42,48 @@
entities)]
(when (:shown? entities)
- (render! screen [(:fade entities) (:overlay entities)]))
+ (render! screen [(:fade entities) (:overlay entities)])
+ (render! screen (:items entities))
+ (if-let [item (:highlighted-item entities)]
+ (label! (:highlighted-text entities) :set-text (name item))
+ (label! (:highlighted-text entities) :set-text ""))
+ (render! screen [(:highlighted-text entities)]))
entities))
- :show-screen (fn [screen [entities]]
- (assoc entities :start-showing? true))
+ :show-screen (fn [{items :items} [entities]]
+ (assoc entities :start-showing? true
+ :items (for [[item index] (map vector items (range))
+ :let [x (+ (* 79 4) (* index (* 24 4)))
+ y (* 4 180)
+ item-width 16
+ offset-x (+ x (/ item-width 2))
+ offset-y (+ y (/ item-width 2))
+ padding (/ item-width 2)
+ padding (* 4 padding)]]
+ (assoc (texture (aget (:all-items entities) 0 (.indexOf utils/+all-cursors+ item)))
+ :x x :y y
+ :scale-x 4
+ :scale-y 4
+ :item item
+ :box (zone/box (- offset-x padding) (- offset-y padding) (+ offset-x item-width padding) (+ offset-y item-width padding))))))
+
+ :on-mouse-moved (fn [screen [entities]]
+ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
+ selected-entity (first (filter #((:box %) x y) (:items entities)))]
+ (if selected-entity
+ (assoc entities :highlighted-item (:item selected-entity))
+ (assoc entities :highlighted-item nil))))
:on-touch-down (fn [screen [entities]]
(when (:shown? entities)
+ (run! @(resolve 'advent.screens.scene/scene) :on-reactivate)
+ (let [{:keys [highlighted-item]} entities]
+ (when highlighted-item
+ (run! @(resolve 'advent.screens.scene/scene) :on-chose-item :item highlighted-item)))
(-> entities
(assoc :shown? false)
(assoc :start-showing? false))))
:on-resize (fn [screen entities]
- (size! screen 320 240)
+ (height! screen 960)
entities))
diff --git a/desktop/src-common/advent/screens/rooms.clj b/desktop/src-common/advent/screens/rooms.clj
new file mode 100644
index 00000000..4ebc4c0f
--- /dev/null
+++ b/desktop/src-common/advent/screens/rooms.clj
@@ -0,0 +1,28 @@
+(ns advent.screens.rooms
+ (:require [advent.zone :as zone]))
+
+(defn make [& {:keys [collision interactions entities] :as params}]
+ (let [interactions-as-list (for [[id spec] interactions]
+ (merge spec {:mouse-in? (fn [_ x y]
+ ((apply zone/box (:box spec)) x y))
+ :get-script (fn [cursor [x y]]
+ (if (= :main cursor)
+ (:script spec)
+ (get-in spec [:scripts cursor])))}))
+ entities (into {} (for [[id entity] entities]
+ [id (merge entity
+ {:mouse-in? (fn [entities x y]
+ (let [{entity-x :x entity-y :y region :object} (get-in entities [:room :entities id])
+ width (.getRegionWidth region)
+ height (.getRegionHeight region)]
+ ((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y)))}
+ (when (:script entity)
+ {:get-script (fn [cursor [x y]]
+ (if (= :main cursor)
+ (:script entity)
+ (get-in entity [:scripts cursor])))}))]))]
+ (merge params {:collision (advent.pathfind/map-from-resource collision)
+ :interactions interactions-as-list
+ :entities entities})))
+
+
diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj
new file mode 100644
index 00000000..586c61e3
--- /dev/null
+++ b/desktop/src-common/advent/screens/rooms/behind_house.clj
@@ -0,0 +1,47 @@
+(ns advent.screens.rooms.behind-house
+ (:require [advent.screens.rooms :as rooms]
+ [advent.actions :as actions]
+ [advent.utils :as utils]
+ [clojure.zip :as zip]
+ [play-clj.core :refer :all]
+ [play-clj.ui :refer :all]
+ [play-clj.utils :refer :all]
+ [play-clj.g2d :refer :all]))
+
+(defn make [screen]
+ (rooms/make :interactions
+ {:left-dir {:box [0 131 20 224]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [122 140])
+ (actions/transition-background entities :outside-house [244 150])
+ (actions/walk-to entities :ego [195 140]))
+ :cursor :left}
+ :crack {:box [68 100 73 114]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [70 80])
+ (actions/talk entities :ego "I can see Fangald, the wizard inside.")
+ (actions/talk entities :ego "It looks like he's opening his Magi-safe.")
+ (actions/talk entities :ego "[todo: sounds play.]")
+ (actions/talk entities :ego "A lot of good it'll do me to know his password while he's still there."))}
+ :mushrooms {:box [247 59 269 76]
+ :script (actions/get-script
+ entities
+ (if ((get-in @entities [:state :inventory]) :mushrooms)
+ (actions/talk entities :ego "I've already got a junk ton of mushrooms.")
+ (do
+ (actions/walk-to entities :ego [242 75])
+ (actions/give entities :mushrooms)
+ (actions/talk entities :ego "Perfectly ripe mushrooms!"))))}
+ :window {:box [103 44 130 140]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [128 100])
+ (actions/talk entities :ego "I can see Fangald moving around in there but it's hard to see at this angle."))}}
+ :layers [(assoc (texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)
+ (assoc (texture "behindhouse/house.png") :x 0 :y 0 :baseline 122)
+ (assoc (texture "behindhouse/brush.png") :x 0 :y 0 :baseline 240)]
+ :entities {}
+ :collision "behindhouse/collision.png"
+ :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00)))
diff --git a/desktop/src-common/advent/screens/rooms/cat_tree.clj b/desktop/src-common/advent/screens/rooms/cat_tree.clj
new file mode 100644
index 00000000..f07be0ea
--- /dev/null
+++ b/desktop/src-common/advent/screens/rooms/cat_tree.clj
@@ -0,0 +1,24 @@
+(ns advent.screens.rooms.cat-tree
+ (:require [advent.screens.rooms :as rooms]
+ [advent.actions :as actions]
+ [advent.utils :as utils]
+ [clojure.zip :as zip]
+ [play-clj.core :refer :all]
+ [play-clj.ui :refer :all]
+ [play-clj.utils :refer :all]
+ [play-clj.g2d :refer :all]))
+
+(defn make [screen]
+ (rooms/make :interactions
+ {:down-dir {:box [150 0 270 20]
+ :script (actions/get-script entities
+ (actions/walk-to entities :ego [203 1])
+ (actions/transition-background entities :outside-house [137 204])
+ (actions/walk-to entities :ego [195 140]))
+ :cursor :down}}
+ :layers [(assoc (texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
+ (assoc (texture "cat-tree/tree-and-rock.png") :x 0 :y 0 :baseline 161)
+ (assoc (texture "cat-tree/sillhoute.png") :x 0 :y 0 :baseline 240)]
+ :entities {}
+ :collision "cat-tree/collision.png"
+ :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.20)))
diff --git a/desktop/src-common/advent/screens/rooms/inside_house.clj b/desktop/src-common/advent/screens/rooms/inside_house.clj
new file mode 100644
index 00000000..7b198fc5
--- /dev/null
+++ b/desktop/src-common/advent/screens/rooms/inside_house.clj
@@ -0,0 +1,34 @@
+(ns advent.screens.rooms.inside-house
+ (:require [advent.screens.rooms :as rooms]
+ [advent.actions :as actions]
+ [advent.utils :as utils]
+ [clojure.zip :as zip]
+ [play-clj.core :refer :all]
+ [play-clj.ui :refer :all]
+ [play-clj.utils :refer :all]
+ [play-clj.g2d :refer :all]))
+
+(defn make [screen]
+ (let [wizard-sheet (texture! (texture "wizard/talk.png") :split 20 46)
+ wizard-stand (animation 0.2 (for [i (flatten [(repeat 10 0) 1])]
+ (aget wizard-sheet 0 i)))
+ wizard-talk (animation 0.2 (for [i [0 2 0 2 1 2 0 3 0 2 0 1 0 2]]
+ (aget wizard-sheet 0 i)))]
+ (rooms/make :interactions {:down-dir {:box [151 0 320 20]
+ :script (actions/get-script entities
+ (actions/walk-to entities :ego [237 1])
+ (actions/transition-background entities :outside-house [262 88]))
+ :cursor :down}
+ :wizard {:box [228 80 248 126]}}
+ :layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0)
+ (assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200)
+ (assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)]
+ :entities {:wizard (actions/start-animation screen (assoc (animation->texture screen wizard-stand) :x 228 :y 80 :baseline 160 :scale-x 1.75 :scale-y 1.75
+ :left {:talk (utils/flip wizard-talk)
+ :stand (utils/flip wizard-stand)}
+ :right {:talk wizard-talk
+ :stand wizard-stand}
+ :facing :left)
+ :stand)}
+ :collision "inside-house/collision.png"
+ :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.75))))
diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj
new file mode 100644
index 00000000..501fc791
--- /dev/null
+++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj
@@ -0,0 +1,58 @@
+(ns advent.screens.rooms.outside-castle
+ (:require [advent.screens.rooms :as rooms]
+ [advent.actions :as actions]
+ [advent.utils :as utils]
+ [clojure.zip :as zip]
+ [play-clj.core :refer :all]
+ [play-clj.ui :refer :all]
+ [play-clj.utils :refer :all]
+ [play-clj.g2d :refer :all]))
+
+(defn make [screen]
+ (let [peddler-sheet (texture! (texture "outside-castle/peddler-talk.png" ) :split 18 36)
+ peddler-talk (animation 0.18 (for [i (flatten [2 3 2 3 2 3 6 1 0 1 0 1 0 1 0 1 2 3 2 3 2 3 6 4 5 4 5 4 5 4 5])]
+ (aget peddler-sheet 0 i)))
+ peddler-stand (animation 0.2 (for [i (flatten [(repeat 5 0) 6])]
+ (aget peddler-sheet 0 i)))]
+ (rooms/make :interactions
+ {:right-dir {:box [300 40 320 140]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [310 80])
+ (actions/transition-background entities :outside-house [0 80]))
+ :cursor :right}
+ :garden {:box [103 170 178 200]
+ :script (actions/get-script
+ entities
+ (if ((get-in @entities [:state :inventory]) :carrot)
+ (actions/talk entities :ego "If I steal any more, I might get caught.")
+ (do
+ (actions/walk-to entities :ego [128 180])
+ (actions/talk entities :ego "Hey! Carrots. No one will notice one missing.")
+ (actions/give entities :carrot))))}
+ :peddler {:box [110 90 128 146]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [191 90])
+ (actions/do-dialogue entities
+ :ego "Hello there, peddler."
+ :peddler "Good day sir! Care to see any of my wares?"
+ :peddler "I have only the choicest of wares."
+ :ego "What 'wares' are you selling?"
+ :peddler "I have the choicest of all types of wares..."
+ :peddler "...I'm well stocked on used earplugs..."
+ :peddler "...glass eyes, motivational tapes... "
+ :peddler "...and useful books like this:"
+ :peddler "'Checkers Mastery in Less Than 10 Seconds'"
+ :ego "I sure am interested on that book on checkers."
+ :peddler "An excellent selection! It is the choicest of checkers book you'll ever find."
+ :peddler "This book will only set you back 75 sheckels."
+ :ego "But I haven't got any money!"
+ :peddler "Then you won't have the choicest of checkers books."))}}
+ :layers [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)]
+ :entities {:peddler (actions/start-animation screen
+ (assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil
+ :talk peddler-talk :stand peddler-stand)
+ :stand)}
+ :collision "outside-castle/collision.png"
+ :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00))))
diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj
new file mode 100644
index 00000000..fc3dc26d
--- /dev/null
+++ b/desktop/src-common/advent/screens/rooms/outside_house.clj
@@ -0,0 +1,170 @@
+(ns advent.screens.rooms.outside-house
+ (:require [advent.screens.rooms :as rooms]
+ [advent.actions :as actions]
+ [advent.utils :as utils]
+ [clojure.zip :as zip]
+ [play-clj.core :refer :all]
+ [play-clj.ui :refer :all]
+ [play-clj.utils :refer :all]
+ [play-clj.g2d :refer :all]))
+
+(defn wizard-dialogue [entities]
+ (actions/do-dialogue entities :ego "Hello there Mr. Fangald!" :wizard "Oh no, not you again!")
+ (actions/present-choices entities
+ {:choices ["What do you mean, \"Not you again?\""
+ {:run #(actions/respond entities % :wizard "I mean, you've wrecked my life and I never want to see you again.")
+ :choices ["You mean the time I set your house on fire with a fire mint?"
+ {:run #(do
+ (actions/respond entities %
+ :wizard "That was you!?"
+ :wizard "My house was nearly destroyed!"
+ :wizard "I spent weeks rebuilding my home!"
+ :wizard "Leave, now, or I'll turn you into a ..."
+ :wizard "... a ..."
+ :wizard "... a frog!"
+ :ego "Okay, okay! I'm leaving.")
+ (actions/transition-background entities :outside-house [262 88])
+ (actions/talk entities :ego "I guess he's really upset with me."))}
+ "You're still cross about my stealing your magic cowboy hat?"
+ {:run #(do (actions/respond entities %
+ :wizard "Of course I'm cross! It's irreplaceable!"
+ :wizard "That cowboy hat accented my facial physique."
+ :wizard "And complemented my skin color."
+ :wizard "And you little cheat stole it from me!"
+ :wizard "That's why I bought my MagiSafe 5000, to keep out intruders like you."
+ :wizard "Now leave.")
+ (actions/transition-background entities :outside-house [262 88]))}
+ "Even an old hoot like you needs a kick in the pants every now and again."
+ {:run #(actions/respond entities % :wizard "What gives you the right to try to teach me a lesson?")
+ :choices ["My good looks?"
+ {:run #(do (actions/respond entities %
+ :wizard "You know, handsome looks aren't all they're chocked up to be."
+ :wizard "Take me for example."
+ :wizard "When you have a bod like man, you can hardly go to the grocery store without being noticed."
+ :wizard "But no. Your looks, however good they may be, don't give you the right to teach me a lesson."
+ :wizard "Now please leave me in peace.")
+ (actions/transition-background entities :outside-house [262 88]))}
+ "My good standing within the community?"
+ {:run #(do (actions/respond entities %
+ :wizard "Ha! Good standing?"
+ :wizard "You're the neighborhood cheat and everyone knows it."
+ :wizard "Now please leave me in peace.")
+ (actions/transition-background entities :outside-house [262 88]))}
+ "I'm going to be a knight! That counts for something doesn't it?"
+ {:run #(do (actions/respond entities %
+ :wizard "You are, are you?"
+ :wizard "Pray tell, how do you, a mere wreckless youth, plan on becoming a knight?"))
+ :choices ["By pulling the Sword of Blergh from its stone!"
+ {:run #(actions/respond entities %
+ :wizard "Well, well. It sounds I was wrong about you."
+ :wizard "Indeed, you are on the path of setting your destructive past behind you."
+ :wizard "But know this, the stone cannot be cheated easily."
+ :wizard "You must fulfill the age-old prophecy."
+ :wizard "'The Sword of Blergh with magic sting,' ..."
+ :wizard "... 'Shall yield to no earthly king.'"
+ :wizard "'To draw from hardened, weathered stone,' ..."
+ :wizard "... 'One must have valor, right to the bone.'"
+ :wizard "'Worthy in courage, wisdom and might,' ..."
+ :wizard "... 'only then with sword he'll fight.'"
+ :wizard "'But a hero should he prove not be,' ..."
+ :wizard "... 'Only ruin will fall on he.'"
+ :wizard "'Should he use guile or guise'..."
+ )
+ :choices ["Is this almost over?"
+ {:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
+ (actions/respond entities %
+ :wizard "Patience, boy."
+ :wizard "... 'Such a man will have great surprise.'"
+ :wizard "If this is truely your quest, boy, then I will help you in your quest. "
+ :wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
+ :ego "No cheating."
+ :ego "Check."))}
+ "*cough* *cough* *ahem*"
+ {:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
+ (actions/respond entities %
+ :wizard "Excuse you. Moving on..."
+ :wizard "... 'Such a man will have great surprise.'"
+ :wizard "If this is truely your quest, boy, then I will help you in your quest. "
+ :wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
+ :ego "No cheating."
+ :ego "Check."))}]}
+ "By besting swamp, foe, and the occasional bizarre conversation tree."
+ {:run #(do (actions/respond entities %
+ :wizard "While your goal sounds noble, no amount of bizarre conversation tree searching will earn my respect."
+ :wizard "Now please leave.")
+ (actions/transition-background entities :outside-house [262 88]))}]}]}]}
+ "You're not happy to see me, Mr. Fangald?"
+ {:run #(actions/respond entities % :wizard "Of course not, you little brat. You've made my life a living hell!")
+ :choices #(-> % zip/left)}
+ "Good bye, Mr. Fangald!"
+ {:run #(do
+ (actions/respond entities % :wizard "Now scram!")
+ (actions/transition-background entities :outside-house [262 88]))}]}))
+(defn make [screen]
+ (let [sheep-stand-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
+ sheep-walk-sheet (texture! (texture "outsidehouse/sheep-walk.png") :split 33 21)
+ sheep-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
+ (aget sheep-stand-sheet 0 i)))
+ sheep-walk (animation 0.15 (for [i (range 6)]
+ (aget sheep-walk-sheet 0 i)))]
+ (rooms/make :interactions
+ {:door {:box [258 100 281 160]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [262 88])
+ (actions/talk entities :ego (str "Anyone home?"))
+ (actions/transition-background entities :inside-house [237 0])
+ (if (get-in @entities [:state :convinced-wizard?])
+ (actions/talk entities :wizard (str "Oh, hello there boy."))
+ (wizard-dialogue entities)))}
+ :sword {:box [274 55 305 88]
+ :script (actions/get-script
+ entities
+ (actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
+ (actions/walk-to entities :ego [290 66])
+ (actions/talk entities :ego "Maybe I can pull it out."))}
+ :right-dir {:box [300 131 320 224]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [244 150])
+ (actions/transition-background entities :behind-house [122 140])
+ (actions/walk-to entities :ego [172 122]))
+ :cursor :right}
+ :up-dir {:box [60 180 224 240]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [137 204])
+ (actions/transition-background entities :cat-tree [203 1]))
+ :cursor :up}
+ :left-dir {:box [0 40 20 140]
+ :script (actions/get-script
+ entities
+ (actions/walk-to entities :ego [0 80])
+ (actions/transition-background entities :outside-castle [310 80]))
+ :cursor :left}}
+ :layers [(assoc (texture "bg5.png") :x 0 :y 0 :baseline 0)
+ (assoc (texture "house.png") :x 0 :y 0 :baseline 122)
+ (assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240)
+ (assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)]
+ :entities {:sheep (actions/start-animation screen
+ (assoc (animation->texture screen sheep-stand) :x 38 :y 160 :baseline 160
+ :box [38 160 71 181]
+ :script (actions/get-script
+ entities
+ (if ((get-in @entities [:state :inventory]) :wool)
+ (actions/talk entities :ego "The sheep has given me enough wool.")
+ (do (actions/give entities :wool)
+ (actions/talk entities :ego "I guess her wool is shedding."))))
+ :scripts {:wool (actions/get-script entities
+ (actions/talk entities :ego "She doesn't need it back."))
+ :carrot (actions/get-script entities
+ (actions/walk-to entities :ego [132 140])
+ (actions/talk entities :ego "Come on girl, get the carrot!")
+ (actions/walk-straight-to entities :sheep [95 150]))}
+ :left {:walk (utils/flip sheep-walk)
+ :stand (utils/flip sheep-stand)}
+ :right {:walk sheep-walk
+ :stand sheep-stand})
+ sheep-stand)}
+ :collision "outsidehouse/collision.png"
+ :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00))))
diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj
index 38cece3b..22da29e4 100644
--- a/desktop/src-common/advent/screens/scene.clj
+++ b/desktop/src-common/advent/screens/scene.clj
@@ -2,12 +2,20 @@
(:require [play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
+ [play-clj.entities :as entities]
[play-clj.g2d :refer :all]
+ [clojure.zip :as zip]
[clojure.pprint]
[advent.pathfind]
[advent.actions :as actions]
[advent.zone :as zone]
[advent.utils :as utils]
+ [advent.screens.rooms :as rooms]
+ [advent.screens.rooms.outside-house :as rooms.outside-house]
+ [advent.screens.rooms.inside-house :as rooms.inside-house]
+ [advent.screens.rooms.behind-house :as rooms.behind-house]
+ [advent.screens.rooms.outside-castle :as rooms.outside-castle]
+ [advent.screens.rooms.cat-tree :as rooms.cat-tree]
[advent.screens.dialogue :refer [talking-screen]]
[advent.screens.inventory :refer [inventory-screen]]
[clojure.core.async :refer [put! ! chan go thread take! alts!!]])
@@ -16,33 +24,22 @@
[java.lang Object]
[com.badlogic.gdx Gdx]))
-(def +screen-width+ 320)
-(def +screen-height+ 240)
-
-(defprotocol IMouseIn
- (mouse-in? [this location]))
-
-(defprotocol ICursorOverridable
- (cursor-override [this]))
-
-(defprotocol IInteractable
- (get-script [this location]))
-
(def default-interaction
- (reify
- IInteractable
- (get-script [_ [x y]]
- (actions/get-script entities
- (actions/walk-to entities :ego [x y])))))
+ {:get-script (fn [cursor [x y]] (if (= :main cursor)
+ (actions/get-script entities
+ (actions/walk-to entities :ego [x y] true))
+ (actions/get-script entities
+ (actions/talk entities :ego "I don't know what to do with that."))))})
(defn find-override [screen entities [x y]]
- (first (filter #(and (mouse-in? % [x y])
- (satisfies? ICursorOverridable %))
- (get-in entities [:background :interactions]))))
+ (first (filter #(and ((:mouse-in? %) entities x y)
+ (:cursor %))
+ (get-in entities [:room :interactions]))))
(defn open-inventory [screen entities]
- (run! inventory-screen :show-screen))
+ (run! inventory-screen :show-screen :items (get-in entities [:state :inventory]))
+ (assoc-in entities [:state :active?] false))
(defn left-click [screen entities]
@@ -50,28 +47,32 @@
(if ((:mouse-in? (:inventory entities)) x y)
(open-inventory screen entities)
- (let [interaction (first (filter #(mouse-in? % [x y])
- (get-in entities [:background :interactions])))
+ (let [interaction (first (filter #((:mouse-in? %) entities x y)
+ (get-in entities [:room :interactions])))
+ interacting-entity (first (filter #(and (:mouse-in? %)
+ (:get-script %)
+ ((:mouse-in? %) entities x y))
+ (vals (get-in entities [:room :entities]))))
+
+ current-action (get-in entities [:actions :current])
;; TODO - hacky way of resetting queue
- entities (if-let [current-action (get-in entities [:actions :current])]
- (assoc (actions/terminate current-action screen entities)
- :actions {:channel (chan) :current nil :started? false})
- entities)
- script (or (when interaction
- (get-script interaction [x y]))
- (get-script default-interaction [x y]))]
+ entities (if (and current-action (actions/can-skip? current-action screen entities))
+ (let [terminated-entities (actions/terminate current-action screen entities)]
+ (do (put! (actions/get-channel current-action) terminated-entities)
+ (-> terminated-entities
+ (assoc-in [:actions :current] nil)
+ (assoc-in [:actions :started?] false))))
+ (assoc-in entities [:actions :channel] (chan)))]
- (script entities)
+ (if current-action
+ entities
+ ((or (when interaction
+ ((:get-script interaction) (get-in entities [:cursor :current]) [x y]))
+ (when interacting-entity
+ ((:get-script interacting-entity) (get-in entities [:cursor :current]) [x y]))
+ ((:get-script default-interaction) (get-in entities [:cursor :current]) [x y])) entities))
entities))))
-(defn flip [anim]
- (animation (animation! anim :get-frame-duration)
- (for [src-frame (animation! anim :get-key-frames)
- :let [frame (texture (texture! src-frame :get-texture))]]
- (do
- (texture! frame :set-region src-frame)
- (texture! frame :flip true false)
- frame))))
(defn get-ego [screen]
(let [player-sheet (texture! (texture "player.png") :split 18 36)
@@ -86,17 +87,15 @@
ego {:right {:walk walk-right
:stand stand-anim
:talk talk-anim}
- :left {:walk (flip walk-right)
- :stand (flip stand-anim)
- :talk (flip talk-anim)}
-
-
+ :left {:walk (utils/flip walk-right)
+ :stand (utils/flip stand-anim)
+ :talk (utils/flip talk-anim)}
:baseline 95
:facing :right
:origin-x 9
:origin-y 0
:scaled true
- :inventory #{}
+
:x 150 :y 95
:id "ego"}]
(actions/start-animation screen
@@ -116,13 +115,6 @@
(let [[current _] (alts!! [channel] :default nil)]
(assoc entities :actions {:channel channel :current current :started? false}))))
-(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]]
- (let [maximum-size (or maximum-size 1.0)]
- (fn [y]
- (if (< y baseline) maximum-size
- (let [percent-complete (- 1.0 (/ (- y baseline) (- +screen-height+ baseline)))
- range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)]
- range)))))
(defn update-cursor [screen {{:keys [current override last]} :cursor :as entities}]
(when-not (= (or override current)
@@ -130,178 +122,7 @@
(input! :set-cursor-image (utils/cursor "cursor.png" (or override current)) 0 0))
(assoc-in entities [:cursor :last] (or override current)))
-(defn make-background [& {:keys [collision interactions] :as params}]
- (let [interactions-as-list (for [[id spec] interactions]
- (reify
- IMouseIn
- (mouse-in? [_ location]
- (apply (apply zone/box (:box spec)) location))
- IInteractable
- (get-script [_ location]
- (:script spec))
- ICursorOverridable
- (cursor-override [this] (:cursor spec)))
- )]
- (merge params {:collision (advent.pathfind/map-from-resource collision)
- :interactions interactions-as-list})))
-(defn backgrounds [screen]
- (let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
- sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
- (aget sheep-sheet 0 i)))
-
- peddler-sheet (texture! (texture "outside-castle/peddler-talk.png" ) :split 18 36)
- peddler-talk (animation 0.18 (for [i (flatten [2 3 2 3 2 3 6 1 0 1 0 1 0 1 0 1 2 3 2 3 2 3 6 4 5 4 5 4 5 4 5])]
- (aget peddler-sheet 0 i)))
- peddler-stand (animation 0.2 (for [i (flatten [(repeat 5 0) 6])]
- (aget peddler-sheet 0 i)))
- wizard (texture "wizard.png")
- _ (texture! wizard :flip true false)]
- {:inside-house
- (make-background :interactions {:down-dir {:box [151 0 320 20]
- :script (actions/get-script entities
- (actions/walk-to entities :ego [237 1])
- (actions/transition-background entities :outside-house [262 88]))
- :cursor :down}}
- :layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0)
- (assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200)
- (assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)]
- :entities {:wizard (assoc wizard :x 228 :y 80 :baseline 160 :scale-x 1.75 :scale-y 1.75)}
- :collision "inside-house/collision.png"
- :scale-fn (scaler-fn-with-baseline 110 0.10 1.75))
- :outside-house
- (make-background :interactions
- {:door {:box [258 100 281 160]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [262 88])
- (actions/talk entities :ego (str "Anyone home?"))
- (actions/transition-background entities :inside-house [237 0]))}
- :sword {:box [274 55 305 88]
- :script (actions/get-script
- entities
- (actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
- (actions/walk-to entities :ego [290 66])
- (actions/talk entities :ego "Maybe I can pull it out."))}
- :sheep {:box [38 160 71 181]
- :script (actions/get-script
- entities
- (if ((get-in @entities [:background :entities :ego :inventory]) :wool)
- (actions/talk entities :ego "The sheep has given me enough wool.")
- (do (actions/give entities :ego :wool)
- (actions/talk entities :ego "I guess his wool is shedding."))))}
- :right-dir {:box [300 131 320 224]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [244 150])
- (actions/transition-background entities :behind-house [122 140])
- (actions/walk-to entities :ego [172 122]))
- :cursor :right}
- :up-dir {:box [60 180 224 240]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [137 204])
- (actions/transition-background entities :cat-tree [203 1]))
- :cursor :up}
- :left-dir {:box [0 40 20 140]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [0 80])
- (actions/transition-background entities :outside-castle [310 80]))
- :cursor :left}}
- :layers [(assoc (texture "bg5.png") :x 0 :y 0 :baseline 0)
- (assoc (texture "house.png") :x 0 :y 0 :baseline 122)
- (assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240)
- (assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)]
- :entities {:sheep (actions/start-animation screen
- (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160)
- sheep)}
- :collision "outsidehouse/collision.png"
- :scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
- :behind-house
- (make-background :interactions
- {:left-dir {:box [0 131 20 224]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [122 140])
- (actions/transition-background entities :outside-house [244 150])
- (actions/walk-to entities :ego [195 140]))
- :cursor :left}
- :crack {:box [68 100 73 114]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [70 80])
- (actions/talk entities :ego "I can see Fangald, the wizard inside.")
- (actions/talk entities :ego "It looks like he's opening his Magi-safe.")
- (actions/talk entities :ego "[todo: sounds play.]")
- (actions/talk entities :ego "A lot of good it'll do me to know his password while he's still there."))}
- :mushrooms {:box [247 59 269 76]
- :script (actions/get-script
- entities
- (if ((get-in @entities [:background :entities :ego :inventory]) :mushrooms)
- (actions/talk entities :ego "I've already got a junk ton of mushrooms.")
- (do
- (actions/walk-to entities :ego [242 75])
- (actions/give entities :ego :mushrooms)
- (actions/talk entities :ego "Perfectly ripe mushrooms!"))))}
- :window {:box [103 44 130 140]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [128 100])
- (actions/talk entities :ego "I can see Fangald moving around in there but it's hard to see at this angle."))}}
- :layers [(assoc (texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)
- (assoc (texture "behindhouse/house.png") :x 0 :y 0 :baseline 122)
- (assoc (texture "behindhouse/brush.png") :x 0 :y 0 :baseline 240)]
- :entities {}
- :collision "behindhouse/collision.png"
- :scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
- :cat-tree
- (make-background :interactions
- {:down-dir {:box [150 0 270 20]
- :script (actions/get-script entities
- (actions/walk-to entities :ego [203 1])
- (actions/transition-background entities :outside-house [137 204])
- (actions/walk-to entities :ego [195 140]))
- :cursor :down}}
- :layers [(assoc (texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
- (assoc (texture "cat-tree/tree-and-rock.png") :x 0 :y 0 :baseline 161)
- (assoc (texture "cat-tree/sillhoute.png") :x 0 :y 0 :baseline 240)]
- :entities {}
- :collision "cat-tree/collision.png"
- :scale-fn (scaler-fn-with-baseline 110 0.10 1.20))
- :outside-castle
- (make-background :interactions
- {:right-dir {:box [300 40 320 140]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [310 80])
- (actions/transition-background entities :outside-house [0 80]))
- :cursor :right}
- :peddler {:box [110 90 128 146]
- :script (actions/get-script
- entities
- (actions/walk-to entities :ego [191 90])
- (actions/talk entities :ego "Hello there, peddler.")
- (actions/talk entities :peddler "Good day sir! Care to see any of my wares?" :stop? false)
- (actions/talk entities :peddler "I have only the choicest of wares.")
- (actions/talk entities :ego "What 'wares' are you selling?")
- (actions/talk entities :peddler "I have the choicest of all types of wares..." :stop? false)
- (actions/talk entities :peddler "...I'm well stocked on used earplugs..." :stop? false)
- (actions/talk entities :peddler "...glass eyes, motivational tapes... " :stop? false)
- (actions/talk entities :peddler "...and useful books like this:" :stop? false)
- (actions/talk entities :peddler "'Checkers Mastery in Less Than 10 Seconds'")
- (actions/talk entities :ego "I sure am interested on that book on checkers.")
- (actions/talk entities :peddler "An excellent selection! It is the choicest of checkers book you'll ever find." :stop? false)
- (actions/talk entities :peddler "This book will only set you back 75 sheckels.")
- (actions/talk entities :ego "But I haven't got any money!")
- (actions/talk entities :peddler "Then you won't have the choicest of checkers books."))}}
- :layers [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)]
- :entities {:peddler (actions/start-animation screen
- (assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil
- :talk peddler-talk :stand peddler-stand)
- :stand)}
- :collision "outside-castle/collision.png"
- :scale-fn (scaler-fn-with-baseline 110 0.10 1.00))}))
(defn animate [entity screen]
(merge entity (animation->texture (update-in screen [:total-time] #(- % (:anim-start entity)))
@@ -311,10 +132,17 @@
(fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
- music (sound "town-music.mp3")
+ music (sound "town-music.mp3")
_ (sound! music :loop 0.20)
- backgrounds (backgrounds screen)]
- {:backgrounds backgrounds
+ rooms {:inside-house (rooms.inside-house/make screen)
+ :outside-house (rooms.outside-house/make screen)
+ :behind-house (rooms.behind-house/make screen)
+ :cat-tree (rooms.cat-tree/make screen)
+ :outside-castle (rooms.outside-castle/make screen)}]
+ {:rooms rooms
+ :state {:object nil
+ :active? true
+ :inventory (sorted-set)}
:actions {:object nil
:channel (chan)
:current nil
@@ -323,26 +151,24 @@
:current :main
:last :main
:override nil}
- :background (assoc-in (:outside-house backgrounds)
+ :room (assoc-in (:outside-house rooms)
[:entities :ego] (get-ego screen))
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
:mouse-in? (zone/box 278 0 320 42))
- :fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)}))
+ :fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}))
:on-render
(fn [screen [entities]]
(clear!)
- (.glEnable (.getGL20 Gdx/graphics) GL20/GL_BLEND)
- #_(.glEnable (.getGL30 Gdx/graphics) GL30/GL_BLEND)
(let [entities (update-cursor screen entities)
entities (update-from-script screen entities)
- entities (update-in entities [:background :entities] (fn [entities]
+ entities (update-in entities [:room :entities] (fn [entities]
(into entities
(for [[id entity] entities]
(if (:anim entity)
[id (animate entity screen)]
[id entity])))))
- all-entities (concat (vals entities) (get-in entities [:background :layers]) (vals (get-in entities [:background :entities])))]
+ all-entities (concat (vals entities) (get-in entities [:room :layers]) (vals (get-in entities [:room :entities])))]
(label! (:fps entities) :set-text (str (game :fps)))
(render! screen (sort-by :baseline all-entities))
entities))
@@ -352,13 +178,28 @@
: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 (find-override screen entities [x y])]
- (assoc-in entities [:cursor :override] (cursor-override mouse-override))
- (assoc-in entities [:cursor :override] nil))))
+ (when (get-in entities [:state :active?])
+ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
+ (if-let [mouse-override (find-override screen entities [x y])]
+ (assoc-in entities [:cursor :override] (:cursor mouse-override))
+ (assoc-in entities [:cursor :override] nil)))))
:on-touch-down (fn [screen [entities]]
- (if (= (button-code :right)
- (:button screen))
- (assoc-in entities [:cursor :current] :main)
- (left-click screen entities))))
+ (when (get-in entities [:state :active?])
+ (if (= (button-code :right)
+ (:button screen))
+ (assoc-in entities [:cursor :current] :main)
+ (left-click screen entities))))
+
+ :on-deactivate (fn [screen [entities]]
+ (assoc-in entities [:state :active?] false))
+
+ :on-reactivate (fn [screen [entities]]
+ (assoc-in entities [:state :active?] true))
+
+ :on-chose-item (fn [{:keys [item]} [entities]]
+ (assoc-in entities [:cursor :current] item))
+
+ :on-start-script (fn [{:keys [script]} [entities]]
+ (script entities)
+ entities))
diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj
index bc91bdd0..937a4135 100644
--- a/desktop/src-common/advent/utils.clj
+++ b/desktop/src-common/advent/utils.clj
@@ -11,7 +11,7 @@
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(println (:input-x screen) (:input-y screen) "->" x y)))
-(def +all-cursors+ [:main :wool :mushrooms :talk :right :down :left :up])
+(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up])
(defn cursor [filename which]
(let [scale 2
@@ -24,3 +24,31 @@
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
0 0 target-width target-height)
resized ))
+
+
+(defn get-font [filename]
+ (let [font (bitmap-font filename)
+ tr (bitmap-font! font :get-region)
+ tx (.getTexture tr)]
+ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
+ font))
+
+(def +screen-width+ 320)
+(def +screen-height+ 240)
+
+(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]]
+ (let [maximum-size (or maximum-size 1.0)]
+ (fn [y]
+ (if (< y baseline) maximum-size
+ (let [percent-complete (- 1.0 (/ (- y baseline) (- +screen-height+ baseline)))
+ range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)]
+ range)))))
+
+(defn flip [anim]
+ (animation (animation! anim :get-frame-duration)
+ (for [src-frame (animation! anim :get-key-frames)
+ :let [frame (texture (texture! src-frame :get-texture))]]
+ (do
+ (texture! frame :set-region src-frame)
+ (texture! frame :flip true false)
+ frame))))