adding camera panning. nice.

This commit is contained in:
2015-02-19 11:24:32 -08:00
parent dfdfcd7914
commit e517fffbd4
6 changed files with 179 additions and 116 deletions

View File

@@ -12,6 +12,7 @@
[advent.actions :as actions]
[advent.zone :as zone]
[advent.utils :as utils]
[advent.tween :as tween]
[advent.screens.rooms :as rooms]
[advent.screens.rooms.common :as common]
[advent.screens.items :as items]
@@ -33,7 +34,7 @@
[advent.screens.inventory :refer [inventory-screen]]
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!!]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation]
[java.lang Object]
[com.badlogic.gdx Gdx]))
@@ -65,7 +66,7 @@
((:mouse-in? (:inventory entities)) x y)
(click-inventory screen entities)
(utils/intersects? (:close entities) [x y])
(assoc-in entities [:tweens :fade-out] (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
(assoc-in entities [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 :finish #(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
%)))
:else
@@ -341,7 +342,7 @@
(defn get-animation-point [animation total-time]
(defn get-animation-point [^Animation animation total-time]
(loop [time total-time]
(if (> (- time (animation! animation :get-animation-duration)) 0)
(recur (- time (animation! animation :get-animation-duration)))
@@ -391,77 +392,81 @@
:on-show
(fn [screen entities]
(let [screen (assoc screen :total-time 0)]
(update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
rooms {:inside-house (rooms.inside-house/make screen)
:inside-stash (rooms.inside-stash/make screen)
:outside-house (rooms.outside-house/make screen)
:behind-house (rooms.behind-house/make screen)
:cat-tree (rooms.cat-tree/make screen)
:inside-castle (rooms.inside-castle/make screen)
:space (rooms.space/make screen)
:inside-cafeteria (rooms.inside-cafeteria/make screen)
:inside-antique (rooms.inside-antique/make screen)
:inside-jail (rooms.inside-jail/make screen)
:dream (rooms.dream/make screen)
:castle-gate (rooms.castle-gate/make screen)
:outside-jail (rooms.outside-jail/make screen)
:outside-castle (rooms.outside-castle/make screen)}
entities {:rooms rooms
:musics {:object nil
:inside-antique (utils/make-music "inside-antique.ogg")
:town-1 (utils/make-music "town-music-1.ogg")
:town-2 (utils/make-music "town-music-2.ogg")
:inside-fangald (utils/make-music "inside-fangald.ogg")
:fight (utils/make-music "megaboss.mp3")
:pull-sword (utils/make-music "pull-sword.ogg")
:night (utils/make-music "night.ogg")}
:state (get-state)
:fade (assoc (texture "black.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:white-fade (assoc (texture "white.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:actions {:object nil
:channel (chan)
:current nil
:script-running? false
:started? false}
:volume {:object nil
:value 0.0}
:music-override {:object nil
:value nil}
:close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000)
:cursor {:id "cursor"
:current :main
:last :main
:override nil
:last-pos [0 0]}
:tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.5 :power 3.0)
:fade-in-music (utils/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :power 3.0)}
:all-items (assoc items/items :object nil)
:room (as-> (get rooms (:last-room (get-state))) room
(assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room)))))
: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 0)}]
(music! (utils/get-current-music entities) :set-volume (get-in entities [:volume :value]))
(let [cam (orthographic)]
(set! (. cam zoom) 0.95)
(update! screen :renderer (stage) :camera cam)
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
rooms {:inside-house (rooms.inside-house/make screen)
:inside-stash (rooms.inside-stash/make screen)
:outside-house (rooms.outside-house/make screen)
:behind-house (rooms.behind-house/make screen)
:cat-tree (rooms.cat-tree/make screen)
:inside-castle (rooms.inside-castle/make screen)
:space (rooms.space/make screen)
:inside-cafeteria (rooms.inside-cafeteria/make screen)
:inside-antique (rooms.inside-antique/make screen)
:inside-jail (rooms.inside-jail/make screen)
:dream (rooms.dream/make screen)
:castle-gate (rooms.castle-gate/make screen)
:outside-jail (rooms.outside-jail/make screen)
:outside-castle (rooms.outside-castle/make screen)}
entities {:rooms rooms
:cam {:value cam
:object nil}
:musics {:object nil
:inside-antique (utils/make-music "inside-antique.ogg")
:town-1 (utils/make-music "town-music-1.ogg")
:town-2 (utils/make-music "town-music-2.ogg")
:inside-fangald (utils/make-music "inside-fangald.ogg")
:fight (utils/make-music "megaboss.mp3")
:pull-sword (utils/make-music "pull-sword.ogg")
:night (utils/make-music "night.ogg")}
:state (get-state)
:fade (assoc (texture "black.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:white-fade (assoc (texture "white.png")
:scale-x 20
:scale-y 20
:baseline 9500
:opacity 0.0)
:actions {:object nil
:channel (chan)
:current nil
:script-running? false
:started? false}
:volume {:object nil
:value 0.0}
:music-override {:object nil
:value nil}
:close (assoc (texture "close.png") :x 304 :y 224 :width 16 :height 16 :baseline 9000)
:cursor {:id "cursor"
:current :main
:last :main
:override nil
:last-pos [0 0]}
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.5 :ease tween/ease-in-cubic)
:fade-in-music (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 1.5 :ease tween/ease-in-cubic)}
:all-items (assoc items/items :object nil)
:room (as-> (get rooms (:last-room (get-state))) room
(assoc-in room [:entities :ego] (get-ego screen (:start-pos room) ((:scale-fn room) (:start-pos room)))))
: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 0)}]
(music! (utils/get-current-music entities) :set-volume (get-in entities [:volume :value]))
(utils/play-sound (get-in entities [:musics (actions/get-music (get-in entities [:room :music]) (get-in entities [:state :time]))]))
(utils/play-sound (get-in entities [:musics (actions/get-music (get-in entities [:room :music]) (get-in entities [:state :time]))]))
(doseq [[k [start time fn]] (get-in entities [:room :timers])]
(add-timer! screen k start time))
#_(when (not (get-in entities [:state :seen-intro?]))
((actions/get-script entities (rooms.dream/do-intro entities)) entities))
(if-let [apply-state (get-in entities [:room :apply-state])]
(apply-state entities)
entities))))
(doseq [[k [start time fn]] (get-in entities [:room :timers])]
(add-timer! screen k start time))
#_(when (not (get-in entities [:state :seen-intro?]))
((actions/get-script entities (rooms.dream/do-intro entities)) entities))
(if-let [apply-state (get-in entities [:room :apply-state])]
(apply-state entities)
entities)))))
:on-render
(fn [screen [entities]]
@@ -487,15 +492,19 @@
layers (get-layers entities)
all-entities (concat (vals entities) layers (vals (get-in entities [:room :entities])))]
(set! (. (:value (:cam entities)) zoom) (:zoom (:cam entities) 1.0))
(set! (.. (:value (:cam entities)) position x) (:x (:cam entities) 160.0))
(set! (.. (:value (:cam entities)) position y) (:y (:cam entities) 120.0))
(play-key-sounds (get-in entities [:room :entities]))
(doseq [m (vals (get-in entities [:musics]))]
(when m
(music! m :set-volume (get-in entities [:volume :value]) )))
(music! m :set-volume (get-in entities [:volume :value]))))
(label! (:fps entities) :set-text (str (game :fps)))
(render! screen (sort-by :baseline all-entities))
#_(render! screen [(:fps entities)])
(render! screen [(:fps entities)])
entities))
:on-resize (fn [screen entities]