diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index 95d8609f..8132e284 100644 Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ diff --git a/desktop/resources/inside-house/safe-1.ogg b/desktop/resources/inside-house/safe-1.ogg new file mode 100644 index 00000000..6a0e0cc9 Binary files /dev/null and b/desktop/resources/inside-house/safe-1.ogg differ diff --git a/desktop/resources/inside-house/safe-2.ogg b/desktop/resources/inside-house/safe-2.ogg new file mode 100644 index 00000000..35d7ab80 Binary files /dev/null and b/desktop/resources/inside-house/safe-2.ogg differ diff --git a/desktop/resources/inside-house/safe-3.ogg b/desktop/resources/inside-house/safe-3.ogg new file mode 100644 index 00000000..6b60da5e Binary files /dev/null and b/desktop/resources/inside-house/safe-3.ogg differ diff --git a/desktop/resources/inside-house/safe-4.ogg b/desktop/resources/inside-house/safe-4.ogg new file mode 100644 index 00000000..e95881bf Binary files /dev/null and b/desktop/resources/inside-house/safe-4.ogg differ diff --git a/desktop/resources/inside-house/safe-5.ogg b/desktop/resources/inside-house/safe-5.ogg new file mode 100644 index 00000000..1e9ea653 Binary files /dev/null and b/desktop/resources/inside-house/safe-5.ogg differ diff --git a/desktop/resources/inside-house/safe-screen.png b/desktop/resources/inside-house/safe-screen.png new file mode 100644 index 00000000..f7a43f0c Binary files /dev/null and b/desktop/resources/inside-house/safe-screen.png differ diff --git a/desktop/resources/safe-sound.ogg b/desktop/resources/safe-sound.ogg new file mode 100644 index 00000000..d146ca59 Binary files /dev/null and b/desktop/resources/safe-sound.ogg differ diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 257767c3..3805d7d9 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -110,7 +110,7 @@ (can-skip? [this screen entities] false)))) -(defn play-animation [entities target-id anim] +(defn play-animation [entities target-id anim & {:keys [stop?]}] (run-action entities (begin [this screen entities] (update-in entities [:room :entities target-id] #(start-animation screen % anim) )) @@ -123,7 +123,9 @@ (- (:total-time screen) (get-in entities [:room :entities target-id :anim-start])))) (terminate [this screen entities] - (stop screen entities target-id)) + (if (or (nil? stop?) stop?) + (stop screen entities target-id) + (assoc-in entities [:room :entities target-id :anim] nil))) (can-skip? [this screen entities] false))) @@ -196,9 +198,10 @@ (defn get-text-duration [text] (* (count (s/split text #" ")) 0.5)) -(defn talk [entities target-id text & {:keys [stop?]}] +(defn talk [entities target-id text & {:keys [stop? animate?]}] (let [initial-time (atom nil) - stop? (if (nil? stop?) true stop?)] + stop? (if (nil? stop?) true stop?) + animate? (if (nil? animate?) true animate?)] (run-action entities (begin [this screen entities] (let [_ (swap! initial-time #(or % (:total-time screen))) @@ -211,7 +214,9 @@ :x (get-in entities [:room :entities target-id :x]) :y (+ (get-in entities [:room :entities target-id :y]) height) :target-id target-id :scale scale) - (update-in entities [:room :entities target-id ] #(start-animation screen % :talk)))) + (if animate? + (update-in entities [:room :entities target-id ] #(start-animation screen % :talk)) + entities))) (continue [this screen entities] entities) @@ -303,6 +308,23 @@ (can-skip? [this screen entities] false))) +(defn play-sound [entities sound-file] + (let [m (music sound-file)] + (run-action entities + (begin [this screen entities] + (music! m :play) + entities) + + (continue [this screen entities] entities) + + (done? [this screen entities] + (not (music! m :is-playing))) + + (terminate [this screen entities] + entities) + (can-skip? [this screen entities] + false)))) + (defn give [entities item] (run-action entities (begin [this screen entities] diff --git a/desktop/src-common/advent/core.clj b/desktop/src-common/advent/core.clj index 21acaf89..fa766662 100644 --- a/desktop/src-common/advent/core.clj +++ b/desktop/src-common/advent/core.clj @@ -6,6 +6,7 @@ [advent.screens.scene :as scene] [advent.screens.dialogue :as dialogue] [advent.screens.inventory :as inventory] + [advent.screens.safe :as safe] [clojure.pprint] [advent.pathfind]) (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] @@ -16,4 +17,4 @@ (defgame advent :on-create (fn [this] - (set-screen! this scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen))) + (set-screen! this scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen))) diff --git a/desktop/src-common/advent/screens/items.clj b/desktop/src-common/advent/screens/items.clj index 15d23a5c..7e7e6b66 100644 --- a/desktop/src-common/advent/screens/items.clj +++ b/desktop/src-common/advent/screens/items.clj @@ -50,5 +50,8 @@ (def stool {:name "Stool" :value :stool :cursor :stool}) (def teddy {:name "Teddy Bear" :value :teddy :cursor :teddy}) (def portrait {:name "Portrait" :value :portrait :cursor :portrait}) +(def recipe {:name "Strength potion recipe" :value :recipe :cursor :recipe}) - +(def glass-eye {:name "Choicest of glass eyes" :value :glass-eye :cursor :glass-eye}) +(def motivational-tapes {:name "Choicest motivational tapes" :value :motivational-tapes :cursor :motivational-tapes}) +(def used-earplugs {:name "Choicest used earplugs" :value :used-earplugs :cursor :used-earplugs}) diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj index 9276c03f..9c887b75 100644 --- a/desktop/src-common/advent/screens/rooms/behind_house.clj +++ b/desktop/src-common/advent/screens/rooms/behind_house.clj @@ -55,13 +55,12 @@ :script (actions/get-script entities (if (get-in @entities [:state :opened-crack?]) (do (actions/walk-to entities :ego [70 80]) - (actions/play-animation entities :ego :squat) - (actions/talk entities :ego "I can see Gandarf, the wizard inside.") - (actions/play-animation entities :ego :squat) - (actions/talk entities :ego "It looks like he's opening his Magi-safe.") - (actions/play-animation entities :ego :squat) - (actions/talk entities :ego "[todo: sounds play.]") - (actions/play-animation entities :ego :squat) + (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 Magi-safe." :animate? false :stop? false) + (actions/play-sound entities "safe-sound.ogg") + (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.")) (do (actions/walk-to entities :ego [80 80]) (actions/talk entities :ego "It looks like the wall is crumbling here.") diff --git a/desktop/src-common/advent/screens/rooms/inside_house.clj b/desktop/src-common/advent/screens/rooms/inside_house.clj index c39592b6..5beae356 100644 --- a/desktop/src-common/advent/screens/rooms/inside_house.clj +++ b/desktop/src-common/advent/screens/rooms/inside_house.clj @@ -1,6 +1,7 @@ (ns advent.screens.rooms.inside-house (:require [advent.screens.items :as items] [advent.screens.rooms :as rooms] + [advent.screens.safe :as safe] [advent.actions :as actions] [advent.utils :as utils] [clojure.zip :as zip] @@ -9,6 +10,21 @@ [play-clj.utils :refer :all] [play-clj.g2d :refer :all])) +(defn open-safe [entities] + (screen! safe/safe-screen :show-screen + :success (actions/get-script entities + (actions/talk entities :ego "Yes! That worked.") + (actions/play-animation entities :ego :squat) + (actions/give entities items/recipe) + (actions/talk entities :ego "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 items/frog-legs) + (actions/talk entities :ego "Eww. Frog legs.")) + :failure (actions/get-script entities + (actions/talk entities :ego "I don't think that worked..."))) + (actions/update-state entities #(assoc % :active? false))) + (defn do-wizard-dialogue [entities] (actions/do-dialogue entities :wizard "What can I do for you boy?") (actions/present-choices entities @@ -42,10 +58,7 @@ (actions/walk-to entities :ego [59 65]) (if (get-in @entities [:room :entities :wizard]) (actions/talk entities :wizard "Don't touch my MagiSafe!!") - (do - (actions/play-animation entities :ego :squat) - (actions/give entities items/frog-legs) - (actions/talk entities :ego "I found some frog legs inside."))))} + (open-safe entities)))} } :layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0) (assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200) diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj index 2bd72145..a1398369 100644 --- a/desktop/src-common/advent/screens/rooms/outside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj @@ -69,8 +69,7 @@ :peddler "Well I'm afraid you won't have the choicest of earplugs." :ego "Can't I give you something else for them?" :peddler "Well, I am low on choice children's toys." - :peddler "If you can bring me one, and I mean the choicest of toys, I will give you the earplugs.")) - :choices actions/previous-choices} + :peddler "If you can bring me one, and I mean the choicest of toys, I will give you the earplugs."))} "I'm interested in a glass eye." {:run #(do (actions/update-state entities (fn [state] (assoc state :wants-toy true))) (actions/respond entities % @@ -82,8 +81,7 @@ :peddler "Well I'm afraid you won't have the choicest of glass eyes." :ego "Can't I give you something else for them?" :peddler "I'll tell you what, I don't have any thing for the kids that come to my stand." - :peddler "If you can bring me the choicest of toys, I will give you the glass eye.")) - :choices actions/previous-choices} + :peddler "If you can bring me the choicest of toys, I will give you the glass eye."))} "I'm interested in the motivational tapes." {:run #(do (actions/update-state entities (fn [state] (assoc state :wants-toy true))) (actions/respond entities % @@ -92,10 +90,9 @@ :peddler "These choicest of motivation tapes will convince you that life isn't so bad." :peddler "For only 3 easy payments of 29.99 scheckles, they're yours!" :ego "But I'm broke!" - :peddler "Well I'm afraid you won't have the choicest of glass eyes." + :peddler "Well I'm afraid you won't have the choicest of motivational tapes." :ego "Is there anything else you'd take instead?" - :peddler "If you can bring me a nice kid's toy, I will give you the tapes.")) - :choices actions/previous-choices} + :peddler "If you can bring me a nice kid's toy, I will give you the tapes."))} "Nevermind." {:run #(actions/respond entities % :peddler "Goodbye, sir.")}]})) :scripts {:teddy (actions/get-script entities (actions/remove-item entities items/teddy) @@ -105,11 +102,14 @@ :peddler "What would you like?") (actions/present-choices entities {:choices ["The glass eye." - {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go."))} + {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go.") + (actions/give entities items/glass-eye))} "The motivational tapes." - {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go."))} + {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go.") + (actions/give entities items/motivational-tapes))} "The used earplugs." - {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go."))}]}) + {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go.") + (actions/give entities items/used-earplugs))}]}) (actions/talk entities :peddler "And, of course, here is your balloon.") (actions/give entities items/balloon) (actions/talk entities :peddler "Thank you for your business!"))}}} diff --git a/desktop/src-common/advent/screens/safe.clj b/desktop/src-common/advent/screens/safe.clj new file mode 100644 index 00000000..c8729603 --- /dev/null +++ b/desktop/src-common/advent/screens/safe.clj @@ -0,0 +1,96 @@ +(ns advent.screens.safe + (:require [play-clj.core :refer :all] + [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 Application Audio Files Game Gdx Graphics Input + InputMultiplexer InputProcessor Net Preferences Screen])) + + +(def start-x 60) +(def start-y 83) + +(defn close [entities] + (screen! @(resolve 'advent.screens.scene/scene) :on-reactivate) + (-> 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 16))) + +(defn get-button [[x y]] + (first (filter (fn [{:keys [in?] :as button}] + (when (in? x y) + button)) + [{:in? (button-box 9 17) :sound (sound "inside-house/safe-1.ogg") :id 1 } + {:in? (button-box 29 17) :sound (sound "inside-house/safe-2.ogg") :id 2} + {:in? (button-box 49 17) :sound (sound "inside-house/safe-3.ogg") :id 3} + {:in? (button-box 70 17) :sound (sound "inside-house/safe-4.ogg") :id 4} + {:in? (button-box 91 17) :sound (sound "inside-house/safe-5.ogg") :id 5}]))) + +(defscreen safe-screen + :on-show + (fn [screen entities] + (update! screen :renderer (stage) :camera (orthographic)) + {:fade (assoc (texture "black.png") + :scale-x 80 + :scale-y 80 + :opacity 0.7) + :safe (assoc (texture "inside-house/safe-screen.png") :x start-x :y start-y) + :start-showing? false + :shown? false}) + + :on-render + (fn [screen [entities]] + (let [entities (if (:start-showing? entities) + (-> entities + (assoc :start-showing? false) + (assoc :shown? true)) + entities)] + + (when (:shown? entities) + (render! screen [(:fade entities) (:safe entities)])) + entities)) + + :show-screen (fn [{:keys [success failure]} [entities]] + (assoc entities + :start-showing? true + :button-choices [] + :success success + :failure failure)) + + :on-mouse-moved (fn [screen [entities]] + entities) + + :on-touch-up (fn [screen [entities]] + (when (:shown? entities) + (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] + (if-let [button (get-button [x y])] + (do (sound! (:sound button) :play) + (let [new-state (update-in entities [:button-choices] #(conj % (:id button)))] + (cond (= [4 2 1 5 3] (:button-choices new-state)) + (do ((:success entities) (-> @(resolve 'advent.screens.scene/scene) + :entities + deref + first)) + (close entities)) + (= 5 (count (:button-choices new-state))) + (do ((:failure entities) (-> @(resolve 'advent.screens.scene/scene) + :entities + deref + first)) + (close entities)) + :else + new-state))) + (close entities))))) + + :on-resize (fn [screen entities] + (size! screen 320 240))) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 00995fa2..cd6243cb 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -91,6 +91,10 @@ (texture (aget stand-sheet 0 i)))) talk-anim (animation 0.2 (for [i (range 8)] (texture (aget talk-sheet 0 i)))) + start-squat (animation 0.05 (for [i [0 1 2 3]] + (texture (aget squat-sheet 0 i)))) + end-squat (animation 0.05 (for [i [3 2 1 0]] + (texture (aget squat-sheet 0 i)))) squat-anim (animation 0.05 (for [i [0 1 2 3 3 3 3 3 3 3 3 3 3 3 3 2 1] ] (texture (aget squat-sheet 0 i)))) reach-anim (animation 0.1 (for [i [0 1 2 3 3 3 3 3 3 2 1 0]] @@ -107,6 +111,8 @@ :stand stand-anim :talk talk-anim :squat squat-anim + :start-squat start-squat + :end-squat end-squat :reach reach-anim :cat-toy cat-toy-anim [:fire 1] fire-1-anim @@ -115,6 +121,8 @@ :left {:walk (utils/flip walk-right) :stand (utils/flip stand-anim) :talk (utils/flip talk-anim) + :start-squat (utils/flip start-squat) + :end-squat (utils/flip end-squat) :squat (utils/flip squat-anim) :reach (utils/flip reach-anim) :cat-toy (utils/flip cat-toy-anim) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index d9142614..00f245ff 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -11,7 +11,7 @@ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] (println (:input-x screen) (:input-y screen) "->" x y))) -(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :stool :stick :cat-toy :balloon :frog-legs :teddy :portrait]) +(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :stool :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs]) (defn cursor [filename which] (let [scale 2