correct cursor logic, scared animation update, choosable volume.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
{:sound-volume 84.0, :music-volume 38.0}
|
{:sound-volume 45.0, :music-volume 53.0}
|
||||||
@@ -344,13 +344,14 @@
|
|||||||
scaled (get-in entities [:room :entities target-id :scaled])
|
scaled (get-in entities [:room :entities target-id :scaled])
|
||||||
scale-fn (get-in entities [:room :scale-fn])
|
scale-fn (get-in entities [:room :scale-fn])
|
||||||
scale (get-in entities [:room :entities target-id :scale-y] 1)
|
scale (get-in entities [:room :entities target-id :scale-y] 1)
|
||||||
height (* scale height)]
|
height (* scale height)]
|
||||||
(screen! dialogue/talking-screen :on-talk :text text
|
(screen! dialogue/talking-screen :on-talk :text text
|
||||||
:x target-x :y (+ (get-in entities [:room :entities target-id :y]) height)
|
:scene-viewport (:viewport screen)
|
||||||
:color (get-in entities [:room :entities target-id :talk-color])
|
:x target-x :y (+ target-y height)
|
||||||
|
:color (get-in entities [:room :entities target-id :talk-color])
|
||||||
:target-id target-id
|
|
||||||
:scale scale)
|
:target-id target-id
|
||||||
|
:scale scale)
|
||||||
(if animate?
|
(if animate?
|
||||||
(update-in entities [:room :entities target-id ] #(start-animation screen % (or anim :talk)))
|
(update-in entities [:room :entities target-id ] #(start-animation screen % (or anim :talk)))
|
||||||
entities)))
|
entities)))
|
||||||
@@ -611,7 +612,7 @@
|
|||||||
entities (if apply-state
|
entities (if apply-state
|
||||||
(apply-state entities)
|
(apply-state entities)
|
||||||
entities)
|
entities)
|
||||||
entities (utils/update-override entities)]
|
entities (utils/update-override screen entities)]
|
||||||
(when (and (not= new-music old-music) transition-music?)
|
(when (and (not= new-music old-music) transition-music?)
|
||||||
(doseq [[k v] (:musics entities)
|
(doseq [[k v] (:musics entities)
|
||||||
:when (and v (not= new-music k))]
|
:when (and v (not= new-music k))]
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
(: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.scenes.scene2d.utils Align]
|
[com.badlogic.gdx.scenes.scene2d.utils Align]
|
||||||
|
[com.badlogic.gdx.math Vector3 Vector2 Matrix4]
|
||||||
[com.badlogic.gdx Screen]))
|
[com.badlogic.gdx Screen]))
|
||||||
|
|
||||||
(defn ensure-on-screen [talk]
|
(defn ensure-on-screen [talk]
|
||||||
@@ -19,10 +20,19 @@
|
|||||||
minimum-x margin-width
|
minimum-x margin-width
|
||||||
maximum-x (- (game :width) margin-width)
|
maximum-x (- (game :width) margin-width)
|
||||||
label-width (label! talk :get-width)
|
label-width (label! talk :get-width)
|
||||||
label-right (+ (:x talk) label-width)]
|
label-right (+ (:x talk) label-width)
|
||||||
(cond (> label-right maximum-x) (assoc talk :x (- maximum-x label-width))
|
talk (cond (> label-right maximum-x) (assoc talk :x (- maximum-x label-width))
|
||||||
(< (:x talk) minimum-x) (assoc talk :x minimum-x)
|
(< (:x talk) minimum-x) (assoc talk :x minimum-x)
|
||||||
:else talk)))
|
:else talk)]
|
||||||
|
(doto talk
|
||||||
|
(label! :set-x (:x talk))
|
||||||
|
(label! :set-y (:y talk)))))
|
||||||
|
|
||||||
|
(defn scene-world->talk-world [scene-viewport [x y]]
|
||||||
|
(let [[screen-x screen-y] (utils/project {:viewport scene-viewport} [x y])
|
||||||
|
x (/ screen-x (/ (game :width) 1280.0 ))
|
||||||
|
y (/ screen-y (/ (game :height) 960.0 ))]
|
||||||
|
[x y]))
|
||||||
|
|
||||||
(defscreen talking-screen
|
(defscreen talking-screen
|
||||||
:on-show
|
:on-show
|
||||||
@@ -30,12 +40,13 @@
|
|||||||
(utils/setup-viewport screen 1280 960)
|
(utils/setup-viewport screen 1280 960)
|
||||||
{})
|
{})
|
||||||
:on-render
|
:on-render
|
||||||
(fn [screen [entities]]
|
(fn [{:keys [camera] :as screen} [entities]]
|
||||||
|
|
||||||
(render! screen (vals entities))
|
(render! screen (vals entities))
|
||||||
entities)
|
entities)
|
||||||
|
|
||||||
:on-talk
|
:on-talk
|
||||||
(fn [{:keys [create-talk target-id color text x y scale]} [entities]]
|
(fn [{:keys [create-talk target-id color text x y scale scene-viewport] :as screen} [entities]]
|
||||||
(let [font (bitmap-font "ego/font.fnt" )
|
(let [font (bitmap-font "ego/font.fnt" )
|
||||||
p (nine-patch {:region (:object (texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9})
|
p (nine-patch {:region (:object (texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9})
|
||||||
_ (nine-patch! p :set-padding 25 25 5 15)
|
_ (nine-patch! p :set-padding 25 25 5 15)
|
||||||
@@ -48,16 +59,31 @@
|
|||||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||||
style (style :label font color)
|
style (style :label font color)
|
||||||
#__ #_(set! (.background style) bg)
|
#__ #_(set! (.background style) bg)
|
||||||
talk (assoc (label text style) :y (* 4 y) )]
|
[source-x source-y] [x y]
|
||||||
(label! talk :set-font-scale scale)
|
|
||||||
(label! talk :set-alignment Align/center)
|
[x y] (scene-world->talk-world scene-viewport [source-x
|
||||||
(assoc entities target-id (-> talk
|
source-y])
|
||||||
(assoc :x (- (* 4 x) (/ (label! talk :get-width) 2)))
|
talk (assoc (label text style :set-font-scale scale :set-alignment Align/center)
|
||||||
ensure-on-screen ))))
|
:source-x source-x :source-y source-y)
|
||||||
|
x (- x (/ (label! talk :get-width) 2))
|
||||||
|
talk (assoc talk :x x :y y)
|
||||||
|
talk (ensure-on-screen talk)]
|
||||||
|
|
||||||
|
(assoc entities :dialogue talk)))
|
||||||
|
|
||||||
|
:on-update-camera
|
||||||
|
(fn [{:keys [scene-viewport scene-camera viewport] :as screen} [ {:keys [dialogue] :as entities}]]
|
||||||
|
(when dialogue
|
||||||
|
(let [[x y] (scene-world->talk-world scene-viewport [(:source-x dialogue)
|
||||||
|
(:source-y dialogue)])]
|
||||||
|
(-> entities
|
||||||
|
(assoc-in [:dialogue :x] (- x (/ (label! dialogue :get-width) 2)))
|
||||||
|
(assoc-in [:dialogue :y] y)
|
||||||
|
(update-in [:dialogue] ensure-on-screen)))))
|
||||||
|
|
||||||
:stop-talk
|
:stop-talk
|
||||||
(fn [{:keys [target-id] } [entities]]
|
(fn [{:keys [target-id] } [entities]]
|
||||||
(dissoc entities target-id))
|
(dissoc entities :dialogue))
|
||||||
|
|
||||||
|
|
||||||
:on-resize (fn [{:keys [viewport width height]} entities]
|
:on-resize (fn [{:keys [viewport width height]} entities]
|
||||||
|
|||||||
@@ -621,23 +621,26 @@
|
|||||||
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
||||||
(when (nil? (:zoom (:cam entities)))
|
(when (nil? (:zoom (:cam entities)))
|
||||||
(println entities))
|
(println entities))
|
||||||
|
(screen! talking-screen :on-update-camera :scene-viewport (:viewport screen) :scene-camera (:camera screen))
|
||||||
(set! (. camera zoom) (:zoom (:cam entities)))
|
(set! (. camera zoom) (:zoom (:cam entities)))
|
||||||
(set! (.. camera position x) (:x (:cam entities) 160.0))
|
(set! (.. camera position x) (:x (:cam entities) 160.0))
|
||||||
(set! (.. camera position y) (:y (:cam entities) 120.0))
|
(set! (.. camera position y) (:y (:cam entities) 120.0))
|
||||||
|
(let [entities (utils/update-override screen entities)]
|
||||||
(when (= (get-in entities [:fade :opacity])
|
|
||||||
0.0)
|
|
||||||
(play-key-sounds entities))
|
(when (= (get-in entities [:fade :opacity])
|
||||||
(doseq [m (vals (get-in entities [:musics]))]
|
0.0)
|
||||||
(when m
|
(play-key-sounds entities))
|
||||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
(doseq [m (vals (get-in entities [:musics]))]
|
||||||
(doseq [e (sort-by :baseline all-entities)]
|
(when m
|
||||||
(if (:parallax e)
|
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||||
(render-parallax screen e)
|
(doseq [e (sort-by :baseline all-entities)]
|
||||||
(render! screen [e])))
|
(if (:parallax e)
|
||||||
|
(render-parallax screen e)
|
||||||
|
(render! screen [e])))
|
||||||
entities))
|
|
||||||
|
|
||||||
|
entities)))
|
||||||
|
|
||||||
:on-resize (fn [{:keys [viewport width height]} [entities]]
|
:on-resize (fn [{:keys [viewport width height]} [entities]]
|
||||||
(.update viewport width height))
|
(.update viewport width height))
|
||||||
@@ -654,8 +657,7 @@
|
|||||||
(.getScreenWidth viewport) (.getScreenHeight viewport)
|
(.getScreenWidth viewport) (.getScreenHeight viewport)
|
||||||
input-x input-y)
|
input-x input-y)
|
||||||
|
|
||||||
(let [[x y] (utils/unproject screen)]
|
(utils/update-override screen (assoc-in entities [:cursor :last-pos] [input-x input-y]))
|
||||||
(utils/update-override (assoc-in entities [:cursor :last-pos] [x y])))
|
|
||||||
(assoc-in entities [:cursor :override] nil)))
|
(assoc-in entities [:cursor :override] nil)))
|
||||||
|
|
||||||
:on-touch-up (fn [{:keys [input-x input-y viewport] :as screen} [entities]]
|
:on-touch-up (fn [{:keys [input-x input-y viewport] :as screen} [entities]]
|
||||||
|
|||||||
@@ -34,51 +34,46 @@
|
|||||||
(defscreen title-screen
|
(defscreen title-screen
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(let [cam (orthographic)
|
|
||||||
viewport (FitViewport. 1280 960 cam)]
|
(utils/setup-viewport screen 1280 960)
|
||||||
(utils/load-settings!)
|
(utils/load-settings!)
|
||||||
(update! screen :renderer (stage) :camera cam :viewport viewport)
|
(let [font (utils/get-font "ego/font.fnt")
|
||||||
(.apply viewport)
|
start-playing (assoc (label "Embark on thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 100)
|
||||||
(let [font (utils/get-font "ego/font.fnt")
|
start-playing (center start-playing)
|
||||||
start-playing (assoc (label "Embark on thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 100)
|
quit (assoc (label "Quit thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 50)
|
||||||
start-playing (center start-playing)
|
quit (center quit)
|
||||||
quit (assoc (label "Quit thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 50)
|
music (utils/make-music "intro.ogg")
|
||||||
quit (center quit)
|
ui-skin (skin "ui/ui.json")]
|
||||||
music (utils/make-music "intro.ogg")
|
(label! start-playing :set-alignment Align/center)
|
||||||
ui-skin (skin "ui/ui.json")]
|
|
||||||
(label! start-playing :set-alignment Align/center)
|
{:overlay (assoc (texture "title-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
|
||||||
|
:fade (assoc (texture "black.png")
|
||||||
{:overlay (assoc (texture "title-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
|
:scale-x 80
|
||||||
:fade (assoc (texture "black.png")
|
:scale-y 80
|
||||||
:scale-x 80
|
:opacity 1.0)
|
||||||
:scale-y 80
|
:music-volume-slider (assoc (slider {:min 0 :max 100 :step 1} ui-skin :set-value (:music-volume @utils/settings))
|
||||||
:opacity 1.0)
|
:x ( - (/ (game :width) 2)
|
||||||
:music-volume-slider (assoc (slider {:min 0 :max 100 :step 1} ui-skin :set-value (:music-volume @utils/settings))
|
150)
|
||||||
:x ( - (/ (game :width) 2)
|
:width 300
|
||||||
150)
|
:y 200)
|
||||||
:width 300
|
:sound-volume-slider (assoc (slider {:min 0 :max 100 :step 1 } ui-skin :set-value (:sound-volume @utils/settings))
|
||||||
:y 200)
|
:width 300
|
||||||
:sound-volume-slider (assoc (slider {:min 0 :max 100 :step 1 } ui-skin :set-value (:sound-volume @utils/settings))
|
:x ( - (/ (game :width) 2)
|
||||||
:width 300
|
150)
|
||||||
:x ( - (/ (game :width) 2)
|
:y 150)
|
||||||
150)
|
|
||||||
:y 150)
|
:font font
|
||||||
:viewport viewport
|
:music music
|
||||||
:font font
|
:volume 1.0
|
||||||
:music music
|
:start-showing? false
|
||||||
:volume 1.0
|
:start-playing start-playing
|
||||||
:start-showing? false
|
:quit quit
|
||||||
:start-playing start-playing
|
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
|
||||||
:quit quit
|
:finish #(do (utils/play-sound (:music %)) %)
|
||||||
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
|
:ease tween/ease-in-quadratic)}}))
|
||||||
:finish #(do (utils/play-sound (:music %)) %)
|
|
||||||
:ease tween/ease-in-quadratic)}})))
|
|
||||||
|
|
||||||
:on-render
|
:on-render
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
(.update (:camera screen))
|
|
||||||
(.apply (:viewport screen))
|
|
||||||
|
|
||||||
|
|
||||||
(clear!)
|
(clear!)
|
||||||
(let [entities (utils/apply-tweens screen entities (:tweens entities))]
|
(let [entities (utils/apply-tweens screen entities (:tweens entities))]
|
||||||
@@ -129,6 +124,6 @@
|
|||||||
:else
|
:else
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
:on-resize (fn [screen [entities]]
|
:on-resize (fn [{:keys [viewport width height]} [entities]]
|
||||||
(.update (:viewport entities) (game :width) (game :height) true)
|
(.update viewport width height)
|
||||||
nil))
|
nil))
|
||||||
|
|||||||
@@ -129,13 +129,7 @@
|
|||||||
(:cursor %))
|
(:cursor %))
|
||||||
(get-in entities [:room :interactions]))))
|
(get-in entities [:room :interactions]))))
|
||||||
|
|
||||||
(defn update-override [entities]
|
|
||||||
(if (get-in entities [:state :active?])
|
|
||||||
(let [last-pos (get-in entities [:cursor :last-pos])]
|
|
||||||
(if-let [mouse-override (find-override entities last-pos)]
|
|
||||||
(assoc-in entities [:cursor :override] (:cursor mouse-override))
|
|
||||||
(assoc-in entities [:cursor :override] nil)))
|
|
||||||
entities))
|
|
||||||
|
|
||||||
(defn remove-interaction [entities id]
|
(defn remove-interaction [entities id]
|
||||||
(update-in entities [:room :interactions] (fn [i] (remove #(= id (:id %)) i))))
|
(update-in entities [:room :interactions] (fn [i] (remove #(= id (:id %)) i))))
|
||||||
@@ -180,12 +174,30 @@
|
|||||||
(.apply viewport)
|
(.apply viewport)
|
||||||
[cam viewport stage]))
|
[cam viewport stage]))
|
||||||
|
|
||||||
(defn unproject [screen]
|
(defn unproject
|
||||||
(let [pj (.unproject (:viewport screen) (vector-2 (:input-x screen) (:input-y screen)))
|
([screen]
|
||||||
x (.x pj)
|
(unproject screen [(:input-x screen) (:input-y screen)]) )
|
||||||
y (.y pj)]
|
([screen [x y]]
|
||||||
[x y]))
|
(let [pj (.unproject ^FitViewport (:viewport screen) (vector-2 x y))
|
||||||
|
x (.x pj)
|
||||||
|
y (.y pj)]
|
||||||
|
[x y])))
|
||||||
|
|
||||||
|
(defn project
|
||||||
|
([screen [x y]]
|
||||||
|
(let [pj (.project ^FitViewport (:viewport screen) (vector-2 x y))
|
||||||
|
x (.x pj)
|
||||||
|
y (.y pj)]
|
||||||
|
[x y])))
|
||||||
|
|
||||||
(defn contains-point? [x1 y1 width height x y]
|
(defn contains-point? [x1 y1 width height x y]
|
||||||
(and (< x1 x (+ x1 width))
|
(and (< x1 x (+ x1 width))
|
||||||
(< y1 y (+ y1 height))))
|
(< y1 y (+ y1 height))))
|
||||||
|
|
||||||
|
(defn update-override [screen entities]
|
||||||
|
(let [last-pos (unproject screen (get-in entities [:cursor :last-pos]))]
|
||||||
|
(if (get-in entities [:state :active?])
|
||||||
|
(if-let [mouse-override (find-override entities last-pos)]
|
||||||
|
(assoc-in entities [:cursor :override] (:cursor mouse-override))
|
||||||
|
(assoc-in entities [:cursor :override] nil))
|
||||||
|
entities)))
|
||||||
|
|||||||
Reference in New Issue
Block a user