This commit is contained in:
2014-11-11 17:07:16 -08:00
17 changed files with 171 additions and 29 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

View File

@@ -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]

View File

@@ -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)))

View File

@@ -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})

View File

@@ -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.")

View File

@@ -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)

View File

@@ -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!"))}}}

View File

@@ -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)))

View File

@@ -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)

View File

@@ -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