This commit is contained in:
Bryce Covert
2017-08-10 19:55:06 -07:00
1305 changed files with 14202 additions and 4888 deletions

View File

@@ -3,7 +3,7 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[clojure.string :as s]
[clojure.zip :as zip]
[clojure.set :as set]
@@ -70,7 +70,10 @@
(let [fg-bg-key *fg-bg-key*]
(run-action entities
(begin [this screen entities]
(update-in entities [fg-bg-key] assoc :script-running? state :last-skip-type (if state :end nil)))
(-> entities
(update-in [fg-bg-key]
assoc :script-running? state :last-skip-type (if state :end nil))
(assoc-in [:cursor :came-from-inventory?] false)))
(continue [this screen entities] entities)
@@ -105,7 +108,7 @@
(defn force-end [entities current-action key]
(do (when current-action
(put! (get-channel current-action) :end))
(screen! dialogue/talking-screen :stop-talk :id key)
(screen! dialogue/talking-screen :stop-talk {:id key})
(-> entities
(assoc-in [key :script-running?] false)
(assoc-in [key :current] nil)
@@ -121,29 +124,28 @@
~@forms
(change-script-state ~entities false))))))))
(defn bound-to-camera [x length zoom]
(min (- length (* length 0.5 zoom ))
(max (* length 0.5 zoom )
x)))
(defn pan-to [screen entities x y scale-fn & [ease duration]]
(let [ease (or ease tween/ease-in-out-quadratic)
duration (or duration 3.0)
target-zoom (min 0.95 (max 0.75 (scale-fn [(max 0 (min 319 x)) (max 0 (min 240 y))])))
target-zoom (min utils/min-zoom (max utils/max-zoom (scale-fn [(max 0 (min 319 x)) (max 0 (min 240 y))])))
current-zoom (get-in entities [:cam :zoom] 1.0)
;; don't zoom if it's a subtle difference
target-zoom (if (< (Math/abs (- target-zoom current-zoom))
target-zoom (if (< (Math/abs (double (- target-zoom current-zoom)))
0.07)
current-zoom
target-zoom)
target-x (bound-to-camera x 320 target-zoom)
target-y (bound-to-camera y 240 target-zoom)]
target-x (utils/bound-to-camera x 320 target-zoom)
target-y (utils/bound-to-camera y 240 target-zoom)]
(if (and (or (not= target-x (get-in entities [:cam :x]))
(not= target-y (get-in entities [:cam :y]))
(not= target-zoom (get-in entities [:cam :zoom])))
(not (get-in entities [:cam :paused?])))
(-> entities
(assoc-in [:cam :ideal-x] x)
(assoc-in [:cam :ideal-y] y)
(assoc-in [:tweens :cam-zoom]
(tween/tween :cam-zoom screen
[:cam :zoom]
@@ -185,14 +187,15 @@
(defn start-animation
([entity anim]
(start-animation {:total-time 0} entity anim))
(start-animation {:total-time 0} entity anim))
([screen entity anim]
(let [new-anim (find-animation entity anim)]
(if (and anim (not= new-anim (:anim entity)))
(assoc entity
:anim new-anim
:anim-start (:total-time screen))
entity))))
(let [new-anim (find-animation entity anim)]
(if (and anim (not= new-anim (:anim entity)))
(assoc entity
:force-rerender true
:anim new-anim
:anim-start (:total-time screen))
entity))))
(defn stop [screen entities target-id & {:keys [face]}]
(update-in entities [:room :entities target-id] (comp #(start-animation screen % (or (:stand-override %) :stand) ) (if face #(assoc % :facing face) identity))))
@@ -251,9 +254,9 @@
0
(* speed (/ delta-y distance)))]
(if (< distance speed)
(-> 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]
#(jump-to screen entities % [final-x final-y] update-baseline?))
(update-in entities [:room :entities target-id]
#(start-animation screen
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)] update-baseline?)
@@ -341,37 +344,52 @@
(continue [this screen entities]
(when (= (rand-int 5) 2)
#_(particle-effect! (:step-particles entities) :start))
(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)
distance (utils/dist from-x from-y target-x target-y)
speed (* (or scale-x 1.0) 1.5)
speed (* speed
(/ (:delta-time screen)
(/ 1.0 60.0)))
moved-x (if (= 0.0 distance)
0
(* speed (/ delta-x distance)))
moved-y (if (= 0.0 distance)
0
(* speed (/ delta-y distance)))]
(if (< distance speed)
(do (swap! targets-left rest)
(-> entities
(assoc-in [:room :entities target-id :x] target-x)
(assoc-in [:room :entities target-id :y] target-y)
(assoc-in [:step-particles :x] target-x)
(assoc-in [:step-particles :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)] true)
:facing (cond force-dir force-dir
(< delta-x 0) :left
(> delta-x 0) :right
:else (:facing %)))
:walk
))))))
(loop [entities entities
base-speed (* 1.5
(/ (:delta-time screen)
(/ 1.0 60.0))
1.0)]
(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)
distance (utils/dist from-x from-y target-x target-y)
speed (* (or scale-x 1.0) base-speed)
moved-x (if (= 0.0 distance)
0
(* speed (/ delta-x distance)))
moved-y (if (= 0.0 distance)
0
(* speed (/ delta-y distance)))]
(cond (<= speed 0)
entities
(> distance speed)
(update-in entities [:room :entities target-id]
#(start-animation screen
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)] true)
:facing (cond force-dir force-dir
(< delta-x 0) :left
(> delta-x 0) :right
:else (:facing %)))
:walk
))
(seq remainder)
(do
(swap! targets-left rest)
(recur (-> entities
(update-in [:room :entities target-id] #(jump-to screen entities % [target-x target-y] true))
(assoc-in [:step-particles :x] target-x)
(assoc-in [:step-particles :y] target-y))
(- base-speed distance)))
:else
(-> entities
(update-in [:room :entities target-id] #(jump-to screen entities % [target-x target-y] true))
(assoc-in [:step-particles :x] target-x)
(assoc-in [:step-particles :y] target-y)))))))
(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])]
@@ -399,23 +417,23 @@
target-y (get-in entities [:room :entities target-id :y])
target-x (get-in entities [:room :entities target-id :x])
width (or (get-in entities [:room :entities target-id :width])
(.getRegionWidth (get-in entities [:room :entities target-id :object])))
(texture! (get-in entities [:room :entities target-id]) :get-region-width))
origin-x (get-in entities [:room :entities target-id :origin-x])
target-x (if (nil? origin-x) (+ target-x (/ width 2)) target-x )
height (or (get-in entities [:room :entities target-id :height])
(.getRegionHeight (get-in entities [:room :entities target-id :object])))
(texture! (get-in entities [:room :entities target-id]) :get-region-height))
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)]
(screen! dialogue/talking-screen :on-talk :text text
:id fg-or-bg
:scene-viewport (:viewport screen)
:x target-x :y (+ target-y height)
:color (or color (get-in entities [:room :entities target-id :talk-color]))
:target-id target-id
:scale scale)
(screen! dialogue/talking-screen :on-talk { :text text
:id fg-or-bg
:scene-viewport (:viewport screen)
:x target-x :y (+ target-y height)
:color (or 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-override %) :talk)))
entities)))
@@ -432,7 +450,7 @@
(terminate [this screen entities]
(if wait
(do
(screen! dialogue/talking-screen :stop-talk :id fg-or-bg)
(screen! dialogue/talking-screen :stop-talk {:id fg-or-bg})
(if stop?
(stop screen entities target-id)
entities))
@@ -468,11 +486,8 @@
dialogue-choices (filter first (partition 2 (:choices node)))]
(run-action entities
(begin [this screen entities]
(screen! dialogue/choice-screen :on-present-choices :choices dialogue-choices :callback #(reset! selected-index %))
(screen! @(resolve 'advent.screens.scene/scene) :on-deactivate)
(-> entities
(assoc-in [:cursor :override] nil)
(assoc-in [:cursor :current] :main)))
(screen! dialogue/choice-screen :on-present-choices { :choices dialogue-choices :callback #(reset! selected-index %)})
(assoc-in entities [:state :active?] false))
(continue [this screen entities] entities)
@@ -480,9 +495,7 @@
(not (nil? @selected-index)))
(terminate [this screen entities]
(-> entities
(assoc-in [:state :active?] true)
(assoc-in [:cursor :override] nil)))
(assoc-in entities [:state :active?] true))
(skip-type [this screen entities]
:none))
@@ -538,12 +551,13 @@
(defn update-state [entities f]
(update-entities entities #(update-in % [:state] f)))
(defn remove-item [entities item]
(defn remove-item [entities item & {:keys [quiet?] :or {quiet? false}}]
(run-action entities
(begin [this screen entities]
(when-not quiet?
(screen! @(resolve 'advent.screens.scene/hud) :on-remove-item { :item ((:all-items entities) item)}))
(-> entities
(update-in [:state :inventory] #(remove (partial = item) %))
(assoc-in [:cursor :current] :main)))
(update-in [:state :inventory] #(remove (partial = item) %))))
(continue [this screen entities] entities)
@@ -558,7 +572,7 @@
([entities sound-file vol & [wait?]]
(let [wait? (if (nil? wait?) true wait?)
s (if (string? sound-file)
(sound sound-file)
(utils/load-sound sound-file)
sound-file)]
(run-action entities
(begin [this screen entities]
@@ -582,10 +596,10 @@
(run-action entities
(begin [this screen entities]
(utils/play-sound! screen entities :pickup (constantly 0.3))
(screen! @(resolve 'advent.screens.scene/hud) :on-give-item { :item ((:all-items entities) item)})
(-> entities
(update-in [:state :inventory] #(conj % item))
(update-in [:state :obtained-items] #(conj % item))
(assoc-in [:cursor :current] ((:all-items entities) item))))
(update-in [:state :obtained-items] #(conj % item))))
(continue [this screen entities] entities)
@@ -661,8 +675,10 @@
(defn transition-background [entities new-background [x y] & {:keys [transition-music? between time face]}]
(let [transition-music? (if (nil? transition-music?) true transition-music?)
old-music (get-music (get-in @entities [:room :music]) (get-in @entities [:state :time]))
new-music (get-music (get-in @entities [:rooms new-background :music]) (get-in @entities [:state :time]))
old-music (get-music (get-in @entities [:room-musics (get-in @entities [:state :last-room])]) (get-in @entities [:state :time]))
;; TODO FIX
new-music (get-music (get-in @entities [:room-musics new-background]) (get-in @entities [:state :time]))
_ (println old-music new-music)
music-changed? (and transition-music? (not= old-music new-music))
time (/ (float (or time 1.0)) 2.0)]
(run-action entities
@@ -673,8 +689,7 @@
(assoc-in e [:tweens :fade-out] (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 time))
(if music-changed?
(assoc-in e [:tweens :fade-out-music] (tween/tween :fade-out-music screen [:volume :value] 1.0 0.0 time))
e)
(assoc-in e [:cursor :current] :main)))
e)))
(continue [this screen entities]
entities)
@@ -683,6 +698,7 @@
(>= (get-in entities [:fade :opacity]) 1.0))
(terminate [this screen entities]
(utils/release-resources screen :room)
(let [entities (stop screen (if-let [next-time (get-in entities [:state :next-time])]
(-> entities
(assoc-in [:state :time] next-time)
@@ -699,14 +715,14 @@
(skip-type [this screen entities]
:none))
(log/info "Entering room " new-background )
(screen! dialogue/talking-screen :stop-talk :id :bg-actions)
(screen! dialogue/talking-screen :stop-talk { :id :bg-actions})
(run-action entities
(begin [this screen entities]
(utils/stop-all-sounds! entities)
(let [ego (get-in entities [:room :entities :ego])
old-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
entities (as-> entities e
(assoc-in e [:room] (get-in entities [:rooms new-background]))
(assoc-in e [:room] ((get-in entities [:rooms new-background]) screen))
(assoc-in e [:room :entities :ego] ego)
(assoc-in e [:current-sounds :value] [])
(if between (between screen e) e)
@@ -715,20 +731,20 @@
(if-not (get-in entities [:cam :paused?])
(-> e
(update-in [:tweens] dissoc :cam-zoom :cam-x :cam-y)
(assoc-in [:cam :x] 160)
(assoc-in [:cam :y] 120)
(assoc-in [:cam :zoom] 0.95))
(assoc-in [:cam :ideal-x] x)
(assoc-in [:cam :ideal-y] y)
(assoc-in [:cam :x] (utils/bound-to-camera x 320 (get-in entities [:cam :zoom])))
(assoc-in [:cam :y] (utils/bound-to-camera y 240 (get-in entities [:cam :zoom]))))
e)
(if music-changed?
(assoc-in e [:tweens :fade-in-music] (tween/tween :fade-in-music screen [:volume :value] 0.0 1.0 time))
e))
new-music (get-music (get-in entities [:room :music]) (get-in entities [:state :time]))
apply-state (get-in entities [:room :apply-state])
entities (if apply-state
(apply-state screen entities)
entities)
entities (utils/update-override screen 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))]
@@ -780,31 +796,8 @@
:y (get-in entities [:room :entities :ego :y])
:baseline (get-in entities [:room :entities :ego :baseline]))
(particle-effect! :reset) (particle-effect! :start)))
(assoc-in [:room :entities :cloud] (assoc (utils/get-texture "space/cloud.png")
:x (get-in entities [:room :entities :ego :x])
:y (get-in entities [:room :entities :ego :y])
:origin-x 7
:origin-y 7
:scale-x 0.5
:scale-y 0.5
:opacity 0.5
:baseline 240))
(assoc-in [:tweens :cloud-up] (tween/tween :cloud-up screen [:room :entities :cloud :y]
(get-in entities [:room :entities :ego :y])
(+ (get-in entities [:room :entities :ego :y]) 10)
1.0))
(assoc-in [:tweens :cloud-fade] (tween/tween :cloud-fade screen [:room :entities :cloud :opacity]
0.5
0.0
1.0))
(assoc-in [:tweens :cloud-grow] (tween/tween :cloud-grow screen [:room :entities :cloud :scale-y]
0.5
1.0
1.0))
(assoc-in [:tweens :cloud-grow-2] (tween/tween :cloud-grow-2 screen [:room :entities :cloud :scale-x]
0.5
1.0
1.0)))))
)))
(continue [this screen entities]
(assoc-in entities [:room :entities :glad-jump :y] (+ (get-in entities [:room :entities :ego :y]) 5))
@@ -989,7 +982,7 @@
([entities]
(play-safe entities true))
([entities whistle?]
(let [safe-song-anim (utils/make-anim-seq "safe-song/safe-song" [100 35] 0.05
(let [safe-song-anim (utils/make-anim-seq (texture-atlas "packed/global.atlas") "safe-song/safe-song" [100 35] 0.05
(flatten
[
[1 2 3]
@@ -1011,7 +1004,7 @@
(wait entities 400)
(add-entity entities :safe-song
(rooms/make-entity :safe-song
(assoc (utils/get-texture "safe-song/safe-song-1")
(assoc (utils/atlas->texture (texture-atlas "packed/global.atlas") "safe-song/safe-song" 0)
:x 110
:y 120
:baseline 241

View File

@@ -3,6 +3,7 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[advent.utils :as utils]
[advent.screens.scene :as scene]
[advent.screens.dialogue :as dialogue]
[clojure.tools.logging :as log]
@@ -10,8 +11,10 @@
[advent.screens.splash :as splash]
[advent.screens.credits :as credits]
[advent.screens.inventory :as inventory]
[advent.screens.safe :as safe]
[advent.screens.fade :as fade]
[advent.steam :as steam]
[clojure.pprint]
[advent.pathfind])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
@@ -22,21 +25,24 @@
(defonce am (asset-manager))
(set-asset-manager! am)
(defn create-game [advent]
(set-screen-wrapper! (fn [screen screen-fn]
(try (screen-fn)
(catch Exception e
(.log Gdx/app "ERROR" (with-out-str (.printStackTrace e)))
(set-screen! advent title/title-screen)))))
(log/log-capture! *ns* :warn :error)
(log/info "Starting game on version v" (advent.version/version))
(utils/listen-for-screenshots)
(set-screen! advent splash/splash-screen))
(defgame advent
:on-create
(fn [this]
(log/log-capture! *ns* :warn :error)
(log/info "Starting game on version v" (advent.version/version))
(steam/init)
(set-screen! this splash/splash-screen)))
(create-game advent)))
(defn reload []
(on-gl (set-screen! advent title/title-screen)))
(set-screen-wrapper! (fn [screen screen-fn]
(try (screen-fn)
(catch Exception e
(.log Gdx/app "ERROR" (with-out-str (.printStackTrace e)))
(log/error e (with-out-str (.printStackTrace e)))
(set-screen! advent title/title-screen)))))

View File

@@ -0,0 +1,28 @@
(ns advent.max-progress-bar
(:require [play-clj.utils :as u])
(:import [play_clj.entities ActorEntity])
)
(gen-class :name advent.max-progress-bar.MaxProgressBar
:extends com.badlogic.gdx.scenes.scene2d.ui.Slider
:state state
:init init
:exposes-methods {setValue parentSetValue}
:constructors {[float float float boolean com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle float] [float float float boolean com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle]}
)
(defn -init [min max step-size vertical style artificial-max]
[[min max step-size vertical style] artificial-max])
(defn -setValue [this value]
(.parentSetValue this (min value (.state this))))
(defn max-progress-bar
[min max step vertical? arg artificial-max]
(println min max step vertical? arg artificial-max)
(ActorEntity.
(advent.max-progress-bar.MaxProgressBar. (float min) (float max) (float step) vertical? arg (float artificial-max))))
(defmacro max-progress-bar!
"Calls a single method on a `slider`."
[entity k & options]
`(u/call! ^advent.max-progress-bar.MaxProgressBar (u/get-obj ~entity :object) ~k ~@options))

View File

@@ -1,5 +1,7 @@
(ns advent.pathfind
(:require [play-clj.core :refer :all])
(:require [play-clj.core :refer :all]
[play-clj.utils :refer :all]
[clojure.tools.logging :as log])
(:import (java.lang Math)))
(def scale 2)
@@ -77,9 +79,10 @@
ty (long ty)]
(if (= 0 (nth (nth my-map tx) ty))
nil
(let [cost-so-far ^java.util.HashMap (java.util.HashMap. {play-loc 0})
came-from ^java.util.HashMap (java.util.HashMap.)
fronteir ^java.util.PriorityQueue (java.util.PriorityQueue. (/ (* 320 240) scale) cost-comparator)]
(let [^java.util.HashMap cost-so-far (java.util.HashMap.)
_ (.put cost-so-far play-loc 0)
^java.util.HashMap came-from (java.util.HashMap.)
^java.util.PriorityQueue fronteir (java.util.PriorityQueue. (/ (* 320 240) scale) cost-comparator)]
(.offer fronteir [0 play-loc])
(loop [current-loc (.poll fronteir)]
(if (or (nil? current-loc)
@@ -119,18 +122,21 @@
(println path)))
(defn map-from-resource [filename]
(log/info "Loading collision from" filename)
(let [pm (pixmap filename)
black (color 0 0 0 255)
painful (color 255 0 0 255)
result (transient [])
scale (long scale)
height (long (pixmap! pm :get-height))]
(doseq [^long x (range (/ (pixmap! pm :get-width) scale))
^long y (range (/ height scale))
:let [
current-color (color (pixmap! pm :get-pixel (unchecked-multiply scale x) (unchecked-subtract height (unchecked-multiply scale y))))]]
(conj! result (cond
(color! current-color :equals black) 0
(color! current-color :equals painful) 2
:else 1)))
(partition (/ (pixmap! pm :get-height) scale) (persistent! result) )))
height (long (pixmap! pm :get-height))
_ (doseq [^long x (range (/ (pixmap! pm :get-width) scale))
^long y (range (/ height scale))
:let [current-color (color (pixmap! pm :get-pixel (unchecked-multiply scale x) (unchecked-subtract height (unchecked-multiply scale y))))]]
(conj! result (cond
(color! current-color :equals black) 0
(color! current-color :equals painful) 2
:else 1)))
result (partition (/ (pixmap! pm :get-height) scale) (persistent! result) )]
(.unload *asset-manager* filename)
(log/info "Finished loading collision from" filename)
result))

View File

@@ -9,10 +9,35 @@
(def chapter-name
{:chapter-1 "Part 1: Our Tale's Beginning"
:chapter-2 "Part 2: To Be a Knight"
:chapter-3 "Part 3: In the Slammer"
:chapter-4 "Part 4: Tick the Ex-con"
:chapter-5 "Part 5: Slingshot Stew"})
{:chapter-1 "Our Tale's Beginning"
:chapter-2 "To Be a Knight"
:chapter-3 "In the Slammer"
:chapter-4 "Tick the Ex-con"
:chapter-5 "Slingshot Stew"})
(defn default-screenshot [state]
(let [answers {:inside-house "screenshots/inside-house.png"
:inside-stash "screenshots/inside-stash.png"
:outside-house {:day "screenshots/outside-house-day.png"
:night "screenshots/outside-house-night.png"}
:behind-house {:day "screenshots/behind-house-day.png"
:night "screenshots/behind-house-night.png"}
:cat-tree {:day "screenshots/cat-tree-day.png"
:night "screenshots/cat-tree-night.png"}
:inside-castle {:day "screenshots/inside-castle-day.png"
:night "screenshots/inside-castle-night.png"}
:space "screenshots/duel.png"
:held "screenshots/held.png"
:inside-cafeteria "screenshots/cafeteria.png"
:inside-antique "screenshots/inside-antique.png"
:inside-jail "screenshots/inside-jail.png"
:dream "screenshots/dream.png"
:castle-gate "screenshots/castle-gate.png"
:outside-jail {:day "screenshots/fountain-day.png"
:night "screenshots/fountain-night.png"}
:outside-castle {:day "screenshots/outside-castle-day.png"
:night "screenshots/outside-castle-night.png"}}]
(get-in answers [(:last-room state) (:time state)]
(get-in answers [(:last-room state)]))))

View File

@@ -3,18 +3,19 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[advent.pathfind]
[advent.tween :as tween]
[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]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx.utils.viewport FitViewport]
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
InputMultiplexer InputProcessor Net Preferences Screen]))
(println "loading " *ns*)
(defn center [e]
(assoc e :x (- (/ 1280 2) (/ (or (:width e) (.getWidth (:object e))) 2))))
@@ -134,12 +135,15 @@
(= 0.0 (get-in entities [:fade :opacity])))
(let [[[logo & msg] & remaining-messages] (:remaining-messages entities)]
(if msg
(-> entities
(fade-logo-if-necessary screen logo)
(assoc :credit-table (msg->table msg entities))
(assoc-in [:tweens [:fade :in]] (chain-tweens screen entities))
(assoc :remaining-messages remaining-messages)
(assoc :last-logo logo))
(do
(utils/clear-stage screen)
(-> entities
(fade-logo-if-necessary screen logo)
(assoc :credit-table (->> (msg->table msg entities)
(utils/add-actor-to-stage screen)))
(assoc-in [:tweens [:fade :in]] (chain-tweens screen entities))
(assoc :remaining-messages remaining-messages)
(assoc :last-logo logo)))
(do (set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
entities)))
entities))
@@ -147,26 +151,27 @@
(defscreen credits
:on-show
(fn [screen entities]
(fn [screen entities options]
(utils/setup-viewport screen 1280 960)
(input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
(let [font (bitmap-font "ego/font.fnt" )]
(graphics! :set-cursor (utils/cursor "cursor.png" :main))
(let [[screen atlas] (utils/acquire-atlas screen "packed/global.atlas")
font (bitmap-font "ego/font.fnt" )]
{:font font
:bg (assoc (utils/get-texture "black.png")
:bg (assoc (utils/atlas->texture atlas "black")
:scale-x 80
:scale-y 80
:opacity 1.0
:origin-x 0
:origin-y 0)
:fade (assoc (utils/get-texture "black.png")
:fade (assoc (utils/atlas->texture atlas "black")
:scale-x 80
:scale-y 80
:opacity 0.0
:origin-x 0
:origin-y 0)
:pos (assoc (utils/get-texture "pos.png") :x 640 :y 700 :scale-x 1 :scale-y 1 :origin-x 145 :origin-y 0 :z 1 :opacity 0.0)
:dbh (assoc (utils/get-texture "dbh.png") :x 640 :y 500 :scale-x 0.5 :scale-y 0.5 :origin-x 640 :origin-y 0 :z 1 :opacity 0.0)
:pos (assoc (utils/atlas->texture atlas "black") :x 640 :y 700 :scale-x 1 :scale-y 1 :origin-x 145 :origin-y 0 :z 1 :opacity 0.0)
:dbh (assoc (utils/atlas->texture atlas "black") :x 640 :y 500 :scale-x 0.5 :scale-y 0.5 :origin-x 640 :origin-y 0 :z 1 :opacity 0.0)
:remaining-messages (cond (= @saved-took? :died)
(conj credit-messages [nil
@@ -181,28 +186,28 @@
(conj credit-messages [nil
["" ""]]))
#_#_:the-end (assoc (utils/get-texture "the-end.png") :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
#_#_:the-end (assoc (utils/atlas->texture atlas "the-end") :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
:tweens {:fade-in
(tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 5.0 :ease tween/ease-out-cubic)}}))
:on-key-up
(fn [screen entities]
(fn [screen entities options]
(when (= (key-code :escape) (:key screen))
(utils/toggle-fullscreen!))
nil)
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
(.apply viewport)
(let [entities (utils/apply-tweens screen entities (:tweens entities))
entities (start-message-if-necessary screen entities)]
(let [entities (start-message-if-necessary screen entities)
entities (utils/apply-tweens screen entities (:tweens entities))]
(clear!)
(render! screen [(:bg entities) (:credit-table entities) (:fade entities) (:dbh entities) (:pos entities)])
entities))
:on-touch-up (fn [screen [entities]]
:on-touch-up (fn [screen entities options]
(set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen)))
:on-resize (fn [{:keys [width height viewport]} entities]
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update viewport width height)))

View File

@@ -3,20 +3,21 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[clojure.tools.logging :as log]
[clojure.set :as set]
[advent.pathfind]
[advent.tween :as tween]
[advent.utils :as utils]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]]
#_[advent.screens.scene :as scene])
[clojure.core.async :refer [put! <! <!! >! >!! 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.utils.viewport FitViewport]
[com.badlogic.gdx.scenes.scene2d.utils Align]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx.math Vector3 Vector2 Matrix4]
[com.badlogic.gdx Screen]
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable ]
[play_clj.entities NinePatchEntity]))
(println "loading " *ns*)
(defn ensure-on-screen [talk]
(let [margin-width (* 0.05 1280)
@@ -24,11 +25,11 @@
maximum-x (- 1280 margin-width)
label-width (label! talk :get-width)
label-right (+ (:x talk) label-width)
y (min (- 900 (label! talk :get-height)) (:y talk))
talk (assoc (cond (> label-right maximum-x) (assoc talk :x (- maximum-x label-width))
(< (:x talk) minimum-x) (assoc talk :x minimum-x)
:else talk)
:y y)]
y (max 30 (min (- 900 (label! talk :get-height)) (:y talk)))
talk (cond-> talk
(> label-right maximum-x) (assoc :x (- maximum-x label-width))
(< (:x talk) minimum-x) (assoc :x minimum-x)
true (assoc :y y))]
(doto talk
(label! :set-x (:x talk))
(label! :set-y (:y talk)))))
@@ -41,49 +42,48 @@
(defscreen talking-screen
:on-show
(fn [screen entities]
(fn [screen entities options]
(utils/setup-viewport screen 1280 960)
{})
:on-render
(fn [{:keys [camera ^FitViewport viewport] :as screen} [entities]]
(fn [{:keys [camera ^FitViewport viewport] :as screen} entities options]
(.apply viewport)
(render! screen (vals entities))
entities)
:on-talk
(fn [{:keys [create-talk target-id color text x y scale scene-viewport id] :as screen} [entities]]
(let [font (bitmap-font "ego/font.fnt" )
p (NinePatchEntity. (skin! (skin "ui/ui.json") :get-patch "ui-bg"))
_ (nine-patch! p :set-padding 25 25 5 15)
bg (drawable :nine-patch (:object p))
_ (bitmap-font! font :set-markup-enabled true)
(fn [screen entities {:keys [create-talk target-id color text x y scale scene-viewport id]}]
(let [font (doto (bitmap-font "ego/font.fnt" )
(bitmap-font! :set-use-integer-positions false))
tr (bitmap-font! font :get-region)
scale (/ scale 2)
scale (or (min (max scale 0.2) 0.25) 0.25)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
scale (* scale (/ utils/ui-scale 2))
scale (or (min
(max scale
(/ utils/ui-scale 5) 0.4)
(/ utils/ui-scale 4))
(/ utils/ui-scale 4))
_ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
style (style :label font color)
#_#__ (set! (.background style) bg)
[source-x source-y] [x y]
[x y] (scene-world->talk-world scene-viewport [source-x
source-y])
talk (-> (label text style :set-font-scale scale :set-alignment Align/bottom)
(assoc :source-x source-x :source-y source-y)
(doto
(doto
(label! :set-wrap true)
(#(label! % :set-width (min 700 (+ 50 (label! % :get-width)))))
))
(#(label! % :set-width (min (* (+ 1 (* 0.5 (- utils/ui-scale 1))) 700) (+ 50 (label! % :get-width))))))
(#(utils/add-actor-to-stage screen %)))
x (- x (/ (label! talk :get-width) 2))
talk (assoc talk :x x :y y :id id)
talk (ensure-on-screen talk)]
(assoc entities id talk)))
:on-update-camera
(fn [{:keys [scene-viewport scene-camera viewport] :as screen} [ entities]]
:on-update-camera
(fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [scene-viewport scene-camera]}]
(reduce-kv (fn [entities id e]
(if (:id e)
(let [[x y] (scene-world->talk-world scene-viewport [(:source-x e)
@@ -97,11 +97,12 @@
entities))
:stop-talk
(fn [{:keys [id] } [entities]]
(fn [screen entities {:keys [id]}]
(utils/remove-actor-from-stage entities (or id :fg-actions))
(dissoc entities (or id :fg-actions)))
:on-resize (fn [{:keys [viewport width height]} entities]
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update viewport width height)))
(def choice-height 40)
@@ -116,84 +117,119 @@
))
(defn style-label [e font mouse-pos]
(label! e :set-style (style :label font (get-color e mouse-pos)))
(table! (:label e) :set-style (style :label font (get-color e mouse-pos)))
e)
(defn mouse-moved [screen entities options]
(let [[x y] (utils/unproject screen options)
entities (assoc-in entities [:state :last-pos] [x y])
choice-count (dec (count entities))]
(when-let [table (get-in entities [:state :table])]
(doseq [e (get-in entities [:state :labels])]
(style-label e (get-in entities [:state :font]) [x y])))
entities))
(defscreen choice-screen
:on-show
(fn [screen entities]
(fn [screen entities options]
(utils/setup-viewport screen 1280 960)
(let [font (bitmap-font "ego/font.fnt" )
(let [font (bitmap-font "ego/font.fnt" )
tr (bitmap-font! font :get-region)
scale 1
tx (.getTexture tr)
p (NinePatchEntity. (skin! (skin "ui/ui.json") :get-patch "ui-bg"))
scale 1
p (NinePatchEntity. (skin! (skin "ui/ui.json") :get-patch "ui-bg"))
_ (nine-patch! p :set-padding 25 25 5 15)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)]
_ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear)]
{:state {:object nil
:callback nil
:choices []
:last-pos [0 0]
:font font
:np (assoc p
:x 5 :y 5 :width 1270)}}))
:bg p
}}))
:on-pinch
(fn [screen entities {:keys [initial-pointer-1 initial-pointer-2]}]
(assoc-in entities [:state :pinching] true))
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
(.apply viewport)
(when (seq (get-in entities [:state :choices]))
(render! screen [(get-in entities [:state :np])])
(render! screen (vals entities)))
(let [entities (update-in entities [:state :bg]
(fn [bg]
(assoc bg :x 0 :y 0 :width 1280 :height (get-in entities [:state :table :height] 0))
))]
(when (seq (get-in entities [:state :choices]))
(render! screen [(get-in entities [:state :bg])])
(render! screen [(get-in entities [:state :table])])
#_(render! screen (vals entities))))
entities)
:on-present-choices
(fn [{:keys [choices callback]} [entities]]
(fn [screen entities {:keys [choices callback]}]
(let [choice-count (count choices)
font (get-in entities [:state :font])]
font (get-in entities [:state :font])
label-width (- 1280 (* utils/ui-scale 100))
labels (vec (->> (for [[[text] i] (map vector choices (range))]
(assoc
(label text (style :label font (color 0.6 1.0 1.0 1.0)) :set-wrap true :set-alignment Align/bottomLeft
:set-font-scale (* utils/ui-scale 0.25)
:set-width label-width)
:index i
:width label-width))
(map (fn [l] (assoc
(table [[l :width label-width
:pad-bottom (* utils/ui-scale 12)
:pad-top (* utils/ui-scale 12)]])
:label l
:index (:index l))))))]
(-> entities
(into (for [[[text] i] (map vector choices (range))
:let [e (label text (style :label font (color 0.6 1.0 1.0 1.0)) :set-alignment Align/bottomLeft)
e (assoc e :height choice-height :x 30 :y (+ 25 (* choice-height (- choice-count i 1))) :index i)
e (style-label e font (get-in entities [:state :last-pos]))]]
[i (doto e
(label! :set-x (:x e))
(label! :set-y (:y e))
(label! :set-height (:height e))
(label! :set-font-scale 0.25))]))
(assoc-in [:state :choices] choices)
(assoc-in [:state :callback] callback)
(assoc-in [:state :np :height] (* choice-height (inc choice-count))))))
(assoc-in [:state :labels] labels)
(assoc-in [:state :table]
(doto (-> labels
(vertical :align Align/bottomLeft :pad (* utils/ui-scale 20))
:on-touch-up (fn [screen [entities]]
(let [[x y] (utils/unproject screen)]
(when (seq (get-in entities [:state :choices]))
(when-let [choice (first (filter #(utils/intersects? % [x y]) (vals entities)))]
((get-in entities [:state :callback]) (:index choice))
(-> entities
(assoc-in [:state :callback] nil)
(assoc-in [:state :choices] [])
(select-keys [:state]))))))
(#(utils/add-actor-to-stage screen %))
(assoc :x 0 :y 0 :width 1240)
(#(assoc % :height (vertical! % :get-pref-height)))
))))))
:on-mouse-moved (fn [screen [entities]]
(let [[x y] (utils/unproject screen)
entities (assoc-in entities [:state :last-pos] [x y])
choice-count (dec (count entities))]
(doseq [e (vals entities)
:when (:object e)]
(style-label e (get-in entities [:state :font]) [x y]))
entities))
:on-resize (fn [{:keys [width height viewport]} entities]
:on-touch-up (fn [screen entities options]
(let [[x y] (utils/unproject screen options)]
(if (and (seq (get-in entities [:state :choices]))
(not (get-in entities [:state :pinching])))
(when-let [choice (first (filter #(utils/intersects? % [x y]) (get-in entities [:state :labels])))]
(utils/clear-stage screen)
((get-in entities [:state :callback]) (:index choice))
(-> entities
(assoc-in [:state :callback] nil)
(assoc-in [:state :pinching] false)
(assoc-in [:state :choices] [])
(assoc-in [:state :labels] [])
(assoc-in [:state :table] nil)
(select-keys [:state])))
(assoc-in entities [:state :pinching] false))))
:on-mouse-moved mouse-moved
:on-touch-dragged mouse-moved
:on-touch-down mouse-moved
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update viewport width height)))
(defscreen toast-screen
:on-show
(fn [screen entities]
(fn [screen entities options]
(utils/setup-viewport screen 1280 960)
{})
:on-render
(fn [{:keys [camera ^FitViewport viewport] :as screen} [entities]]
(fn [{:keys [camera ^FitViewport viewport] :as screen} entities options]
(.apply viewport)
(let [entities (utils/apply-tweens screen entities (:tweens entities))]
(when (:dialogue entities)
@@ -202,35 +238,157 @@
entities))
:on-toast
(fn [{:keys [message] :as screen} [entities]]
(let [font (bitmap-font "ego/font.fnt" )
p (nine-patch {:region (:object (utils/get-texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9})
_ (nine-patch! p :set-padding 25 25 5 15)
bg (drawable :nine-patch (:object p))
_ (bitmap-font! font :set-markup-enabled true)
(fn [screen entities {:keys [message]}]
(let [font (bitmap-font "ego/font.fnt" )
tr (bitmap-font! font :get-region)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
_ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
style (style :label font (color :red))
[x y] [(/ 1280 2) (/ 960 2)]
talk (label message style :set-alignment Align/center :set-font-scale 0.25)
x (- x (/ (label! talk :get-width) 2))
talk (assoc talk :x x :y y :opacity 1.0)
talk (ensure-on-screen talk)]
(-> entities
#_#_talk (ensure-on-screen talk)]
(utils/add-actor-to-stage screen talk)
(-> entities
(assoc :dialogue talk)
(assoc-in [:tweens :fade-out-toast]
(tween/tween :fade-out-toast screen [:dialogue :opacity] 1.0 0.0 1.0
:finish #(dissoc % :dialogue))))))
:finish #(do
(utils/remove-actor-from-stage entities :dialogue)
(dissoc % :dialogue)))))))
:stop-talk
(fn [{:keys [target-id] } [entities]]
(fn [_ entities {:keys [target-id]}]
(utils/remove-actor-from-stage entities :dialogue)
(dissoc entities :dialogue))
:on-resize (fn [{:keys [viewport width height]} entities]
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update viewport width height)))
(defscreen tooltip-screen
:on-show
(fn [screen entities options]
(let [screen (utils/setup-viewport screen 1280 960)]
(let [font (doto (bitmap-font "label-font.fnt" )
(bitmap-font! :set-use-integer-positions false))
tr (bitmap-font! font :get-region)
_ (.setFilter (.getTexture tr) Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
style (doto (style :label font (color :white))
(#(-> % .font .getData (.setScale (/ utils/ui-scale 4)))))]
{:label (as-> (label "" style) l
(do (label! l :set-alignment (if utils/mobile? Align/bottomLeft Align/center))
(label! l :set-font-scale (* utils/ui-scale 0.25))
l)
(assoc l :x 0 :y 0 :baseline 10000)
(utils/add-actor-to-stage screen l))
:all-icons (texture! (texture (pixmap "cursor.png")) :split 18 16)
:action-icon nil})))
:on-render
(fn [{:keys [camera ^FitViewport viewport] :as screen} entities options]
(.apply viewport)
(let [entities (utils/apply-tweens screen entities (:tweens entities))]
(render! screen [(:label entities) (or (:action-icon entities) (:item-icon entities) )])
entities))
:on-hover-start
(fn [screen {:keys [all-icons] :as entities} {:keys [hover-text x y scene-viewport cursor ]}]
(let [x (if utils/mobile? x (+ 8 x))
[scene-x scene-y] (scene-world->talk-world scene-viewport [x y])
depressed? (< 0.5 (- (or (:total-time screen) 0) (int (or (:total-time screen) 0))))
item-cursor (:cursor (first (:last cursor)))
action-cursor (utils/translate-depressed (first (:last cursor)) depressed?)]
(label! (get-in entities [:label]) :set-text hover-text)
(cond-> entities
true (assoc-in [:label :text] hover-text)
utils/mobile? (update-in [:label] assoc :x (* 52 4 utils/ui-scale) :y 12)
(and utils/mobile? (or item-cursor action-cursor)
(= :main action-cursor))
(assoc :action-icon nil)
item-cursor
(assoc :action-icon nil)
(and utils/mobile? action-cursor (not item-cursor) (not= :main action-cursor))
(assoc-in [:action-icon]
(assoc
;; todo reflection here
(texture (aget all-icons 0 (.indexOf utils/+all-cursors+ (or item-cursor action-cursor))))
:x (* utils/ui-scale 32 4) :y (* utils/ui-scale 4)
:width (* 18 4 utils/ui-scale) :height (* 16 4 utils/ui-scale)))
(not utils/mobile?) (update-in [:label] assoc :x scene-x :y scene-y)
true (update-in [:label] ensure-on-screen))))
:on-select-item
(fn [screen {:keys [all-icons] :as entities} {:keys [selected-item upright? in-or-out hide-or-show notify]}]
(let [fade-tween (if (= :hide hide-or-show)
(tween/tween :appear-item screen [:item-icon :opacity] 1.0 0.0 0.5 :ease tween/ease-linear :finish (fn [entities] (reset! notify true) (dissoc entities :item-icon)))
(tween/tween :appear-item screen [:item-icon :opacity] 0.0 1.0 0.5 :ease tween/ease-linear :finish (fn [entities] (reset! notify true) entities)))
move-tween (condp = in-or-out
:far-out
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 40) (* utils/ui-scale 4 45) 0.5 :ease tween/ease-linear)
:out
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 35) (* utils/ui-scale 4 40) 0.5 :ease tween/ease-linear)
:in
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 40) (* utils/ui-scale 4 35) 0.5 :ease tween/ease-linear)
:none
(tween/tween :appear-item-y screen [:item-icon :x] (* utils/ui-scale 4 40) (* utils/ui-scale 4 40) 0.5 :ease tween/ease-linear))]
(-> entities
(assoc :item-icon
(assoc (texture (aget all-icons 0 (.indexOf utils/+all-cursors+ (:cursor selected-item))))
:origin-x 8
:origin-y 0
:scale-x (* 4 utils/ui-scale)
:scale-y (* 4 utils/ui-scale)
:x (* utils/ui-scale 4 (condp = in-or-out
:in
40
:out
35
:none
40
:far-out
40))
:y 0
:baseline 9000
:opacity (if (= :hide hide-or-show) 1.0 0.0)
:item selected-item))
(assoc-in [:tweens :appear-item] fade-tween)
(assoc-in [:tweens :appear-item-y] move-tween))))
#_#_:on-update-camera
(fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [scene-viewport scene-camera]}]
(reduce-kv (fn [entities id e]
(if (:id e)
(let [[x y] (scene-world->talk-world scene-viewport [(:source-x e)
(:source-y e)])]
(-> entities
(assoc-in [id :x] (- x (/ (label! e :get-width) 2)))
(assoc-in [id :y] y)
(update-in [id] ensure-on-screen)))
entities))
entities
entities))
#_#_:on-hover-end
(fn [screen entities {:keys [id]}]
(utils/remove-actor-from-stage entities (or id :fg-actions))
(dissoc entities (or id :fg-actions)))
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update viewport width height)))

View File

@@ -3,40 +3,47 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[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]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
InputMultiplexer InputProcessor Net Preferences Screen]))
InputMultiplexer InputProcessor Net Preferences Screen]
[com.badlogic.gdx.utils.viewport FitViewport]))
(println "loading " *ns*)
(defscreen fade-screen
:on-show
(fn [screen entities]
(utils/setup-viewport screen 320 240)
{:fade (assoc (utils/get-texture "black.png")
:scale-x 100
:scale-y 100
:x -1
:y -1
:opacity 0.0
:origin-x 0
:origin-y 0)})
(fn [screen entities options]
(let [[screen global-atlas] (utils/acquire-atlas screen "packed/global.atlas")]
(utils/setup-viewport screen 320 240)
{:fade (assoc (utils/atlas->texture global-atlas "black.png")
:scale-x 100
:scale-y 100
:x -1
:y -1
:opacity 1.0
:origin-x 0
:origin-y 0)}))
:on-render
(fn [screen [entities]]
(fn [screen entities options]
(render! screen [(:fade entities)])
entities)
:update-fade (fn [{:keys [opacity]} [entities]]
:on-hide
(fn [screen entities options]
(utils/release-resources screen))
:update-fade (fn [_ entities {:keys [opacity]}]
(assoc-in entities [:fade :opacity] opacity))
:on-resize (fn [{:keys [width height viewport]} entities]
(.update viewport width height)))
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update ^FitViewport viewport width height)))

View File

@@ -4,145 +4,212 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.tools.logging :as log]
[clojure.pprint]
[advent.pathfind]
[advent.actions :as actions]
[advent.zone :as zone]
[advent.tween :as tween]
[advent.utils :as utils])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.utils.viewport FitViewport]
[com.badlogic.gdx.scenes.scene2d.utils Align]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
InputMultiplexer InputProcessor Net Preferences Screen]))
(println "loading " *ns*)
(defn interactable? [entities]
(and (:shown? entities) (= 1.0 (:opacity entities))))
(defn close [screen entities]
(defn close [screen {:keys [selected-item] :as entities} script-started? dragged-out?]
(log/info "closing inventory")
(screen! @(resolve 'advent.screens.scene/scene) :on-reactivate)
(screen! @(resolve 'advent.screens.scene/scene) :on-reactivate { :came-from-inventory? dragged-out?})
(screen! @(resolve 'advent.screens.scene/hud) :on-reactivate { :script-started? script-started? :item selected-item})
(-> entities
(assoc-in [:tweens :fade-out] (tween/tween :fade-out screen [:opacity] 1.0 0.0 0.2 :ease tween/ease-out-cubic
:finish #(assoc % :shown? false)))))
:finish #(assoc % :shown? false :hovered-item nil :selected-item nil)))))
(defn mouse-interact [screen [entities]]
(let [[x y] (utils/unproject 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))))
(defn left-click [screen entities]
(let [{:keys [highlighted-item]} entities
(defn mouse-down [screen entities options]
(when (interactable? entities)
(let [[x y] (utils/unproject screen options)
selected-entity (first (filter #((:box %) x y) (vals (:items entities))))]
(assoc entities :selected-item (:item selected-entity)
:down-time (:total-time screen)))))
(defn mouse-outside-inventory? [[x y]]
(or (< x 140)
(> x 1140)
(< y 320)
(> y 880)))
(defn mouse-drag [screen {:keys [selected-item] :as entities} options]
(when (interactable? entities)
(let [[x y] (utils/unproject screen options)
hovered-entity (first (filter #((:box %) x y) (vals (:items entities))))]
(cond
(and selected-item (mouse-outside-inventory? [x y]))
(close screen entities false true)
selected-item
(-> entities
(assoc-in [:items selected-item :x] x)
(assoc-in [:items selected-item :y] y)
(assoc :dragged? true)
(assoc :hovered-item (:item hovered-entity)))
:else
(assoc entities :hovered-item (:item hovered-entity) :dragged? true)))))
(defn mouse-move [screen entities options]
(let [[x y] (utils/unproject screen options)
hovered-entity (first (filter #((:box %) x y) (vals (:items entities))))]
(assoc entities :hovered-item (:item hovered-entity))))
(defn left-click [screen {:keys [selected-item hovered-item dragged?] :as entities} options]
(let [room-entities (-> @(resolve 'advent.screens.scene/scene)
:entities
deref)]
(log/info "chose inventory item" selected-item)
(println selected-item hovered-item dragged?)
(cond (not selected-item)
(close screen entities false false)
(and
(> (- (:total-time screen) (:down-time entities)) 0.5)
(= selected-item hovered-item)
dragged?)
(dissoc entities :selected-item :hovered-item :dragged?)
(and (or (not hovered-item) (= selected-item hovered-item)))
(do (screen! @(resolve 'advent.screens.scene/scene) :on-chose-item { :item selected-item})
(close screen entities false false))
:else
(when-let [interaction-script (or ((or (:scripts selected-item) (constantly nil)) (:value hovered-item))
(actions/get-script entities (actions/talk entities :ego "I'm not sure how those go together.")))]
(interaction-script room-entities)
(close screen entities true false)))))
(defn right-click [screen {:keys [selected-item] :as entities} options]
(let [
room-entities (-> @(resolve 'advent.screens.scene/scene)
:entities
deref
first)
current-cursor (get-in room-entities [:cursor :current])]
(log/info "chose inventory item" highlighted-item)
(if highlighted-item
(if (= :main current-cursor)
(screen! @(resolve 'advent.screens.scene/scene) :on-chose-item :item highlighted-item)
(when-let [interaction-script ((or (:scripts highlighted-item) (constantly nil)) (:value current-cursor))]
(interaction-script room-entities)
(close screen entities)))
(close screen entities))))
(defn right-click [screen entities]
(let [{:keys [highlighted-item]} entities
room-entities (-> @(resolve 'advent.screens.scene/scene)
:entities
deref
first)
current-cursor (get-in room-entities [:cursor :current])
)
ego (get-in room-entities [:room :entities :ego])]
(when (and highlighted-item (= :main current-cursor))
(((:get-script ego) highlighted-item [0 0]) room-entities)
(close screen entities))))
(when selected-item
(((:get-script ego) selected-item [0 0]) room-entities)
(close screen entities true false))))
(defn update-hovered-text [screen {:keys [hovered-text hovered-item selected-item] :as entities}]
(cond
(and hovered-item selected-item (not= hovered-item selected-item))
(label! (:hovered-text entities) :set-text (str "Use " (:name selected-item) " with " (:name hovered-item)))
hovered-item
(label! (:hovered-text entities) :set-text (:name hovered-item))
:else
(label! (:hovered-text entities) :set-text "")))
(defscreen inventory-screen
:on-show
(fn [screen entities]
(utils/setup-viewport screen 1280 960)
(let [highlighted-text (assoc (label "Hello" (style :label (utils/get-font "ego/font.fnt") (color :white)) :set-font-scale 0.25) :x 0 :y 850 :width 1280 )]
(label! highlighted-text :set-alignment Align/bottom)
{:overlay (assoc (utils/get-texture "inventory-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :opacity 0.0)
:fade (assoc (utils/get-texture "black.png")
(fn [screen entities options]
(let [[screen atlas] (utils/acquire-atlas screen "packed/global.atlas")
screen (utils/setup-viewport screen 1280 960)
hovered-text (assoc (label "" (style :label (utils/get-font "ego/font.fnt") (color :white)) :set-font-scale 0.25) :x 0 :y 850 :width 1280 )]
(label! hovered-text :set-alignment Align/bottom)
(utils/add-actor-to-stage screen hovered-text)
{:overlay (assoc (utils/atlas->texture atlas "inventory-overlay" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :opacity 0.0)
:fade (assoc (utils/atlas->texture atlas "black.png")
:scale-x 80
:scale-y 80
:scale-y 80
:opacity 0.7
:origin-x 0
:origin-y 0)
:all-items (texture! (texture (pixmap "cursor.png")) :split 18 16)
:items []
:shown? false
:highlighted-item nil
:hovered-item nil
:opacity 0.0
:tweens {}
:highlighted-text highlighted-text}))
:tweens {}
:hovered-text hovered-text}))
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
(fn [{:keys [^FitViewport viewport] :as screen} {:keys [shown? tweens] :as entities} options]
(.apply viewport)
(let [
entities (utils/apply-tweens screen entities (:tweens entities))
(let [entities (utils/apply-tweens screen entities tweens)
opacity (get-in entities [:opacity])
entities (-> entities
(assoc-in [:overlay :opacity] opacity)
(assoc-in [:fade :opacity] (* 0.6 opacity))
(assoc-in [:highlighted-text :opacity] opacity)
(update-in [:items] (fn [i]
(map #(assoc % :opacity opacity) i))))]
(when (:shown? entities)
(doto (:highlighted-text entities)
(assoc-in [:hovered-text :opacity] opacity)
(update-in [:items] (fn [items]
(reduce-kv (fn [c k i]
(assoc c k (assoc i :opacity opacity)))
items items))))]
(when shown?
(doto (:hovered-text entities)
(label! :set-color (color 1 1 1 opacity)))
(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)]))
(render! screen (vals (:items entities)))
(render! screen [(get-in entities [:items (:selected-item entities)])])
(update-hovered-text screen entities)
(render! screen [(:hovered-text entities)]))
entities))
:show-screen (fn [{items :items :as screen} [entities]]
:show-screen (fn [screen entities {:keys [items]}]
(log/info "showing inventory")
(if (:shown? entities)
entities
(when-not (:shown? entities)
(label! (entities :hovered-text) :set-text "")
(-> entities
(assoc-in [:hovered-text :text] "")
(assoc :shown? true
:opacity 0.0
:items (for [[item index] (map vector items (range))
:let [row (int (/ index 8))
column (mod index 8)
base-x (* 79 4)
base-y (* 180 4)
x (+ base-x (* column (* 24 4)))
y (- base-y (* row (* 24 4)))
item-width 18
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+ (:cursor item))))
:x x :y y
:scale-x 4
:scale-y 4
:origin-x 0
:origin-y 0
:item item
:box (zone/box (- offset-x padding) (- offset-y padding) (+ offset-x item-width padding padding) (+ offset-y item-width padding padding)))))
:items (into {} (for [[item index] (map vector items (range))
:let [row (int (/ index (Math/floor (/ 8 utils/ui-scale))))
column (mod index (Math/floor (/ 8 utils/ui-scale)))
base-x (* 79 4)
base-y (* 180 4)
item-width (* utils/ui-scale 4 18)
padding (/ item-width 4)
item-height (* utils/ui-scale 4 16)
padding-height (/ item-height 4)
x (+ base-x (* column (+ padding item-width)))
y (- base-y (* row (+ padding item-width)))
offset-x (+ x (/ item-width 2))
offset-y (+ y (/ item-width 2))
padded-width (/ (+ item-width padding padding) 2)
padded-height (/ (+ item-height padding-height padding-height) 2)
#_#_padding (* 4 padding)]]
[item (assoc (texture (aget (:all-items entities) 0 (.indexOf utils/+all-cursors+ (:cursor item))))
:x (+ x (/ padding 2)) :y y
:scale-x (* utils/ui-scale 4)
:scale-y (* utils/ui-scale 4)
:origin-x 9
:origin-y 8
:item item
:box (zone/box (- x padded-width) (- y padded-height) (+ x padded-width) (+ y padded-height)))])))
(assoc-in [:tweens :fade-in] (tween/tween :fade-in screen [:opacity] 0.0 1.0 0.2 :ease tween/ease-out-cubic)))))
:on-mouse-moved mouse-interact
:on-touch-down mouse-interact
:on-mouse-moved mouse-move
:on-touch-dragged mouse-drag
:on-touch-down mouse-down
:on-touch-up (fn [screen [entities]]
(when (and (:shown? entities) (= 1.0 (:opacity entities)))
(if (= (button-code :left) (:button screen))
(left-click screen entities)
(right-click screen entities))))
:on-touch-up (fn [screen entities options]
(when (interactable? entities)
(if (= (button-code :left) (:button options))
(left-click screen entities options)
(right-click screen entities options))))
:on-resize (fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [width height]}]
(.update viewport width height true))
:on-hide (fn [screen entities options]
(utils/release-resources screen)))
:on-resize (fn [screen entities]
(.update (:viewport screen) (:width screen) (:height screen) true)))

View File

@@ -1,62 +1,63 @@
(ns advent.screens.items
(:require [advent.actions :as actions]))
(println "loading " *ns*)
(def make-cat-toy
(actions/get-script entities
(actions/remove-item entities :stick)
(actions/remove-item entities :wool)
(actions/remove-item entities :stick :quiet? true)
(actions/remove-item entities :wool :quiet? true)
(actions/give entities :cat-toy)
(actions/talk entities :ego "It makes a little cat toy!")))
(defn make-cream-of-mushroom [entities]
(actions/remove-item entities :flask-1-with-mushrooms)
(actions/remove-item entities :flask-1-with-milk)
(actions/remove-item entities :mushrooms)
(actions/remove-item entities :flask-1-with-mushrooms :quiet? true)
(actions/remove-item entities :flask-1-with-milk :quiet? true)
(actions/remove-item entities :mushrooms :quiet? true)
(actions/give entities :flask-1-with-cream-of-mushroom)
(actions/talk entities :ego "It's just like cream of mushroom soup."))
(defn add-slobber []
(actions/get-script entities
(actions/remove-item entities :flask-1-with-cream-of-mushroom)
(actions/remove-item entities :slobber)
(actions/remove-item entities :flask-1-with-cream-of-mushroom :quiet? true)
(actions/remove-item entities :slobber :quiet? true)
(actions/give entities :flask-1-slobber)
(actions/talk entities :ego "I put the slobber in with the cream of mushroom.")))
(defn make-strength-potion []
(actions/get-script entities
(actions/remove-item entities :flask-1-slobber)
(actions/remove-item entities :mandrake)
(actions/remove-item entities :flask-1-slobber :quiet? true)
(actions/remove-item entities :mandrake :quiet? true)
(actions/give entities :flask-1-strength)
(actions/talk entities :ego "It's the completed strength potion!")
(actions/glad entities)))
(defn make-water-and-ash [entities]
(actions/remove-item entities :flask-water)
(actions/remove-item entities :ash)
(actions/remove-item entities :flask-water :quiet? true)
(actions/remove-item entities :ash :quiet? true)
(actions/give entities :flask-water-ash)
(actions/talk entities :ego "I added the ashes to the water."))
(defn make-water-and-flies [entities]
(actions/remove-item entities :flask-water)
(actions/remove-item entities :flies)
(actions/remove-item entities :flask-water :quiet? true)
(actions/remove-item entities :flies :quiet? true)
(actions/give entities :flask-water-flies)
(actions/talk entities :ego "I put those flies in the flask."))
(defn make-flies-ash [entities]
(actions/remove-item entities :flask-water)
(actions/remove-item entities :flask-water-ash)
(actions/remove-item entities :flask-water-flies)
(actions/remove-item entities :ash)
(actions/remove-item entities :flies)
(actions/remove-item entities :flask-water :quiet? true)
(actions/remove-item entities :flask-water-ash :quiet? true)
(actions/remove-item entities :flask-water-flies :quiet? true)
(actions/remove-item entities :ash :quiet? true)
(actions/remove-item entities :flies :quiet? true)
(actions/give entities :flask-flies-ash)
(actions/talk entities :ego "Now it's got the fountain water, flies, and the ashes in it."))
(defn make-finished-component [entities]
(actions/talk entities :ego "I'll just mix this up.")
(actions/remove-item entities :flask-flies-ash)
(actions/remove-item entities :feather)
(actions/remove-item entities :flask-flies-ash :quiet? true)
(actions/remove-item entities :feather :quiet? true)
(actions/play-animation entities :ego :reach)
(actions/give entities :spell-component)
(actions/talk entities :ego "It looks like it's ready!"))
@@ -64,8 +65,8 @@
(defn add-mushrooms-to-flask []
(actions/get-script entities
(if (actions/has-item? entities :recipe)
(do (actions/remove-item entities :flask-1)
(actions/remove-item entities :mushrooms)
(do (actions/remove-item entities :flask-1 :quiet? true)
(actions/remove-item entities :mushrooms :quiet? true)
(actions/give entities :flask-1-with-mushrooms)
(actions/talk entities :ego "I'll just put a few of these in here."))
(actions/talk entities :ego "I don't know if I could get them back out."))))

View File

@@ -1,45 +1,72 @@
(ns advent.screens.rooms
(:require [advent.zone :as zone])
(:require [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.utils.viewport FitViewport]
[com.badlogic.gdx.scenes.scene2d Actor Stage]
[java.lang Object]))
(println "loading " *ns*)
(defn make-entity [id entity]
(defn make-entity [id {:keys [scripts script only-script] :as entity}]
(merge entity
{:id id
:mouse-in? (fn [entities x y]
(let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id])
(let [e (utils/get-entity entities id)]
(if-let [[bx1 by1 bx2 by2] (:box e)]
(zone/within bx1 by1 bx2 by2 x y)
(let [{^float entity-x :x ^float entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (-> entities :room :entities id)
width (or width (if (instance? TextureRegion region ) (.getRegionWidth ^TextureRegion region) 0))
height (or height (if (instance? TextureRegion region ) (.getRegionHeight ^TextureRegion region) 0))
entity-x (double (unchecked-add (float entity-x) (unchecked-multiply (float -1.0)
(unchecked-multiply (float (or origin-x 0))
(float (or scale-x 1))))))
entity-y (double (unchecked-add (float entity-y) (unchecked-multiply
(float -1.0)
(unchecked-multiply (float (or origin-y 0))
(float (or scale-y 1))))))]
width (or width (if (instance? TextureRegion region ) (.getRegionWidth region) 0))
height (or height (if (instance? TextureRegion region ) (.getRegionHeight region) 0))
entity-x (- entity-x (* (or origin-x 0)
(or scale-x 1)))
entity-y (- entity-y (* (or origin-y 0)
(or scale-y 1)))]
((zone/box entity-x entity-y
(+ entity-x (* width (or scale-x 1)))
(+ entity-y (* height (or scale-y 1)))) x y)))}
(when (or (:scripts entity) (:script entity))
(zone/within entity-x entity-y
(unchecked-add (float entity-x) (unchecked-multiply (float width) (float (or scale-x 1))))
(unchecked-add (float entity-y) (unchecked-multiply (float height) (float (or scale-y 1))))
x y)))))}
(when (or script scripts only-script)
{:get-script (fn [cursor [x y]]
(if (= :main cursor)
(:script entity)
(when-let [scripts (:scripts entity)]
(or (scripts (:value cursor)) (scripts :default)))))})))
(cond only-script
only-script
(= :main cursor)
script
scripts
(or (scripts (:value cursor)) (scripts :default))
:else
nil)
)})))
(defn make [& {:keys [collision interactions entities] :as params}]
(let [interactions-as-list (for [[id spec] interactions]
(let [interactions-as-list (for [[id {:keys [script scripts only-script box] :as spec}] interactions]
(merge spec
(when (:box spec)
(when box
{:mouse-in? (fn [_ x y]
((apply zone/box (:box spec)) x y))})
{:get-script (fn [cursor [x y]]
(if (= :main cursor)
(:script spec)
(when-let [scripts (:scripts spec)]
(or (scripts (:value cursor)) (scripts :default)))))
:id id}))
(let [[bx1 by1 bx2 by2] box]
(zone/within bx1 by1 bx2 by2 x y)))})
(when (or script scripts only-script)
{:get-script (fn [cursor [x y]]
(cond only-script
only-script
(= :main cursor)
script
scripts
(or (scripts (:value cursor)) (scripts :default))
:else
nil)
)})
{:id id}))
entities (into {} (for [[id entity] entities]
[id (make-entity id entity)]))]
(merge params {:collision (advent.pathfind/map-from-resource collision)

View File

@@ -11,13 +11,14 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all])
)
(println "loading behindhouse")
(defn make-night [entities]
(assoc-in entities [:room :entities :peeling :opacity] 0))
(defn make-left-dir [box]
{:box box
:script (actions/get-script
:only-script (actions/get-script
entities
(actions/walk-to entities :ego [122 140] :skip-type :end)
(actions/transition-background entities :outside-house [244 150])
@@ -28,9 +29,8 @@
(actions/update-state entities
(fn [state] (assoc state :safe-listen-count (inc (:safe-listen-count state 0))))))
(defn make [screen]
(rooms/make :music {:day :town-2 :night :night}
:name "Behind house"
(defn make [screen atlas global-atlas]
(rooms/make :name "Behind house"
:interactions
{:left-dir-1 (make-left-dir [0 48 20 240])
:left-dir-2 (make-left-dir [0 160 148 217])
@@ -42,6 +42,8 @@
entities
)}
:mushrooms {:box [247 59 269 76]
:label "Mushrooms"
:cursor :hand
:script (actions/get-script
entities
(if (actions/has-obtained? entities :mushrooms)
@@ -52,116 +54,122 @@
(actions/give entities :mushrooms)
(actions/talk entities :ego "Perfectly ripe mushrooms!"))))}
:window {:box [109 100 130 153]
:label "Window"
:cursor :look
:script (actions/get-script
entities
(actions/walk-to entities :ego [128 100] :face :left)
(cond
(= :night (get-in @entities [:state :time]))
(actions/do-dialogue entities :ego "The house is dark and empty.")
(= :night (get-in @entities [:state :time]))
(actions/do-dialogue entities :ego "The house is dark and empty.")
(actions/has-obtained? entities :tune)
(actions/do-dialogue entities
:ego "Gandarf's just working on one of his spells.")
(actions/has-obtained? entities :tune)
(actions/do-dialogue entities
:ego "Gandarf's just working on one of his spells.")
(get-in @entities [:state :peeked-in-window?])
(actions/do-dialogue entities
:ego "Gandarf is moving around in the corner of the room."
:ego "I think he's opening his MagiSafe!"
:ego "I'll need a better spying angle if I hope to crack the safe.")
(get-in @entities [:state :peeked-in-window?])
(actions/do-dialogue entities
:ego "Gandarf is moving around in the corner of the room."
:ego "I think he's opening his MagiSafe!"
:ego "I'll need a better spying angle if I hope to crack the safe.")
:else
(do
(actions/do-dialogue entities
:ego "I can see Gandarf moving around in the corner of the room."
:ego "It's hard to make out from this angle.")
(actions/update-state entities #(assoc % :peeked-in-window? true)))))}}
:layers {:day [(assoc (utils/get-texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "behindhouse/house.png") :x 0 :y 0 :baseline 122)
(assoc (utils/get-texture "behindhouse/brush.png") :x 0 :y 0 :baseline 240)
(assoc (utils/get-texture "behindhouse/fgleft.png") :x -10 :y 0 :baseline 240 :parallax 1.5)
(assoc (utils/get-texture "behindhouse/fg2.png") :x (- 320 122) :y 0 :baseline 240 :parallax 1.5)]
:night [(assoc (utils/get-texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "behindhouse/house.png") :x 0 :y 0 :baseline 122)
(assoc (utils/get-texture "behindhouse/brush.png") :x 0 :y 0 :baseline 240)
(assoc (utils/get-texture "behindhouse/fgleft.png") :x -10 :y 0 :baseline 240 :parallax 1.5)
(assoc (utils/get-texture "behindhouse/fg2.png") :x (- 320 122) :y 0 :baseline 240 :parallax 1.5)]}
:entities {:stick (assoc (utils/get-texture "behindhouse/stick.png")
:x 26 :y 80 :baseline 160
:script (actions/get-script entities
(actions/walk-to entities :ego [50 80])
(actions/play-animation entities :ego :reach)
(actions/remove-entity entities :stick)
(actions/give entities :stick)
(actions/talk entities :ego "This stick might be useful.")))
:else
(do
(actions/do-dialogue entities
:ego "I can see Gandarf moving around in the corner of the room."
:ego "It's hard to make out from this angle.")
(actions/update-state entities #(assoc % :peeked-in-window? true)))))}}
:layers {:day [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "house") :x 0 :y 0 :baseline 122)
(assoc (utils/atlas->texture atlas "brush") :x 0 :y 0 :baseline 240)
(assoc (utils/atlas->texture atlas "fgleft") :x -10 :y 0 :baseline 240 :parallax 1.5)
(assoc (utils/atlas->texture atlas "fg2") :x (- 320 122) :y 0 :baseline 240 :parallax 1.5)]
:night [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "house") :x 0 :y 0 :baseline 122)
(assoc (utils/atlas->texture atlas "brush") :x 0 :y 0 :baseline 240)
(assoc (utils/atlas->texture atlas "fgleft") :x -10 :y 0 :baseline 240 :parallax 1.5)
(assoc (utils/atlas->texture atlas "fg2") :x (- 320 122) :y 0 :baseline 240 :parallax 1.5)]}
:entities {:stick (assoc (utils/atlas->texture atlas "stick")
:x 26 :y 80 :baseline 160
:label "Stick"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [50 80])
(actions/play-animation entities :ego :reach)
(actions/remove-entity entities :stick)
(actions/give entities :stick)
(actions/talk entities :ego "This stick might be useful.")))
:peeling (assoc (utils/get-texture "behindhouse/house-cover.png")
:x 60 :y 92 :baseline 148
:script (actions/get-script entities
(cond (= :night (get-in @entities [:state :time]))
(actions/talk entities :ego "The house is empty right now.")
:peeling (assoc (utils/atlas->texture atlas "house-cover")
:x 60 :y 92 :baseline 148
:label "Crumbly wall"
:cursor :hand
:script (actions/get-script entities
(cond (= :night (get-in @entities [:state :time]))
(actions/talk entities :ego "The house is empty right now.")
(and (get-in @entities [:state :opened-crack?])
(= 0 (get-in @entities [:state :safe-listen-count] 0)))
(and (get-in @entities [:state :opened-crack?])
(= 0 (get-in @entities [:state :safe-listen-count] 0)))
(do (actions/walk-to entities :ego [70 80])
(actions/play-animation entities :ego :start-squat :stop? false)
(actions/talk entities :ego "I can see Gandarf the wizard inside." :animate? false :stop? false)
(actions/talk entities :ego "It looks like he's opening his MagiSafe." :animate? false :stop? false)
(actions/play-safe entities false)
(actions/talk entities :ego "So that's the code to his safe..." :animate? false :stop? false)
(actions/play-animation entities :ego :end-squat)
(actions/talk entities :ego "A lot of good it'll do me to know his password while he's still there.")
(steam/set-achievement "SAFE_AND_SOUND")
(increment-safe-listens entities))
(do (actions/walk-to entities :ego [70 80])
(actions/play-animation entities :ego :start-squat :stop? false)
(actions/talk entities :ego "I can see Gandarf the wizard inside." :animate? false :stop? false)
(actions/talk entities :ego "It looks like he's opening his MagiSafe." :animate? false :stop? false)
(actions/play-safe entities false)
(actions/talk entities :ego "So that's the code to his safe..." :animate? false :stop? false)
(actions/play-animation entities :ego :end-squat)
(actions/talk entities :ego "A lot of good it'll do me to know his password while he's still there.")
(steam/set-achievement "SAFE_AND_SOUND")
(increment-safe-listens entities))
(and (get-in @entities [:state :opened-crack?])
(= 1 (get-in @entities [:state :safe-listen-count] 0)))
(and (get-in @entities [:state :opened-crack?])
(= 1 (get-in @entities [:state :safe-listen-count] 0)))
(do (actions/walk-to entities :ego [70 80])
(actions/talk entities :ego "I'll give it another listen.")
(actions/play-animation entities :ego :start-squat :stop? false)
(actions/talk entities :ego "It looks like Gandarf's opening his MagiSafe." :animate? false :stop? false)
(actions/play-safe entities false)
(actions/play-animation entities :ego :end-squat)
(actions/talk entities :ego "Ugh! Now I've got it stuck in my head!")
(increment-safe-listens entities)
(actions/give entities :tune))
(do (actions/walk-to entities :ego [70 80])
(actions/talk entities :ego "I'll give it another listen.")
(actions/play-animation entities :ego :start-squat :stop? false)
(actions/talk entities :ego "It looks like Gandarf's opening his MagiSafe." :animate? false :stop? false)
(actions/play-safe entities false)
(actions/play-animation entities :ego :end-squat)
(actions/talk entities :ego "Ugh! Now I've got it stuck in my head!")
(increment-safe-listens entities)
(actions/give entities :tune))
(get-in @entities [:state :opened-crack?])
(actions/talk entities :ego "I've got the tune stuck in my head already.")
(get-in @entities [:state :opened-crack?])
(actions/talk entities :ego "I've got the tune stuck in my head already.")
:else
(do (actions/walk-to entities :ego [80 80] :face :left)
(actions/talk entities :ego "It looks like the wall is crumbling here.")
(actions/play-animation entities :ego :reach)
(actions/update-entity entities :peeling #(assoc % :opacity 0))
(actions/update-state entities (fn [state] (assoc state :opened-crack? true))))))
:scripts {:stick (actions/get-script entities
(if (get-in @entities [:state :opened-crack?])
(actions/talk entities :ego "I could shove the stick in that hole, but why?")
(actions/do-dialogue entities
:ego "It looks like that wall is crumbling."
:ego "I can probably scratch it off with my hand.")))
:sword (actions/get-script entities
(actions/do-dialogue entities
:ego "I should be careful with this sword."
:ego "It's sharp!"))})
:bird (utils/make-bird screen [[50 235] [80 220] [100 239] [180 235] [85 225]])
:else
(do (actions/walk-to entities :ego [80 80] :face :left)
(actions/talk entities :ego "It looks like the wall is crumbling here.")
(actions/play-animation entities :ego :reach)
(actions/update-entity entities :peeling #(assoc % :opacity 0))
(actions/update-state entities (fn [state] (assoc state :opened-crack? true))))))
:scripts {:stick (actions/get-script entities
(if (get-in @entities [:state :opened-crack?])
(actions/talk entities :ego "I could shove the stick in that hole, but why?")
(actions/do-dialogue entities
:ego "It looks like that wall is crumbling."
:ego "I can probably scratch it off with my hand.")))
:sword (actions/get-script entities
(actions/do-dialogue entities
:ego "I should be careful with this sword."
:ego "It's sharp!"))})
:bird (utils/make-bird screen global-atlas [[50 235] [80 220] [100 239] [180 235] [85 225]])
:outside-particles (common/make-outside-particles)}
:collision "behindhouse/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00)
:apply-state (fn [_ entities]
(utils/fast-forward-particle (get-in entities [:room :entities :outside-particles]))
(as-> entities entities
(if (get-in entities [:state :opened-crack?])
(assoc-in entities [:room :entities :peeling :opacity] 0)
entities)
(if (actions/has-obtained? entities :stick)
(update-in entities [:room :entities] #(dissoc % :stick))
entities)
(if (= :night (get-in entities [:state :time]))
(make-night entities)
entities)))
(if (get-in entities [:state :opened-crack?])
(assoc-in entities [:room :entities :peeling :opacity] 0)
entities)
(if (actions/has-obtained? entities :stick)
(update-in entities [:room :entities] #(dissoc % :stick))
entities)
(if (= :night (get-in entities [:state :time]))
(make-night entities)
entities)))
:start-pos [172 122]))

View File

@@ -16,15 +16,18 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn make-night [entities]
entities)
(defn make-coin-flip [screen]
(let [coin-flip (utils/make-anim "castle-gate/coinflip.png" [10 10] 0.05 (range 5))]
(defn make-coin-flip [screen atlas]
(let [coin-flip (utils/make-anim atlas "coinflip" [10 10] 0.05 (range 5))]
(assoc (animation->texture screen coin-flip)
:x 212 :y 114 :baseline 151
:opacity 0.0
:label "Coin"
:cursor :hand
:origin-x 5
:origin-y 5
:night-profile :none
@@ -38,10 +41,12 @@
:walk coin-flip
:coinflip coin-flip)))
(defn make-goon-1 [screen]
(let [stand (utils/make-anim "castle-gate/goon-1.png" [13 33] 0.21 [0 0 0 0 0 0 0 0 0 1])]
(defn make-goon-1 [screen atlas]
(let [stand (utils/make-anim atlas "goon-1" [13 33] 0.21 [0 0 0 0 0 0 0 0 0 1])]
(assoc (animation->texture screen stand)
:x 244 :y 102 :baseline 138
:label "Goon"
:cursor :talk
:scale-x 1.4
:scale-y 1.4
:night-profile :sprite
@@ -49,18 +54,21 @@
:anim-start 0
:stand stand)))
(defn make-goon-2 [screen]
(let [stand (utils/make-anim "castle-gate/goon-2.png" [12 32] 0.175 [0 0 0 0 0 0 0 0 0 0 0 0 0 1])
talk (utils/make-anim "castle-gate/goon-2-talk.png" [12 32] 0.175 (range 2))
flip (utils/make-anim "castle-gate/goon-2-flip.png" [12 32] 0.05 [1 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ])
search (utils/make-anim "castle-gate/goon-2-search.png" [24 32] 0.3 [0 1 2 3 2 3 2 1 4 5 6 5 6 7 6 7 6 7 6 1 0])
walk (utils/flip (utils/make-anim "castle-gate/goon-2-walk.png" [24 34] 0.075 (range 7)))]
(defn make-goon-2 [screen atlas]
(let [
stand (utils/make-anim atlas "goon-2" [12 32] 0.175 [0 0 0 0 0 0 0 0 0 0 0 0 0 1])
talk (utils/make-anim atlas "goon-2-talk" [12 32] 0.175 (range 2))
flip (utils/make-anim atlas "goon-2-flip" [12 32] 0.05 [1 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ])
search (utils/make-anim atlas "goon-2-search" [24 32] 0.3 [0 1 2 3 2 3 2 1 4 5 6 5 6 7 6 7 6 7 6 1 0])
walk (utils/flip (utils/make-anim atlas "goon-2-walk" [24 34] 0.075 (range 7)))]
(assoc (animation->texture screen stand)
:x 214 :y 102 :baseline 151
:scale-x 1.4
:scale-y 1.4
:origin-x 6
:origin-y 0
:label "Bubba"
:cursor :talk
:anim stand
:talk talk
:flip flip
@@ -91,7 +99,7 @@
(assoc-in [:room :entities :coin-flip :opacity] 1.0))))
(actions/walk-straight-to entities :coin-flip [212 90] :update-baseline? false :speed 3.0)
(screen! dialogue/talking-screen :stop-talk)
(screen! dialogue/talking-screen :stop-talk {})
(actions/do-stop entities :ego)
(actions/walk-straight-to entities :coin-flip [210 105] :update-baseline? false :speed 1.0)
@@ -127,6 +135,7 @@
(actions/walk-to entities :ego [245 90] :skip-type :end))
(defn flip-coin [screen entities]
(println "here")
(if (and (= 0 (rand-int 2))
(not (get-in entities [:state :has-dropped-coin?]))
(not (get-in entities [:state :bubba-gone?]))
@@ -182,16 +191,18 @@
(defn make-note []
{:box [97 102 111 132]
:label "Note"
:cursor :look
:script (actions/get-script entities
(look-at-note entities))
:scripts {:charcoal (actions/get-script entities
(sign-note entities))}})
(defn make [screen]
(let [throw-walkie (utils/make-anim-seq "castle-gate/throw-walkie" [205 136] 0.1 (flatten [(repeat 55 0) (range 9) (repeat 55 8)]))
walkie-visible (animation 1.0 [(utils/get-texture "castle-gate/throw-walkie-9.png")])
walkie-invisible (animation 1.0 [(utils/get-texture "castle-gate/throw-walkie-1.png")])]
(rooms/make :music {:day :town-2 :night :night}
(defn make [screen atlas global-atlas]
(let [throw-walkie (utils/make-anim-seq atlas "throw-walkie" [205 136] 0.1 (flatten [(repeat 55 0) (range 9) (repeat 55 8)]))
walkie-visible (animation 1.0 [(utils/atlas->texture atlas "throw-walkie" 8)])
walkie-invisible (animation 1.0 [(utils/atlas->texture atlas "throw-walkie" 0)])]
(rooms/make
:name "Castle gate"
:timers {:taunt [1.0 6.0 flip-coin]}
:interactions {:right-dir {:box [280 40 320 83]
@@ -207,6 +218,8 @@
:cursor :left}
:window {:box [192 157 215 215]
:label "Window"
:cursor :look
:script (actions/get-script entities
(actions/talk entities :ego "That's a big window!"))
:scripts {:walkie-talkies (actions/get-script entities
@@ -223,15 +236,15 @@
(actions/walk-straight-to entities :ego [285 71]))}}
:note (make-note)}
:layers {:day [(assoc (utils/get-texture "castle-gate/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "castle-gate/overlay.png") :x 0 :y 0 :baseline 240)]
:night [(assoc (utils/get-texture "castle-gate/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "castle-gate/overlay.png") :x 0 :y 0 :baseline 240)]}
:entities {:frankie (common/make-frankie screen)
:goon-1 (make-goon-1 screen)
:goon-2 (make-goon-2 screen)
:layers {:day [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "overlay") :x 0 :y 0 :baseline 240)]
:night [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "overlay") :x 0 :y 0 :baseline 240)]}
:entities {:frankie (common/make-frankie screen global-atlas)
:goon-1 (make-goon-1 screen atlas)
:goon-2 (make-goon-2 screen atlas)
:outside-particles (common/make-outside-particles)
:coin-flip (make-coin-flip screen)
:coin-flip (make-coin-flip screen atlas)
}
:walkie-talkies (rooms/make-entity :walkie-talkies
(assoc (animation->texture screen walkie-visible)
@@ -260,8 +273,7 @@
(if (and (not (actions/has-obtained? entities :money))
(get-in entities [:state :has-dropped-coin?]))
(do
(update-in entities [:room :entities :coin-flip] assoc :x 185 :y 44 :opacity 1.0))
(do (update-in entities [:room :entities :coin-flip] assoc :x 185 :y 44 :opacity 1.0))
entities)
(if (actions/has-obtained? entities :money)
(update-in entities [:room :entities] dissoc :coin-flip)

View File

@@ -11,6 +11,9 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn get-down [entities & break]
(actions/walk-straight-to entities :ego [151 50] :update-baseline? false :face :left)
@@ -244,6 +247,8 @@
:ego "Thanks, I guess."))
(defn make-ladder-area [box]
{:box box
:cursor :hand
:label "Tree"
:script (actions/get-script entities
(actions/walk-to entities :ego [144 58] )
(actions/talk entities :ego "Maybe I can climb it!")
@@ -260,57 +265,58 @@
(actions/walk-straight-to entities :ego [140 85] :face :right :update-baseline? false)
(actions/add-entity entities :blank (get-in @entities [:room :blank])))}})
(defn make [screen]
(let [cat-stand-sheet (texture! (utils/get-texture "cat-tree/cat-stand.png") :split 22 10)
(defn make [screen atlas global-atlas]
(let [cat-stand-sheet (texture! (utils/atlas->texture atlas "cat-stand") :split 22 10)
cat-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0 0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0])]
(aget cat-stand-sheet 0 i)))
cat-walk (animation 0.2 [(utils/get-texture "cat-tree/pounce.png")])
destroy-ladder (utils/make-anim "cat-tree/destroy-ladder.png" [29 38] 0.1 (range 18))
ladder-entity (assoc (utils/get-texture "inside-cafeteria/ladder.png") :x 130 :y 60 :baseline 162
cat-walk (animation 0.2 [(utils/atlas->texture atlas "pounce")])
destroy-ladder (utils/make-anim atlas "destroy-ladder" [29 38] 0.1 (range 18))
ladder-entity (assoc (utils/atlas->texture atlas "ladder") :x 130 :y 60 :baseline 162
:origin-x 0
:destroy-ladder destroy-ladder
:ladder-break-sound (utils/load-sound "cat-tree/ladder-break.ogg")
:anim-sound-frames {destroy-ladder {4 [:ladder-break-sound 0.6]}})
grandma-stand (utils/make-anim "cat-tree/grandma.png" [25 36] 0.2 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
grandma-squat-1 (utils/make-anim "cat-tree/grandma.png" [25 36] 0.2 [3 4 5 5 5 5 5])
grandma-squat-2 (utils/make-anim "cat-tree/grandma.png" [25 36] 0.2 [5 5 4 3])
grandma-talk (utils/make-anim "cat-tree/grandma.png" [25 36] 0.2 [0 2 0 2 0 2 0 2 0 2 0 1 0 2 0 0])
grandma-kiss (utils/make-anim "cat-tree/grandma.png" [25 36] 0.2 [0 8 9 10 9 10 9 10 9 8 0])
grandma-cry (utils/make-anim-seq "cat-tree/grandma-cry" [58 40] 0.15 (flatten [(range 20) 0 0 0 0 0 0 0 0 0]))
owl-stand (utils/make-anim "cat-tree/owl.png" [21 30] 0.2 [0 0 0 0 0 0 0 2])
owl-talk (utils/make-anim "cat-tree/owl.png" [21 30] 0.2 [1 0 1 0 1 0 0 0 2 0])
owl-puke (utils/make-anim "cat-tree/owl.png" [21 30] 0.10 [0 0 2 2 3 2 2 3 3 2 3 3 3 4 5 6 7 4 4 3 3 2 2 2 2 2])
owl-eye (utils/make-anim-seq "cat-tree/eye" [44 48] 0.10 [0 0 1 1 2 2 2 2 2 2 2 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 3 4 4 4 3 4 4 4 5 6 7 8 9 9 9 9 9 9 9 9 9 10 11 12 12 11 10 9 9 9 9 9 9 9 9 10 11 12 12 12 11 10 9 9 9 9 9 8 7 6 5])
grandma-stand (utils/make-anim atlas "grandma" [25 36] 0.2 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
grandma-squat-1 (utils/make-anim atlas "grandma" [25 36] 0.2 [3 4 5 5 5 5 5])
grandma-squat-2 (utils/make-anim atlas "grandma" [25 36] 0.2 [5 5 4 3])
grandma-talk (utils/make-anim atlas "grandma" [25 36] 0.2 [0 2 0 2 0 2 0 2 0 2 0 1 0 2 0 0])
grandma-kiss (utils/make-anim atlas "grandma" [25 36] 0.2 [0 8 9 10 9 10 9 10 9 8 0])
grandma-cry (utils/make-anim-seq atlas "grandma-cry" [58 40] 0.15 (flatten [(range 20) 0 0 0 0 0 0 0 0 0]))
owl-stand (utils/make-anim atlas "owl" [21 30] 0.2 [0 0 0 0 0 0 0 2])
owl-talk (utils/make-anim atlas "owl" [21 30] 0.2 [1 0 1 0 1 0 0 0 2 0])
owl-puke (utils/make-anim atlas "owl" [21 30] 0.10 [0 0 2 2 3 2 2 3 3 2 3 3 3 4 5 6 7 4 4 3 3 2 2 2 2 2])
owl-eye (utils/make-anim-seq atlas "eye" [44 48] 0.10 [0 0 1 1 2 2 2 2 2 2 2 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 3 4 4 4 3 4 4 4 5 6 7 8 9 9 9 9 9 9 9 9 9 10 11 12 12 11 10 9 9 9 9 9 9 9 9 10 11 12 12 12 11 10 9 9 9 9 9 8 7 6 5])
puke (particle-effect "particles/puke")]
(rooms/make :music {:day :town-2 :night :night}
:name "Tree"
(rooms/make :name "Tree"
:sounds {:cat (utils/load-sound "cat-tree/cat.ogg")
:kiss (utils/load-sound "cat-tree/kiss.ogg")}
:ladder ladder-entity
:blank (rooms/make-entity :blank
{:object nil :x 0 :y 0 :width 320 :height 240 :baseline 240
:script (actions/get-script entities
:only-script (actions/get-script entities
(when (get-in @entities [:room :entities :ladder])
(actions/talk entities :ego "I'll get down.")
(get-down entities)))})
:interactions
{:down-dir {:box [150 0 270 20]
:script (actions/get-script entities
(if (get-in @entities [:room :entities :ladder])
(do
(actions/talk entities :ego "I'll get down.")
(get-down entities)))
(actions/walk-to entities :ego [200 10] :skip-type :end :stop? false)
(actions/walk-straight-to entities :ego [223 -51])
(actions/transition-background entities :outside-house [137 204])
(actions/walk-to entities :ego [158 110] :skip-type :end))
:only-script (actions/get-script entities
(if (get-in @entities [:room :entities :ladder])
(do
(actions/talk entities :ego "I'll get down.")
(get-down entities)))
(actions/walk-to entities :ego [200 10] :skip-type :end :stop? false)
(actions/walk-straight-to entities :ego [223 -51])
(actions/transition-background entities :outside-house [137 204])
(actions/walk-to entities :ego [158 110] :skip-type :end))
:cursor :down}
:ladder-area-1 (make-ladder-area [123 100 167 199])
:ladder-area-2 (make-ladder-area [87 151 227 212])
:ladder-area-3 (make-ladder-area [133 69 205 92])
:rock {:box [62 83 101 103]
:cursor :hand
:label "Suspicous looking rock"
:script (actions/get-script entities
(when (and (actions/has-obtained? entities :note-1)
(not (actions/has-obtained? entities :walkie-talkies)))
@@ -330,6 +336,8 @@
(actions/talk entities :ego "Tin cans connected with string?")
(actions/do-dialogue entities :ego "I wonder what all of these magic devices do.")))}
:grass {:box [26 105 60 160]
:cursor :hand
:label "Grass"
:script (actions/get-script entities
(if (not (actions/has-obtained? entities :grass))
(do
@@ -340,6 +348,8 @@
:ego "It's a high protein variety."))
(actions/talk entities :ego "I don't really need any more grass.")))}
:grandma {:box [109 33 132 98]
:cursor :talk
:label "Damsel"
:script (actions/get-script entities (do-grandma-dialogue entities))
:scripts #(condp = %
:kiss
@@ -350,71 +360,73 @@
(actions/do-dialogue entities :grandma "No thank you, handsome.")
(if (get-in @entities [:room :entities :ladder])
(actions/do-stop entities :ego :face :right))))
}}
:layers {:day [(assoc (utils/get-texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "cat-tree/tree-and-rock.png") :x 0 :y 0 :baseline 161)
(assoc (utils/get-texture "cat-tree/brush-l.png") :x -5 :y -5 :parallax 1.3 :baseline 240)
(assoc (utils/get-texture "cat-tree/tree-r.png") :x 270 :y 0 :scale-x 1.1 :scale-y 1.1 :parallax 1.5 :baseline 240)]
:night [(assoc (utils/get-texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "cat-tree/tree-and-rock.png") :x 0 :y 0 :baseline 161)
(assoc (utils/get-texture "cat-tree/brush-l.png") :x -5 :y -5 :parallax 1.3 :baseline 240)
(assoc (utils/get-texture "cat-tree/tree-r.png") :x 270 :y 0 :scale-x 1.1 :scale-y 1.1 :parallax 1.5 :baseline 240)]}
}}
:layers {:day [(assoc (utils/atlas->texture atlas "background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "tree-and-rock.png") :x 0 :y 0 :baseline 161)
(assoc (utils/atlas->texture atlas "brush-l.png") :x -5 :y -5 :parallax 1.3 :baseline 240)
(assoc (utils/atlas->texture atlas "tree-r.png") :x 270 :y 0 :scale-x 1.1 :scale-y 1.1 :parallax 1.5 :baseline 240)]
:night [(assoc (utils/atlas->texture atlas "background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "tree-and-rock.png") :x 0 :y 0 :baseline 161)
(assoc (utils/atlas->texture atlas "brush-l.png") :x -5 :y -5 :parallax 1.3 :baseline 240)
(assoc (utils/atlas->texture atlas "tree-r.png") :x 270 :y 0 :scale-x 1.1 :scale-y 1.1 :parallax 1.5 :baseline 240)]}
:entities {
:outside-particles (common/make-outside-particles)
:cat (actions/start-animation screen
(assoc (animation->texture screen cat-stand)
:x 184 :y 173 :baseline 1000
:walk cat-walk
:stand cat-stand
:script (actions/get-script entities
(actions/talk entities :ego "Here kitty, kitty, kitty.")
(actions/talk entities :ego "Kitty's so bored, he doesn't even notice me."))
:scripts {:cat-toy (actions/get-script entities
(actions/play-animation entities :ego :cat-toy)
(if (get-in @entities [:room :entities :ladder])
(do (actions/talk entities :ego "I think he's going for it!")
(actions/play-animation entities :ego :cat-toy-first-half :stop? false)
(actions/play-sound entities :cat 0.5)
(actions/walk-straight-to entities :cat [138 40] :update-baseline? false :speed 3)
(actions/play-animation entities :ego :cat-toy-last-half)
(actions/play-animation entities :grandma :squat-1 :stop? false)
(actions/remove-entity entities :cat)
(actions/play-animation entities :grandma :squat-2)
(actions/do-dialogue entities :grandma "Thank you for rescuing my furry friend, young man!")
(get-down entities true)
(actions/walk-straight-to entities :ego [165 45] :face :left)
(actions/do-dialogue entities
:ego "It's no big deal."
:grandma "You won't go unrewarded!"
:grandma "Come here, young man.")
(actions/walk-straight-to entities :ego [133 35])
(actions/talk entities :grandma "For your impressive display of courage and bravery, I give you this. ")
(assoc (animation->texture screen cat-stand)
:x 184 :y 173 :baseline 1000
:label "Smuffle Wuffles"
:cursor :talk
:walk cat-walk
:stand cat-stand
:script (actions/get-script entities
(actions/talk entities :ego "Here kitty, kitty, kitty.")
(actions/talk entities :ego "Kitty's so bored, he doesn't even notice me."))
:scripts {:cat-toy (actions/get-script entities
(actions/play-animation entities :ego :cat-toy)
(if (get-in @entities [:room :entities :ladder])
(do (actions/talk entities :ego "I think he's going for it!")
(actions/play-animation entities :ego :cat-toy-first-half :stop? false)
(actions/play-sound entities :cat 0.5)
(actions/walk-straight-to entities :cat [138 40] :update-baseline? false :speed 3)
(actions/play-animation entities :ego :cat-toy-last-half)
(actions/play-animation entities :grandma :squat-1 :stop? false)
(actions/remove-entity entities :cat)
(actions/play-animation entities :grandma :squat-2)
(actions/do-dialogue entities :grandma "Thank you for rescuing my furry friend, young man!")
(get-down entities true)
(actions/walk-straight-to entities :ego [165 45] :face :left)
(actions/do-dialogue entities
:ego "It's no big deal."
:grandma "You won't go unrewarded!"
:grandma "Come here, young man.")
(actions/walk-straight-to entities :ego [133 35])
(actions/talk entities :grandma "For your impressive display of courage and bravery, I give you this. ")
(actions/play-sound entities :kiss 0.7)
(actions/play-animation entities :grandma :kiss)
(actions/play-animation entities :ego :get-sick :stop? false)
(actions/walk-straight-to entities :ego [165 45])
(actions/do-dialogue entities :ego
"Ugh! Gross!"
:ego "What's this?")
(actions/give entities :kiss)
(actions/do-dialogue entities :ego "A kiss for an inventory item?"
:ego "Sounds like the game designer was running out of good ideas.")
(steam/set-achievement "KITTY_KISS"))
(actions/talk entities :ego "I can't get his attention from way down here.")))
:stick (actions/get-script entities
(if (get-in @entities [:room :entities :ladder])
(do
(actions/play-animation entities :ego :poke)
(actions/do-dialogue entities
:ego "He's still too far for me to poke him."
:ego "Maybe I can encourage him to come down on his own."))
(do
(actions/walk-to entities :ego [210 58] :face :right)
(actions/play-animation entities :ego :poke)
(actions/talk entities :ego "I can't poke him from way down here."))))
:wool (actions/get-script entities (actions/talk entities :ego "I don't think the cat would notice the wool from all the way up there."))
:default (actions/get-script entities (actions/talk entities :ego "Kitty seems disinterested in it."))})
cat-stand)
(actions/play-animation entities :grandma :kiss)
(actions/play-animation entities :ego :get-sick :stop? false)
(actions/walk-straight-to entities :ego [165 45])
(actions/do-dialogue entities :ego
"Ugh! Gross!"
:ego "What's this?")
(actions/give entities :kiss)
(actions/do-dialogue entities :ego "A kiss for an inventory item?"
:ego "Sounds like the game designer was running out of good ideas.")
(steam/set-achievement "KITTY_KISS"))
(actions/talk entities :ego "I can't get his attention from way down here.")))
:stick (actions/get-script entities
(if (get-in @entities [:room :entities :ladder])
(do
(actions/play-animation entities :ego :poke)
(actions/do-dialogue entities
:ego "He's still too far for me to poke him."
:ego "Maybe I can encourage him to come down on his own."))
(do
(actions/walk-to entities :ego [210 58] :face :right)
(actions/play-animation entities :ego :poke)
(actions/talk entities :ego "I can't poke him from way down here."))))
:wool (actions/get-script entities (actions/talk entities :ego "I don't think the cat would notice the wool from all the way up there."))
:default (actions/get-script entities (actions/talk entities :ego "Kitty seems disinterested in it."))})
cat-stand)
:grandma (let [gma (assoc (animation->texture screen grandma-stand)
:x 130 :y 37 :baseline 200
:anim grandma-stand
@@ -441,10 +453,12 @@
:x 194 :y 188 :baseline 241)}
:owl (rooms/make-entity :owl (assoc (animation->texture screen owl-stand)
:x 187 :y 172 :baseline 241
:label "Owl"
:stand owl-stand
:talk owl-talk
:puke owl-puke
:eye owl-eye
:cursor :talk
:talk-color (color 0.5 0.5 1.0 1.0)
:anim owl-stand
:anim-start 0
@@ -529,5 +543,5 @@
(if (= :night (get-in entities [:state :time]))
(make-night entities)
(utils/remove-interaction entities :rock)
)))
)))
:start-pos [200 10])))

View File

@@ -15,6 +15,8 @@
[play-clj.g2d :refer :all])
(:import [com.badlogic.gdx.graphics Color]))
(println "loading " *ns*)
(defn go-to-jail [entities & [time]]
(actions/update-state entities #(assoc % :chest-contents (concat (remove #{:key :ladder} (:inventory %)) (:chest-contents %))))
@@ -27,13 +29,13 @@
:time time)
(actions/play-animation entities :ego :standup))
(defn make-wizard [screen wizard-spec]
(let [wizard-sheet (texture! (utils/get-texture "wizard/talk.png") :split 20 46)
(defn make-wizard [screen atlas wizard-spec]
(let [wizard-sheet (texture! (utils/atlas->texture atlas "wizard/talk") :split 20 46)
wizard-stand (animation 0.2 (for [i (flatten [(repeat 10 0) 1])]
(aget wizard-sheet 0 i)))
wizard-talk-angry (utils/make-anim "wizard/talk-angry.png" [20 50] 0.2 [0 2 0 2 1 2 0 3 0 2 0 1 0 2])
wizard-magic-hands (utils/make-anim "wizard/magic-hands.png" [20 50] 0.2 (range 2))
wizard-disappear (utils/make-anim "wizard/disappear.png" [20 46] 0.075 (range 19))
wizard-talk-angry (utils/make-anim atlas "wizard/talk-angry" [20 50] 0.2 [0 2 0 2 1 2 0 3 0 2 0 1 0 2])
wizard-magic-hands (utils/make-anim atlas "wizard/magic-hands" [20 50] 0.2 (range 2))
wizard-disappear (utils/make-anim atlas "wizard/disappear" [20 46] 0.075 (range 19))
disappear-left (utils/flip wizard-disappear)
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)))
@@ -66,6 +68,8 @@
disappear-left {1 [:disappear 0.7]}
}
:night-profile :sprite
:label "Gandarf"
:cursor :talk
:origin-x 0
:origin-y 0
:talk-color (color 0.95 0.3 1.0 1.0)
@@ -292,16 +296,18 @@
"Nevermind."
{:run #(actions/respond entities % :frankie "Come back when you've got some good valuables.")}]}))
(defn make-frankie [screen]
(let [stand (utils/make-anim "castle-gate/frankie.png" [24 35] 0.19 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
talk (utils/make-anim "castle-gate/frankie.png" [24 35] 0.2 [2 0 2 0 2 0 2 0 0 1 0])
walk (utils/make-anim-seq "castle-gate/frankie-walk" [24 35] 0.2 (range 8))
laugh (utils/make-anim "castle-gate/frankie.png" [24 35] 0.1 [1 3 4 3 4 3 4 3 4 3 4 3 4 1 0])
glance (utils/make-anim "castle-gate/frankie.png" [24 35] 0.25 [0 6 0 6 5 5 5 6 7 7 7 6 ])
reach (utils/make-anim "castle-gate/frankie.png" [24 35] 0.2 [0 8 9 9 9 9 8])
flex (utils/make-anim "castle-gate/frankie.png" [24 35] 0.2 [0 10 11 12 12 12 12 11 10])]
(defn make-frankie [screen atlas]
(let [stand (utils/make-anim atlas "frankie" [24 35] 0.19 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
talk (utils/make-anim atlas "frankie" [24 35] 0.2 [2 0 2 0 2 0 2 0 0 1 0])
walk (utils/make-anim-seq atlas "frankie-walk" [24 35] 0.2 (range 8))
laugh (utils/make-anim atlas "frankie" [24 35] 0.1 [1 3 4 3 4 3 4 3 4 3 4 3 4 1 0])
glance (utils/make-anim atlas "frankie" [24 35] 0.25 [0 6 0 6 5 5 5 6 7 7 7 6 ])
reach (utils/make-anim atlas "frankie" [24 35] 0.2 [0 8 9 9 9 9 8])
flex (utils/make-anim atlas "frankie" [24 35] 0.2 [0 10 11 12 12 12 12 11 10])]
(assoc (animation->texture screen stand)
:x 235 :y 90 :baseline 150
:label "Frankie Rockfist"
:cursor :talk
:origin-x 12
:origin-y 0
:anim stand
@@ -455,7 +461,9 @@
:bloodclot-head "Give it here!")
(actions/transition-background entities :space [200 45] :between (fn [s e]
(-> e
(assoc-in [:room :entities :ego :stand-override] :crawl-stand)
(assoc-in [:room :entities :ego :previous-frame-index] -1)
(update-in [:room :entities :ego] #(actions/start-animation s % :crawl-stand)))
))
(actions/do-dialogue entities

View File

@@ -19,19 +19,23 @@
[play-clj.g2d :refer :all])
(:import [com.badlogic.gdx.graphics Color]))
(println "loading " *ns*)
(def walk-chan (a/chan))
(defn set-opacity [entities opacity tool-opacity]
(-> entities
(assoc-in [:room :layers 0 :opacity] opacity)
(assoc-in [:room :layers 1 :opacity] opacity)
(assoc-in [:room :layers 2 :opacity] opacity)
(assoc-in [:room :layers 3 :opacity] opacity)
(assoc-in [:room :layers 4 :opacity] opacity)
(assoc-in [:room :layers 5 :opacity] opacity)
(assoc-in [:room :layers 6 :opacity] opacity)
(assoc-in [:room :layers 7 :opacity] opacity)
(assoc-in [:room :layers 8 :opacity] opacity)
(assoc-in [:room :current-layers 0 :opacity] opacity)
(assoc-in [:room :current-layers 1 :opacity] opacity)
(assoc-in [:room :current-layers 2 :opacity] opacity)
(assoc-in [:room :current-layers 3 :opacity] opacity)
(assoc-in [:room :current-layers 4 :opacity] opacity)
(assoc-in [:room :current-layers 5 :opacity] opacity)
(assoc-in [:room :current-layers 6 :opacity] opacity)
(assoc-in [:room :current-layers 7 :opacity] opacity)
(assoc-in [:room :current-layers 8 :opacity] opacity)
(assoc-in [:room :entities :fairy-godfather :label] (if (> opacity 0.0) "Fairy Godfather" nil))
(assoc-in [:room :entities :fairy-godfather :cursor] (if (> opacity 0.0) :talk nil))
(assoc-in [:room :entities :sword :opacity] tool-opacity)
(assoc-in [:room :entities :case :opacity] tool-opacity)
(assoc-in [:room :entities :broom :opacity] tool-opacity)
@@ -47,13 +51,13 @@
(begin [this screen entities]
(-> entities
(assoc-in [:tweens :fade-in]
(tween/tween :fade-in screen [:room :layers 0 :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quintic))))
(tween/tween :fade-in screen [:room :current-layers 0 :opacity] 0.0 1.0 0.5 :ease tween/ease-in-out-quintic))))
(continue [this screen entities]
(set-opacity entities (get-in entities [:room :layers 0 :opacity] ) 0.0))
(set-opacity entities (get-in entities [:room :current-layers 0 :opacity] ) 0.0))
(done? [this screen entities]
(= 1.0 (get-in entities [:room :layers 0 :opacity])))
(= 1.0 (get-in entities [:room :current-layers 0 :opacity])))
(terminate [this screen entities]
entities)
@@ -363,13 +367,15 @@
:fairy-godfather "Imagine the sweet smell of victory once you've mopped up some spilled milk."
:fairy-godfather "Or the smell of soap in the bathroom, where you'll spend your time making the tile and porcelain shine."))
(defn make [screen]
(let [fairy-godfather-anim (utils/make-anim "dream/fairy-godfather.png" [63 77] 0.15 [0 1 2 3 2 1 0 1 4 3 2 1])
fairy-godfather-talk-anim (utils/make-anim "dream/fairy-godfather.png" [63 77] 0.15 [5 6 7 8 7 6])
fairy-godfather-magic-anim (utils/make-anim "dream/fairy-godfather-magic.png" [100 77] 0.15 [0 1 2 3 4 4 4 4 3 2 1 0])]
(rooms/make :music {:intro :wind :day :dream}
(defn make [screen atlas global-atlas]
(let [fairy-godfather-anim (utils/make-anim atlas "fairy-godfather" [63 77] 0.15 [0 1 2 3 2 1 0 1 4 3 2 1])
fairy-godfather-talk-anim (utils/make-anim atlas "fairy-godfather" [63 77] 0.15 [5 6 7 8 7 6])
fairy-godfather-magic-anim (utils/make-anim atlas "fairy-godfather-magic" [100 77] 0.15 [0 1 2 3 4 4 4 4 3 2 1 0])]
(rooms/make
:name "Dream"
:interactions {:pit {:box [54 0 219 36]
:label "Pit of destiny"
:cursor :look
:script (actions/get-script entities
(actions/walk-to entities :ego [154 41])
(actions/talk entities :ego "Wow! That's a long way down."))
@@ -401,21 +407,32 @@
:ego "It seems like misery!"
:ego "Plus, how can I ever win the heart of my true love, Georgia McGorgeous?"))}}}
:timers {:return [1.0 1.0 return-from-island]}
:layers [(assoc (utils/get-texture "dream/sky.png") :x 0 :y 0 :baseline -3 :parallax 0.01)
(assoc (utils/get-texture "dream/far.png") :x -10 :y 0 :baseline -2 :parallax 0.01)
(assoc (utils/get-texture "dream/clouds1.png") :x -10 :y 0 :baseline -1 :parallax 0.2 :scale-x 1.1 :scale-y 1.1)
(assoc (utils/get-texture "dream/island.png") :x 180 :y 180 :baseline 0 :parallax 0.3 :scale-x 1.1 :scale-y 1.1)
(assoc (utils/get-texture "dream/cliff.png") :x 50 :y 133 :baseline 1 :parallax 0.6 :scale-x 1.2 :scale-y 1.2)
(assoc (utils/get-texture "dream/background.png") :x 0 :y 0 :baseline 2)
(assoc (utils/get-texture "dream/corner-l.png") :x -10 :y -10 :baseline 240 :parallax 2.0 )
(assoc (utils/get-texture "dream/corner-r.png") :x (- 320 80) :y -20 :baseline 240 :parallax 3.2)
(assoc (utils/get-texture "dream/pedestals.png") :x 0 :y 0 :baseline 139)]
:layers [(assoc (utils/atlas->texture atlas "sky") :x 0 :y 0 :baseline -3 :parallax 0.5)
(assoc (utils/atlas->texture atlas "far") :x -10 :y 0 :baseline -2 :origin-x 160 :parallax 0.5)
(assoc (utils/atlas->texture atlas "clouds1") :x -10 :y 0 :baseline -1 :parallax 0.2 :scale-x 1.1 :scale-y 1.1)
(assoc (utils/atlas->texture atlas "island") :x 180 :y 180 :baseline 0 :parallax 0.3 :scale-x 1.1 :scale-y 1.1)
(assoc (utils/atlas->texture atlas "cliff") :x 50 :y 133 :baseline 1 :parallax 0.6 :scale-x 1.2 :scale-y 1.2)
(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 2)
(assoc (utils/atlas->texture atlas "corner-l") :x -10 :y -10 :baseline 240 :parallax 2.0 )
(assoc (utils/atlas->texture atlas "corner-r") :x (- 320 80) :y -20 :baseline 240 :parallax 3.2)
(assoc (utils/atlas->texture atlas "pedestals") :x 0 :y 0 :baseline 139)]
:current-layers [(assoc (utils/atlas->texture atlas "sky") :x 160 :y 120 :origin-y 120 :baseline -3 :origin-x 160 :parallax 0.01)
(assoc (utils/atlas->texture atlas "far") :x 160 :y 120 :baseline -2 :origin-y 120 :origin-x 160 :parallax 0.01)
(assoc (utils/atlas->texture atlas "clouds1") :x 150 :y 120 :baseline -1 :origin-x 160 :origin-y 120 :parallax 0.1 :scale-x 1.1 :scale-y 1.1)
(assoc (utils/atlas->texture atlas "island") :x 180 :y 180 :origin-x 15 :origin-y 10 :baseline 0 :parallax 0.2 :scale-x 1.1 :scale-y 1.1)
(assoc (utils/atlas->texture atlas "cliff") :x 160 :y 120 :origin-x 160 :origin-y 120 :baseline 1 :parallax 0.6 :scale-x 1.2 :scale-y 1.2)
(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 2)
(assoc (utils/atlas->texture atlas "corner-l") :x -10 :y -10 :baseline 240 :parallax 2.0 )
(assoc (utils/atlas->texture atlas "corner-r") :x (- 320 80) :y -20 :baseline 240 :parallax 3.2)
(assoc (utils/atlas->texture atlas "pedestals") :x 0 :y 0 :baseline 139)]
:entities {:magic (assoc (particle-effect "particles/dream-magic") :x 160 :y 80 :baseline 240)
:clouds (assoc (particle-effect "particles/cloudy2") :x 160 :y 120 :baseline 241)
:case (assoc (utils/get-texture "dream/case.png")
:case (assoc (utils/atlas->texture atlas "case")
:x 144 :y 122 :baseline 139
:label "Glass case"
:cursor :look
:script (actions/get-script entities
(read-sword-plaque entities))
:scripts {:shovel (actions/get-script entities
@@ -439,9 +456,9 @@
(actions/walk-straight-to entities :ego [180 100] :anim :jumping-straight :update-baseline? false :stop? false :speed 2.0)
(actions/walk-straight-to entities :ego [190 30] :anim :jumping-straight :update-baseline? false :stop? false :speed 3.0)
(actions/walk-straight-to entities :ego [200 -80] :anim :jumping-straight :update-baseline? false :stop? false :speed 8.0)
(actions/remove-item entities :dream-sword)
(actions/remove-item entities :broom)
(actions/remove-item entities :shovel)
(actions/remove-item entities :dream-sword :quiet? true)
(actions/remove-item entities :broom :quiet? true)
(actions/remove-item entities :shovel :quiet? true)
(actions/transition-background entities :inside-castle [92 150] :time 8.0)
(actions/resume-camera entities)
(actions/walk-straight-to entities :ego [79 145] :stop? false)
@@ -462,15 +479,17 @@
(do (actions/walk-to entities :ego [148 76] :face :right)
(actions/do-dialogue entities
:fairy-godfather "What are you doing?" :ego "Erm... Nothing."))))})
:sword (assoc (utils/get-texture "dream/sword.png")
:sword (assoc (utils/atlas->texture atlas "sword")
:x 144 :y 122 :baseline 139)
:explode (assoc (particle-effect "particles/explode") :x 150 :y 138 :baseline 240)
:broom (assoc (utils/get-texture "dream/broom.png") :x 286 :y 122
:broom (assoc (utils/atlas->texture atlas "broom") :x 286 :y 122
:path (catmull-rom-spline (map #(apply vector-2* %) [[286 122] [286 128]]) true)
:update-fn (partial utils/update-path-location 0.30)
:baseline 240
:label "Broom"
:cursor :hand
:script (actions/get-script entities
(if ((get-in @entities [:state :plaques-read]) :broom)
(do
@@ -481,11 +500,13 @@
(actions/give entities :broom))
(read-broom-plaque entities))))
:shovel (assoc (utils/get-texture "dream/shovel.png") :x 33 :y 122
:shovel (assoc (utils/atlas->texture atlas "shovel") :x 33 :y 122
:path (catmull-rom-spline (map #(apply vector-2* %) [[22 122] [22 128]]) true)
:update-fn (partial utils/update-path-location 0.33)
:baseline 240
:label "Shovel"
:cursor :hand
:script (actions/get-script entities
(if ((get-in @entities [:state :plaques-read]) :shovel)
(do
@@ -496,10 +517,10 @@
(actions/give entities :shovel))
(read-shovel-plaque entities))))
:sign (assoc (utils/get-texture "dream/sign.png") :x 229 :y 33 :baseline 207)
:plaque-1 (assoc (utils/get-texture "dream/plaque1.png") :x 39 :y 99 :baseline 139 :script (actions/get-script entities (read-shovel-plaque entities)))
:plaque-2 (assoc (utils/get-texture "dream/plaque2.png") :x 147 :y 104 :baseline 139 :script (actions/get-script entities (read-sword-plaque entities)))
:plaque-3 (assoc (utils/get-texture "dream/plaque3.png") :x 283 :y 98 :baseline 139 :script (actions/get-script entities (read-broom-plaque entities)))
:sign (assoc (utils/atlas->texture atlas "sign") :x 229 :y 33 :baseline 207)
:plaque-1 (assoc (utils/atlas->texture atlas "plaque1") :x 39 :y 99 :baseline 139 :label "Plaque" :cursor :look :script (actions/get-script entities (read-shovel-plaque entities)))
:plaque-2 (assoc (utils/atlas->texture atlas "plaque2") :x 147 :y 104 :baseline 139 :label "Plaque" :cursor :look :script (actions/get-script entities (read-sword-plaque entities)))
:plaque-3 (assoc (utils/atlas->texture atlas "plaque3") :x 283 :y 98 :baseline 139 :label "Plaque" :cursor :look :script (actions/get-script entities (read-broom-plaque entities)))
:outside-particles (common/make-outside-particles)
:bounce-surrogate {:object nil
:path (catmull-rom-spline (map #(apply vector-2* %) [[200 130] [200 150]]) true)
@@ -539,8 +560,11 @@
:default {:origin-x 31}}
:facing :left
:update-fn (fn [s es e]
(assoc-in e [:offset-y] (* (:scale-y e) (get-in es [:bounce-surrogate :delta-y] 0))))
:talk-color (Color/valueOf "ADA6FFFF")
:label "Fairy godfather"
:cursor :talk
:script (actions/get-script entities
(if (get-in @entities [:room :entities :fairy-godfather :distracted?])
(actions/do-dialogue entities :ego "He wouldn't be able to hear me from there.")
@@ -564,7 +588,7 @@
(utils/fast-forward-particle (get-in entities [:room :entities :outside-particles]))
(as-> entities entities
(if (get-in entities [:state :seen-intro?])
(if (get-in entities [:state :seen-intro?])
(set-opacity entities 1.0 1.0)
(set-opacity entities 0.0 0.0))
(if (actions/has-item? entities :broom)

View File

@@ -17,40 +17,41 @@
[play-clj.g2d :refer :all])
(:import [com.badlogic.gdx.graphics Color]))
(defn make [screen]
(let [
peddler-sheet (texture! (utils/get-texture "outside-castle/peddler-talk.png" ) :split 18 36)
(println "loading " *ns*)
(defn make [screen atlas global-atlas]
(let [peddler-sheet (texture! (utils/atlas->texture atlas "peddler-talk" ) :split 18 36)
peddler-stand (utils/flip (animation 0.2 (for [i (flatten [(repeat 8 0) 6 (repeat 8 0) 6 (repeat 5 0) 4 5 4 5 4 5])]
(aget peddler-sheet 0 i))))
warden-stand (utils/make-anim "ending-castle/warden-2.png" [21 41] 0.21 (flatten [(repeat 7 0) 1]))
warden-stand (utils/make-anim atlas "warden-2" [21 41] 0.21 (flatten [(repeat 7 0) 1]))
game-player-stand (utils/make-anim "ending-castle/game-player.png" [14 39] 0.2 (flatten [(repeat 5 0) 1] ))
game-player-stand (utils/make-anim atlas "game-player" [14 39] 0.2 (flatten [(repeat 5 0) 1] ))
ladder-guard-stand-1 (animation 0.1 [(utils/get-texture "inside-cafeteria/ladder-guard-2.png")])
ladder-guard-stand-2 (utils/flip (animation 0.1 [(utils/get-texture "inside-cafeteria/ladder-guard-2.png")]))
grandma-stand (utils/make-anim "cat-tree/grandma.png" [25 36] 0.2 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
cat-stand (utils/make-anim "cat-tree/cat-stand.png" [22 10] 0.15 (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0 0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0]))
duke-stand (utils/make-anim "ending-castle/duke.png" [40 48] 0.23 (flatten [(repeat 4 0) 1]))
duke-talk (utils/make-anim "ending-castle/duke.png" [40 48] 0.23 [0 2 0 2 1 2])
duke-reach (utils/make-anim "ending-castle/duke.png" [40 48] 0.23 [3 4 5 6])
duke-reach-talk (utils/make-anim "ending-castle/duke.png" [40 48] 0.23 [6 7])
duke-knight (utils/make-anim "ending-castle/duke.png" [40 48] 0.23 [8 9 10 9 8])
ladder-guard-stand-1 (animation 0.1 [(utils/atlas->texture atlas "ladder-guard-2")])
ladder-guard-stand-2 (utils/flip (animation 0.1 [(utils/atlas->texture atlas "ladder-guard-2")]))
grandma-stand (utils/make-anim atlas "grandma" [25 36] 0.2 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1])
cat-stand (utils/make-anim atlas "cat-stand" [22 10] 0.15 (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0 0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0]))
duke-stand (utils/make-anim atlas "duke" [40 48] 0.23 (flatten [(repeat 4 0) 1]))
duke-talk (utils/make-anim atlas "duke" [40 48] 0.23 [0 2 0 2 1 2])
duke-reach (utils/make-anim atlas "duke" [40 48] 0.23 [3 4 5 6])
duke-reach-talk (utils/make-anim atlas "duke" [40 48] 0.23 [6 7])
duke-knight (utils/make-anim atlas "duke" [40 48] 0.23 [8 9 10 9 8])
georgia-stand (utils/make-anim "georgia/stand.png" [20 43] 0.2 (flatten [(repeat 20 0) 1 (repeat 10 0) 1]))
georgia-hand-hold (utils/make-anim "georgia/stand.png" [20 43] 0.2 (flatten [(repeat 3 0) 3 4]))
georgia-talk (utils/make-anim "georgia/stand.png" [20 43] 0.2 (flatten [0 2 0 2 0 1 0 0 2]))
georgia-kick (utils/make-anim-seq "georgia/kick" [40 43] 0.1 (flatten [(repeat 10 0) (repeat 7 1) (repeat 7 2)
georgia-stand (utils/make-anim atlas "georgia/stand" [20 43] 0.2 (flatten [(repeat 20 0) 1 (repeat 10 0) 1]))
georgia-hand-hold (utils/make-anim atlas "georgia/stand" [20 43] 0.2 (flatten [(repeat 3 0) 3 4]))
georgia-talk (utils/make-anim atlas "georgia/stand" [20 43] 0.2 (flatten [0 2 0 2 0 1 0 0 2]))
georgia-kick (utils/make-anim-seq atlas "georgia/kick" [40 43] 0.1 (flatten [(repeat 10 0) (repeat 7 1) (repeat 7 2)
3 4 5 6 7 8 9 10 11 12 13 (repeat 10 14)
15 16 17 18 19 (repeat 10 0)]))
frankie-fall (utils/make-anim-seq "ending-castle/frankie-fall" [40 35] 0.1 (flatten [(range 8) (repeat 20 7) 8 9 10 11 7]))
frankie-down (utils/make-anim-seq "ending-castle/frankie-fall" [40 35] 0.1 [0])
frankie-fall (utils/make-anim-seq atlas "frankie-fall" [40 35] 0.1 (flatten [(range 8) (repeat 20 7) 8 9 10 11 7]))
frankie-down (utils/make-anim-seq atlas "frankie-fall" [40 35] 0.1 [0])
scaler (utils/scaler-fn-with-baseline 20 1.3 1.30)]
(rooms/make :music :dream
(rooms/make
:sounds {:cloud (utils/load-sound "ending-castle/cloud.ogg")}
:name "Ending"
:interactions {}
:layers [(assoc (utils/get-texture "ending-castle/ending-castle2-assets/background.png") :x 0 :y 0 :origin-x 0 :origin-y 0 :baseline 0)
(assoc (utils/get-texture "ending-castle/ending-castle2-assets/foreground.png") :x 160 :y 0 :origin-x 165 :origin-y 5 :baseline 240 :parallax 1.4)]
:layers [(assoc (utils/atlas->texture atlas "ending-castle2-assets/background") :x 0 :y 0 :origin-x 0 :origin-y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "ending-castle2-assets/foreground") :x 160 :y 0 :origin-x 165 :origin-y 5 :baseline 240 :parallax 1.4)]
:apply-state (fn [screen e]
(as-> e e
(utils/play-sound! screen e :cloud (fn [e]
@@ -70,14 +71,14 @@
:stand georgia-stand
:talk georgia-talk
:kick georgia-kick
:walk (utils/make-anim "georgia/walk.png" [20 43] 0.2 (range 8))
:walk (utils/make-anim atlas "georgia/walk" [20 43] 0.2 (range 8))
:hand-hold georgia-hand-hold
:kick-sound (utils/load-sound "georgia/kick.ogg")
:anim-sound-frames {georgia-kick {27 [:kick-sound (constantly 0.6)]}}
:anim-merges {georgia-stand {:origin-x 10 :origin-y 1}
:default {:origin-x 10 :origin-y 1}
georgia-kick {:origin-x 19 :origin-y 0}}))
:entities {:frankie (assoc (common/make-frankie screen)
:entities {:frankie (assoc (common/make-frankie screen global-atlas)
:x 28 :y 21 :baseline 200
:fall frankie-fall
:down frankie-down
@@ -88,7 +89,7 @@
:anim-merges {:default {:origin-x 12 :origin-y 0}
frankie-fall {:origin-x 22 :origin-y 0}
frankie-down {:origin-x 22 :origin-y 0}})
:gandarf (assoc (common/make-wizard screen {:x 205 :y 400 :baseline 239})
:gandarf (assoc (common/make-wizard screen global-atlas {:x 205 :y 400 :baseline 239})
:update-fn (fn [screen entities gandarf]
(assoc gandarf :y (or (get-in entities [:gandarf-cloud :y])
(:y gandarf)))))
@@ -119,22 +120,22 @@
:scale-x 0.65
:scale-y 0.65
:scaled true)
:crowd-left (assoc (utils/get-texture "ending-castle/crowd-left.png")
:crowd-left (assoc (utils/atlas->texture atlas "crowd-left")
:x 0 :y 0
:scale-x 1.3
:scale-y 1.3
:baseline 239)
:crowd-right (assoc (utils/get-texture "ending-castle/crowd-right.png")
:crowd-right (assoc (utils/atlas->texture atlas "crowd-right")
:x 196 :y 0
:scale-x 1.3
:scale-y 1.3
:baseline 238)
:guard-1 (assoc (utils/get-texture "ending-castle/guard-1.png")
:guard-1 (assoc (utils/atlas->texture atlas "guard-1")
:x 91 :y 73
:scale-x 0.9
:scale-y 0.9
:baseline 140)
:guard-2 (assoc (utils/get-texture "ending-castle/guard-2.png")
:guard-2 (assoc (utils/atlas->texture atlas "guard-2")
:x 182 :y 73
:scale-x 0.9
:scale-y 0.9

View File

@@ -15,6 +15,7 @@
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn bloodclot-choices [entities]
@@ -56,12 +57,13 @@
(actions/get-script entities
(actions/talk entities who msg)))
(defn make [screen]
(let [bloodclot-talk (utils/make-anim-seq "held/bloodclot-head" [114 82] 0.1 [0 1 2 1 0 3 3 0 1 2 1 0 3 4 5 6 5 3 3 1 2 1 3 3 3 3 3 0 0 0 7 8 7])
bloodclot-stand (utils/make-anim-seq "held/bloodclot-head" [114 82] 0.1 (flatten [(repeat 15 0) 7 8 7]))]
(rooms/make :music :fight
:name "Held"
(defn make [screen atlas global-atlas]
(let [bloodclot-talk (utils/make-anim-seq atlas "bloodclot-head" [114 82] 0.1 [0 1 2 1 0 3 3 0 1 2 1 0 3 4 5 6 5 3 3 1 2 1 3 3 3 3 3 0 0 0 7 8 7])
bloodclot-stand (utils/make-anim-seq atlas "bloodclot-head" [114 82] 0.1 (flatten [(repeat 15 0) 7 8 7]))]
(rooms/make :name "Held"
:interactions {:bloodclot {:box [182 42 270 196]
:label "Bloodclot"
:cursor :talk
:script (actions/get-script entities
(bloodclot-talk-script entities))
:scripts #(condp = %
@@ -79,8 +81,8 @@
(actions/talk entities :bloodclot-head "Don't make me laugh, kid!")))
}}
:timers {:taunt [5.0 1.0 add-second]}
:layers [(assoc (utils/get-texture "held/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "held/hand.png") :x 0 :y 0 :baseline 240)]
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "hand") :x 0 :y 0 :baseline 240)]
:entities {:bloodclot-head (assoc (animation->texture screen bloodclot-stand)
:x 211 :y 115 :baseline 240
:origin-x 57 :origin-y 0

View File

@@ -11,6 +11,7 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(def boy-names
["Steve" "Bob" "Bud" "Clement" "Terrence" "Flapjack" "Ticklemonster" "Peter" "Greg" "Dave" "Stu" "Calsbad" "Fatso" "Tanner" "Klug"
"Griswold" "Leonardo" "Donatello" "Raphael" "Michelangelo" "Francis" "Ebeneezer" "Pierre" "Finn" "Slade" "Gilbert" "Graham"
@@ -159,20 +160,25 @@
(actions/walk-to entities :ego [143 58] :face :left)
(actions/play-animation entities :ego :reach)
(actions/add-entity entities :portrait (get-in @entities [:room :portrait]))
(actions/remove-item entities :portrait))
(actions/remove-item entities :portrait)
(actions/remove-entity entities :return-portrait)
(actions/remove-entity entities :return-portrait-2))
(defn get-portrait [entities]
(actions/walk-to entities :ego [140 58] :face :left)
(actions/play-animation entities :ego :reach)
(actions/remove-entity entities :portrait)
(actions/give entities :portrait)
(actions/talk entities :ego "It's a portrait. There's something on the back but it's too dim to read."))
(actions/talk entities :ego "It's a portrait. There's something on the back but it's too dim to read.")
(actions/add-entity entities :return-portrait-2 (get-in @entities [:room :return-portrait-2]))
(actions/add-entity entities :return-portrait (get-in @entities [:room :return-portrait])))
(defn return-teddy [entities]
(actions/walk-to entities :ego [242 49] :face :right)
(actions/play-animation entities :ego :reach)
(actions/add-entity entities :teddy (get-in @entities [:room :teddy]))
(actions/remove-item entities :teddy))
(actions/remove-item entities :teddy)
(actions/remove-entity entities :return-teddy))
(defn has-to-return-teddy? [entities]
(and (actions/has-item? entities :teddy)
@@ -191,22 +197,25 @@
(assoc-in [:room :entities :darken :opacity] 0.4)
(assoc-in [:room :entities :glow :opacity] 0.0))))
(defn make [screen]
(let [shopkeep-sheet (texture! (utils/get-texture "inside-antique/shopkeep-talk.png") :split 18 21)
(defn make [screen atlas global-atlas]
(let [shopkeep-sheet (texture! (utils/atlas->texture atlas "shopkeep-talk") :split 18 21)
shopkeep-stand (animation 0.1 (for [i (flatten [(repeat 30 0) 1 (repeat 50 0) 1 0 1 0])]
(aget shopkeep-sheet 0 i)))
shopkeep-talk (animation 0.15 (for [i [0 2 0 2 0 3 1 0]]
(aget shopkeep-sheet 0 i)))
shopkeep-sigh (utils/make-anim "inside-antique/antique-sigh.png" [24 21] 0.12 (flatten [ (range 9) 0 0 ]))
shopkeep-sigh (utils/make-anim atlas "antique-sigh" [24 21] 0.12 (flatten [ (range 9) 0 0 ]))
beard (utils/make-anim "inside-antique/beard.png" [28 54] 0.5 [0 1 0 2])
teddy (assoc (utils/get-texture "inside-antique/teddy.png")
beard (utils/make-anim atlas "beard" [28 54] 0.5 [0 1 0 2])
teddy (assoc (utils/atlas->texture atlas "teddy")
:x 255
:y 95
:baseline 160
:label "Choicest teddy bear"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [242 49] :face :right)
(actions/play-animation entities :ego :reach)
(actions/add-entity entities :return-teddy (get-in @entities [:room :return-teddy]))
(actions/give entities :teddy)
(actions/remove-entity entities :teddy)
(when (not (get-in @entities [:state :allowed-to-keep-teddy?]))
@@ -215,16 +224,49 @@
:shopkeep "Don't get any fast ideas."
:shopkeep "That teddy bear does not leave my store."
:shopkeep "My son would be stricken with grief to find it missing."))))]
(rooms/make :music :inside-antique
(rooms/make
:name "Antique shop"
:sounds {:fire-1 (utils/load-sound "inside-antique/fire-1.ogg")
:fire-2 (utils/load-sound "inside-antique/fire-2.ogg")
:fire-3 (utils/load-sound "inside-antique/fire-3.ogg")
}
:return-portrait (rooms/make-entity :return-portrait {:box [103 70 206 116]
:label "Desk"
:baseline 0
:cursor :look
:script (actions/get-script entities (actions/talk entities :ego "It's the shopkeep's desk."))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}})
:return-portrait-2 (rooms/make-entity :return-portrait-2
{:box [103 116 131 131]
:label "Desk"
:baseline 0
:cursor :look
:script (actions/get-script entities (if (actions/has-item? entities :portrait)
(actions/talk entities :ego "The shopkeep's portrait used to sit there.")
(get-portrait entities)
))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}})
:return-teddy (rooms/make-entity :return-teddy {:box [227 90 301 105]
:baseline 0
:cursor :look
:label "Shelf"
:script (actions/get-script entities
(actions/talk entities :ego "It's a shelf."))
:scripts {:teddy (actions/get-script entities
(return-teddy entities))
:portrait (actions/get-script entities
(return-portrait entities))}})
:interactions
{:right {:box [250 0 320 75]
:cursor :right
:script (actions/get-script entities
:only-script (actions/get-script entities
(when (or (actions/has-item? entities :portrait)
(has-to-return-teddy? entities))
(actions/walk-to entities :ego [235 15])
@@ -238,30 +280,12 @@
(actions/walk-straight-to entities :ego [320 -5])
(actions/transition-background entities :inside-castle [182 90])
(actions/walk-to entities :ego [187 75]))}
:return-portrait-2 {:box [103 116 131 131]
:script (actions/get-script entities (if (actions/has-item? entities :portrait)
(actions/talk entities :ego "The shopkeep's portrait used to sit there.")
(get-portrait entities)
))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}}
:return-portrait {:box [103 70 206 116]
:script (actions/get-script entities (actions/talk entities :ego "It's the shopkeep's desk."))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}}
:return-teddy {:box [227 90 301 105]
:script (actions/get-script entities
(actions/talk entities :ego "It's a shelf."))
:scripts {:teddy (actions/get-script entities
(return-teddy entities))
:portrait (actions/get-script entities
(return-portrait entities))}}
:window {:box [195 121 256 190]
:label "Window"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [207 68] :face :right)
@@ -294,29 +318,39 @@
(actions/play-animation entities :ego :hold-up-to-window)
(actions/talk entities :ego "It's just too dim."))))}}
:grandfather-clock {:box [55 70 103 185]
:label "Grandfather clock"
:cursor :look
:script (actions/get-script entities
(actions/do-dialogue entities :ego "Cool grandfather clock!"
:shopkeep "It's quite the exquisite piece, isn't it?"))}
:shelf {:box [0 60 52 199]
:cursor :look
:label "Trinkets"
:script (actions/get-script entities
(actions/walk-to entities :ego [48 58])
(actions/talk entities :ego "All of these trinkets seem too bulky to fit in my pack."))}
:flowers {:box [178 115 188 143]
:label "Flowers"
:cursor :look
:script (actions/get-script entities
(actions/talk entities :ego "I've never been a fan of flowers."))}
:lian {:box [264 103 317 198]
:cursor :look
:label "Tapestry"
:script (actions/get-script entities
(actions/walk-to entities :ego [220 35] :face :right)
(actions/do-dialogue entities
:ego "It's a tapestry of Rupert the Lion!"
:ego "He's the town of Remington's mascot."))}
}
:layers [(assoc (utils/get-texture "inside-antique/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "inside-antique/desk.png") :x 0 :y 0 :baseline 113)
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "desk") :x 0 :y 0 :baseline 113)
(assoc (utils/get-texture "inside-antique/fg.png") :x 0 :y 0 :baseline 320 :parallax 1.5)
(assoc (utils/atlas->texture atlas "fg") :x 0 :y 0 :baseline 320 :parallax 1.5)
]
:entities {:shopkeep (actions/start-animation screen (assoc (animation->texture screen shopkeep-stand) :x 148 :y 122 :baseline 112
:label "Shopkeeper"
:cursor :talk
:stand shopkeep-stand
:scale-x 1.6
:scale-y 1.6
@@ -348,10 +382,10 @@
(actions/get-script entities
(actions/talk entities :shopkeep "No thanks, sonny."))))
:stand)
:glow (assoc (utils/get-texture "inside-antique/glow.png") :x 0 :y 0 :baseline 240 :additive? true :opacity 0.3)
:closed-blinds (assoc (utils/get-texture "inside-antique/closed-blinds.png") :x 0 :y 0 :baseline 0 :opacity 1.0)
:open-blinds (assoc (utils/get-texture "inside-antique/open-blinds.png") :x 0 :y 0 :baseline 0 :opacity 0.0)
:darken (assoc (utils/get-texture "inside-antique/darken.png") :x 0 :y 0 :baseline 321 :opacity 0.4 )
:glow (assoc (utils/atlas->texture atlas "glow") :x 0 :y 0 :baseline 240 :additive? true :opacity 0.3)
:closed-blinds (assoc (utils/atlas->texture atlas "closed-blinds") :x 0 :y 0 :baseline 1 :opacity 1.0)
:open-blinds (assoc (utils/atlas->texture atlas "open-blinds") :x 0 :y 0 :baseline 1 :opacity 0.0)
:darken (assoc (utils/atlas->texture atlas "darken") :x 0 :y 0 :baseline 321 :opacity 0.4 )
:beard (assoc (animation->texture screen beard)
:anim beard
:anim-start 0
@@ -364,14 +398,16 @@
:fire-particle (doto (assoc (particle-effect "particles/fire-particle") :x 162 :y 104
:baseline 240)
(particle-effect! :set-position 162 104))
:bowl (assoc (utils/get-texture "inside-antique/bowl.png")
:images [(utils/get-texture "inside-antique/bowl-0.png")
(utils/get-texture "inside-antique/bowl-1.png")
(utils/get-texture "inside-antique/bowl-2.png")
(utils/get-texture "inside-antique/bowl-3.png")]
:bowl (assoc (utils/atlas->texture atlas "bowl")
:images [(utils/atlas->texture atlas "bowl-0")
(utils/atlas->texture atlas "bowl-1")
(utils/atlas->texture atlas "bowl-2")
(utils/atlas->texture atlas "bowl-3")]
:x 165
:y 110
:baseline 125
:label "Mint bowl"
:cursor :hand
:script (actions/get-script entities
(if (= 3 (get-in @entities [:state :mints-eaten]))
(do (actions/walk-to entities :ego [159 58] :face :right)
@@ -415,10 +451,12 @@
:shopkeep "Pronto!"))))))
:teddy teddy}
:portrait (rooms/make-entity :portrait
(assoc (utils/get-texture "inside-antique/portrait.png")
(assoc (utils/atlas->texture atlas "portrait")
:x 112
:y 114
:baseline 120
:cursor :hand
:label "Portrait"
:script (actions/get-script entities
(get-portrait entities))))
:teddy (rooms/make-entity :teddy teddy)
@@ -431,6 +469,17 @@
(update-in entities [:room :entities] #(dissoc % :teddy))
entities)
(if (actions/has-item? entities :portrait)
(update-in entities [:room :entities] assoc
:return-portrait (get-in entities [:room :return-portrait])
:return-portrait-2 (get-in entities [:room :return-portrait-2]))
entities)
(if (actions/has-item? entities :teddy)
(update-in entities [:room :entities] assoc
:return-teddy (get-in entities [:room :return-teddy]))
entities)
(update-in entities
[:room :entities :bowl]
(fn [b]

View File

@@ -11,8 +11,10 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn make-fight-entity []
(assoc (utils/get-texture "black.png")
(println "loading " *ns*)
(defn make-fight-entity [global-atlas]
(assoc (utils/atlas->texture global-atlas "black.png")
:x 0
:y 0
:scale-x 21
@@ -171,22 +173,15 @@
(defn pace [xs speed]
(mapcat #(repeat (- 4 speed) %) xs))
(defn make [screen]
(let [#_#_warriors-stand-sheet (texture! (utils/get-texture "inside-cafeteria/warriors-stand.png") :split 66 126)
#_#_warriors-stand (animation 0.2 (for [i [0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 2 2 2 2 3 3 3 0 0 0 2 2 2 ]]
(aget warriors-stand-sheet 0 i)))
#_#_ladder-guard-sheet (texture! (utils/get-texture "inside-cafeteria/ladder-guard.png") :split 37 87)
#_#_ladder-guard-stand (animation 0.1 [(aget ladder-guard-sheet 0 0)])
ladder-guard-stand (animation 0.1 [(utils/get-texture "inside-cafeteria/ladder-guard-2.png")])
ladder-guard-talk (animation 0.1 [ (utils/get-texture "inside-cafeteria/ladder-guard-2.png")])
warriors-stand (utils/make-anim "inside-cafeteria/knights-stand.png" [49 80] 0.6 (take 100 (repeatedly #(rand-int 10))))
knight-a-stand (utils/make-anim "inside-cafeteria/knight-a.png" [70 85] 0.2 (flatten [(repeat 3 [(repeat 7 0) (repeat 7 1) (repeat 7 0) (repeat 7 2)]) [3 4 5 6 7 8 9]]))
(defn make [screen atlas global-atlas]
(let [ladder-guard-stand (animation 0.1 [(utils/atlas->texture atlas "ladder-guard-2")])
ladder-guard-talk (animation 0.1 [ (utils/atlas->texture atlas "ladder-guard-2")])
warriors-stand (utils/make-anim atlas "knights-stand" [49 80] 0.6 (take 100 (repeatedly #(rand-int 10))))
knight-a-stand (utils/make-anim atlas "knight-a" [70 85] 0.2 (flatten [(repeat 3 [(repeat 7 0) (repeat 7 1) (repeat 7 0) (repeat 7 2)]) [3 4 5 6 7 8 9]]))
#_#_ladder-guard-talk (animation 0.2 (for [i [0 0 0 0 1 0 0 1]]
(aget ladder-guard-sheet 0 i)))
hands-fight-win (utils/make-anim-seq "inside-cafeteria/fight-new-assets/fight" [256 192] 0.025 (flatten [(pace [0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 0 1 1 1 1 0 0 0 4 0 1 1 1 1 1 1 1 1 4 0 4 0 4 0 4 5 5 5 5 5 4 4 4] 0)
hands-fight-win (utils/make-anim-seq atlas "fight-new-assets/fight" [256 192] 0.025 (flatten [(pace [0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 0 1 1 1 1 0 0 0 4 0 1 1 1 1 1 1 1 1 4 0 4 0 4 0 4 5 5 5 5 5 4 4 4] 0)
(pace (flatten (repeat 6 [12 13])) 0)
(pace (flatten (repeat 15 [7 8])) 0)
(pace (flatten (repeat 15 [9])) 0)
@@ -202,25 +197,26 @@
(pace (flatten (repeat 6 [12 13])) 0)
(pace [0 0 0 0 2 1 1 2 2 1 1 2 2 2 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3] 0)]))
hands-fight-lose (utils/make-anim-seq "inside-cafeteria/fight-new-assets/fight" [256 192] 0.1 (flatten [4 4 4 4 4 4 0 0 0 0 4 4 4 0 0 0 5 5 5 6 6 6 6 6 6]))]
(rooms/make :music :town-1
:name "Cafeteria"
hands-fight-lose (utils/make-anim-seq atlas "fight-new-assets/fight" [256 192] 0.1 (flatten [4 4 4 4 4 4 0 0 0 0 4 4 4 0 0 0 5 5 5 6 6 6 6 6 6]))]
(rooms/make :name "Cafeteria"
:interactions
{:right-dir {:box [272 45 320 120]
:script (actions/get-script
:only-script (actions/get-script
entities
(actions/walk-to entities :ego [319 50] :skip-type :end)
(actions/transition-background entities :inside-castle [65 150])
(actions/walk-to entities :ego [126 80] :skip-type :end))
:cursor :right}
}
:layers [(assoc (utils/get-texture "inside-cafeteria/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "inside-cafeteria/doorway.png") :x 306 :y 34 :baseline 202)
(assoc (utils/get-texture "inside-cafeteria/glow.png") :y 0 :baseline 240 :additive? true :opacity 0.3)
(assoc (utils/get-texture "inside-cafeteria/fg.png") :x 10 :y 0 :scale-x 1.1 :scale-y 1.0 :baseline 320 :parallax 1.5)
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "doorway") :x 306 :y 34 :baseline 202)
(assoc (utils/atlas->texture atlas "glow") :y 0 :baseline 240 :additive? true :opacity 0.3)
(assoc (utils/atlas->texture atlas "fg") :x 10 :y 0 :scale-x 1.1 :scale-y 1.0 :baseline 320 :parallax 1.5)
]
:entities {:warriors (actions/start-animation screen (assoc (animation->texture screen warriors-stand) :x 31 :y 36 :baseline 180
:cursor :talk
:label "Knights"
:left {:stand (utils/flip warriors-stand)
:talk (utils/flip warriors-stand)}
:right {:stand warriors-stand
@@ -239,8 +235,19 @@
:anim knight-a-stand
:anim-start 0
:talk knight-a-stand
:stand knight-a-stand)
:stand knight-a-stand
:label "Knights"
:cursor :talk
:talk-color (color 1.0 0.2 0.3 1.0)
:script (actions/get-script entities
(do-warrior-dialogue entities))
:scripts (constantly (actions/get-script entities
(actions/walk-to entities :ego [150 45] :face :left)
(actions/do-dialogue entities :warriors
"We are warriors. We coveteth not earthly possessions."))))
:ladder-guard (actions/start-animation screen (assoc (animation->texture screen ladder-guard-stand) :x 180 :y 70 :baseline 170
:cursor :talk
:label "On-duty knight"
:stand ladder-guard-stand
:talk ladder-guard-talk
:talk-color (color 0.2 0.6 1.0 1.0)
@@ -252,12 +259,14 @@
"Do not durst telleth a soul about that ladder!"
"No thank you, young sire."))))
:stand)
:ladder (assoc (utils/get-texture "inside-cafeteria/ladder.png") :x 205 :y 70 :baseline 170
:ladder (assoc (utils/atlas->texture atlas "ladder") :x 205 :y 70 :baseline 170
:cursor :hand
:label "Ladder"
:script (actions/get-script entities
(actions/talk entities :ladder-guard "Do not toucheth, young sire.")))}
:collision "inside-cafeteria/collision.png"
:fight (make-fight-entity)
:hands-fight (assoc (animation->texture screen hands-fight-win)
:fight (make-fight-entity global-atlas)
:hands-fight (assoc (utils/atlas->texture atlas "fight-new-assets/fight" 0)
:origin-x 128
:origin-y 96
:x 150

View File

@@ -16,6 +16,7 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn brian [screen entities]
(when (and (not (get-in entities [:fg-actions :script-running?]))
(not (get-in entities [:bg-actions :script-running?]))
@@ -360,32 +361,31 @@
(do (actions/do-dialogue entities :ego "What about this?" :game-player "No, that's not the solution. Keep looking.")
nil)))
(defn make [screen]
(let [sign (utils/make-anim-seq "inside-castle/sign" [44 20] 0.3 (flatten [(repeat 20 0) 1 0 2 0 1 0 2 0 1 0 2 0 1]))
game-player-talk-sheet (texture! (utils/get-texture "inside-castle/game-player-talk.png") :split 40 44)
(defn make [screen atlas global-atlas]
(let [sign (utils/make-anim-seq atlas "sign" [44 20] 0.3 (flatten [(repeat 20 0) 1 0 2 0 1 0 2 0 1 0 2 0 1]))
game-player-talk-sheet (texture! (utils/atlas->texture atlas "game-player-talk") :split 40 44)
game-player-talk-up (animation 0.15 (for [i [0 2 0 2 0 2 0 3 0 2 0 1 0 0 0 0 2 0 2 0 3 0 1 0 1 0 0 1 0 2 0 3 0]]
(aget game-player-talk-sheet 0 i)))
game-player-stand-up (animation 0.15 (for [i [0 0 0 0 0 0 0 0 0 0 0 1]]
(aget game-player-talk-sheet 0 i)))
game-player-stand-down (utils/make-anim "inside-castle/brian-working.png" [40 44] 0.1 (flatten (repeat 4 [0 1 1 2 0 2 2 1 0 2 2 2 2 2 1 1 ])))
game-player-talk-down (utils/make-anim "inside-castle/brian-working.png" [40 44] 0.2 [2 3 2 2 3 2 3 2])
game-player-pause-from-work (utils/make-anim "inside-castle/brian-working.png" [40 44] 0.15 [2 3 4 5 6 7])
game-player-get-to-work (utils/make-anim "inside-castle/brian-working.png" [40 44] 0.15 (reverse [2 3 4 5 6 7]))
game-player-stand-down (utils/make-anim atlas "brian-working" [40 44] 0.1 (flatten (repeat 4 [0 1 1 2 0 2 2 1 0 2 2 2 2 2 1 1 ])))
game-player-talk-down (utils/make-anim atlas "brian-working" [40 44] 0.2 [2 3 2 2 3 2 3 2])
game-player-pause-from-work (utils/make-anim atlas "brian-working" [40 44] 0.15 [2 3 4 5 6 7])
game-player-get-to-work (utils/make-anim atlas "brian-working" [40 44] 0.15 (reverse [2 3 4 5 6 7]))
game-player-flex (animation 0.075 (for [i [0 0 4 4 5 5 5 5 5 5 5 6 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 9 7 8 7 6 5 5 5 5 5 5 5 5 5 5 4 4 0 0 0 0]]
(aget game-player-talk-sheet 0 i)))
trophy (utils/make-anim "inside-castle/trophy.png" [16 16] 0.1 (flatten [(repeat 50 0) 1 2 3 3 3 3 2 1]))
pull-sword-anim (utils/make-anim "inside-castle/pull-sword.png" [95 190] 0.10 (flatten [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 3 2 3 2 3 3 2 3 2 2 3 3 2 3 2 3 2 3 2 3 2 3 2 2 3 3 3 2 3 2 3 3 2 3 2 3 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ]))
monocle (utils/make-anim "inside-castle/monocle.png" [19 19] 0.05 (flatten [(repeat 70 0) 1 2 3 3 3 2 1]))
door (utils/make-anim "inside-castle/door.png" [21 49] 0.15 (flatten [(range 4) 3 3 3 3 3 3 3]))
trophy (utils/make-anim atlas "trophy" [16 16] 0.1 (flatten [(repeat 50 0) 1 2 3 3 3 3 2 1]))
pull-sword-anim (utils/make-anim atlas "pull-sword" [95 190] 0.10 (flatten [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 3 2 3 2 3 3 2 3 2 2 3 3 2 3 2 3 2 3 2 3 2 3 2 2 3 3 3 2 3 2 3 3 2 3 2 3 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ]))
monocle (utils/make-anim atlas "monocle" [19 19] 0.05 (flatten [(repeat 70 0) 1 2 3 3 3 2 1]))
door (utils/make-anim atlas "door" [21 49] 0.15 (flatten [(range 4) 3 3 3 3 3 3 3]))
]
(rooms/make :music {:day :town-1 :night :night :sunrise :night}
:name "Inside castle"
(rooms/make :name "Inside castle"
:timers {:brian [10.0 7.0 brian]}
:interactions
{:right-door {:box [286 140 306 160]
:cursor :right
:script (actions/get-script entities
:only-script (actions/get-script entities
(actions/walk-to entities :ego [284 145] :skip-type :end)
(actions/walk-straight-to entities :ego [295 145])
(if (outside-castle/should-block? entities)
@@ -397,7 +397,7 @@
(actions/walk-straight-to entities :ego [82 180])
(actions/walk-to entities :ego [129 148] :skip-type :end))))}
:up-door {:box [50 150 70 170]
:script (actions/get-script entities
:only-script (actions/get-script entities
(actions/walk-to entities :ego [65 155] :skip-type :end)
(if (= :night (get-in @entities [:state :time]))
(actions/talk entities :ego "It's locked.")
@@ -406,7 +406,7 @@
:cursor :up}
:antique-door {:box [154 90 189 150]
:cursor :up
:script (actions/get-script entities
:only-script (actions/get-script entities
(actions/walk-to entities :ego [182 90] :face :left :skip-type :end)
(actions/play-animation entities :ego :reach)
(if (= :night (get-in @entities [:state :time]))
@@ -424,6 +424,8 @@
:shopkeep "Oh, you're not him."
:shopkeep "Welcome to Ye Olde Antique Shop.")))))}
:sword {:box [15 93 49 125]
:label "Pedestal"
:cursor :hand
:script (actions/get-script entities
(if (actions/has-item? entities :sword)
(actions/talk entities :ego "I already have the Sword of Blergh!")
@@ -436,43 +438,51 @@
(pull-sword entities)
(try-to-pull-sword entities missing-items obtained-items))))))}
:sign {:box [125 140 165 155]
:label "Sign"
:cursor :look
:script (actions/get-script entities
(actions/talk entities :ego "Ye Ol' Antique Shoppe."))}
:background-houses {:box [84 145 126 180]
:script (actions/get-script entities
:only-script (actions/get-script entities
(actions/walk-to entities :ego [81 148] :face :right :stop? false :skip-type :end)
(actions/walk-straight-to entities :ego [92 150] :face :right)
(actions/transition-background entities :outside-jail [159 -20])
(actions/walk-straight-to entities :ego [159 20]))
:cursor :right}
:mid-house {:box [217 125 250 180]
:cursor :look
:label "Billy's house"
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Billy Billigan's house."
:ego "He's probably still angry from when I put his dog in the dryer."))}
:frankie-house {:box [251 140 266 160]
:cursor :look
:label "Frankie's house"
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Frankie Rockfist's house."
:ego "The last time I saw him, he socked me one, right in the kisser."))}
:georgia-house {:box [271 150 286 170]
:cursor :look
:label "Georgia's house"
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Georgia McGorgeous' house."
:ego "One day, when I'm a knight, she'll say...")
(actions/georgia-say entities "Kiss me, brave Sir Tick!")
#_(actions/in-love entities))}}
:layers {:day [(assoc (utils/get-texture "inside-castle/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "inside-castle/way-back-tree.png") :x 0 :y 0 :baseline 97)
(assoc (utils/get-texture "inside-castle/roof.png") :x (- 320 57) :y 0 :baseline 240 :parallax 1.5)
(assoc (utils/get-texture "inside-castle/bookstack.png") :x 244 :y 67 :baseline 190 :origin-x 0 :origin-y 0)]
:night [(assoc (utils/get-texture "inside-castle/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "inside-castle/way-back-tree.png") :x 0 :y 0 :baseline 97)
(assoc (utils/get-texture "inside-castle/roof.png") :x (- 320 57) :y 0 :baseline 240 :parallax 1.5)]
:sunrise [(assoc (utils/get-texture "inside-castle/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "inside-castle/way-back-tree.png") :x 0 :y 0 :baseline 97)
(assoc (utils/get-texture "inside-castle/roof.png") :x (- 320 57) :y 0 :baseline 240 :parallax 1.5)]}
:blackout (assoc (utils/get-texture "black.png")
:layers {:day [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "way-back-tree") :x 0 :y 0 :baseline 97)
(assoc (utils/atlas->texture atlas "roof") :x (- 320 57) :y 0 :baseline 238 :parallax 1.5)
(assoc (utils/atlas->texture atlas "bookstack") :x 244 :y 67 :baseline 190 :origin-x 0 :origin-y 0)]
:night [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "way-back-tree") :x 0 :y 0 :baseline 97)
(assoc (utils/atlas->texture atlas "roof") :x (- 320 57) :y 0 :baseline 238 :parallax 1.5)]
:sunrise [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "way-back-tree") :x 0 :y 0 :baseline 97)
(assoc (utils/atlas->texture atlas "roof") :x (- 320 57) :y 0 :baseline 238 :parallax 1.5)]}
:blackout (assoc (utils/atlas->texture global-atlas "black")
:x -10 :y -10
:width 340
:height 260 :opacity 0.8
@@ -508,31 +518,33 @@
(particle-effect! magic :allow-completion)
entities)
entities))}]
:entities {:bird-1 (utils/make-bird screen (as-> [[185 235]
:entities {:bird-1 (utils/make-bird screen global-atlas (as-> [[185 235]
[220 225] [210 230] [250 235]] p
(concat p (reverse p))))
:sign (assoc (animation->texture screen sign )
:anim sign
:anim-start 0
:x 125 :y 138 :baseline 239)
:bird-2 (utils/make-bird screen (as-> [[220 225] [195 235] [210 230] [250 225]] p
:x 125 :y 138 :baseline 237)
:bird-2 (utils/make-bird screen global-atlas (as-> [[220 225] [195 235] [210 230] [250 225]] p
(concat p (reverse p))))
:outside-particles (common/make-outside-particles)
:door (assoc (animation->texture screen door)
:door (assoc (animation->texture (assoc screen :total-time 0) door)
:x 160 :y 97 :baseline 99
:open door
:door-sound (utils/load-sound "door.ogg")
:anim-sound-frames {door {1 [:door-sound 0.1]}}
)
:sword (assoc (utils/get-texture "inside-castle/sword.png")
:sword (assoc (utils/atlas->texture atlas "sword")
:x 22
:y 110
:baseline 95)
:walkie-talkie (assoc (utils/get-texture "inside-castle/walkie-talkie.png")
:walkie-talkie (assoc (utils/atlas->texture atlas "walkie-talkie")
:label "Walkie-talkie"
:cursor :talk
:x 257
:y 135
:baseline 0
:baseline 1
:night-profile :sprite
:script (actions/get-script entities
(actions/talk entities :ego "Let's see if this thing works.")
@@ -543,6 +555,8 @@
:trophy (assoc (animation->texture screen trophy)
:x 230 :y 69 :baseline 191
:label "Trophy"
:cursor :hand
:anim trophy
:anim-start 0
:script (actions/get-script entities
@@ -556,12 +570,16 @@
(brian-get-to-work entities))
(actions/do-dialogue entities :ego "Can't you give me your trophy of wisdom?"
:game-player "If you want my trophy, you'll have to help me with my riddles."))))
:books (assoc (utils/get-texture "inside-castle/books.png")
:books (assoc (utils/atlas->texture atlas "books")
:label "Books"
:cursor :hand
:x 230 :y 30 :baseline 191
:script (actions/get-script entities
(walk-to-player entities)
(actions/talk entities :game-player "Don't touch my books!")))
:game-player (assoc (utils/get-texture "inside-castle/gameplayer.png") :x 266 :y 49 :baseline 191
:game-player (assoc (utils/atlas->texture atlas "gameplayer") :x 266 :y 49 :baseline 191
:label "Brian O'Brainy"
:cursor :talk
:talk-color (color 1.0 0.3 0.4 1.0)
:script (actions/get-script entities (do-game-player-dialogue entities))
:writing-sound (utils/load-sound "inside-castle/writing.ogg")
@@ -651,6 +669,8 @@
game-player-flex {1 [:flex-sound 0.5]}}
:flex game-player-flex)}
:monocle (rooms/make-entity :monocle (assoc (animation->texture screen monocle)
:label "A reflective thing"
:cursor :hand
:x 209 :y 160 :baseline 240
:origin-x 9
:anim monocle

View File

@@ -11,36 +11,38 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn open-safe [entities]
(actions/play-animation entities :ego :start-squat :stop? false)
(Thread/sleep 500)
(screen! safe/safe-screen :show-screen
:success (actions/get-script entities
(Thread/sleep 500)
(actions/play-animation entities :ego :end-squat)
{ :success (actions/get-script entities
(Thread/sleep 500)
(actions/play-animation entities :ego :end-squat)
(if (actions/has-item? entities :recipe)
(do
(actions/talk entities :ego "I already took everything interesting from there."))
(do
(actions/talk entities :ego "Yes! That worked.")
(actions/talk entities :ego "Let's see here...")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "No, that's a recipe to turn someone into a professional dancer...")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "Here's a recipe to make everything taste like cotton candy. I'll just put that back.")
(actions/play-animation entities :ego :squat)
(actions/give entities :recipe)
(actions/talk entities :ego "Aha! Here it is! I found a recipe for a strength potion!")
(actions/talk entities :ego "Looks like there's something else in here too...")
(actions/play-animation entities :ego :squat)
(actions/give entities :mandrake)
(actions/talk entities :ego "Weird. It's some kind of root."))))
:failure (actions/get-script entities
(Thread/sleep 500)
(actions/play-animation entities :ego :end-squat)
(actions/talk entities :ego "I don't think that worked...")))
(if (actions/has-item? entities :recipe)
(do
(actions/talk entities :ego "I already took everything interesting from there."))
(do
(actions/talk entities :ego "Yes! That worked.")
(actions/talk entities :ego "Let's see here...")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "No, that's a recipe to turn someone into a professional dancer...")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "Here's a recipe to make everything taste like cotton candy. I'll just put that back.")
(actions/play-animation entities :ego :squat)
(actions/give entities :recipe)
(actions/talk entities :ego "Aha! Here it is! I found a recipe for a strength potion!")
(actions/talk entities :ego "Looks like there's something else in here too...")
(actions/play-animation entities :ego :squat)
(actions/give entities :mandrake)
(actions/talk entities :ego "Weird. It's some kind of root."))))
:failure (actions/get-script entities
(Thread/sleep 500)
(actions/play-animation entities :ego :end-squat)
(actions/talk entities :ego "I don't think that worked..."))})
(actions/update-state entities #(assoc % :active? false)))
(defn do-wizard-dialogue [entities]
@@ -131,22 +133,23 @@
"Nevermind."
{:run #(actions/do-dialogue entities :ego %)}]}))
(defn make [screen]
(let [
safe-lock (utils/make-anim "inside-house/safe-lock.png" [11 8] 0.1 (flatten [(repeat 20 0) 1 2 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 (range 3 20) 20 20 20 20 21 21 21 21 21 20 20 21 21 21 21 21 20 20 20 ]))
candle (utils/make-anim "inside-house/candle.png" [34 32] 0.2 [1 0 1 2])
candle-aura (utils/make-anim "inside-house/candle-aura.png" [27 27] 0.2 [0 1 2 3 2 1] )
experiment-left (utils/flip (utils/make-anim-seq "wizard/experiment" [45 55] 0.075 [0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 2 3 3 3 4 4 5 5 6 6 6 6 6 6 7 8 9 9 10 10 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 14 14 14 14 14 15 15 16 16 17 17 18 18 18 18 19 20 21 21 21 21 21 21 22 23 22 23 22 23 22 23 23 23 23 23 23 23 23 24 24 24 24 24 24 24 24 24 25 26 27 37 38 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 29 29 29 28 28 28 28 29 29 28 28 28 28 28 28 28 28 30 30 30 30 31 32 33 31 31 31 31 31 31 31 31 34 35 36 36 36 36 36 36 36 36 36] ))]
(rooms/make :music :inside-fangald
(defn make [screen atlas global-atlas]
(let [safe-lock (utils/make-anim atlas "safe-lock" [11 8] 0.1 (flatten [(repeat 20 0) 1 2 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 (range 3 20) 20 20 20 20 21 21 21 21 21 20 20 21 21 21 21 21 20 20 20 ]))
candle (utils/make-anim atlas "candle" [34 32] 0.2 [1 0 1 2])
candle-aura (utils/make-anim atlas "candle-aura" [27 27] 0.2 [0 1 2 3 2 1] )
experiment-left (utils/flip (utils/make-anim-seq global-atlas "wizard/experiment" [45 55] 0.075 [0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 2 3 3 3 4 4 5 5 6 6 6 6 6 6 7 8 9 9 10 10 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 14 14 14 14 14 15 15 16 16 17 17 18 18 18 18 19 20 21 21 21 21 21 21 22 23 22 23 22 23 22 23 23 23 23 23 23 23 23 24 24 24 24 24 24 24 24 24 25 26 27 37 38 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 29 29 29 28 28 28 28 29 29 28 28 28 28 28 28 28 28 30 30 30 30 31 32 33 31 31 31 31 31 31 31 31 34 35 36 36 36 36 36 36 36 36 36] ))]
(rooms/make
:name "Inside house"
:interactions {:down-dir {:box [151 0 320 40]
:script (actions/get-script entities
:only-script (actions/get-script entities
(actions/update-state entities #(assoc % :wizard-left? false))
(actions/walk-to entities :ego [237 1] :stop? false :skip-type :end)
(actions/walk-straight-to entities :ego [245 -60])
(actions/transition-background entities :outside-house [257 90] :face :left))
:cursor :down}
:safe {:box [34 70 70 115]
:label "MagiSafe 2000"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [59 65])
(if (get-in @entities [:room :entities :wizard])
@@ -159,51 +162,58 @@
(actions/talk entities :ego "How did that tune go again?")
(actions/play-safe entities))))}}
:knight {:box [71 70 102 190]
:cursor :look
:label "Armor"
:script (actions/get-script entities
(actions/talk entities :ego "Maybe when I am an older knight, Gandarf will give me his armor!"))}
:shelves {:box [215 100 320 220]
:cursor :look
:label "Shelves"
:script (actions/get-script entities
(actions/talk entities :ego "His shelves are full of books and strange ingredients."))}
:window {:box [119 120 203 190]
:label "Window"
:cursor :look
:script (actions/get-script entities
(actions/talk entities :ego "It's a really big window!"))}}
:layers [(assoc (utils/get-texture "inside-house/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "inside-house/desk.png") :x 0 :y 0 :baseline 200)
(assoc (utils/get-texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240 :parallax 2.0)
(assoc (utils/get-texture "inside-house/glow.png") :x 0 :y 0 :baseline 199 :additive? true)]
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "desk") :x 0 :y 0 :baseline 200)
(assoc (utils/atlas->texture atlas "sillhoute") :x 0 :y 0 :baseline 240 :parallax 2.0)
(assoc (utils/atlas->texture atlas "glow") :x 0 :y 0 :baseline 199 :additive? true)]
:entities {
:wizard (common/make-wizard screen {:x 228 :y 60 :baseline 160 :scale-x 1.75 :scale-y 1.75 :origin-x 0 :origin-y 0
:script (actions/get-script entities (do-wizard-dialogue entities))
:scripts #(condp = %
:kiss (actions/get-script entities
(actions/do-dialogue entities
:wizard "Good job, boy! You saved a damsel in distress."
:wizard "You have proven yourself worthy in courage."))
:medal (actions/get-script entities
(actions/do-dialogue entities
:wizard "So you beat Captain McHulk at arm wrestling? "
:wizard "You must have been working out!"))
:trophy (actions/get-script entities
(actions/do-dialogue entities
:wizard "My, my, you have proven your worth in wisdom!"
:wizard "One day, you'll be as wise as I am!"))
:recipe (actions/get-script entities
(actions/do-dialogue entities
:ego "I probably shouldn't show him that I have his stolen possessions."))
:frog-legs (actions/get-script entities
(actions/do-dialogue entities
:ego "I probably shouldn't show him that I have his stolen possessions."))
:mandrake (actions/get-script entities
(actions/do-dialogue entities
:ego "I probably shouldn't show him that I have his stolen possessions."))
:flask-1 (actions/get-script entities
(actions/do-dialogue entities
:wizard "You can keep the flask."))
:tune (actions/get-script entities
(actions/talk entities :ego "I think he already has it memorized."))
(actions/get-script entities
:wizard (common/make-wizard screen global-atlas
{:x 228 :y 60 :baseline 160 :scale-x 1.75 :scale-y 1.75 :origin-x 0 :origin-y 0
:script (actions/get-script entities (do-wizard-dialogue entities))
:scripts #(condp = %
:kiss (actions/get-script entities
(actions/do-dialogue entities
:wizard "Good job, boy! You saved a damsel in distress."
:wizard "You have proven yourself worthy in courage."))
:medal (actions/get-script entities
(actions/do-dialogue entities
:wizard "No thank you.")))})
:wizard "So you beat Captain McHulk at arm wrestling? "
:wizard "You must have been working out!"))
:trophy (actions/get-script entities
(actions/do-dialogue entities
:wizard "My, my, you have proven your worth in wisdom!"
:wizard "One day, you'll be as wise as I am!"))
:recipe (actions/get-script entities
(actions/do-dialogue entities
:ego "I probably shouldn't show him that I have his stolen possessions."))
:frog-legs (actions/get-script entities
(actions/do-dialogue entities
:ego "I probably shouldn't show him that I have his stolen possessions."))
:mandrake (actions/get-script entities
(actions/do-dialogue entities
:ego "I probably shouldn't show him that I have his stolen possessions."))
:flask-1 (actions/get-script entities
(actions/do-dialogue entities
:wizard "You can keep the flask."))
:tune (actions/get-script entities
(actions/talk entities :ego "I think he already has it memorized."))
(actions/get-script entities
(actions/do-dialogue entities
:wizard "No thank you.")))})
:safe-lock (actions/start-animation screen (assoc (animation->texture screen safe-lock) :x 50 :y 92 :baseline 145
:stand safe-lock)
:stand)
@@ -213,6 +223,8 @@
:baseline 200
:anim candle
:anim-start 0
:label "Candle"
:cursor :look
:script (actions/get-script entities (actions/do-dialogue entities :ego "It's just a candle.")))
:candle-aura (assoc (animation->texture screen candle-aura) :x 172 :y 97 :baseline 239 :additive? true :origin-x 13 :opacity 0.5 :anim candle-aura :anim-start 0)
:candle-smoke (doto (assoc (particle-effect "particles/candle") :x 172 :y 112
@@ -221,16 +233,20 @@
:magic-frog-particle (doto (assoc (particle-effect "particles/magic-frog") :x 230 :y 0
:baseline 241)
(particle-effect! :set-position 237 0))
:flask (assoc (utils/get-texture "inside-house/flask.png")
:flask (assoc (utils/atlas->texture atlas "flask")
:x 265 :y 80 :baseline 240
:label "Flask"
:cursor :hand
:script (actions/get-script entities
(actions/remove-entity entities :flask)
(actions/give entities :flask-1)
(when (get-in @entities [:room :entities :wizard])
(actions/do-dialogue entities :ego "Hey, you think I could have this flask?"
:wizard "Sure."))))
:frog-legs (assoc (utils/get-texture "inside-house/frog-legs.png")
:frog-legs (assoc (utils/atlas->texture atlas "frog-legs")
:x 180 :y 77 :baseline 240
:label "Frog legs"
:cursor :hand
:script (actions/get-script entities
(if (get-in @entities [:room :entities :wizard])
(actions/do-dialogue entities :wizard "Hey, I need those frog legs for one of my spells!")

View File

@@ -14,6 +14,7 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn remove-lock [entities]
(-> entities
@@ -121,6 +122,7 @@
:warden "Be a good chap and let me rest.")
(actions/play-animation entities :warden :fall-asleep :stop? false)
(actions/begin-animation entities :warden :sleep)
(actions/update-state entities (fn [s] (assoc s :warden-sleeping? true))))}]}))
(defn get-key [ entities]
@@ -215,8 +217,8 @@
(defn make [screen]
(let [warden-sheet (texture! (utils/get-texture "inside-jail/warden.png") :split 43 58)
(defn make [screen atlas global-atlas]
(let [warden-sheet (texture! (utils/atlas->texture atlas "warden") :split 43 58)
warden-talk (animation 0.2 (for [i [1 0 1 0 1 0 1 0 0 0 2 0]]
(aget warden-sheet 0 i)))
warden-stand (animation 0.1 (for [i (flatten [(repeat 30 0) 2 (repeat 20 0) 2])]
@@ -225,23 +227,26 @@
(aget warden-sheet 0 i)))
warden-sleep (animation 0.25 (for [i (flatten [ 3 4 3 4 3 4 3 4 3 4 5 5 2 2 2 2 2 2])]
(aget warden-sheet 0 i)))
candle (utils/make-anim "inside-jail/candle.png" [20 25] 0.1 (range 4))
candle-aura (utils/make-anim "inside-house/candle-aura.png" [27 27] 0.2 [0 1 2 3 2 1])
crowbar (utils/make-anim "inside-jail/crowbar.png" [16 33] 0.15 (flatten [(repeat 120 0) [1 2 3 3 2 1]]))]
(rooms/make :music :inside-antique
:name "In jail"
candle (utils/make-anim atlas "candle" [20 25] 0.1 (range 4))
candle-aura (utils/make-anim atlas "candle-aura" [27 27] 0.2 [0 1 2 3 2 1])
crowbar (utils/make-anim atlas "crowbar" [16 33] 0.15 (flatten [(repeat 120 0) [1 2 3 3 2 1]]))]
(rooms/make :name "In jail"
:sounds {
:squeek (utils/load-sound "inside-jail/squeak.ogg")
:crowbar-sound (utils/load-sound "ego/crowbar.ogg")
}
:interactions {
:lock {:box [172 102 190 124]
:label "Lock"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [174 80] :face :right)
(actions/play-animation entities :ego :reach)
(actions/talk entities :ego "There's no helping it. It's locked."))
:scripts {:key (actions/get-script entities (open-lock entities))}}
:window {:box [98 110 118 140]
:label "Window"
:cursor :look
:script (actions/get-script entities
(actions/walk-to entities :ego [102 88] :face :right)
(actions/do-dialogue entities
@@ -269,6 +274,7 @@
(get-in @entities [:room :entities :ego :drop-sound])
0.2)
(actions/update-state entities #(assoc % :dropped-ball? true))
(actions/remove-item entities :ball-n-chain)
(actions/do-dialogue entities :ego "Geronimo!!")
(actions/play-sound entities
"inside-jail/guard-crash.ogg"
@@ -285,7 +291,7 @@
(Thread/sleep 300)
(actions/play-animation entities :warden :fall-asleep :stop? false)
(actions/begin-animation entities :warden :sleep)
(actions/remove-item entities :ball-n-chain)
(actions/talk entities :ego "Phew! That was close!"))
(actions/do-dialogue entities :ego "I don't know what to do with that.")))
:sword (actions/get-script entities (actions/talk entities :ego "I wouldn't want to accidentally break the Sword of Blergh."))
@@ -317,6 +323,8 @@
:ego "The door locks without a key."
:ego "If I get caught, I won't be able to get out."))}}
:hay {:box [130 86 177 102]
:label "Hay"
:cursor :hand
:script (actions/get-script entities
(search-hay entities))
:scripts {:default (actions/get-script entities
@@ -326,6 +334,8 @@
(actions/do-dialogue entities :ego "I'm trying to escape."
:ego "Not help the next bloke who gets trapped here."))}}
:chest {:box [194 62 228 99]
:label "Chest"
:cursor :hand
:script (actions/get-script entities (touch-chest entities))
:scripts {:key (actions/get-script entities
(if (get-in @entities [:state :opened-bars?])
@@ -337,13 +347,13 @@
(actions/talk entities :ego "Not while I'm in this cell.")))}}
:door {:box [257 62 301 152]
:cursor :down
:script (actions/get-script entities (leave entities))}
:only-script (actions/get-script entities (leave entities))}
}
:layers [(assoc (utils/get-texture "inside-jail/background.png") :x 0 :y 0 :baseline 0 :night-profile :none)
(assoc (utils/get-texture "inside-jail/bars.png") :x 0 :y 0 :baseline 165 :night-profile :none)
(assoc (utils/get-texture "inside-jail/glow.png") :x 0 :y 0 :baseline 240 :additive? true :opacity 0.35 :night-profile :none)
(assoc (utils/get-texture "inside-jail/fg.png") :x 0 :y 5 :baseline 241 :parallax 1.5 :night-profile :none)]
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0 :night-profile :none)
(assoc (utils/atlas->texture atlas "bars") :x 0 :y 0 :baseline 165 :night-profile :none)
(assoc (utils/atlas->texture atlas "glow") :x 0 :y 0 :baseline 240 :additive? true :opacity 0.35 :night-profile :none)
(assoc (utils/atlas->texture atlas "fg") :x 0 :y 5 :baseline 241 :parallax 1.5 :night-profile :none)]
:hotspots [{:box [121 40 258 44]
:fn (fn [screen entities]
@@ -363,7 +373,7 @@
(common/go-to-jail entities)) entities)
entities)
entities)))}]
:entities {:warden (assoc (utils/get-texture "inside-jail/warden.png" )
:entities {:warden (assoc (utils/atlas->texture atlas "warden" )
:x 40 :y 60 :baseline 166
:stand warden-stand
:talk warden-talk
@@ -382,6 +392,8 @@
18 [:blink 0.15]}
warden-sleep {0 [:inhale 0.1]
10 [:exhale 0.1]}}
:label "Warden"
:cursor :talk
:script (actions/get-script entities
(cond
(actions/has-item? entities :key) (actions/talk entities :ego "Shh! It's best not to wake him now.")
@@ -390,6 +402,7 @@
(actions/do-dialogue entities
:ego "Yoo-hoo! Mr. Warden?"
:ego "I guess he's really fast asleep!")
(actions/update-entities entities (fn [e] (assoc-in e [:room :entities :warden :cursor] :hand)))
(actions/update-state entities #(assoc % :warden-fast-asleep? true)))
:else (do (actions/walk-to entities :ego [103 82])
@@ -399,21 +412,23 @@
:ego "I can't kill him just for doing his job."))
:rope (actions/get-script entities (tie-up-warden entities "I'll tie him up."))
:ball-n-chain (actions/get-script entities (tie-up-warden entities "I'll lock him up."))})
:chest-top (assoc (utils/get-texture "inside-jail/chest-top.png")
:chest-top (assoc (utils/atlas->texture atlas "chest-top")
:x 193 :y (- 240 165) :baseline 166
:origin-x 0 :origin-y 0
:night-profile :none
:open (animation 0.8 [(utils/get-texture "inside-jail/chest-top-open.png")])
:close (animation 0.8 [(utils/get-texture "inside-jail/chest-top.png")]))
:ball-n-chain (assoc (utils/get-texture "inside-jail/ball-n-chain.png")
:open (animation 0.8 [(utils/atlas->texture atlas "chest-top-open")])
:close (animation 0.8 [(utils/atlas->texture atlas "chest-top")]))
:ball-n-chain (assoc (utils/atlas->texture atlas "ball-n-chain")
:x 80 :y 80 :baseline 160
:night-profile :none
:label "Ball-n-chain"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [103 83] :face :left)
(actions/play-animation entities :ego :squat)
(actions/remove-entity entities :ball-n-chain)
(actions/give entities :ball-n-chain)))
:moveable-bars (assoc (utils/get-texture "inside-jail/moveable-bars.png")
:moveable-bars (assoc (utils/atlas->texture atlas "moveable-bars")
:night-profile :none
:x 132 :y 77 :baseline 163)
:candle (assoc (animation->texture screen candle)
@@ -423,6 +438,8 @@
:night-profile :none)
:candle-aura (assoc (animation->texture screen candle-aura) :x 215 :y 130 :baseline 2
:additive? true :origin-x 13 :origin-y 13 :opacity 0.5 :anim candle-aura :anim-start 0 :night-profile :none
:label "Candle"
:cursor :look
:script (actions/get-script entities (actions/talk entities :ego "Just a candle."))
:scripts {:default (actions/get-script entities (actions/talk entities :ego "I might catch the place on fire."))})
:candle-smoke (doto (assoc (particle-effect "particles/candle") :x 215 :y 130
@@ -434,6 +451,8 @@
:x 300 :y 60 :baseline 175
:night-profile :none
:label "Crowbar"
:cursor :hand
:script (actions/get-script entities
(if (get-in @entities [:state :opened-bars?])
(do (actions/walk-to entities :ego [295 55] :face :right)
@@ -442,7 +461,7 @@
(actions/give entities :crowbar)
(actions/talk entities :ego "It's a crowbar."))
(actions/talk entities :ego "I can't reach it."))))
:closed-window (assoc (utils/get-texture "inside-jail/window.png")
:closed-window (assoc (utils/atlas->texture atlas "window")
:night-profile :none
:x 99 :y 111 :baseline 128)
:guard { :object nil :width 100 :height 100 :x 70 :y 55 :talk-color (color 0.2 0.6 1.0 1.0)}}
@@ -459,8 +478,10 @@
(if (actions/has-obtained? entities :crowbar)
(update-in entities [:room :entities] #(dissoc % :crowbar))
entities)
(if (get-in entities [:state :warden-sleeping?])
(update-in entities [:room :entities :warden] #(actions/start-animation % :sleep))
(if (get-in entities [:state :warden-fast-asleep?])
(-> entities
(update-in [:room :entities :warden] #(actions/start-animation % :sleep))
(update-in [:room :entities :warden] assoc :cursor :hand))
entities)
(if (get-in entities [:state :opened-bars?])
(update-in (remove-lock entities)

View File

@@ -8,6 +8,7 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn bust-chest [entities]
(if (get-in @entities [:state :broke-lock?])
@@ -54,21 +55,24 @@
(defn make [screen]
(let [candle-flame (utils/make-anim "inside-stash/candle.png" [4 4] 0.1 (range 4))
candle-aura (utils/make-anim "inside-house/candle-aura.png" [27 27] 0.2 [0 1 2 3 2 1] )
(defn make [screen atlas global-atlas]
(let [[screen atlas] (utils/acquire-atlas screen "packed/inside-stash.atlas")
candle-flame (utils/make-anim atlas "candle" [4 4] 0.1 (range 4))
candle-aura (utils/make-anim atlas "candle-aura" [27 27] 0.2 [0 1 2 3 2 1] )
]
(rooms/make :music {:day :secret-hideout :night :secret-hideout}
(rooms/make
:name "Inside stash"
:interactions
{:left-dir {:box [91 60 125 140]
:script (actions/get-script
:only-script (actions/get-script
entities
(actions/walk-straight-to entities :ego [118 96])
(actions/transition-background entities :outside-jail [200 97])
(actions/walk-straight-to entities :ego [167 100]))
:cursor :left}
:candle {:box [160 130 170 140]
:label "Candle"
:cursor :look
:script (actions/get-script
entities
(actions/talk entities :ego "Just a candle."))
@@ -85,14 +89,16 @@
:default (actions/get-script entities
(actions/talk entities :ego "Momma always told me not to play with fire."))}}
:chest {:box [151 107 180 124]
:label "Chest"
:cursor :hand
:script (actions/get-script entities (explore-chest entities))
:scripts {:sword (actions/get-script entities (actions/talk entities :ego "There's not enough room to swing my sword here."))
:crowbar (actions/get-script entities
(bust-chest entities))
:key (actions/get-script entities
(unlock-chest entities))}}}
:layers [(assoc (utils/get-texture "inside-stash/background.png") :x 0 :y 0 :baseline 0 :night-profile :none)]
:entities {:lid (assoc (utils/get-texture "inside-stash/lid.png")
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0 :night-profile :none)]
:entities {:lid (assoc (utils/atlas->texture atlas "lid")
:x 156 :y 116 :baseline 125 :night-profile :none)
:candle-flame (assoc (animation->texture screen candle-flame)
:x 165 :y 135 :baseline 1

View File

@@ -12,6 +12,7 @@
[play-clj.math :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn flies-vol [entities]
(utils/proximity-volume entities [201 175] :scale 0.20))
@@ -262,10 +263,16 @@
:frankie "And some gold..."
:frankie "And what's this?")
(actions/play-animation entities :frankie :reach)
(actions/remove-item entities :slingshot)
(actions/remove-item entities :medal)
(actions/remove-item entities :trophy)
(actions/do-dialogue entities
:frankie "The Slinger's Shot?"
:ego "No, not the Slinger's Shot!"
:frankie "Looks like we hit the jackpot tonight, boys!")
(actions/remove-item entities :flask-1-strength)
(frankie-comment-on-item entities)
(actions/update-state entities #(assoc % :bubba-gone? true))
(actions/do-dialogue entities
@@ -278,10 +285,6 @@
:frankie "Before we decide to take all of your stuff."
:ego "But I need that slingshot!"
:frankie "Too bad. Move along.")
(actions/remove-item entities :flask-1-strength)
(actions/remove-item entities :medal)
(actions/remove-item entities :trophy)
(actions/remove-item entities :slingshot)
(actions/walk-to entities :ego [181 79])
(actions/do-dialogue entities
@@ -324,25 +327,24 @@
(actions/talk entities :ego "Eww! He slobbered on my hand.")
(actions/give entities :slobber))
(defn make [screen]
(let [peddler-sheet (texture! (utils/get-texture "outside-castle/peddler-talk.png" ) :split 18 36)
(defn make [screen atlas global-atlas]
(let [peddler-sheet (texture! (utils/atlas->texture atlas "peddler-talk" ) :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 8 0) 6 (repeat 15 0) 6 (repeat 5 0) 4 5 4 5 4 5 (repeat 10 0)] )]
(aget peddler-sheet 0 i)))
balloon-sheet (texture! (utils/get-texture "outside-castle/balloons.png") :split 20 36)
balloon-sheet (texture! (utils/atlas->texture atlas "balloons") :split 20 36)
balloon-stand (animation 0.25 (for [i [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 0 1 2 1 0 1 2 1 0 1 2 1 0 1 2]]
(aget balloon-sheet 0 i)))
steer-sheet (texture! (utils/get-texture "outside-castle/steer.png") :split 50 35)
steer-sheet (texture! (utils/atlas->texture atlas "steer") :split 50 35)
steer-stand (animation 0.2 (for [i [0 0 0 0 0 0 0 0 0 1 0 2 0 1 0 2 0 1 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 0 0 0 0]]
(aget steer-sheet 0 i)))
flies-stand (utils/make-anim "outside-castle/flies.png" [15 15] 0.075 (flatten (repeat 2 [0 1 2 1])))]
(rooms/make :music {:day :town-2 :night :night :sunrise :night}
:name "Outside castle"
flies-stand (utils/make-anim atlas "flies" [21 21] 0.075 (flatten (repeat 2 [0 1 2 1])))]
(rooms/make :name "Outside castle"
:interactions
{:right-dir {:box [280 40 320 140]
:script (actions/get-script
:only-script (actions/get-script
entities
(actions/walk-to entities :ego [310 80] :stop? false :skip-type :end)
(actions/walk-straight-to entities :ego [340 80])
@@ -350,17 +352,23 @@
(actions/walk-straight-to entities :ego [30 80]))
:cursor :right}
:door {:box [66 180 85 195]
:script (actions/get-script
:only-script (actions/get-script
entities
(go-through-gate entities))
:cursor :left}
:castle {:box [0 181 100 240]
:cursor :look
:label "Castle"
:script (actions/get-script entities
(actions/do-dialogue entities :ego "That's the town of Remington in the distance."))}
:wares {:box [69 75 97 110]
:cursor :look
:label "Wares"
:script (actions/get-script entities
(actions/talk entities :ego "That peddler has all kinds of strange trinkets."))}
:garden {:box [103 170 178 200]
:label "Garden"
:cursor :hand
:script (actions/get-script
entities
(if (actions/has-obtained? entities :carrot)
@@ -373,29 +381,31 @@
(actions/give entities :carrot))))}}
:flies-sound {:sound (utils/load-sound "outside-castle/flies2.ogg")
:id nil}
:layers {:day [(assoc (utils/get-texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outside-castle/blanket.png") :x 60 :y (- 240 173) :baseline 1)
(assoc (utils/get-texture "outside-castle/brush-bl.png") :origin-x 25 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 25 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/get-texture "outside-castle/brush-br.png") :origin-x 88 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 315 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/get-texture "outside-castle/walk-behind.png") :x 0 :y 0 :baseline 69)]
:night [(assoc (utils/get-texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)
:layers {:day [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "blanket") :x 60 :y (- 240 173) :baseline 1)
(assoc (utils/atlas->texture atlas "brush-bl") :origin-x 25 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 25 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/atlas->texture atlas "brush-br") :origin-x 88 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 315 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/atlas->texture atlas "walk-behind") :x 0 :y 0 :baseline 69)]
:night [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outside-castle/brush-bl.png") :origin-x 25 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 25 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/get-texture "outside-castle/brush-br.png") :origin-x 88 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 315 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/get-texture "outside-castle/walk-behind.png") :x 0 :y 0 :baseline 69)]
:sunrise [(assoc (utils/get-texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "brush-bl") :origin-x 25 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 25 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/atlas->texture atlas "brush-br") :origin-x 88 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 315 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/atlas->texture atlas "walk-behind") :x 0 :y 0 :baseline 69)]
:sunrise [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outside-castle/brush-bl.png") :origin-x 25 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 25 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/get-texture "outside-castle/brush-br.png") :origin-x 88 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 315 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/get-texture "outside-castle/walk-behind.png") :x 0 :y 0 :baseline 69)]}
(assoc (utils/atlas->texture atlas "brush-bl") :origin-x 25 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 25 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/atlas->texture atlas "brush-br") :origin-x 88 :origin-y 20 :scale-x 1.0 :scale-y 1.0 :x 315 :y 0 :baseline 240 :parallax 1.2)
(assoc (utils/atlas->texture atlas "walk-behind") :x 0 :y 0 :baseline 69)]}
:entities {:peddler (actions/start-animation screen
(assoc (utils/get-texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil
(assoc (utils/atlas->texture atlas "peddler") :x 110 :y 90 :baseline 150 :anim nil
:anim-sound-frames {peddler-stand {8 [:blink 0.3 0.8]
24 [:blink 0.3 0.8]
30 [:scratch 0.15]}
peddler-talk {23 [:scratch 0.15]
6 [:blink 0.3 0.8]
22 [:blink 0.3 0.8]}}
:cursor :talk
:label "Peddler"
:scratch (utils/load-sound "outside-castle/scratch.ogg")
:talk peddler-talk :stand peddler-stand
:talk-color (color 1.0 0.9 0.4 1.0)
@@ -418,7 +428,9 @@
:peddler "No, I have no use for it."))))
:stand)
:steer (actions/start-animation screen (assoc (animation->texture screen steer-stand) :x 203 :y 155 :baseline 80
:steer (actions/start-animation screen (assoc (animation->texture screen steer-stand) :x 203 :y 151 :baseline 80
:label "Angus, the buff bull"
:cursor :hand
:stand steer-stand
:night-profile :sprite
:moo (utils/load-sound "outside-castle/moo.ogg")
@@ -453,12 +465,14 @@
(assoc (animation->texture screen balloon-stand)
:x 75
:y 100
:cursor :look
:label "Balloons"
:baseline 140
:stand balloon-stand
:script (actions/get-script entities
(actions/talk entities :ego "Those look like the choicest of balloons.")))
:stand)
:bird (utils/make-bird screen (as-> [[82 235] [134 215] [185 235] [165 238]
:bird (utils/make-bird screen global-atlas (as-> [[82 235] [134 215] [185 235] [165 238]
[220 225] [210 230] [250 235]] p
(concat p (reverse p))))
@@ -466,7 +480,9 @@
:outside-particles (common/make-outside-particles)
:flies (assoc (animation->texture screen flies-stand)
:x 201
:y 175
:y 178
:label "Flies"
:cursor :look
:anim flies-stand
:anim-start 0
:baseline 240
@@ -487,7 +503,9 @@
:script (actions/get-script entities
(actions/talk entities :ego "Those flies seem to be attracted to Angus' stench."))
)}
:note (rooms/make-entity :note (assoc (utils/get-texture "outside-castle/note.png")
:note (rooms/make-entity :note (assoc (utils/atlas->texture atlas "note")
:label "Bingo card"
:cursor :hand
:x 198 :y 66 :baseline 174
:script (actions/get-script entities
(actions/walk-to entities :ego [210 79] :face :left)

View File

@@ -16,6 +16,7 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn dawn-fade [entities]
@@ -121,7 +122,7 @@
(actions/play-animation entities :ego :reach-stop :stop? true)
(actions/remove-item entities :slingshot)
(actions/remove-item entities :slingshot :quiet? true )
(actions/give entities :magic-slingshot)
(actions/do-dialogue entities :ego "It worked!")
@@ -194,9 +195,7 @@
(particle-effect! (get-in @entities [:room :entities :magic-frog-particle]) :reset)
(particle-effect! (get-in @entities [:room :entities :magic-frog-particle]) :start)
(Thread/sleep 1500)
(actions/transition-background entities :outside-house [257 90] :face :left)
(dotimes [_ 160]
(particle-effect! (get-in @entities [:rooms :inside-house :entities :magic-frog-particle]) :update 0.2)))
(actions/transition-background entities :outside-house [257 90] :face :left))
(defn do-prophecy [entities]
{:run #(do (actions/respond entities %
@@ -550,10 +549,10 @@
(/ (:delta-time screen)
(/ 1.0 60.0)))
speed (if (< delta-x 0) (- speed) speed)
moved-x (if (< (Math/abs delta-x) speed)
moved-x (if (< (Math/abs (int delta-x)) speed)
target-x
(* speed (/ delta-x delta-x) ))]
(if (< (Math/abs delta-x) speed)
(if (< (Math/abs (int delta-x)) speed)
(actions/start-animation screen
(dissoc e :target-x)
:stand)
@@ -604,32 +603,32 @@
(actions/talk entities :ego "That's a big cauldron!"))))
(defn make [screen]
(let [sheep-stand-sheet (texture! (utils/get-texture "outsidehouse/sheep-anim.png") :split 33 21)
sheep-walk-sheet (texture! (utils/get-texture "outsidehouse/sheep-walk.png") :split 33 21)
lamb-walk-sheet (texture! (utils/get-texture "outsidehouse/lamb-walk.png") :split 27 28)
(defn make [screen atlas global-atlas]
(let [sheep-stand-sheet (texture! (utils/atlas->texture atlas "sheep-anim") :split 33 21)
sheep-walk-sheet (texture! (utils/atlas->texture atlas "sheep-walk") :split 33 21)
lamb-walk-sheet (texture! (utils/atlas->texture atlas "lamb-walk") :split 27 28)
sheep-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 11) (repeat 15 12)])]
(aget sheep-stand-sheet 0 i)))
sheep-1 (utils/make-anim "outsidehouse/sheep-1.png" [33 21] 0.15 (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 0) (repeat 15 9)]))
sheep-2 (utils/make-anim "outsidehouse/sheep-2.png" [33 21] 0.15 (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 0) (repeat 15 9)]))
sheep-3 (utils/make-anim "outsidehouse/sheep-3.png" [33 21] 0.15 (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 0) (repeat 15 9)]))
door (utils/make-anim "outsidehouse/door.png" [24 58] 0.15 (flatten [(range 4) 3 3 3 3 3 3 3]))
sheep-1 (utils/make-anim atlas "sheep-1" [33 21] 0.15 (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 0) (repeat 15 9)]))
sheep-2 (utils/make-anim atlas "sheep-2" [33 21] 0.15 (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 0) (repeat 15 9)]))
sheep-3 (utils/make-anim atlas "sheep-3" [33 21] 0.15 (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 2 1 (repeat 25 0) (repeat 15 9)]))
door (utils/make-anim atlas "door" [24 58] 0.15 (flatten [(range 4) 3 3 3 3 3 3 3]))
door-closed (utils/make-anim atlas "door" [24 58] 0.15 [0])
sheep-walk (animation 0.05 (for [i (range 6)]
(aget sheep-walk-sheet 0 i)))
butterfly-stand (utils/make-anim "butterfly.png" [7 7] 0.1 [0 1])
cauldron (utils/make-anim "outsidehouse/cauldron.png" [50 38] 0.15 (range 4))
charcoal (utils/make-anim-seq "outsidehouse/charcoal" [18 18] 0.25 (range 4))
butterfly-stand (utils/make-anim atlas "butterfly" [7 7] 0.1 [0 1])
cauldron (utils/make-anim atlas "cauldron" [50 38] 0.15 (range 4))
charcoal (utils/make-anim-seq atlas "charcoal" [24 18] 0.25 (range 4))
scaler (utils/scaler-fn-with-baseline 110 0.10 1.00)
lamb-stand (aget lamb-walk-sheet 0 0)
lamb-walk (animation 0.075 (for [i (range 4)]
(aget lamb-walk-sheet 0 i)))]
(rooms/make :music {:day :town-2 :night :night}
:name "Outside house"
(rooms/make :name "Outside house"
:update-fn jump-around
:cauldron-sound {:object nil :sound (utils/load-sound "outsidehouse/cauldron.ogg")}
:interactions
{:door {:box [250 100 281 160]
:script
:only-script
(actions/get-script
entities
(actions/walk-to entities :ego [257 90] :face :right :skip-type :end)
@@ -646,7 +645,7 @@
:else
(do (actions/play-animation entities :door :open)
(actions/transition-background entities :inside-house [237 0] :between (fn [s e]
(if (= 1 (rand-int 2))
(if (= 1 (rand-int 5))
(assoc-in e [:room :entities :experiment] (get-in e [:room :experiment]))
e)))
(when (get-in @entities [:room :entities :experiment])
@@ -660,43 +659,45 @@
:cursor :right}
:right-dir {:box [220 141 320 204]
:script (actions/get-script
:only-script (actions/get-script
entities
(actions/walk-to entities :ego [244 150] :skip-type :end)
(actions/transition-background entities :behind-house [122 140])
(actions/walk-to entities :ego [172 122]))
:cursor :right}
:up-dir {:box [105 180 203 240]
:script (actions/get-script
:only-script (actions/get-script
entities
(actions/walk-to entities :ego [137 204] :skip-type :end)
(actions/transition-background entities :cat-tree [223 -51])
(actions/walk-straight-to entities :ego [200 10]))
:cursor :up}
:left-dir {:box [0 40 40 140]
:script (actions/get-script
:only-script (actions/get-script
entities
(walk-to-castle entities))
:cursor :left}}
:layers {:day [(assoc (utils/get-texture "outsidehouse/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outsidehouse/house.png") :x 0 :y 0 :baseline 122)
(assoc (utils/get-texture "outsidehouse/fence.png") :x 0 :y 0 :baseline 93)
:layers {:day [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "house") :x 0 :y 0 :baseline 122)
(assoc (utils/atlas->texture atlas "fence") :x 0 :y 0 :baseline 93)
(assoc (utils/get-texture "outsidehouse/background-trees.png") :x 0 :y 0 :baseline 44)
(assoc (utils/get-texture "outsidehouse/fg1.png") :x 0 :y 0 :baseline 1000 :parallax 1.5)
(assoc (utils/get-texture "outsidehouse/fg2.png") :x (- 320 55) :y 0 :baseline 1000 :parallax 1.5)]
:night [(assoc (utils/get-texture "outsidehouse/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outsidehouse/house.png") :x 0 :y 0 :baseline 122)
(assoc (utils/get-texture "outsidehouse/fence.png") :x 0 :y 0 :baseline 93)
(assoc (utils/atlas->texture atlas "background-trees") :x 0 :y 0 :baseline 44)
(assoc (utils/atlas->texture atlas "fg1") :x 0 :y 0 :baseline 1000 :parallax 1.5)
(assoc (utils/atlas->texture atlas "fg2") :x (- 320 55) :y 0 :baseline 1000 :parallax 1.5)]
:night [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "house") :x 0 :y 0 :baseline 122)
(assoc (utils/atlas->texture atlas "fence") :x 0 :y 0 :baseline 93)
(assoc (utils/get-texture "outsidehouse/background-trees.png") :x 0 :y 0 :baseline 44)
(assoc (utils/get-texture "outsidehouse/fg1.png") :x 0 :y 0 :baseline 1000 :parallax 1.5)
(assoc (utils/get-texture "outsidehouse/fg2.png") :x (- 320 55) :y 0 :baseline 1000 :parallax 1.5)]}
(assoc (utils/atlas->texture atlas "background-trees") :x 0 :y 0 :baseline 44)
(assoc (utils/atlas->texture atlas "fg1") :x 0 :y 0 :baseline 1000 :parallax 1.5)
(assoc (utils/atlas->texture atlas "fg2") :x (- 320 55) :y 0 :baseline 1000 :parallax 1.5)]}
:entities {:sheep (actions/start-animation screen
(assoc (animation->texture screen sheep-stand) :x 38 :y 160 :baseline 80
[:stand 1] sheep-1
[:stand 2] sheep-2
[:stand 3] sheep-3
:label "Sheep"
:cursor :hand
:origin-y 3
:origin-x 6
:scale-x (scaler [38 160])
@@ -751,7 +752,7 @@
(if (is-sheep-close? @entities)
(do (walk-to-sheep entities)
(actions/play-animation entities :ego :milk)
(actions/remove-item entities :flask-1)
(actions/remove-item entities :flask-1 :quiet? true)
(actions/give entities :flask-1-with-milk)
(actions/talk entities :ego "Sheep's milk.")
)
@@ -785,30 +786,32 @@
:outside-particles (common/make-outside-particles)
:magic (assoc (doto (particle-effect "particles/magic") )
:magic (assoc (particle-effect "particles/magic")
:x 153
:y 105
:baseline 238)
:door (assoc (animation->texture screen door)
:x 252 :y 88 :baseline 122
:door (assoc (animation->texture screen door-closed)
:x 252 :y 88 :baseline 123
:open door
:door-sound (utils/load-sound "door.ogg")
:anim-sound-frames {door {1 [:door-sound 0.1]}}
)
:lamb (assoc (utils/get-texture "outsidehouse/lamb.png")
:x 10 :y 163 :baseline 77
:right {:stand (animation 0.1 [lamb-stand])
:walk lamb-walk}
:left {:stand (utils/flip (animation 0.1 [lamb-stand]))
:walk (utils/flip lamb-walk)}
:scale-x (scaler [10 163])
:scale-y (scaler [10 163])
:script (actions/get-script entities
(actions/talk entities :ego "Aww, it's a newborn lamb!"))
:scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
:grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
:sword (actions/get-script entities (actions/talk entities :ego "I prefer to let the butcher make lamb chops."))})
:lamb (assoc (utils/atlas->texture atlas "lamb")
:cursor :look
:label "Baby lamb"
:x 10 :y 163 :baseline 77
:right {:stand (animation 0.1 [lamb-stand])
:walk lamb-walk}
:left {:stand (utils/flip (animation 0.1 [lamb-stand]))
:walk (utils/flip lamb-walk)}
:scale-x (scaler [10 163])
:scale-y (scaler [10 163])
:script (actions/get-script entities
(actions/talk entities :ego "Aww, it's a newborn lamb!"))
:scripts {:carrot (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
:grass (actions/get-script entities (actions/talk entities :ego "I think it's still nursing."))
:sword (actions/get-script entities (actions/talk entities :ego "I prefer to let the butcher make lamb chops."))})
:butterfly (assoc (animation->texture screen butterfly-stand)
:x 161
:y 218
@@ -820,10 +823,12 @@
(let [speed 0.009
pos-f (- (* (:total-time screen) speed) (int (* (:total-time screen) speed)))
v (vector-2 0 0)
a (catmull-rom-spline! (:path entity) :value-at v pos-f)]
a (catmull-rom-spline! ^CatmullRomSpline (:path entity) :value-at v pos-f)]
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))}
:cauldron (rooms/make-entity :cauldron (assoc (animation->texture screen cauldron)
:cursor :look
:x 139 :y 73 :baseline 167
:label "Magical cauldron"
:anim cauldron
:anim-start 0
:night-profile :none
@@ -832,10 +837,12 @@
:scripts put-something-in-cauldron))
:charcoal (rooms/make-entity :charcoal
(assoc (animation->texture screen charcoal)
:cursor :hand
:label "Charcoal"
:anim charcoal
:anim-start 0
:night-profile :none
:x 125 :y 73 :baseline 167
:x 119 :y 73 :baseline 167
:script (actions/get-script entities
(actions/walk-to entities :ego [120 73])
(actions/play-animation entities :ego :start-squat-2 :stop? false)
@@ -846,14 +853,16 @@
(actions/talk entities :ego "It's a small, sharp piece of charcoal.")
)
))
:wizard (rooms/make-entity :wizard (common/make-wizard screen {:x 190 :y 78 :baseline 162 :scale-x 1.2 :scale-y 1.2
:wizard (rooms/make-entity :wizard (common/make-wizard screen global-atlas {:x 190 :y 78 :baseline 162 :scale-x 1.2 :scale-y 1.2
:script (actions/get-script entities (talk-to-gandarf-outside entities))
:scripts {:default (actions/get-script entities (actions/talk entities :wizard "No time for that!"))
:sword (actions/get-script entities (actions/do-dialogue entities
:wizard "The Sword of Blergh!"
:wizard "Good job, Tick."))}}))
:note (rooms/make-entity :note (assoc (utils/get-texture "outsidehouse/note.png")
:note (rooms/make-entity :note (assoc (utils/atlas->texture atlas "note")
:x 277 :y 74 :baseline 160
:label "Paper airplane"
:cursor :hand
:night-profile :none
:script (actions/get-script entities
(actions/walk-to entities :ego [280 80] :face :right)

View File

@@ -9,6 +9,7 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn add-spear-if-necessary [entities]
(if (and (not (actions/has-obtained? entities :spear))
@@ -93,19 +94,19 @@
(actions/walk-straight-to entities :ego [142 96])
(actions/talk entities :ego "This must be Frankie Rockfist's secret stash!")))
(defn make [screen]
(let [guard-sheet (texture! (utils/get-texture "inside-cafeteria/ladder-guard.png") :split 37 87)
(defn make [screen atlas global-atlas]
(let [guard-sheet (texture! (utils/atlas->texture atlas "guard") :split 37 87)
guard-stand (animation 0.1 [(aget guard-sheet 0 0)])
guard-talk (animation 0.2 (for [i [0 0 0 0 1 0 0 1]] (aget guard-sheet 0 i)))
guard-sleep (utils/make-anim "outside-jail/guard-sleep.png" [43 67] 0.1 (range 4))
open-stash (utils/make-anim "outside-jail/open-stash.png" [58 41] 0.075 (reverse (range 5)))
close-stash (utils/make-anim "outside-jail/open-stash.png" [58 41] 0.075 (range 5))
candle-flame (utils/make-anim "outside-jail/candle.png" [20 25] 0.075 (range 4))
candle-aura (utils/make-anim "outside-jail/candle-aura2.png" [135 135] 0.3 [0 1 2 1] )]
(rooms/make :music {:day :town-1 :night :night}
guard-sleep (utils/make-anim atlas "guard-sleep" [43 67] 0.1 (range 4))
open-stash (utils/make-anim atlas "open-stash" [58 41] 0.075 (reverse (range 5)))
close-stash (utils/make-anim atlas "open-stash" [58 41] 0.075 (range 5))
candle-flame (utils/make-anim atlas "candle" [20 25] 0.075 (range 4))
candle-aura (utils/make-anim atlas "candle-aura2" [135 135] 0.3 [0 1 2 1] )]
(rooms/make
:name "Fountain"
:interactions {:down-dir {:box [30 0 227 40]
:script (actions/get-script entities
:only-script (actions/get-script entities
(actions/walk-to entities :ego [159 5] :skip-type :end :stop? false)
(actions/walk-straight-to entities :ego [159 -20])
(actions/transition-background entities :inside-castle [92 150])
@@ -113,24 +114,34 @@
(actions/walk-to entities :ego [159 74] :skip-type :end))
:cursor :down}
:door {:box [22 42 46 124]
:script (actions/get-script entities
:cursor :left
:only-script (actions/get-script entities
(if (= :night (get-in @entities [:state :time]))
(actions/talk entities :ego "I do NOT want to go back in there!")
(do (actions/walk-to entities :ego [50 46])
(actions/talk entities :warden "NO VISITORS!"))))}
:window {:box [62 175 80 212]
:label "Window"
:cursor :look
:script (actions/get-script entities
(if (= :night (get-in @entities [:state :time]))
(actions/do-dialogue entities :ego "Boy am I glad to be out of there!"
:ego "They didn't even give me my one telephone call!")
(actions/talk entities :ego "I wonder if anyone is imprisoned up there?")))}
:sign {:box [5 173 61 199]
:label "Sign"
:cursor :look
:script (actions/get-script entities
(actions/talk entities :ego "J.A.I.L. Jail. Can't you read?"))}
:my-house {:box [89 128 118 179]
:label "House"
:cursor :look
:script (actions/get-script entities
(actions/talk entities :ego "That's my house. I'd rather play outside."))}
:sherrif-house {:box [138 143 160 168]
:label "Sherriff's house"
:cursor :look
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's the Sheriff's house."
@@ -139,6 +150,8 @@
:ego "Or windows."
:ego "What's the big deal?"))}
:mchulk-house {:box [223 137 282 172]
:label "Captain McHulk's house"
:cursor :look
:script (actions/get-script entities
(actions/do-dialogue entities
:ego "That's Captain McHulk's house!"
@@ -146,6 +159,8 @@
:ego "If only I could be as strong as he is one day."
))}
:stump {:box [205 68 251 100]
:label "Stump"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [170 71] :face :right)
(actions/walk-straight-to entities :ego [188 71] :face :right)
@@ -178,6 +193,8 @@
:frog-legs (actions/get-script entities (actions/talk entities :ego "They're already chopped up!"))
:broken-clock (actions/get-script entities (actions/talk entities :ego "It's already split in half!"))}}
:lever {:box [3 72 20 90]
:label "Candle"
:cursor :hand
:script (actions/get-script entities
(interact-with-lever entities))
:scripts {:rope (actions/get-script entities
@@ -202,24 +219,27 @@
(actions/talk entities :ego "Why would I want to burn that?")
(actions/talk entities :ego "The candle's not lit right now.")))}}
:end-of-rope {:box [177 101 185 108]
:label "Rope"
:cursor :hand
:script (actions/get-script entities (try-to-go-in-stash entities))}
:fountain {:box [150 126 193 170]
:label "Fountain"
:cursor :look
:script (actions/get-script entities
(actions/walk-to entities :ego [151 119] :face :right)
(actions/do-dialogue entities :ego "Some would say this is life-giving nectar."
:ego "... Me?"
:ego "I'd just as soon say it's nasty public fountain water.")
(actions/play-animation entities :ego :get-sick))
:ego "I'd just as soon say it's nasty public fountain water."))
:scripts {:flask-2 (actions/get-script entities
(actions/walk-to entities :ego [151 119] :face :right)
(actions/play-animation entities :ego :reach)
(actions/remove-item entities :flask-2)
(actions/remove-item entities :flask-2 :quiet? true)
(actions/give entities :flask-water)
(actions/talk entities :ego "Filled up with water, just as Gandarf wanted."))}}}
:layers {:day [(assoc (utils/get-texture "outside-jail/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outside-jail/fountain.png") :x 0 :y 0 :baseline 114)]
:night [(assoc (utils/get-texture "outside-jail/background.png") :x 0 :y 0 :baseline 0)
(assoc (utils/get-texture "outside-jail/fountain.png") :x 0 :y 0 :baseline 114)]}
:layers {:day [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "fountain") :x 0 :y 0 :baseline 114)]
:night [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)
(assoc (utils/atlas->texture atlas "fountain") :x 0 :y 0 :baseline 114)]}
:entities {:warden {:object nil
:x 36
:y 86
@@ -241,8 +261,8 @@
:x 172
:y 140
:baseline 114)
:axe (assoc (utils/get-texture "outside-jail/axe.png") :x 213 :y 63 :baseline 176 :night-profile :sprite)
:bent-bar-window (assoc (utils/get-texture "outside-jail/bent-bar-window.png")
:axe (assoc (utils/atlas->texture atlas "axe") :x 213 :y 63 :baseline 176 :night-profile :sprite)
:bent-bar-window (assoc (utils/atlas->texture atlas "bent-bar-window")
:x 69 :y (- 240 63) :baseline 2)
:outside-particles (common/make-outside-particles)}
:fountain-sound {:sound (utils/load-sound "outside-jail/fountain-2.ogg")
@@ -257,23 +277,29 @@
:stand guard-stand
:talk guard-talk
:sleep guard-sleep
:label "Knocked out guard"
:cursor :hand
:script (actions/get-script entities (search-guard entities))
:night-profile :sprite))
:rope (rooms/make-entity :rope (assoc (utils/get-texture "outside-jail/rope.png")
:rope (rooms/make-entity :rope (assoc (utils/atlas->texture atlas "rope")
:x 14 :y 20 :baseline 1 :night-profile :sprite))
:spear (rooms/make-entity :spear (assoc (utils/get-texture "outside-jail/spear.png")
:spear (rooms/make-entity :spear (assoc (utils/atlas->texture atlas "spear")
:night-profile :none
:x 60 :y 65 :baseline 180
:label "Spear"
:cursor :hand
:script (actions/get-script entities (grab-spear entities))))
:alarm-clock (rooms/make-entity :alarm-clock (assoc (utils/get-texture "outside-jail/alarm-clock.png")
:alarm-clock (rooms/make-entity :alarm-clock (assoc (utils/atlas->texture atlas "alarm-clock")
:x 217 :y 83 :baseline 160
:label "Broken clock"
:cursor :hand
:script (actions/get-script entities
(actions/walk-to entities :ego [189 65] :face :right)
(actions/play-animation entities :ego :reach)
(actions/remove-entity entities :alarm-clock)
(actions/give entities :alarm-clock))))
:stash (rooms/make-entity :stash (assoc (animation->texture screen open-stash)
:stash (rooms/make-entity :stash (assoc (animation->texture (assoc screen :total-time 0) open-stash)
:x 197 :y 94 :baseline 146
:open open-stash
:close close-stash))
@@ -285,15 +311,30 @@
:apply-state (fn [screen entities]
(utils/fast-forward-particle (get-in entities [:room :entities :outside-particles]))
(as-> entities entities
(utils/play-sound! screen entities (get-in entities [:room :fountain-sound :sound])
(utils/sourced-volume-fn :fountain 0.06 [172 120])
(utils/get-sound-pan 172)
:loop)
(if (= :night (get-in entities [:state :time]))
(make-night entities)
(update-in entities [:room :entities] dissoc :candle-aura :candle-flame))
(if (get-in entities [:state :dropped-ball?])
(update-in entities [:room :entities :guard] #(actions/start-animation % :sleep))
(update-in entities [:room :entities] dissoc :bent-bar-window )))))))
(if (get-in entities [:state :knows-about-stash?])
(update-in entities [:room :interactions] (fn [xs]
(for [i xs]
(if (= (:id i)
:lever)
(assoc i :cursor :hand)
i))))
(update-in entities [:room :interactions] (fn [xs]
(for [i xs]
(if (= (:id i)
:lever)
(assoc i :cursor :look)
i)))))
(if (= :night (get-in entities [:state :time]))
(make-night entities)
(update-in entities [:room :entities] dissoc :candle-aura :candle-flame))
(if (get-in entities [:state :dropped-ball?])
(update-in entities [:room :entities :guard] #(actions/start-animation % :sleep))
(update-in entities [:room :entities] dissoc :bent-bar-window )))))))

View File

@@ -15,6 +15,7 @@
[play-clj.utils :refer :all]
[play-clj.math :refer :all]
[play-clj.g2d :refer :all]))
(println "loading " *ns*)
(defn taunt [screen entities]
(when (and (not (get-in entities [:fg-actions :script-running?]))
@@ -80,7 +81,7 @@
(skip-type [this screen entities]
:none)))
(defn swing-at-blergh [entities]
(defn swing-at-blergh [entities atlas]
(let [jump-path (bezier (map #(apply vector-2* %) [[35 45] [110 145] [195 180]]))
swing-path (bezier (map #(apply vector-2* %) [[195 180] [205 45]]))
jump-dist (utils/dist 35 45 205 45)
@@ -94,7 +95,7 @@
(utils/play-sound! screen entities :jump (constantly 0.9))
(-> entities
(assoc-in [:room :entities :cloud] (assoc (utils/get-texture "space/cloud.png")
(assoc-in [:room :entities :cloud] (assoc (utils/atlas->texture atlas "cloud")
:x (- (get-in entities [:room :entities :ego :x]) 10)
:y (get-in entities [:room :entities :ego :y])
:origin-x 7
@@ -182,33 +183,32 @@
(defn grunt-vol [entities]
(* 0.3 (get-in entities [:room :entities :bloodclot :opacity])))
(defn make [screen]
(let [bloodclot-head-talk-anim (utils/make-anim-seq "space/bloodclot-head-talk" [82 75] 0.05 [0 0 1 1 2 2 1 1 0 0 1 1 2 2 1 1 0 0 3 4 4 4 3 0 0 1 1 2 2 1 1 0 0 0 0 5 5 5 6 6 6 7 7 7])
bloodclot-head-stand-anim (utils/make-anim-seq "space/bloodclot-head-talk" [82 75] 0.05 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 3])
bloodclot-head-shoot-anim (utils/make-anim-seq "space/bloodclot-head-talk" [82 75] 0.05 [8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 10 11 10 11 10 11 10 11 10 11 10 11])
bloodclot-head-keep-shoot-anim (utils/make-anim-seq "space/bloodclot-head-talk" [82 75] 0.05 [12 13])
blergh-stand-anim (utils/make-anim "space/bloodclot-stand.png" [106 165] 0.9 [0 1])
bloodclot-explode (utils/make-anim-seq "space/bloodclot-explode" [106 165] 0.075 [0 0 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 8 8 8 7 7 7 7 8 8 8 8 8 7 7 7 7 8 8 7 7 7 7 8 8 8 7 8 8 8 8 8 8 8 8 9 8 8 8 8 9 9 8 8 8 8 8 8 8 9 9 9 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 10 9 10 10 8 9 9 9 9 9 10 10 10 10 9 9 9 9 9 9 9 9 9 9 10 10 10 10 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 13 14 15 16 17 18 19 20 21 22])
bullet (utils/make-anim "space/bullet.png" [24 24] 0.0075 [0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 3 3 3 4 4 5 5 6 5 4 7])
(defn make [screen atlas global-atlas]
(let [bloodclot-head-talk-anim (utils/make-anim-seq atlas "bloodclot-head-talk" [82 75] 0.05 [0 0 1 1 2 2 1 1 0 0 1 1 2 2 1 1 0 0 3 4 4 4 3 0 0 1 1 2 2 1 1 0 0 0 0 5 5 5 6 6 6 7 7 7])
bloodclot-head-stand-anim (utils/make-anim-seq atlas "bloodclot-head-talk" [82 75] 0.05 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 3])
bloodclot-head-shoot-anim (utils/make-anim-seq atlas "bloodclot-head-talk" [82 75] 0.05 [8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 8 9 10 11 10 11 10 11 10 11 10 11 10 11])
bloodclot-head-keep-shoot-anim (utils/make-anim-seq atlas "bloodclot-head-talk" [82 75] 0.05 [12 13])
blergh-stand-anim (utils/make-anim atlas "bloodclot-stand" [106 165] 0.9 [0 1])
bloodclot-explode (utils/make-anim-seq atlas "bloodclot-explode" [106 165] 0.075 [0 0 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 8 8 8 7 7 7 7 8 8 8 8 8 7 7 7 7 8 8 7 7 7 7 8 8 8 7 8 8 8 8 8 8 8 8 9 8 8 8 8 9 9 8 8 8 8 8 8 8 9 9 9 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 10 9 10 10 8 9 9 9 9 9 10 10 10 10 9 9 9 9 9 9 9 9 9 9 10 10 10 10 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 13 14 15 16 17 18 19 20 21 22])
bullet (utils/make-anim atlas "bullet" [24 24] 0.0075 [0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 3 3 3 4 4 5 5 6 5 4 7])
effect (particle-effect "particles/appear")
blowup-effect (particle-effect "particles/blowup")
lightning-effect (particle-effect "particles/lightning")
grow-explode (particle-effect "particles/grow-explode")]
(rooms/make :music :fight
:name "Duel"
(rooms/make :name "Duel"
:sounds {:shock (utils/load-sound "space/shock.ogg")
:shock-short (utils/load-sound "space/shock-short.ogg")
:jump (utils/load-sound "space/jump.ogg")
:swing-sword (utils/load-sound "space/swingsword.ogg")}
:interactions
{}
:layers [(assoc (utils/get-texture "space/background.png") :x 0 :y 0 :baseline 0)]
:layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0)]
:timers {:taunt [10.0 8.0 taunt]
:shock [5.0 15.0 shock]}
:entities {:appear (assoc effect
:x 240 :y 50
:baseline 200)
:later (assoc (utils/get-texture "space/later.png")
:later (assoc (utils/atlas->texture atlas "later")
:x 0 :y 0
:baseline 240
:opacity 0.0)
@@ -248,6 +248,8 @@
:explode bloodclot-explode
:label "Bloodclot"
:cursor :talk
:script (actions/get-script entities
(actions/do-dialogue entities
:bloodclot-head "No time to talk."
@@ -271,7 +273,7 @@
(if (actions/has-item? entities :magic-slingshot)
(if (get-in @entities [:state :broke-jewel?])
(do
(swing-at-blergh entities)
(swing-at-blergh entities atlas)
(actions/do-dialogue entities
:bloodclot-head "Ha ha ha! Still a weakling, I see."
:bloodclot-head "But you'll not best me!")
@@ -284,7 +286,7 @@
(actions/update-entity entities :ego (fn [e]
(dissoc e :stand-override :talk-override)))
(actions/update-entity entities :ego #(assoc % :get-script (:original-get-script %)))
(swing-at-blergh entities)
(swing-at-blergh entities atlas)
(actions/do-dialogue entities :bloodclot-head "Ha ha ha! Is that the best you can do?"
:bloodclot-head "Take this!")
@@ -336,7 +338,7 @@
:bullet (assoc (animation->texture screen bullet)
:x 37 :y 85 :baseline 241
:walk bullet)
:broken-jewel (assoc (utils/get-texture "space/broken-jewel.png")
:broken-jewel (assoc (utils/atlas->texture atlas "broken-jewel")
:x 225 :y 170 :baseline 240)
:collision "space/collision.png"
:scale-fn (constantly 1.5)

View File

@@ -3,71 +3,73 @@
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[advent.pathfind]
[advent.zone :as zone]
[advent.utils :as utils])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.utils.viewport FitViewport]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.scenes.scene2d.utils Align]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
InputMultiplexer InputProcessor Net Preferences Screen]))
(println "loading " *ns*)
(def start-x 60)
(def start-x 35)
(def start-y 83)
(defn close [entities]
(screen! @(resolve 'advent.screens.scene/scene) :on-reactivate)
(screen! @(resolve 'advent.screens.scene/scene) :on-end-safe)
(screen! @(resolve 'advent.screens.scene/scene) :on-reactivate {})
(screen! @(resolve 'advent.screens.scene/scene) :on-end-safe {})
(-> entities
(assoc :shown? false)
(assoc :start-showing? false)))
(defn button-box [x y]
(zone/box (+ start-x x) (+ start-y y) (+ start-x x 16) (+ start-y y 20)))
(zone/box (+ start-x x) (+ start-y y) (+ start-x x 30) (+ start-y y 36)))
(defn get-button [[x y]]
(first (filter (fn [{:keys [in?] :as button}]
(when (in? x y)
button))
[{:in? (button-box 9 13) :sound (utils/load-sound "inside-house/safe-1.ogg") :id 1 }
{:in? (button-box 29 13) :sound (utils/load-sound "inside-house/safe-2.ogg") :id 2}
{:in? (button-box 49 13) :sound (utils/load-sound "inside-house/safe-3.ogg") :id 3}
{:in? (button-box 70 13) :sound (utils/load-sound "inside-house/safe-4.ogg") :id 4}
{:in? (button-box 91 13) :sound (utils/load-sound "inside-house/safe-5.ogg") :id 5}])))
[{:in? (button-box 6 16) :sound (utils/load-sound "inside-house/safe-1.ogg") :id 1 }
{:in? (button-box 43 16) :sound (utils/load-sound "inside-house/safe-2.ogg") :id 2}
{:in? (button-box 76 16) :sound (utils/load-sound "inside-house/safe-3.ogg") :id 3}
{:in? (button-box 118 16) :sound (utils/load-sound "inside-house/safe-4.ogg") :id 4}
{:in? (button-box 155 16) :sound (utils/load-sound "inside-house/safe-5.ogg") :id 5}])))
(defscreen safe-screen
:on-show
(fn [screen entities]
(fn [screen entities options]
(utils/setup-viewport screen 320 240)
(let [inputed-key (utils/get-texture "inside-house/inputed-key.png")]
{:fade (assoc (utils/get-texture "black.png")
(let [[screen atlas] (utils/acquire-atlas screen "packed/global.atlas")
inputed-key (utils/atlas->texture atlas "safe/inputed-key.png")]
{:fade (assoc (utils/atlas->texture atlas "black.png")
:scale-x 80
:scale-y 80
:opacity 0.7
:origin-x 0
:origin-y 0)
:safe (assoc (utils/get-texture "inside-house/safe-screen.png") :x start-x :y start-y)
:safe (assoc (utils/atlas->texture atlas "safe/safe-screen") :x start-x :y start-y)
:entered-keys (doall (for [i (range 5)]
(assoc inputed-key
:x (+ start-x 10 (* i 12))
:y (+ start-y 56))))
:x (+ start-x 12 (* i 12))
:y (+ start-y 68))))
:shown? false}))
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
(.apply viewport)
(when (:shown? entities)
(render! screen [(:fade entities) (:safe entities)])
(render! screen (take (count (:button-choices entities)) (:entered-keys entities))))
entities)
:show-screen (fn [{:keys [success failure]} [entities]]
:show-screen (fn [_ entities {:keys [success failure]}]
(sound! (utils/load-sound "inside-house/open-safe.ogg") :play (utils/current-sound-volume 0.3))
(assoc entities
:shown? true
@@ -75,12 +77,12 @@
:success success
:failure failure))
:on-mouse-moved (fn [screen [entities]]
:on-mouse-moved (fn [screen entities options]
entities)
:on-touch-up (fn [screen [entities]]
:on-touch-up (fn [screen entities options]
(when (:shown? entities)
(let [[x y] (utils/unproject screen)]
(let [[x y] (utils/unproject screen options)]
(if-let [button (get-button [x y])]
(do (sound! (:sound button) :play (utils/current-sound-volume 0.3))
(let [new-state (update-in entities [:button-choices] #(conj % (:id button)))]
@@ -88,25 +90,23 @@
(cond (= [4 2 1 5 3] (:button-choices new-state))
(do ((:success entities) (-> @(resolve 'advent.screens.scene/scene)
:entities
deref
first))
deref))
(close entities))
(= 5 (count (:button-choices new-state)))
(do ((:failure entities) (-> @(resolve 'advent.screens.scene/scene)
:entities
deref
first))
deref))
(close entities))
:else
new-state)))
(if (or (< x start-x)
(> x (+ start-x 200))
(> x (+ start-x 250))
(< y start-y)
(> y (+ start-y 75)))
(> y (+ start-y 100)))
(do
(sound! (utils/load-sound "inside-house/close-safe.ogg") :play (utils/current-sound-volume 0.3))
(close entities)))))))
:on-resize (fn [{:keys [width height viewport]} entities]
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]}]
(.update viewport width height)))

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
(ns advent.screens.shader
(:require [advent.utils :as utils]))
(println "loading " *ns*)
(def v-shader (constantly "attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoords;
void main() {
v_color = a_color;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}"))
(def mobile-pix-shader
"
#ifdef GL_ES
#define LOWP lowp
#define HIGHP highp
precision mediump float;
#else
#define LOWP
#define HIGHP
#endif
varying vec4 v_color;
varying HIGHP vec2 v_texCoords;
uniform HIGHP float multiply_amount;
uniform HIGHP float hue_amount;
uniform sampler2D u_texture;
vec4 toGrayscale(in vec4 color)
{
float average = (color.r + color.g + color.b) / 3.0;
return vec4(average, average, average, color.a);
}
vec4 colorize(in vec4 grayscale, in vec4 color)
{
return (grayscale * color);
}
void main ()
{
vec4 scaledColor = texture2D(u_texture, v_texCoords);
vec4 grayscale = toGrayscale(scaledColor);
vec4 colorizedOutput = mix(scaledColor, colorize(grayscale, v_color.rgba), hue_amount);
vec4 multiplied = mix(colorizedOutput.rgba, v_color.rgba * scaledColor.rgba, multiply_amount);
gl_FragColor = vec4(multiplied.rgb, scaledColor.a * v_color.a);
}
"
)
(def desktop-pix-shader
"
#ifdef GL_ES
#define LOWP lowp
#define HIGHP highp
precision mediump float;
#else
#define LOWP
#define HIGHP
#endif
varying vec4 v_color;
varying HIGHP vec2 v_texCoords;
uniform HIGHP float multiply_amount;
uniform HIGHP float hue_amount;
uniform sampler2D u_texture;
vec4 toGrayscale(in vec4 color)
{
float average = (color.r + color.g + color.b) / 3.0;
return vec4(average, average, average, color.a);
}
vec4 colorize(in vec4 grayscale, in vec4 color)
{
return (grayscale * color);
}
void main ()
{
HIGHP vec2 sz = vec2 (2048.0, 2048.0);
HIGHP vec3 step = vec3 (1.0 / 4.0, 1.0 / 4.0, 0.0);
HIGHP vec2 tex_pixel = sz * v_texCoords - step.xy / 2.0;
HIGHP vec2 corner = floor (tex_pixel) + 1.0;
HIGHP vec2 frac = min ((corner - tex_pixel) * vec2 (4.0, 4.0), vec2 (1.0, 1.0));
HIGHP vec4 c1 = texture2D (u_texture, (floor (tex_pixel + step.zz) + 0.5) / sz);
HIGHP vec4 c2 = texture2D (u_texture, (floor (tex_pixel + step.xz) + 0.5) / sz);
HIGHP vec4 c3 = texture2D (u_texture, (floor (tex_pixel + step.zy) + 0.5) / sz);
HIGHP vec4 c4 = texture2D (u_texture, (floor (tex_pixel + step.xy) + 0.5) / sz);
c1 *= frac.x * frac.y;
c2 *= (1.0 - frac.x) * frac.y;
c3 *= frac.x * (1.0 - frac.y);
c4 *= (1.0 - frac.x) * (1.0 - frac.y);
vec4 scaledColor = (c1 + c2 + c3 + c4);
vec4 grayscale = toGrayscale(scaledColor);
vec4 colorizedOutput = mix(scaledColor, colorize(grayscale, v_color.rgba), hue_amount);
vec4 multiplied = mix(colorizedOutput.rgba, v_color.rgba * scaledColor.rgba, multiply_amount);
gl_FragColor = vec4(multiplied.rgb, scaledColor.a * v_color.a);
}
")
(defn pix-shader []
(if utils/mobile?
mobile-pix-shader
desktop-pix-shader))

View File

@@ -19,9 +19,11 @@
[com.badlogic.gdx.scenes.scene2d.ui Slider$SliderStyle Widget ButtonGroup TextButton$TextButtonStyle CheckBox$CheckBoxStyle CheckBox Button]
[com.badlogic.gdx.scenes.scene2d Group Actor]
[play_clj.entities ActorEntity]
[com.badlogic.gdx.scenes.scene2d.utils Align NinePatchDrawable TextureRegionDrawable]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable TextureRegionDrawable]
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
InputMultiplexer InputProcessor Net Preferences Screen]))
(println "loading " *ns*)
(defn fade-in [screen e thing then]
(assoc-in e [:tweens :fade-in]
@@ -31,17 +33,12 @@
(defn fade-out [screen e thing then]
(assoc-in e [:tweens :fade-out]
(tween/tween :fade-out screen [thing :opacity] 1.0 0.0 0.5
:finish then
(tween/tween :fade-out screen [thing :opacity] 1.0 0.0 0.5
:finish then
:ease tween/ease-out-quadratic)))
(defn get-texture [path]
(let [atlas-name (str/replace path #".png" "")
atlas (texture-atlas "packed-pop-logo/pack.atlas")]
(texture (texture-atlas! atlas :find-region atlas-name))))
(defn make-anim-seq [file [w h] speed frames]
(animation speed (map #(get-texture (str file "_" (inc %) ".png")) frames)))
(defn make-anim-seq [atlas file [w h] speed frames]
(animation speed (map #(utils/atlas->texture atlas file %) frames)))
(defn animate [entity screen]
(if (:anim entity)
@@ -64,67 +61,90 @@
entities))))
(def steps
[{:can-skip false
:do (fn [screen entities]
(fade-in screen entities :dbhlogo identity))
:duration 1.0}
{:can-skip true
:do (fn [screen entities]
entities)
:duration 2.0}
{:can-skip false
:do (fn [screen entities]
(fade-out screen entities :dbhlogo identity))
:duration 2.0}
{:can-skip true
:do (fn [screen entities]
(utils/play-music (:pop-music entities))
(-> entities
(assoc-in [:pop-logo :anim-start] (:total-time screen))
(assoc-in [:pop-logo :anim] (get-in entities [:pop-logo :main-anim]))))
:duration 10.0}
{:can-skip false
:do (fn [screen entities]
(utils/stop-music (:pop-music entities))
(set-screen! @(resolve 'advent.core/advent) title/title-screen)
entities)
:duration 0.0}])
(-> []
(into [{:can-skip false
:do (fn [screen entities]
(fade-in screen entities :dbhlogo identity))
:duration 1.0}
{:can-skip true
:do (fn [screen entities]
entities)
:duration 2.0}
{:can-skip false
:do (fn [screen entities]
(fade-out screen entities :dbhlogo identity))
:duration 1.0}])
(into (if utils/mobile?
[{:can-skip false
:do (fn [screen entities]
(fade-in screen entities :pop-logo identity))
:duration 1.0}
{:can-skip true
:do (fn [screen entities]
entities)
:duration 2.0}
{:can-skip false
:do (fn [screen entities]
(fade-out screen entities :pop-logo identity))
:duration 1.0}]
[{:can-skip true
:do (fn [screen entities]
(utils/play-music (:pop-music entities))
(-> entities
(assoc-in [:pop-logo :anim-start] (:total-time screen))
(assoc-in [:pop-logo :anim] (get-in entities [:pop-logo :main-anim]))))
:duration 10.0}]))
(conj {:can-skip false
:do (fn [screen entities]
(when-not utils/mobile?
(utils/stop-music (:pop-music entities)))
(set-screen! @(resolve 'advent.core/advent) title/title-screen)
entities)
:duration 0.0})))
(defscreen splash-screen
:on-show
(fn [screen entities]
(utils/setup-viewport screen 1280 960)
(log/info "Starting splash screen.")
(input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0)
(let [screen (assoc screen :total-time 0)
pop-anim (make-anim-seq "POPPixelLogo_02" [320 240] 0.05 (range 200))
entities {:background (assoc (utils/get-texture "black.png")
:scale-x 80
:scale-y 80
:opacity 1.0
:origin-x 0
:origin-y 0
:z 0)
:pop-logo (assoc (animation->texture screen pop-anim)
:main-anim pop-anim
:x 0 :y 0
:origin-x 0 :origin-y 0
:scale-x 4 :scale-y 4
:z 1)
:dbhlogo (assoc (utils/get-texture "dbh.png") :x 0 :y 0 :origin-x 0 :origin-y 0 :z 1 :opacity 0.0)
:steps steps
:pop-music (utils/make-music "music/POPPixelLogo2Audiomix_mixdown.ogg")
:current-step nil}]
(music! (:pop-music entities) :set-volume (utils/current-music-volume 1.0))
entities))
(fn [screen entities options]
(let [[screen splash-atlas] (utils/acquire-atlas screen "packed/splash.atlas")
[screen global-atlas] (utils/acquire-atlas screen "packed/global.atlas")]
(utils/setup-viewport screen 1280 960)
(log/info "Starting splash screen.")
(graphics! :set-cursor (utils/cursor "cursor.png" :hourglass))
(let [screen (assoc screen :total-time 0)
pop-anim (make-anim-seq splash-atlas "POPPixelLogo_02" [320 240] 0.05 (repeat 200 0))
entities {:background (assoc (utils/atlas->texture global-atlas "black.png")
:scale-x 80
:scale-y 80
:opacity 1.0
:origin-x 0
:origin-y 0
:z 0)
:pop-logo (assoc (animation->texture screen pop-anim)
:anim pop-anim
:x 0 :y 0
:origin-x 0 :origin-y 0
:scale-x 4 :scale-y 4
:z 1
:opacity (if utils/mobile? 0.0 1.0))
:dbhlogo (assoc (utils/atlas->texture splash-atlas "dbh.png") :x 0 :y 0 :origin-x 0 :origin-y 0 :scale-x 4 :scale-y 4 :z 1 :opacity 0.0)
:steps steps
:pop-music (utils/make-music "music/POPPixelLogo2Audiomix_mixdown.ogg")
:current-step nil}]
(music! (:pop-music entities) :set-volume (utils/current-music-volume 1.0))
entities)))
:on-hide (fn [screen entities options]
(utils/release-resources screen))
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
(steam/update)
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
#_(steam/update)
(.apply viewport)
(clear!)
(let [entities (utils/apply-tweens screen entities (:tweens entities))
@@ -139,17 +159,17 @@
:show-screen (fn [entities]
entities)
:on-touch-up (fn [screen [entities]]
:on-touch-up (fn [screen entities options]
(if (get-in entities [:current-step :can-skip])
(assoc entities :current-step nil :queued-skip? false)
(assoc entities :queued-skip? true)))
:on-key-up
(fn [screen entities]
(fn [screen entities options]
(when (= (key-code :escape) (:key screen))
(utils/toggle-fullscreen!))
nil)
:on-resize (fn [{:keys [viewport width height]} [entities]]
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]} ]
(.update viewport width height false)
nil))

View File

@@ -18,15 +18,17 @@
[advent.screens.safe :as safe]
[advent.screens.fade :as fade]
[advent.version]
[advent.max-progress-bar :refer [max-progress-bar]]
)
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter Color]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.graphics.g2d TextureRegion NinePatch]
[play_clj.entities NinePatchEntity]
[com.badlogic.gdx.utils.viewport FitViewport]
[com.badlogic.gdx.scenes.scene2d.ui Slider$SliderStyle Widget ButtonGroup TextButton$TextButtonStyle CheckBox$CheckBoxStyle CheckBox Button]
[com.badlogic.gdx.scenes.scene2d Group Actor]
[com.badlogic.gdx.scenes.scene2d.ui Slider$SliderStyle Widget ButtonGroup TextButton$TextButtonStyle CheckBox$CheckBoxStyle CheckBox Button ImageButton ScrollPane]
[com.badlogic.gdx.scenes.scene2d Group Actor Stage]
[play_clj.entities ActorEntity]
[com.badlogic.gdx.scenes.scene2d.utils Align NinePatchDrawable TextureRegionDrawable BaseDrawable]
[com.badlogic.gdx.utils Align]
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable TextureRegionDrawable BaseDrawable]
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
InputMultiplexer InputProcessor Net Preferences Screen]))
@@ -38,6 +40,7 @@
(def button-color (Color/valueOf "9b399eff"))
(def label-color (color 0.81 0.5 0.0 1.0))
(def disabled-label-color (color 0.3 0.3 0.3 1.0))
(defn style-label [e font mouse-pos]
(when (:interactable e)
@@ -53,12 +56,12 @@
(defn style-slider [s mouse-pos]
(if (utils/intersects? s mouse-pos)
(slider! s :set-style (:hover s))
(slider! s :set-style (:default s)))
(slider! s :set-style ^Slider$SliderStyle (:hover s))
(slider! s :set-style ^Slider$SliderStyle (:default s)))
s)
(defn center [e]
(assoc e :x (- (/ 1280 2) (/ (or (:width e) (.getWidth (:object e))) 2))))
(assoc e :x (- (/ 1280 2) (/ (or (:width e) (.getWidth ^Actor (:object e))) 2))))
(defn get-dir [old-x new-x]
@@ -70,7 +73,7 @@
(defn quit [screen entities]
(do (log/info "Quitting.")
(input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0)
(graphics! :set-cursor (utils/cursor "cursor.png" :hourglass))
(-> entities
(assoc-in [:tweens :fade-out]
(tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0
@@ -116,14 +119,14 @@
(defn start-playing [screen entities save]
(do (log/info "Starting/Continuing quest.")
(input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0)
(graphics! :set-cursor (utils/cursor "cursor.png" :hourglass))
(-> entities
(assoc-in [:tweens :fade-out]
(tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0
:finish (fn [entities]
(utils/stop-music (:music entities))
(reset! utils/selected-save save)
(set-screen! @(resolve 'advent.core/advent) scene/scene #_scene/demo scene/hud dialogue/talking-screen dialogue/choice-screen dialogue/toast-screen inventory/inventory-screen safe/safe-screen fade/fade-screen
(set-screen! @(resolve 'advent.core/advent) scene/scene #_scene/demo scene/hud dialogue/tooltip-screen dialogue/talking-screen dialogue/choice-screen dialogue/toast-screen inventory/inventory-screen safe/safe-screen fade/fade-screen
)
entities)
:ease tween/ease-in-cubic))
@@ -131,9 +134,10 @@
(tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.0)))))
(defn button-style []
(let [style (skin! (skin "ui/ui.json") :get TextButton$TextButtonStyle)
(let [^TextButton$TextButtonStyle style (skin! (skin "ui/ui.json") :get TextButton$TextButtonStyle)
tx (-> style .font .getRegion .getTexture)]
(-> style .font (.setScale 0.5 0.5))
(-> style .font .getData (.setScale utils/button-font-scale))
(call! ^Texture tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
style))
@@ -146,7 +150,7 @@
(let [button (merge (text-button msg (button-style))
(apply hash-map rest))]
(doto button save-object ))))
(doto button save-object))))
(defn set-checkbox-state [cb state]
@@ -159,10 +163,7 @@
(defn make-checkbox
([msg checked & rest]
(let [s (skin! (skin "ui/ui.json") :get CheckBox$CheckBoxStyle)]
(-> s
.font
(.setScale 0.25 0.25))
(-> s .font .getData (.setScale utils/title-label-scale))
(doto (merge (check-box msg s)
(apply hash-map rest))
(set-checkbox-state checked)
@@ -172,30 +173,46 @@
([msg]
(make-label msg nil))
([msg col]
(make-label msg col utils/title-label-scale))
([msg col scale]
(let [font (utils/get-font "ego/font.fnt")
p (NinePatchEntity. (skin! (skin "ui/ui.json") :get-patch "ui-bg"))
_ (nine-patch! p :set-padding 0 0 0 0)
bg (drawable :nine-patch (:object p))
bg (drawable :nine-patch ^NinePatch (:object p))
style (style :label font (or col (color 1.0 0.3 0.3 1.0)))
_ (bitmap-font! font :set-markup-enabled true)
#_#__ (set! (.background style) bg)]
(-> style .font .getData (.setScale scale scale))
(-> msg
(label style)
(label style :set-font-scale scale)
(assoc :x 0 :y 0 :height 40 :origin-x 0 :origin-y 0 :z 8)
(doto (label! :set-alignment Align/bottom)
(label! :set-font-scale 0.25)
#_(#(label! % :set-width (/ (label! % :get-width) 2))))
center))))
(defn make-slider [initial-value & rest]
(defn make-slider [min max initial-value & rest]
(let [ui-skin (skin "ui/ui.json")
slider (->
(slider {:min 0 :max 100 :step 1} ui-skin :set-value initial-value)
(assoc :width 305
:hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle)
:default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle)
:z 8)
(slider {:min min :max max :step 1} ui-skin :set-value initial-value)
(assoc
:hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle)
:default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle)
:z 8)
(merge (apply hash-map rest)))]
(doto slider
save-object)))
(defn make-max-progress-bar [min max initial-value artificial-max & rest]
(let [ui-skin (skin "ui/ui.json")
_ (println initial-value)
slider (->
(max-progress-bar min max 1.0 false (skin! ui-skin :get "default-horizontal" Slider$SliderStyle) artificial-max)
(doto (#(slider! % :set-value initial-value)))
(assoc
:hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle)
:default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle)
:z 8)
(merge (apply hash-map rest)))]
(doto slider
save-object)))
@@ -208,49 +225,55 @@
(table)
(doto (table! :set-background (NinePatchDrawable. (skin! (skin "ui/ui.json") :get-patch "ui-bg" ))))
(assoc
:y 32 :width 504 :height 335
:x (- (/ 1280 2) (/ 504 2))
:y 32 :width (* utils/ui-scale 504) :height (* utils/ui-scale 335)
:x (- (/ 1280 2) (/ (* utils/ui-scale 504) 2))
:z 8
:opacity 1.0)))
(defn main-menu []
(defn main-menu [screen]
(let [start-playing-label (quest-label)
is-starting? (= "Begin Quest" start-playing-label)]
(make-table [[(make-button start-playing-label :key :continue-or-start) :height 56 :pad-bottom 4 :width 250]
:row
[(doto (make-button "Load" :key :load)
(text-button! :set-disabled (not (seq (utils/snapshot-list))))) :height 56 :pad-bottom 4 :width 250]
:row
[(doto (make-button "Chapters" :key :chapters)
(text-button! :set-disabled (not (->> (utils/get-chapters)
(vals)
(filter identity)
seq)))) :height 56 :pad-bottom 4 :width 250]
:row
[(make-button "Settings" :key :settings) :height 56 :pad-bottom 4 :width 250]
:row
[(make-button "End Quest" :key :end-quest) :height 56 :width 250]
])))
(make-table (concat [[(make-button start-playing-label :key :continue-or-start) :height (* utils/button-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/button-scale 250)]
:row
[(doto (make-button "Restore" :key :load)
(text-button! :set-disabled (not (seq (utils/snapshot-list))))) :height (* utils/button-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/button-scale 250)]
:row
[(doto (make-button "Chapters" :key :chapters)
(text-button! :set-disabled (not (->> (utils/get-chapters)
(vals)
(filter identity)
seq)))) :height (* utils/button-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/button-scale 250)]]
(when-not utils/mobile?
[:row
[(make-button "Settings" :key :settings) :height (* utils/ui-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/ui-scale 250)]
:row
[(make-button "End Quest" :key :end-quest) :height (* utils/ui-scale 56) :width (* utils/ui-scale 250)]])))))
(defn chapters-menu []
(let [chapters (utils/get-chapters)
chapter-table (table
(mapcat identity
(for [chapter [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5]]
[[(doto (make-button (if (chapter chapters)
(saves/chapter-name chapter)
"---")
:chapter (chapter chapters))
(text-button! :set-disabled (nil? (chapter chapters)))) :height 56 :pad-bottom 4 :width 400]
:row])))]
(make-table [[(doto (scroll-pane chapter-table
(skin "ui/ui.json"))
(scroll-pane! :set-fade-scroll-bars false)) :height 240 :width 472]
:row
[ (make-button "Back" :key :back) :height 56]])))
(let [_ (println (utils/get-chapters) )
chapter-count (->> (utils/get-chapters)
(vals)
(filter identity)
count
dec
(max 0))
selected-title (-> (utils/get-chapters) keys (nth chapter-count) saves/chapter-name )]
(make-table (concat [[(doto
(make-label selected-title label-color)
(label! :set-name "explanation")) :width (* utils/ui-scale 250) :height 40 :colspan 5]
:row
[(doto (make-max-progress-bar 0.0 4.0 chapter-count chapter-count :key :current-chapter)
(slider! :set-name "slider")) :width (* utils/ui-scale 260) :height (* utils/ui-scale 50) :colspan 5]
:row]
(map (fn [index [chapter v]]
[(make-label (str (inc index)) (if v label-color disabled-label-color)) :height (* utils/ui-scale 32) :width 30 :pad-bottom (* utils/ui-scale 8)])
(range)
(utils/get-chapters))
[:row
[ (make-button "Back" :key :back) :height (* utils/button-scale 56) :width (* utils/button-scale 100) :colspan 2]
[ (make-label "") :height (* utils/button-scale 56) ]
[ (make-button "Start" :key :start) :height (* utils/button-scale 56) :width (* utils/button-scale 100) :colspan 2]]))))
(defn settings-menu []
(let [fullscreen-button (make-checkbox "Fullscreen" (utils/is-fullscreen?) :key :toggle-fullscreen)
@@ -258,11 +281,11 @@
(assoc (make-table [[(make-label "Music" label-color) :height 40]
:row
[(make-slider (:music-volume @utils/settings) :key :music-volume-slider) :width 240]
[(make-slider 0 100 (:music-volume @utils/settings) :key :music-volume-slider) :width 240]
:row
[(make-label "FX" label-color) :height 40 :width 200]
:row
[(make-slider (:sound-volume @utils/settings) :key :sound-volume-slider) :width 240]
[(make-slider 0 100 (:sound-volume @utils/settings) :key :sound-volume-slider) :width 240]
:row
[fullscreen-button :height 56 :width 240]
:row
@@ -277,12 +300,12 @@
(every-pred :save #(utils/intersects? % [x y]))
(vals entities))))
(defn saves-table [entities stage]
(defn saves-table [entities ^Stage stage]
(let [group (doto (ButtonGroup.)
(.setMaxCheckCount 1)
(.setMinCheckCount 0)
(.setUncheckLast true))
[cell-w cell-h] [218 161]
[cell-w cell-h] (mapv #(* utils/ui-scale %) [218 161])
make-cell (fn [image] [image :width cell-w :pad 4 4 0 0 :height cell-h])
make-save-screenshot (fn [{:keys [screenshot name id state blurb] :as save}]
(let [btn (doto (assoc (image-button (skin "ui/ui.json"))
@@ -292,14 +315,16 @@
(image-button! :add (doto (Group. )
(.setSize (- cell-w 16) (- cell-h 16) )
(.setOrigin (/ (- cell-w 16) 2) (/ (- cell-h 16) 2))
(.addActor (:object (doto (image (texture screenshot))
(.addActor (:object (doto (image
screenshot)
(image! :set-size (- cell-w 16) (- cell-h 16)))))
(.addActor (:object (make-label (str "" (or blurb name)) label-color )))
(.addActor (:object (doto (make-label (str "" (or blurb name)) label-color 0.25)
(label! :set-alignment Align/bottomLeft))))
))
save-object)]
(.add group (:object btn))
(.add group ^ImageButton (:object btn))
(ActorEntity. (:object btn))))
save-screenshots (map make-save-screenshot (:saves-list entities))
grouped-screenshots (->> (partition-all 2 save-screenshots)
@@ -308,9 +333,9 @@
scroll-pane (doto (scroll-pane (table grouped-screenshots)
(skin "ui/ui.json"))
(scroll-pane! :set-fade-scroll-bars false))]
(.setScrollFocus stage (:object scroll-pane))
(.setScrollFocus stage ^ScrollPane (:object scroll-pane))
[scroll-pane
:colspan 3 :height 190 :pad-bottom 4 :width 472]))
:colspan 3 :height (* utils/ui-scale 190) :pad-bottom 4 :width (* utils/ui-scale 472)]))
(defn saves-menu [entities stage]
(let [save-label (make-label "" label-color)
@@ -322,102 +347,104 @@
:row
(saves-table entities stage)
:row
[delete-button :width 150 :height 56]
[(make-button "Back" :key :back) :width 150 :height 56]
[continue-button :width 150 :height 56]])
[delete-button :width (* utils/ui-scale 150) :height (* utils/button-scale 56)]
[(make-button "Back" :key :back) :width (* utils/ui-scale 150) :height (* utils/button-scale 56)]
[continue-button :width (* utils/ui-scale 150) :height (* utils/button-scale 56)]])
:save-label save-label
:delete-button delete-button
:continue-button continue-button)))
(defn confirm-delete [entities]
(make-table [[(make-label "Are you sure you want" label-color) :height 32 :colspan 2]
(make-table [[(make-label "Are you sure you want" label-color 0.25) :height (* utils/ui-scale 32) :colspan 2]
:row
[(make-label "to delete the save" label-color) :height 32 :colspan 2]
[(make-label "to delete the save" label-color 0.25) :height (* utils/ui-scale 32) :colspan 2]
:row
[(make-label (str "\"" (-> entities :selected-save :name) "\"?") label-color) :height 32 :colspan 2 :pad-bottom 4]
[(make-label (str "\"" (-> entities :selected-save :name) "\"?") label-color 0.25) :height (* utils/ui-scale 32) :colspan 2 :pad-bottom 4]
:row
[(make-button "Keep" :key :dont-delete-button) :width 120 :height 56]
[(make-button "Delete" :key :confirm-delete-button) :width 120 :height 56]]))
[(make-button "Keep" :key :dont-delete-button) :width (* utils/ui-scale 120) :height (* utils/button-scale 56)]
[(make-button "Delete" :key :confirm-delete-button) :width (* utils/ui-scale 120) :height (* utils/button-scale 56)]]))
(defscreen title-screen
:on-show
(fn [screen entities]
(utils/setup-viewport screen 1280 960)
(log/info "Starting title screen.")
(let [font (utils/get-font "ego/font.fnt")
music (utils/make-music "music/intro.ogg")
balloon (utils/make-anim "title/balloon.png" [15 30] 0.45 (range 4))
banner-back (utils/make-anim "title/banner-back.png" [180 42] 0.2 [0 1 2 1 0 1 2 1])]
(fn [screen entities options]
(let [[screen global-atlas] (utils/acquire-atlas screen "packed/global.atlas")
[screen title-atlas] (utils/acquire-atlas screen "packed/title.atlas")
_ (update! screen :texture-atlas title-atlas)
screen (utils/setup-viewport screen 1280 960)]
(log/info "Starting title screen.")
(input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0)
(let [entities {:background (assoc (utils/get-texture "title/background.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 0)
:cloud-background (assoc (utils/get-texture "title/clouds.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 2)
:banner-back (assoc (animation->texture (assoc screen :total-time 0.0) banner-back) :x 580 :y 400 :scale-x 4 :scale-y 4
:anim banner-back
:z 3)
:quill (doto (assoc (image-button (BaseDrawable.)) :x 1150 :y 4 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 10 :key :quill)
(image-button! :add (doto (Group. )
(.addActor (:object (doto (image (utils/get-texture "title/quill.png"))
(image! :set-scale 4))))))
save-object)
:logo (assoc (utils/get-texture "title/logo.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 6)
:fade (assoc (utils/get-texture "black.png")
:scale-x 80
:scale-y 80
:opacity 1.0
:origin-x 0
:origin-y 0
:z 100)
:flying-ego (assoc (utils/get-texture "ego/flying.png")
:left (flip (utils/get-texture "ego/flying.png"))
:right (utils/get-texture "ego/flying.png")
:scale-x 5
:scale-y 5
:origin-x 2
:origin-y 0
:path (catmull-rom-spline (map #(apply vector-2* %) [[-800 450] [1280 450] [2000 100] [0 100] [-800 300] [1280 300] [2000 450]]) true)
:x 450
:y 650
:z 5)
:balloon (assoc (animation->texture (assoc screen :total-time 0.0) balloon) :x 100 :y 100 :scale-x 4 :scale-y 4
:anim balloon
:path (catmull-rom-spline (map #(apply vector-2* %)
[[50 50] [70 100] [100 200] [151 206] [300 225]
[480 300] [560 400] [650 440] [700 550] [750 600]
[860 650] [950 700] [1030 800] [1280 960] [1300 1000]
[-50 1000] [-50 -50]]) true)
:z 3)
:particle-clouds (assoc (particle-effect "particles/particle-clouds" :reset :start) :x 640 :y 480 :z 1)
:ego-jet (assoc (particle-effect "particles/jet" :reset :start) :x 450 :y 650 :z 4)
(let [font (utils/get-font "ego/font.fnt")
music (utils/make-music "music/intro.ogg")
balloon (utils/make-anim title-atlas "balloon" [15 30] 0.45 (range 4))
banner-back (utils/make-anim title-atlas "banner-back" [180 42] 0.2 [0 1 2 1 0 1 2 1])]
(graphics! :set-cursor (utils/cursor "cursor.png" :hourglass))
(let [entities {:background (assoc (utils/atlas->texture title-atlas "background.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 0)
:cloud-background (assoc (utils/atlas->texture title-atlas "clouds.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 2)
:banner-back (assoc (animation->texture (assoc screen :total-time 0.0) banner-back) :origin-x 85 :origin-y 150 :x 640 :y 960 :scale-x (/ 4 utils/ui-scale) :scale-y (/ 4 utils/ui-scale)
:anim banner-back
:z 3)
:quill (doto (assoc (image-button (BaseDrawable.)) :x 1150 :y 4 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 10 :key :quill)
(image-button! :add (doto (Group. )
(.addActor (:object (doto (image (utils/atlas->texture title-atlas "quill.png"))
(image! :set-scale 4))))))
save-object
(#(utils/add-actor-to-stage screen %)))
:logo (assoc (utils/atlas->texture title-atlas "logo.png" ) :x 640 :y 960 :scale-x (/ 4 utils/ui-scale) :scale-y (/ 4 utils/ui-scale) :origin-x 160 :origin-y 240 :z 6)
:fade (assoc (utils/atlas->texture global-atlas "black.png")
:scale-x 80
:scale-y 80
:opacity 1.0
:origin-x 0
:origin-y 0
:z 100)
:flying-ego (assoc (utils/atlas->texture global-atlas "ego/flying.png")
:left (flip (utils/atlas->texture global-atlas "ego/flying.png"))
:right (utils/atlas->texture global-atlas "ego/flying.png")
:scale-x 5
:scale-y 5
:origin-x 2
:origin-y 0
:path (catmull-rom-spline (map #(apply vector-2* %) [[-800 450] [1280 450] [2000 100] [0 100] [-800 300] [1280 300] [2000 450]]) true)
:x 450
:y 650
:z 5)
:balloon (assoc (animation->texture (assoc screen :total-time 0.0) balloon) :x 100 :y 100 :scale-x 4 :scale-y 4
:anim balloon
:path (catmull-rom-spline (map #(apply vector-2* %)
[[50 50] [70 100] [100 200] [151 206] [300 225]
[480 300] [560 400] [650 440] [700 550] [750 600]
[860 650] [950 700] [1030 800] [1280 960] [1300 1000]
[-50 1000] [-50 -50]]) true)
:z 3)
:particle-clouds (assoc (particle-effect "particles/particle-clouds" :reset :start) :x 640 :y 480 :z 1)
:ego-jet (assoc (particle-effect "particles/jet" :reset :start) :x 450 :y 650 :z 4)
#_#_:toolbox (-> (assoc (nine-patch {:region (:object (utils/get-texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9})
:y 58 :width 500 :height 297
:z 7)
center)
:main-menu (main-menu)
:saves-list (utils/snapshot-screenshots)
:save-index 0
:font font
:music music
:volume 1.0
:copyright (make-label (str "© Digital Bounce House 2016 - v" (advent.version/version)) label-color)
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:finish #(do
:main-menu (->> (main-menu screen)
(utils/add-actor-to-stage screen))
:saves-list (utils/snapshot-screenshots title-atlas)
:save-index 0
:font font
:music music
:volume 1.0
:copyright (->> (make-label (str "© Digital Bounce House 2016 - v" (advent.version/version)) label-color 0.25)
(utils/add-actor-to-stage screen))
:tweens {:fade-in (tween/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:finish #(do
(input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
(utils/play-music (:music %)) %)
:ease tween/ease-in-quadratic)}}
]
(merge entities (:main-menu entities)))))
(graphics! :set-cursor (utils/cursor "cursor.png" :main))
(utils/play-music (:music %)) %)
:ease tween/ease-in-quadratic)}}
]
(merge entities (:main-menu entities))))))
:on-render
(fn [{:keys [^FitViewport viewport] :as screen} [entities]]
(steam/update)
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
#_(steam/update)
(.apply viewport)
(clear!)
(let [entities (utils/apply-tweens screen entities (:tweens entities))
@@ -437,14 +464,14 @@
:show-screen (fn [entities] entities)
:on-key-up
(fn [screen entities]
(fn [screen entities options]
(when (= (key-code :escape) (:key screen))
(utils/toggle-fullscreen!))
nil)
:on-ui-changed
(fn [{:keys [actor] :as screen} [entities]]
(fn [screen entities {:keys [^Actor actor] :as options}]
(when-not (get-in entities [:tweens :fade-out])
(let [e (-> actor .getUserObject)
actor-key (:key e)]
@@ -453,6 +480,13 @@
(utils/save-settings!)
entities)
(= :current-chapter actor-key)
(do
(label! (table! (actor! e :get-parent) :find-actor "explanation")
:set-text (saves/chapter-name (nth [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5] (int (slider! e :get-value)))))
entities)
(= :camera-man? actor-key)
(do (swap! utils/settings assoc :camera-man? (check-box! e :is-checked))
(utils/save-settings!)
@@ -479,30 +513,35 @@
(#{:back } actor-key)
(-> entities
(dissoc :save-menu)
(dissoc :chapters-menu)
(dissoc :settings-menu)
(assoc :main-menu (main-menu)))
(utils/remove-actor-from-stage :save-menu)
(utils/remove-actor-from-stage :chapters-menu)
(utils/remove-actor-from-stage :settings-menu)
(assoc :main-menu (->> (main-menu screen)
(utils/add-actor-to-stage screen))))
(#{:dont-delete-button } actor-key)
(as-> entities entities
(dissoc entities :confirm-delete)
(assoc entities :save-menu (saves-menu entities (:renderer screen))))
(utils/remove-actor-from-stage entities :confirm-delete)
(assoc entities :save-menu (->> (saves-menu entities (:renderer screen))
(utils/add-actor-to-stage screen))))
(= :load actor-key)
(as-> entities entities
(dissoc entities :main-menu)
(assoc entities :save-menu (saves-menu entities (:renderer screen))))
(utils/remove-actor-from-stage entities :main-menu)
(assoc entities :save-menu (->> (saves-menu entities (:renderer screen))
(utils/add-actor-to-stage screen))))
(= :chapters actor-key)
(-> entities
(dissoc :main-menu)
(assoc :chapters-menu (chapters-menu )))
(utils/remove-actor-from-stage :main-menu)
(assoc :chapters-menu (->> (chapters-menu )
(utils/add-actor-to-stage screen))))
(= :settings actor-key)
(-> entities
(dissoc :main-menu)
(assoc :settings-menu (settings-menu)))
(utils/remove-actor-from-stage :main-menu)
(assoc :settings-menu (->> (settings-menu)
(utils/add-actor-to-stage screen))))
(= :toggle-fullscreen actor-key)
(utils/toggle-fullscreen!)
@@ -522,16 +561,18 @@
(= :delete actor-key)
(as-> entities entities
(dissoc entities :save-menu)
(assoc entities :confirm-delete (confirm-delete entities)))
(utils/remove-actor-from-stage entities :save-menu)
(assoc entities :confirm-delete (->> (confirm-delete entities)
(utils/add-actor-to-stage screen))))
(= :confirm-delete-button actor-key)
(do
(utils/remove-save (:id (:selected-save entities)))
(as-> entities entities
(dissoc entities :confirm-delete)
(assoc entities :saves-list (utils/snapshot-screenshots))
(assoc entities :save-menu (saves-menu entities (:renderer screen)))))
(utils/remove-actor-from-stage entities :confirm-delete)
(assoc entities :saves-list (utils/snapshot-screenshots (-> screen :texture-atlas)))
(assoc entities :save-menu (->> (saves-menu entities (:renderer screen))
(utils/add-actor-to-stage screen)))))
(:save e)
(do
@@ -548,12 +589,18 @@
(text-button! (-> entities :save-menu :continue-button) :set-disabled true)
(text-button! (-> entities :save-menu :delete-button) :set-disabled true))))
(:chapter e)
(start-playing screen entities (:chapter e))
(= :start actor-key)
(do
(println "SELECTED chapter" (nth [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5]
(int (slider! (table! (actor! e :get-parent) :find-actor "slider") :get-value))))
(start-playing screen entities ((utils/get-chapters) (nth [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5]
(int (slider! (table! (actor! e :get-parent) :find-actor "slider") :get-value))))))
:else
entities))))
:on-resize (fn [{:keys [viewport width height]} [entities]]
:on-resize (fn [{:keys [^FitViewport viewport] :as screen} entities {:keys [width height]}]
(.update viewport width height false)
nil))
nil)
:on-hide (fn [screen entities options]
(utils/release-resources screen)))

View File

@@ -1,142 +1,59 @@
(ns advent.steam
(:require [play-clj.core :refer :all]
[clojure.edn :as edn]
[clojure.tools.logging :as log]
)
(:import [java.nio ByteBuffer CharBuffer]
[java.io ByteArrayOutputStream]
[com.badlogic.gdx.graphics PixmapIO$PNG]
))
(:require [play-clj.core :refer :all])
(:import [com.badlogic.gdx.graphics Pixmap PixmapIO$PNG]
[com.badlogic.gdx.files FileHandle]))
(def has-steam?
(try
(import '[com.codedisaster.steamworks SteamUserStats SteamUserStatsCallback SteamAPI SteamRemoteStorage])
true
(catch Exception e
false)))
(def is-app-store? (System/getProperty "app-store"))
(defmacro steamify [steam-version & [regular-version]]
(if has-steam?
`(if (and has-steam? (not (System/getProperty "no-steam")))
~steam-version
~regular-version)
regular-version))
(defn init []
(steamify
(if (SteamAPI/init)
(log/info "Steam initialized")
(do
(log/info "Steam not initialized")
(def has-steam? false)))))
(defn update []
(steamify
(when (SteamAPI/isSteamRunning)
(SteamAPI/runCallbacks))))
(defn achievement-fn [f achievement]
(steamify
(let [stats (atom nil)]
(log/info "Getting stats...")
(reset! stats (SteamUserStats. (reify SteamUserStatsCallback
(onUserStatsReceived [_ _ _ _]
(f @stats achievement)
)
(onUserStatsStored [_ _ _])
(onUserAchievementStored [_ _ _ _ _ _]))))
(.requestCurrentStats @stats))))
(def set-achievement (partial achievement-fn
(fn [stats achievement]
(log/info "Setting achievement" achievement)
(.setAchievement stats achievement)
(.storeStats stats)
(log/info "Done setting achievement" achievement))))
(def clear-achievement (partial achievement-fn
(fn [stats achievement]
(log/info "Clearing achievement" achievement)
(.clearAchievement stats achievement)
(.storeStats stats)
(log/info "Done clearing achievement" achievement))))
false
)
(println "loading steam")
(def is-app-store? false)
(def all-achievements ["PARDON" "EX_CON" "PRO_WRESTLER" "SHEEP_HORDER" "SAFE_AND_SOUND" "DESTINY" "WISE_UP" "BLOODCLOT" "KITTY_KISS"])
(defn clear-achievement [])
(defn set-achievement [x])
(defn clear-all-achievements []
(doall (map clear-achievement all-achievements)))
(defn get-bytes [filename]
(steamify
(let [rs (SteamRemoteStorage. nil)
len (.getFileSize rs filename)
bb (ByteBuffer/allocateDirect len)
bytes (make-array Byte/TYPE len)]
(.fileRead rs filename bb len)
(.get bb bytes)
bytes)
(.readBytes (if is-app-store?
(files! :external filename)
(files! :local filename)))))
(.readBytes (if is-app-store?
(files! :external filename)
(files! :local filename))))
(defn write-bytes [filename bytes]
(steamify
(let [rs (SteamRemoteStorage. nil)
bb (ByteBuffer/allocateDirect (* 2 (count bytes)))]
(-> bb (.put bytes) )
(.fileWrite rs filename bb (* 2 (count bytes))))
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))]
(.writeBytes f bytes false))))
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))]
(.writeBytes f bytes false)))
(defn list-edn-files []
(steamify
(let [rs (SteamRemoteStorage. nil)]
(for [i (range (.getFileCount rs))
:let [n (.getFileNameAndSize rs i (make-array Integer/TYPE 1))]
:when (.endsWith n ".edn")]
n))
(if is-app-store?
(for [save-file (.list (files! :external "saves/") ".edn")]
(str "saves/" (.name save-file)))
(for [save-file (.list (files! :local "saves/") ".edn")]
(str "saves/" (.name save-file))))))
(if is-app-store?
(for [save-file (.list (files! :external "saves/") ".edn")]
(str "saves/" (.name ^FileHandle save-file)))
(for [save-file (.list (files! :local "saves/") ".edn")]
(str "saves/" (.name ^FileHandle save-file)))))
(defn save-screenshot [pm filename]
(steamify
(let [rs (SteamRemoteStorage. nil)
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))
baos (ByteArrayOutputStream. (* (.getWidth pm) (.getHeight pm) 1.5))
_ (.write png baos pm)
bytes (.toByteArray baos)
bb (ByteBuffer/allocateDirect (count bytes))]
(.put bb bytes)
(.fileWrite rs filename bb (count bytes)))
(defn save-screenshot [^Pixmap pm ^String filename]
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))]
(let [f (if is-app-store?
(files! :external filename)
(files! :local filename))
png (PixmapIO$PNG. (* (.getWidth pm) (.getHeight pm) 1.5))]
(.write png f pm)
(.dispose png))))
(.write png f pm)
(.dispose png)))
(defn delete-file [filename]
(steamify
(.fileDelete (SteamRemoteStorage. nil) filename)
(.delete (if is-app-store?
(files! :external filename)
(files! :local filename)))))
(let [file (if is-app-store?
(files! :external filename)
(files! :local filename))]
(when (.exists file)
(.delete file))))
(defn save-screenshot-file-name [name]
(steamify
(str "screenshot-" (clojure.core/name name) ".png" )
(str "saves/screenshot-" (clojure.core/name name) ".png" )))
(str "saves/screenshot-" (clojure.core/name name) ".png" ))
(defn save-file-name [id]
(steamify
(str id ".edn")
(str "saves/" id ".edn")))
(str "saves/" id ".edn"))

View File

@@ -1,19 +1,22 @@
(ns advent.tween)
(defn ease-in-expo [power t start delta duration]
(let [pct-done (/ t duration)
(set! *unchecked-math* :warn-on-boxed)
(defn ease-in-expo-maker [^double power ]
(fn ^double [^double t ^double start ^double delta ^double duration]
(let [pct-done (/ t duration)
pct-done (Math/pow pct-done power)]
(+ start
(* delta pct-done))))
(+ start
(* delta pct-done)))))
(def ease-linear (partial ease-in-expo 1.0))
(def ease-in-quadratic (partial ease-in-expo 2.0))
(def ease-in-cubic (partial ease-in-expo 3.0))
(def ease-in-quartic (partial ease-in-expo 4.0))
(def ease-in-quintic (partial ease-in-expo 5.0))
(def ease-in-dectic (partial ease-in-expo 10.0))
(def ease-linear (ease-in-expo-maker 1.0))
(def ease-in-quadratic (ease-in-expo-maker 2.0))
(def ease-in-cubic (ease-in-expo-maker 3.0))
(def ease-in-quartic (ease-in-expo-maker 4.0))
(def ease-in-quintic (ease-in-expo-maker 5.0))
(def ease-in-dectic (ease-in-expo-maker 10.0))
(defn ease-in-out-quadratic [t start delta duration]
(defn ease-in-out-quadratic [^double t ^double start ^double delta ^double duration]
(let [t (/ t (/ duration 2))]
(if (< t 1)
(+ (* (/ delta 2)
@@ -24,24 +27,29 @@
(dec (* t (- t 2))))
start)))))
(defn ease-in-out-quintic [t start delta duration]
(let [t (/ t (/ duration 2))]
(if (< t 1)
(+ (* (/ delta 2)
t t t t t)
start)
(let [t (- t 2)]
(+ (* (/ (- delta) 2)
(- (* t t t t) 2))
start)))))
(defn ease-in-out-quintic ^double [^double t ^double start ^double delta ^double duration]
(let [t (/ t (/ duration (double 2.0)))]
(if (< t (double 1))
(let [result (+ (* (/ delta (double 2.0))
t t t t t) start)]
result)
(let [t (- t (double 2.0))
result (+ (* (/ (- delta) (double 2.0))
(- (* t t t t) (double 2.0)))
start)]
result))))
(defn ease-out-quadratic [t start delta duration]
(defn ease-out-quadratic ^double [^double t ^double start ^double delta ^double duration]
(let [t (/ t duration)]
(+ (* (- delta) t (- t 2)) start)))
(unchecked-add (-> (unchecked-subtract 0.0 delta)
(unchecked-multiply t)
(unchecked-multiply (unchecked-subtract t 2.0)))
start)))
(defn ease-out-cubic [t start delta duration]
(let [t (dec (/ t duration))]
(+ (* delta (inc (* t t t))) start)))
(defn ease-out-cubic ^double [^double t ^double start ^double delta ^double duration]
(let [t (unchecked-subtract (/ t duration) 1)]
(unchecked-add (unchecked-multiply delta (unchecked-add 1 (Math/pow t 3))) start)))
(defn tween [id screen path start end duration & {:keys [finish ease entities]}]
(let [ease (or ease ease-linear)
@@ -50,11 +58,11 @@
start (if (and entities (= start :current))
(get-in entities path)
start)
delta (- end start)
delta (unchecked-subtract ^double end ^double start)
]
(fn [e total-time]
(let [delta-time (- total-time start-time)
pct-done (min (/ delta-time duration) 1.0)
(fn [e ^double total-time]
(let [delta-time (- total-time ^double start-time)
pct-done (min (/ delta-time ^double duration) 1.0)
new-val (ease delta-time start delta duration)
e (assoc-in e path (if (= 1.0 pct-done)
end
@@ -62,4 +70,5 @@
(if (= 1.0 pct-done)
(finish (update-in e [:tweens] dissoc id))
e)))))
e))
)))

View File

@@ -1,5 +1,5 @@
(ns advent.utils
(:refer-clojure :exclude [load])
(:require [play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
@@ -11,7 +11,8 @@
[clojure.tools.logging :as log]
[clojure.string :as str]
[advent.saves :as saves]
[advent.steam :as steam])
[advent.steam :as steam]
[clojure.core.async :refer [put! <! <!! >! chan go go-loop thread take! alts!! dropping-buffer]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Format Pixmap$Blending Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation]
[com.badlogic.gdx.utils.viewport FitViewport]
@@ -23,51 +24,165 @@
InputMultiplexer InputProcessor Net Preferences Screen]
[java.lang Object]))
(defn add-actor-to-stage [{:keys [^Stage renderer ui-listeners]} {:keys [^Actor object] :as entity}]
(.addActor renderer object)
(doseq [[_ listener] ui-listeners]
(.addListener ^Actor object listener))
entity)
(def ui-scale (Double/parseDouble (str (or (System/getProperty "ui_scale") 1.5))))
(def button-scale (+ 1 (* (- ui-scale 1.0) 2.0)))
(def mobile? (= 1.5 ui-scale))
(def max-zoom (if mobile? 0.5 0.75))
(def min-zoom 0.95)
(def button-font-scale (if mobile? 0.75 0.5))
(def title-label-scale (if mobile? 0.5 0.25))
(defn clear-stage [{:keys [^Stage renderer]}]
(.clear renderer))
(defn remove-actor-from-stage
([entities id]
(do
(remove-actor-from-stage (id entities))
(dissoc entities id)))
([{:keys [^Actor object]}]
(when object
(.remove object))))
(defn log-coords [screen entities]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(log/info (:input-x screen) (:input-y screen) "->" x y)))
(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :charcoal :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom :tune])
(def ^:const +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :charcoal :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom :tune :hand :hand-depressed :talk :talk-depressed :look :look-depressed])
(def ^:const +cursor-hotspots+ {:look [8 8]
:look-depressed [8 8]
:wool [8 8]
:mushrooms [8 8]
:right [8 8]
:down [8 8]
:left [8 8]
:up [8 8]
:flask [8 8]
:flask-with-contents [8 8]
:trophy [8 8]
:ladder [8 8]
:stick [8 8]
:cat-toy [8 8]
:balloon [3 3]
:frog-legs [8 8]
:teddy [8 8]
:portrait [5 8]
:recipe [8 8]
:glass-eye [8 3]
:motivational-tapes [8 8]
:used-earplugs [8 8]
:grass [2 2]
:slobber [8 8]
:flask-with-strength [8 8]
:medal [8 8]
:kiss [8 8]
:sword [8 8]
:hourglass [0 0]
:mandrake [8 8]
:ball-n-chain [8 8]
:key [3 8]
:rope [8 8]
:crowbar [0 0]
:note-1 [8 8]
:ash [8 10]
:sack-lunch [8 8]
:flies [8 8]
:spear [0 0]
:monocle [8 8]
:feather [8 8]
:spell-component [8 8]
:money [8 8]
:charcoal [1 1]
:broken-clock [8 8]
:slingshot [8 8]
:camera [8 8]
:walkie-talkies [8 8]
:alarm-clock [8 8]
:walkie-talkie [8 8]
:flask-water [8 8]
:flask-water-stuff [8 8]
:flask-water-stuff-2 [8 8]
:note-2 [8 8]
:magic-slingshot [8 8]
:active-main [0 0]
:shovel [8 8]
:broom [0 0]
:tune [8 8]
:hand [3 0]
:hand-depressed [3 0]
:talk [8 8]
:talk-depressed [8 8]})
(def settings (atom {:music-volume 50.0
:sound-volume 75.0
:camera-man? (not mobile?)
:fullscreen true}))
(def selected-save (atom nil))
(defonce selected-save (atom nil))
(defn current-music-volume [& [factor]]
(* (Math/pow (/ (:music-volume @settings) 100.0) 2)
0.25
(or factor 1.0)))
(defn current-music-volume
(^double [] (current-music-volume 1.0))
(^double [^double factor]
(-> (Math/pow (unchecked-multiply (:music-volume @settings) 0.01) 2)
(unchecked-multiply 0.25)
(unchecked-multiply (double factor)))))
(defn current-sound-volume [& [factor]]
(* (Math/pow (/ (:sound-volume @settings) 100.0) 2)
0.5
(or factor 1.0)))
(defn current-sound-volume
(^double [] (current-sound-volume 1.0))
(^double [^double factor]
(-> (Math/pow (unchecked-multiply (:sound-volume @settings) 0.01) 2)
(unchecked-multiply 0.5)
(unchecked-multiply (double factor)))))
(defn cursor [filename which]
(let [scale 2
(let [scale 4
base-cursor (pixmap filename)
target-width (* 16 scale)
target-height (* 16 scale)
resized (Pixmap. target-width target-height (.getFormat base-cursor))
index (.indexOf +all-cursors+ which)]
index (.indexOf +all-cursors+ which)
[hot-x hot-y] (+cursor-hotspots+ which [0 0])
hot-x (int hot-x)
hot-y (int hot-y)]
(Pixmap/setFilter Pixmap$Filter/NearestNeighbour)
(pixmap! resized :draw-pixmap base-cursor (* index 18) 0 16 16
0 0 target-width target-height)
resized ))
(defn get-texture [path]
(let [atlas-name (str/replace path #".png" "")
atlas (texture-atlas "packed/pack.atlas")]
(texture (texture-atlas! atlas :find-region atlas-name))))
(graphics! :new-cursor resized (* hot-x scale) (* hot-y scale) )))
(defn atlas->texture
([atlas path]
(let [region-name (str/replace path #".png" "")]
(if-let [region (texture-atlas! atlas :find-region region-name)]
(texture region)
(log/error path "not found"))))
([atlas path index]
(let [region-name (str/replace path #".png" "")]
(if-let [region (texture-atlas! atlas :find-region region-name index)]
(texture region)
(log/error path index "not found")))))
(defn get-texture
([path]
(println "WARNING: using pack.atlas:" path)
(get-texture "packed/pack.atlas" path))
([atlas path]
(atlas->texture (texture-atlas atlas) path))
([atlas path index]
(atlas->texture (texture-atlas atlas) path index)))
(defn snapshot-list []
(->> (for [filename (steam/list-edn-files)]
(try
(edn/read-string (String. (steam/get-bytes filename) "UTF-8"))
(edn/read-string (String. ^bytes (steam/get-bytes filename) "UTF-8"))
(catch Exception _ nil)))
(filter (every-pred identity :name :id))
(sort-by (fn [s]
@@ -75,13 +190,13 @@
(Long/MIN_VALUE)
(- (Long/parseLong (:id s))))))))
(defn snapshot-screenshots []
(defn snapshot-screenshots [atlas]
(doall (for [snapshot (snapshot-list)]
(assoc-in snapshot [:screenshot]
(try (let [bytes (steam/get-bytes (:screenshot snapshot))]
(Pixmap. bytes 0 (count bytes)))
(texture (Pixmap. ^bytes bytes 0 (count bytes))))
(catch Exception e
(Pixmap. 160 120 Pixmap$Format/RGB888)))))))
(atlas->texture atlas (saves/default-screenshot (:state snapshot)))))))))
(defn save-chapter [entities chapter]
(let [prefs (.getPreferences (Gdx/app) "ticks-tales-saves")
@@ -104,33 +219,59 @@
(first (drop-while #{:fail}
(repeatedly times
#(try (fn)
(catch Exception e
(catch Exception e
(log/error "Could not save!" e)
:fail))))))
(defmacro iosify [mobile-version & [regular-version]]
(if (System/getProperty "is-desktop")
regular-version
mobile-version))
(def screenshot-chan (chan))
(defn publish-screenshot-fn []
(do
(log/info "Taking Desktop screenshot...")
(Pixmap/setFilter Pixmap$Filter/BiLinear)
(let [viewport (-> @ (resolve 'advent.screens.scene/scene) :screen deref :viewport)
[x y w h g-l g-r] [(.getScreenX ^FitViewport viewport) (.getScreenY ^FitViewport viewport) (.getScreenWidth ^FitViewport viewport) (.getScreenHeight ^FitViewport viewport)]
pm (ScreenUtils/getFrameBufferPixmap x y w h)
resized (Pixmap. 160 120 Pixmap$Format/RGB888)]
(.drawPixmap resized pm 0 0 (.getWidth pm) (.getHeight pm) 0 0 160 120)
(.dispose pm)
(fn [] resized))))
(defn save [entities id name & [blurb]]
(let [save-fn (fn []
(let [save-fn (fn []
(log/info "Saving " id name)
(let [save {:name name
:id id
:screenshot (steam/save-screenshot-file-name id)
:state (assoc (entities :state)
:x (get-in entities [:room :entities :ego :x])
:y (get-in entities [:room :entities :ego :y]))
:x (get-in entities [:room :entities :ego :x])
:y (get-in entities [:room :entities :ego :y]))
:blurb (or blurb name)}]
(log/info "writing save file...")
(steam/write-bytes (steam/save-file-name id) (.getBytes (pr-str save) "UTF-8"))
(on-gl (let [gl-func (fn []
(let [_ (Pixmap/setFilter Pixmap$Filter/BiLinear)
viewport (-> @ (resolve 'advent.screens.scene/scene) :screen deref :viewport)
[x y w h g-l g-r] [(.getScreenX viewport) (.getScreenY viewport) (.getScreenWidth viewport) (.getScreenHeight viewport)]
pm (ScreenUtils/getFrameBufferPixmap x y w h)
resized (Pixmap. 160 120 Pixmap$Format/RGB888)
_ (.drawPixmap resized pm 0 0 w h 0 0 160 120)]
(steam/save-screenshot resized (steam/save-screenshot-file-name id))))]
(try-times gl-func 3)))))]
(iosify
nil
(on-gl (let [gl-func (fn []
(log/info "Screenshot captured. Publishing for persistence")
(put! screenshot-chan [id (publish-screenshot-fn)]))]
(try-times gl-func 3)) ))))]
(try-times save-fn 3)))
(defn listen-for-screenshots []
(go-loop [[id ss-fn] (<! screenshot-chan)]
(let [screenshot (ss-fn)]
(log/info "Persisting Screenshot id" id)
(steam/save-screenshot screenshot (steam/save-screenshot-file-name id))
(.dispose screenshot)
(recur (<! screenshot-chan)))))
(defn remove-save [id]
(doseq [f [(steam/save-screenshot-file-name id)
(steam/save-file-name id)]]
@@ -153,7 +294,7 @@
(defn get-font [filename]
(let [font (-> (bitmap-font filename)
(doto (bitmap-font! :set-scale 0.5 0.5)))
#_(doto (bitmap-font! :set-font-scale 0.5 0.5)))
tr (bitmap-font! font :get-region)
tx (.getTexture tr)]
(call! ^Texture tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
@@ -212,31 +353,48 @@
(texture! frame :flip true false)
frame))))
(defn split-texture [file [tile-width tile-height] frames]
(let [sheet (get-texture file)
sheet-obj ^TextureRegion (:object sheet)
width ^int (int (.getRegionWidth sheet-obj))
x ^int (int (.getRegionX sheet-obj))
y ^int (int (.getRegionY sheet-obj))]
(for [frame frames
:let [new-tex ^TextureRegion (TextureRegion. sheet-obj)]]
(do
(.setRegion new-tex
(unchecked-add x (unchecked-multiply tile-width frame))
y
tile-width
tile-height)
(->TextureEntity new-tex))))
)
(defn split-texture
([file [^int tile-width ^int tile-height] frames]
(let [sheet (get-texture file)
sheet-obj ^TextureRegion (:object sheet)
width ^int (int (.getRegionWidth sheet-obj))
x ^int (int (.getRegionX sheet-obj))
y ^int (int (.getRegionY sheet-obj))]
(for [frame frames
:let [new-tex ^TextureRegion (TextureRegion. sheet-obj)]]
(do
(.setRegion new-tex
^int (unchecked-add x (unchecked-multiply tile-width frame))
y
tile-width
tile-height)
(->TextureEntity new-tex)))))
(defn make-anim [file [w h] speed frames]
(animation speed (split-texture file [w h] frames)))
([atlas file [^int tile-width ^int tile-height] frames]
(let [sheet (atlas->texture atlas file)
sheet-obj ^TextureRegion (:object sheet)
width ^int (int (.getRegionWidth sheet-obj))
x ^int (int (.getRegionX sheet-obj))
y ^int (int (.getRegionY sheet-obj))]
(for [frame frames
:let [new-tex ^TextureRegion (TextureRegion. sheet-obj)]]
(do
(.setRegion new-tex
^int (unchecked-add x (unchecked-multiply tile-width frame))
y
tile-width
tile-height)
(->TextureEntity new-tex))))))
(defn make-anim-seq [file [w h] speed frames]
(animation speed (map #(get-texture (str file "-" (inc %) ".png")) frames)))
(defn make-anim
([file [w h] speed frames]
(animation speed (split-texture file [w h] frames)))
([atlas file [w h] speed frames]
(animation speed (split-texture atlas file [w h] frames))))
(defn make-bird [screen p]
(let [bird-sheet (texture! (get-texture "outside-castle/bird.png") :split 1 2)
(defn make-bird [screen global-atlas p]
(let [bird-sheet (texture! (atlas->texture global-atlas "bird") :split 1 2)
bird-stand (animation 0.15 (for [i [0 1]]
(aget bird-sheet 0 i)))]
(assoc (animation->texture screen bird-stand)
@@ -254,8 +412,7 @@
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))))
(defn path-point [speed screen entities entity]
(* (- (:total-time screen) (:path-start-time entity 0.0)) speed)
)
(* (- (:total-time screen) (:path-start-time entity 0.0)) speed))
(defn update-path-location [speed screen entities entity]
(if (:path entity)
@@ -268,20 +425,20 @@
(defn find-override [entities [x y]]
(first (concat (filter #(and ((:mouse-in? %) entities x y)
(:override %))
(get-in entities [:room :interactions]))
(-> entities :room :interactions))
(filter #(and (:mouse-in? %)
((:mouse-in? %) entities x y)
(not= "ego" (:id %))
(:script %))
(vals (get-in entities [:room :entities])))
(:get-script %))
(vals (-> entities :room :entities)))
(filter #(and ((:mouse-in? %) entities x y)
(:script %))
(get-in entities [:room :interactions])))))
(:get-script %))
(-> entities :room :interactions)))))
(defn hovering-ego [entities [x y]]
(when-let [mouse-in (get-in entities [:room :entities :ego :mouse-in?])]
(when-let [mouse-in (-> entities :room :entities :ego :mouse-in?)]
(mouse-in entities x y)))
(defn remove-interaction [entities id]
@@ -295,14 +452,22 @@
(music! snd :stop))
(defn make-music [r]
(log/info "making music from" r)
(try
(doto (music r) (music! :set-looping true))
(catch Exception _
(if mobile?
(doto (music (str r ".mp3")) (music! :set-looping true))
(doto (music r) (music! :set-looping true)))
(catch Exception x
(log/warn "music making error" x)
(doto (music (str r ".mp3")) (music! :set-looping true)))))
(defn load-sound [f]
(try
(sound f)
(try
(iosify
(sound (str f ".mp3"))
(sound f))
(catch Exception e
(log/info e)
(sound (str f ".mp3")))))
@@ -316,16 +481,24 @@
(vals tweens)))
(defn intersects? [e [x y]]
(and (:object e)
(< (:x e) x (+ (:x e) (or (:width e) (when (actor? e) (.getWidth ^Actor (:object e))))))
(< (:y e) y (+ (:y e) (or (:height e) (when (actor? e) (.getHeight ^Actor (:object e))))))))
(when (:object e)
(let [object-width (* (:scale-x e 1.0) (or (:intersect-width e) (:width e) (when (actor? e ) (.getWidth ^Actor (:object e))) 0))
object-height (* (:scale-y e 1.0) (or (:intersect-height e) (:height e) (when (actor? e ) (.getHeight ^Actor (:object e))) 0))
origin-x (* (:scale-x e 1.0) (:origin-x e 0))
origin-y (* (:scale-y e 1.0) (:origin-y e 0))
object-x (- (or (:x e) (when (actor? e ) (.getX ^Actor (:object e))) 0) origin-x)
object-y (- (or (:y e) (when (actor? e ) (.getY ^Actor (:object e))) 0) origin-y)]
(and (:object e)
(< object-x x (+ object-x object-width))
(< object-y y (+ object-y object-height))))))
(defn get-current-music [entities]
(let [time (get-in entities [:state :time])
musics (:musics entities)
override-music (musics (get-in entities [:music-override :value]))
current-music (musics (get-in entities [:room :music]))
current-time-music (musics (get-in entities [:room :music time]))]
current-music (musics (get-in entities [:room-musics (get-in entities [:state :last-room])]))
current-time-music (musics (get-in entities [:room-musics (get-in entities [:state :last-room]) time]))]
(or override-music current-music current-time-music)))
@@ -335,18 +508,18 @@
stage (Stage. viewport)]
(update! screen :renderer stage :viewport viewport :camera cam)
(.apply viewport)
[cam viewport stage]))
(assoc screen :renderer stage :viewport viewport :camera cam)))
(defn unproject
([screen]
(unproject screen [(:input-x screen) (:input-y screen)]) )
([screen [x y]]
(defn unproject
([screen options]
(unproject screen options [(:input-x options) (:input-y options)]) )
([screen options [x y]]
(let [pj (.unproject ^FitViewport (:viewport screen) (vector-2 x y))
x (.x pj)
y (.y pj)]
[x y])))
(defn project
(defn project
([screen [x y]]
(let [pj (.project ^FitViewport (:viewport screen) (vector-2 x y))
x (.x pj)
@@ -354,64 +527,65 @@
[x y])))
(defn contains-point? [x1 y1 width height x y]
(and (< x1 x (+ x1 width))
(< y1 y (+ y1 height))))
(and (<= x1 x (+ x1 width))
(<= y1 y (+ y1 height))))
(defn is-unstoppable-script-running [screen entities]
(let [current-action (get-in entities [:fg-actions :current])
is-script-running (get-in entities [:fg-actions :script-running?])]
(and is-script-running
(= :none (get-in entities [:fg-actions :last-skip-type])))))
(not (#{:end :none-but-arrow} (or (get-in entities [:fg-actions :last-skip-type]) :end))))))
(defn update-override [{:keys [^FitViewport viewport] :as screen} entities]
(let [raw-pos (get-in entities [:cursor :last-pos])
last-pos (unproject screen raw-pos)
(defn update-override [{:keys [^FitViewport viewport] :as screen} entities options]
(let [raw-pos (-> entities :cursor :last-pos)
last-pos (unproject screen options raw-pos)
mouse-override (find-override entities last-pos)
out-of-bounds (not (contains-point? (.getScreenX viewport) (.getScreenY viewport)
(.getScreenWidth viewport) (.getScreenHeight viewport)
(first raw-pos) (last raw-pos)))
hovering-ego (hovering-ego entities last-pos)
current (get-in entities [:cursor :current])]
current (-> entities :cursor :current)
entities (assoc-in entities [:label :text] "")
selected-inventory-item (@(resolve 'advent.screens.scene/get-selected-inventory-item))]
(cond
out-of-bounds
(update-in entities [:cursor] assoc :override nil :active false )
(not (get-in entities [:state :active?]))
(not (-> entities :state :active?))
(-> entities
(assoc-in [:cursor :override] nil)
(assoc-in [:cursor :active] false))
(assoc-in [:cursor :override] nil))
(is-unstoppable-script-running screen entities)
(-> entities
(assoc-in [:cursor :override] :hourglass)
(assoc-in [:cursor :active] false))
(assoc-in [:cursor :override] :hourglass))
(get-in entities [:state :hud-active?])
(-> entities :state :hud-active?)
(-> entities
(assoc-in [:cursor :override] nil)
(assoc-in [:cursor :active] false))
(assoc-in [:label :text] ""))
(and hovering-ego (not= :main current))
(-> entities
(assoc-in [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main)))
(assoc-in [:cursor :active] true))
(and mouse-override (:only-script mouse-override))
(-> entities
(assoc-in [:cursor :override] (:cursor mouse-override))
(assoc-in [:label :text] (:label mouse-override)))
selected-inventory-item
(-> entities
(assoc-in [:cursor :override] selected-inventory-item)
(assoc-in [:label :text] (:label mouse-override)))
mouse-override
(-> entities
(assoc-in [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main)))
(assoc-in [:cursor :active] true))
(assoc-in [:cursor :override] (:cursor mouse-override))
(assoc-in [:label :text] (:label mouse-override)))
:else
(-> entities
(assoc-in [:cursor :override] nil)
(assoc-in [:cursor :active] false)))))
(assoc-in entities [:cursor :override] :main))))
(def default-night-merge {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 1.0 :hue-amount 1.0})
(def default-night-merge-sprite {:r 0.08 :g 0.1 :b 0.36 :multiply-amount 0.3 :hue-amount 0.4})
(def default-night-merge {:r 0.13 :g 0.16 :b 0.61 :multiply-amount 0.5 :hue-amount 0.75})
(def default-night-merge-sprite {:r 0.13 :g 0.16 :b 0.61 :multiply-amount 0.1 :hue-amount 0.35})
(defn clamp-volume [vol]
(max vol 0.005))
@@ -429,9 +603,9 @@
(defn fast-forward-particle [p]
(particle-effect! p :reset)
(particle-effect! p :start)
(particle-effect! p :start)
(particle-effect! p :update 10.0)
(particle-effect! p :update 10.0)
(dotimes [_ 160]
(particle-effect! p :update 0.2)))
@@ -451,29 +625,24 @@
(do
(log/info "Making windowed 800x600 decorated window")
(System/setProperty "org.lwjgl.opengl.Window.undecorated", "false")
(.setDisplayMode Gdx/graphics 800 600 false)))
(.setFullscreenMode Gdx/graphics (.getDisplayMode Gdx/graphics))))
(defmethod make-fullscreen :linux []
(let [width (-> Gdx/graphics .getDesktopDisplayMode .width)
height (-> Gdx/graphics .getDesktopDisplayMode .height)]
(let [width (-> Gdx/graphics .getDisplayMode .width)
height (-> Gdx/graphics .getDisplayMode .height)]
(log/info "Making fullscreen " width "x" height " as undecorated window")
(System/setProperty "org.lwjgl.opengl.Window.undecorated", "true")
(.setDisplayMode Gdx/graphics
width
height
false)))
(.setFullscreenMode Gdx/graphics (.getDisplayMode Gdx/graphics))))
(defmethod is-fullscreen? :linux []
(= "true" (System/getProperty "org.lwjgl.opengl.Window.undecorated")))
(defn make-fullscreen-normal []
(let [width (-> Gdx/graphics .getDesktopDisplayMode .width)
height (-> Gdx/graphics .getDesktopDisplayMode .height)]
(let [width (-> Gdx/graphics .getDisplayMode .width)
height (-> Gdx/graphics .getDisplayMode .height)]
(log/info "Making fullscreen " width "x" height " as true fullscreen")
(.setDisplayMode Gdx/graphics
width
height
true)
(.setFullscreenMode Gdx/graphics
(.getDisplayMode Gdx/graphics))
(set! (.foregroundFPS (-> (class Gdx/graphics)
(.getDeclaredField (name "config"))
(doto (.setAccessible true))
@@ -483,7 +652,7 @@
(do
(log/info "Making windowed 1280x960 decorated window")
(System/setProperty "org.lwjgl.opengl.Window.undecorated", "false")
(.setDisplayMode Gdx/graphics 1280 960 false)))
(.setWindowedMode Gdx/graphics 1280 960)))
(defn is-fullscreen?-normal []
(.isFullscreen Gdx/graphics))
@@ -541,24 +710,88 @@
(play-sound! screen entities snd volume-fn pan type 1.0))
([screen entities snd volume-fn pan type pitch]
(let [vol (volume-fn entities)
snd (if (keyword? snd)
(or (-> entities :room :sounds snd)
(-> entities :sounds snd))
snd)
sound-id (if (= :once type)
(sound! snd :play (scale-vol-from-fade entities (current-sound-volume vol)) (or pitch 1.0) pan )
(sound! snd :loop 0.0 (or pitch 1.0) pan )) ]
(update-in entities [:current-sounds :value]
conj {:id sound-id
:sound snd
:volume-fn volume-fn
:type type
:ends-at (if (= type :once)
(+ (:total-time screen) (sound! snd :duration))
nil)}))))
(let [vol (volume-fn entities)
snd (if (keyword? snd)
(or (-> entities :room :sounds snd)
(-> entities :sounds snd))
snd)
sound-id (if (= :once type)
(sound! snd :play (scale-vol-from-fade entities (current-sound-volume vol)) (or pitch 1.0) pan )
(sound! snd :loop 0.0 (or pitch 1.0) pan )) ]
(update-in entities [:current-sounds :value]
conj {:id sound-id
:sound snd
:volume-fn volume-fn
:type type
:ends-at (if (= type :once)
(+ (:total-time screen) 1.0 #_(sound! snd :duration))
nil)}))
entities))
(defn stop-all-sounds! [entities]
(doseq [snd (get-in entities [:current-sounds :value])]
(doseq [snd (get-in entities [:current-sounds :value] [])]
(sound! (:sound snd) :stop (:id snd))))
(defn translate-depressed [cursor depressed?]
(if depressed?
(get {:hand :hand-depressed
:talk :talk-depressed
:look :look-depressed} cursor cursor)
cursor))
(defn bound-to-camera [x length zoom]
(min (- length (* length 0.5 zoom ))
(max (* length 0.5 zoom )
x)))
(defn get-entity [entities id]
((:entities (:room entities)) id))
(defmacro eager-loop [xs n form]
`(let [xs# ~xs]
(if (instance? clojure.lang.Indexed xs#)
(loop [x# 0]
(if (< x# (count xs#))
(let [~n (nth xs# x#)]
~form
(recur (inc x#)))))
(do
(loop [[~n & r#] xs#]
(if (seq r#)
(do ~form
nil)
(do ~form
(recur r#))))))))
(defn acquire-atlas
([screen file]
(acquire-atlas screen file :default))
([screen file id]
(let [resources (get-in screen [:resources id] [])
atlas (texture-atlas file)]
(update! screen :resources
(assoc (:resources screen) id (conj resources file)))
[(assoc-in screen [:resources id] (conj resources file))
atlas])))
(defn release-resources
([screen]
(release-resources screen :default))
([screen id]
(println (:resources screen))
(doseq [resource (id (:resources screen))]
(println "releasing " resource)
(asset-manager! *asset-manager* :unload resource))
(app! :log "info"(str "Released resources " (.getDiagnostics *asset-manager*)))
(update! screen :resources (assoc (:resources screen {}) id []))))
(defn make-anim-seq
([file [w h] speed frames]
(animation speed (map #(get-texture (str file "-" (inc %) ".png")) frames)))
([atlas file [w h] speed frames]
(animation speed (map #(atlas->texture atlas file %) frames))))

View File

@@ -1,5 +1,7 @@
(ns advent.version
(:gen-class))
(def version-override nil)
(defn version []
(-> (eval 'advent.version) .getPackage .getImplementationVersion))
(or version-override (-> (eval 'advent.version) .getPackage .getImplementationVersion)))

View File

@@ -1,7 +1,14 @@
(ns advent.zone)
(defn within [x1 y1 x2 y2 x3 y3]
(and
(< x1 x3)
(< x3 x2)
(< y1 y3)
(< y3 y2)))
(defn box [x1 y1 x2 y2]
(fn [x y]
(and
(< x1 x x2)
(< y1 y y2))))
(within x1 y1 x2 y2 x y)))