parallax scrolling used elsewhere.

This commit is contained in:
2015-03-02 12:32:33 -08:00
parent 2c2507febf
commit d15b0983f4
21 changed files with 37 additions and 23 deletions

View File

@@ -436,8 +436,8 @@
(update-fn screen entities)
entities))
(defn render-foreground [{:keys [^OrthographicCamera camera ^Stage renderer] :as screen} foreground]
#_(println camera)
(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer] :as screen} {:keys [parallax] :as e }]
(let [tmp (Vector3.)
tmp2 (Vector3.)
parallax-view (Matrix4.)
@@ -445,8 +445,8 @@
(.update camera)
(.set tmp (.position camera))
(set! (.x tmp) (* (.x tmp) 1.5))
(set! (.y tmp) (* (.y tmp) 1.5))
(set! (.x tmp) (* (.x tmp) parallax))
(set! (.y tmp) (* (.y tmp) parallax))
(.setToLookAt parallax-view tmp (-> tmp2
(.set tmp)
(.add (.direction camera)))
@@ -460,9 +460,12 @@
(.begin batch)
(.setProjectionMatrix batch parallax-combined)
(doseq [e (:texes foreground)]
(entities/draw! (assoc e :x (+ (/ (:x e) (.zoom camera)) (- 240 (/ 160 (.zoom camera)) ))
:y (+ (/ (:y e) (.zoom camera)) (- 180 (/ 120 (.zoom camera))))) screen batch))
(entities/draw! (assoc e :x (+ (/ (:x e) (.zoom camera))
(- (* 320 parallax 0.5)
(/ 160 (.zoom camera)) ))
:y (+ (/ (:y e) (.zoom camera))
(- (* 240 parallax 0.5)
(/ 120 (.zoom camera))))) screen batch)
(.end batch))))
@@ -493,7 +496,7 @@
:outside-castle (rooms.outside-castle/make screen)}
entities {:rooms rooms
:step-particles (assoc (particle-effect "ego/step") :x 100 :y 100 :baseline 241)
:cam {:zoom 0.95
:cam {:zoom 0.95
:object nil}
:musics {:object nil
:inside-antique (utils/make-music "inside-antique.ogg")
@@ -531,9 +534,6 @@
:last :main
:override nil
:last-pos [0 0]}
:foreground {:object nil
:texes [(assoc (texture "outsidehouse/fg1.png") :x 0 :y 0 :baseline 1000)
(assoc (texture "outsidehouse/fg2.png") :x (- 320 59) :y 0 :baseline 1000)]}
:all-items (assoc items/items :object nil)
:started? {:value false
@@ -603,8 +603,12 @@
(doseq [m (vals (get-in entities [:musics]))]
(when m
(music! m :set-volume (get-in entities [:volume :value]))))
(render! screen (sort-by :baseline all-entities))
(render-foreground screen (:foreground entities))
(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]]