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])
|
||||
scale-fn (get-in entities [:room :scale-fn])
|
||||
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
|
||||
:x target-x :y (+ (get-in entities [:room :entities target-id :y]) height)
|
||||
:color (get-in entities [:room :entities target-id :talk-color])
|
||||
|
||||
:target-id target-id
|
||||
:scale scale)
|
||||
:scene-viewport (:viewport screen)
|
||||
:x target-x :y (+ target-y height)
|
||||
:color (get-in entities [:room :entities target-id :talk-color])
|
||||
|
||||
:target-id target-id
|
||||
:scale scale)
|
||||
(if animate?
|
||||
(update-in entities [:room :entities target-id ] #(start-animation screen % (or anim :talk)))
|
||||
entities)))
|
||||
@@ -611,7 +612,7 @@
|
||||
entities (if apply-state
|
||||
(apply-state entities)
|
||||
entities)
|
||||
entities (utils/update-override entities)]
|
||||
entities (utils/update-override screen entities)]
|
||||
(when (and (not= new-music old-music) transition-music?)
|
||||
(doseq [[k v] (:musics entities)
|
||||
:when (and v (not= new-music k))]
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
(: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.math Vector3 Vector2 Matrix4]
|
||||
[com.badlogic.gdx Screen]))
|
||||
|
||||
(defn ensure-on-screen [talk]
|
||||
@@ -19,10 +20,19 @@
|
||||
minimum-x margin-width
|
||||
maximum-x (- (game :width) margin-width)
|
||||
label-width (label! talk :get-width)
|
||||
label-right (+ (:x talk) label-width)]
|
||||
(cond (> label-right maximum-x) (assoc talk :x (- maximum-x label-width))
|
||||
(< (:x talk) minimum-x) (assoc talk :x minimum-x)
|
||||
:else talk)))
|
||||
label-right (+ (:x talk) label-width)
|
||||
talk (cond (> label-right maximum-x) (assoc talk :x (- maximum-x label-width))
|
||||
(< (:x talk) minimum-x) (assoc talk :x minimum-x)
|
||||
: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
|
||||
:on-show
|
||||
@@ -30,12 +40,13 @@
|
||||
(utils/setup-viewport screen 1280 960)
|
||||
{})
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
(fn [{:keys [camera] :as screen} [entities]]
|
||||
|
||||
(render! screen (vals entities))
|
||||
entities)
|
||||
|
||||
: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" )
|
||||
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)
|
||||
@@ -48,16 +59,31 @@
|
||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||
style (style :label font color)
|
||||
#__ #_(set! (.background style) bg)
|
||||
talk (assoc (label text style) :y (* 4 y) )]
|
||||
(label! talk :set-font-scale scale)
|
||||
(label! talk :set-alignment Align/center)
|
||||
(assoc entities target-id (-> talk
|
||||
(assoc :x (- (* 4 x) (/ (label! talk :get-width) 2)))
|
||||
ensure-on-screen ))))
|
||||
[source-x source-y] [x y]
|
||||
|
||||
[x y] (scene-world->talk-world scene-viewport [source-x
|
||||
source-y])
|
||||
talk (assoc (label text style :set-font-scale scale :set-alignment Align/center)
|
||||
: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
|
||||
(fn [{:keys [target-id] } [entities]]
|
||||
(dissoc entities target-id))
|
||||
(dissoc entities :dialogue))
|
||||
|
||||
|
||||
:on-resize (fn [{:keys [viewport width height]} entities]
|
||||
|
||||
@@ -621,23 +621,26 @@
|
||||
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
|
||||
(when (nil? (:zoom (:cam 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 position x) (:x (:cam entities) 160.0))
|
||||
(set! (.. camera position y) (:y (:cam entities) 120.0))
|
||||
|
||||
(when (= (get-in entities [:fade :opacity])
|
||||
0.0)
|
||||
(play-key-sounds entities))
|
||||
(doseq [m (vals (get-in entities [:musics]))]
|
||||
(when m
|
||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||
(doseq [e (sort-by :baseline all-entities)]
|
||||
(if (:parallax e)
|
||||
(render-parallax screen e)
|
||||
(render! screen [e])))
|
||||
|
||||
|
||||
entities))
|
||||
(let [entities (utils/update-override screen entities)]
|
||||
|
||||
|
||||
(when (= (get-in entities [:fade :opacity])
|
||||
0.0)
|
||||
(play-key-sounds entities))
|
||||
(doseq [m (vals (get-in entities [:musics]))]
|
||||
(when m
|
||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||
(doseq [e (sort-by :baseline all-entities)]
|
||||
(if (:parallax e)
|
||||
(render-parallax screen e)
|
||||
(render! screen [e])))
|
||||
|
||||
|
||||
entities)))
|
||||
|
||||
:on-resize (fn [{:keys [viewport width height]} [entities]]
|
||||
(.update viewport width height))
|
||||
@@ -654,8 +657,7 @@
|
||||
(.getScreenWidth viewport) (.getScreenHeight viewport)
|
||||
input-x input-y)
|
||||
|
||||
(let [[x y] (utils/unproject screen)]
|
||||
(utils/update-override (assoc-in entities [:cursor :last-pos] [x y])))
|
||||
(utils/update-override screen (assoc-in entities [:cursor :last-pos] [input-x input-y]))
|
||||
(assoc-in entities [:cursor :override] nil)))
|
||||
|
||||
:on-touch-up (fn [{:keys [input-x input-y viewport] :as screen} [entities]]
|
||||
|
||||
@@ -34,51 +34,46 @@
|
||||
(defscreen title-screen
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
(let [cam (orthographic)
|
||||
viewport (FitViewport. 1280 960 cam)]
|
||||
(utils/load-settings!)
|
||||
(update! screen :renderer (stage) :camera cam :viewport viewport)
|
||||
(.apply viewport)
|
||||
(let [font (utils/get-font "ego/font.fnt")
|
||||
start-playing (assoc (label "Embark on thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 100)
|
||||
start-playing (center start-playing)
|
||||
quit (assoc (label "Quit thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 50)
|
||||
quit (center quit)
|
||||
music (utils/make-music "intro.ogg")
|
||||
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")
|
||||
:scale-x 80
|
||||
:scale-y 80
|
||||
:opacity 1.0)
|
||||
:music-volume-slider (assoc (slider {:min 0 :max 100 :step 1} ui-skin :set-value (:music-volume @utils/settings))
|
||||
:x ( - (/ (game :width) 2)
|
||||
150)
|
||||
:width 300
|
||||
:y 200)
|
||||
:sound-volume-slider (assoc (slider {:min 0 :max 100 :step 1 } ui-skin :set-value (:sound-volume @utils/settings))
|
||||
:width 300
|
||||
:x ( - (/ (game :width) 2)
|
||||
150)
|
||||
:y 150)
|
||||
:viewport viewport
|
||||
:font font
|
||||
:music music
|
||||
:volume 1.0
|
||||
:start-showing? false
|
||||
:start-playing start-playing
|
||||
:quit quit
|
||||
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
|
||||
:finish #(do (utils/play-sound (:music %)) %)
|
||||
:ease tween/ease-in-quadratic)}})))
|
||||
|
||||
(utils/setup-viewport screen 1280 960)
|
||||
(utils/load-settings!)
|
||||
(let [font (utils/get-font "ego/font.fnt")
|
||||
start-playing (assoc (label "Embark on thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 100)
|
||||
start-playing (center start-playing)
|
||||
quit (assoc (label "Quit thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 50)
|
||||
quit (center quit)
|
||||
music (utils/make-music "intro.ogg")
|
||||
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")
|
||||
:scale-x 80
|
||||
:scale-y 80
|
||||
:opacity 1.0)
|
||||
:music-volume-slider (assoc (slider {:min 0 :max 100 :step 1} ui-skin :set-value (:music-volume @utils/settings))
|
||||
:x ( - (/ (game :width) 2)
|
||||
150)
|
||||
:width 300
|
||||
:y 200)
|
||||
:sound-volume-slider (assoc (slider {:min 0 :max 100 :step 1 } ui-skin :set-value (:sound-volume @utils/settings))
|
||||
:width 300
|
||||
:x ( - (/ (game :width) 2)
|
||||
150)
|
||||
:y 150)
|
||||
|
||||
:font font
|
||||
:music music
|
||||
:volume 1.0
|
||||
:start-showing? false
|
||||
:start-playing start-playing
|
||||
:quit quit
|
||||
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
|
||||
:finish #(do (utils/play-sound (:music %)) %)
|
||||
:ease tween/ease-in-quadratic)}}))
|
||||
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
(.update (:camera screen))
|
||||
(.apply (:viewport screen))
|
||||
|
||||
|
||||
(clear!)
|
||||
(let [entities (utils/apply-tweens screen entities (:tweens entities))]
|
||||
@@ -129,6 +124,6 @@
|
||||
:else
|
||||
nil)))
|
||||
|
||||
:on-resize (fn [screen [entities]]
|
||||
(.update (:viewport entities) (game :width) (game :height) true)
|
||||
:on-resize (fn [{:keys [viewport width height]} [entities]]
|
||||
(.update viewport width height)
|
||||
nil))
|
||||
|
||||
@@ -129,13 +129,7 @@
|
||||
(:cursor %))
|
||||
(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]
|
||||
(update-in entities [:room :interactions] (fn [i] (remove #(= id (:id %)) i))))
|
||||
@@ -180,12 +174,30 @@
|
||||
(.apply viewport)
|
||||
[cam viewport stage]))
|
||||
|
||||
(defn unproject [screen]
|
||||
(let [pj (.unproject (:viewport screen) (vector-2 (:input-x screen) (:input-y screen)))
|
||||
x (.x pj)
|
||||
y (.y pj)]
|
||||
[x y]))
|
||||
(defn unproject
|
||||
([screen]
|
||||
(unproject screen [(:input-x screen) (:input-y screen)]) )
|
||||
([screen [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]
|
||||
(and (< x1 x (+ x1 width))
|
||||
(< 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