first puzzle complete

This commit is contained in:
2014-09-28 14:52:05 -07:00
parent fbbc7519a8
commit 4bd400dff3
3 changed files with 142 additions and 109 deletions

View File

@@ -19,8 +19,10 @@
(done? [this screen entities]) (done? [this screen entities])
(continue [this screen entities]) (continue [this screen entities])
(terminate [this screen entities]) (terminate [this screen entities])
(can-skip? [this screen entities])
(get-channel [this])) (get-channel [this]))
(defmacro get-script [entities & forms] (defmacro get-script [entities & forms]
`(fn [starting-entities#] `(fn [starting-entities#]
(let [~entities (atom starting-entities#)] (let [~entities (atom starting-entities#)]
@@ -114,7 +116,9 @@
(< (dist final-x final-y from-x from-y) 1))) (< (dist final-x final-y from-x from-y) 1)))
(terminate [this screen entities] (terminate [this screen entities]
(stop screen entities target-id))) (stop screen entities target-id))
(can-skip? [this screen entities]
false))
@entities))) @entities)))
(defn get-text-duration [text] (defn get-text-duration [text]
@@ -147,7 +151,9 @@
(run! dialogue/talking-screen :stop-talk :target-id target-id) (run! dialogue/talking-screen :stop-talk :target-id target-id)
(if stop? (if stop?
(stop screen entities target-id) (stop screen entities target-id)
entities))))) entities))
(can-skip? [this screen entities]
true))))
(defn something-else [zipper] (defn something-else [zipper]
(-> zipper zip/up zip/up)) (-> zipper zip/up zip/up))
@@ -182,7 +188,9 @@
(terminate [this screen entities] (terminate [this screen entities]
(run! @(resolve 'advent.screens.scene/scene) :on-reactivate) (run! @(resolve 'advent.screens.scene/scene) :on-reactivate)
entities)) entities)
(can-skip? [this screen entities]
false))
(let [zipper (nth-child zipper @selected-index) (let [zipper (nth-child zipper @selected-index)
node (zip/node zipper)] node (zip/node zipper)]
@@ -195,6 +203,16 @@
(recur (next-choices zipper)) (recur (next-choices zipper))
(recur zipper))))))) (recur zipper)))))))
(defn update-state [entities f]
(run-action entities
(begin [this screen entities]
(update-in entities [:state] f ))
(continue [this screen entities] entities)
(done? [this screen entities] true)
(terminate [this screen entities]
entities)
(can-skip? [this screen entities]
false)))
(defn give [entities target-id item] (defn give [entities target-id item]
(run-action entities (run-action entities
@@ -210,7 +228,9 @@
(done? [this screen entities] true) (done? [this screen entities] true)
(terminate [this screen entities] (terminate [this screen entities]
entities))) entities)
(can-skip? [this screen entities]
false)))
(defn transition-background [entities new-background [x y]] (defn transition-background [entities new-background [x y]]
(run-action entities (run-action entities
@@ -231,7 +251,9 @@
(>= (get-in entities [:transition :opacity]) 1.0)) (>= (get-in entities [:transition :opacity]) 1.0))
(terminate [this screen entities] (terminate [this screen entities]
entities)) entities)
(can-skip? [this screen entities]
false))
(run-action entities (run-action entities
(begin [this screen entities] (begin [this screen entities]
(let [ego (get-in entities [:background :entities :ego]) (let [ego (get-in entities [:background :entities :ego])
@@ -248,4 +270,7 @@
(<= (get-in entities [:transition :opacity]) 0.0)) (<= (get-in entities [:transition :opacity]) 0.0))
(terminate [this screen entities] (terminate [this screen entities]
(dissoc entities :transition)))) (dissoc entities :transition))
(can-skip? [this screen entities]
false)))

View File

@@ -82,7 +82,7 @@
:on-touch-down (fn [screen [entities]] :on-touch-down (fn [screen [entities]]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(when (seq entities) (when (seq entities)
(when (< y (* 30 (count entities))) (when (< y (* 30 (dec (count entities))))
((get-in entities [:state :callback]) (int (/ y 30))) ((get-in entities [:state :callback]) (int (/ y 30)))
{})))) {}))))

View File

@@ -53,16 +53,22 @@
(let [interaction (first (filter #(mouse-in? % [x y]) (let [interaction (first (filter #(mouse-in? % [x y])
(get-in entities [:background :interactions]))) (get-in entities [:background :interactions])))
;; TODO - hacky way of resetting queue
entities (if-let [current-action (get-in entities [:actions :current])]
(assoc (actions/terminate current-action screen entities)
:actions {:channel (chan) :current nil :started? false})
entities)
script (or (when interaction
(get-script interaction [x y]))
(get-script default-interaction [x y]))]
(script entities) current-action (get-in entities [:actions :current])
;; TODO - hacky way of resetting queue
entities (if (and current-action (actions/can-skip? current-action screen entities))
(let [terminated-entities (actions/terminate current-action screen entities)]
(do (put! (actions/get-channel current-action) terminated-entities)
(-> terminated-entities
(assoc-in [:actions :current] nil)
(assoc-in [:actions :started?] false))))
(assoc-in entities [:actions :channel] (chan)))]
(if current-action
entities
((or (when interaction
(get-script interaction [x y]))
(get-script default-interaction [x y])) entities))
entities)))) entities))))
(defn flip [anim] (defn flip [anim]
@@ -159,6 +165,8 @@
(apply do-dialogue entities :ego line more)) (apply do-dialogue entities :ego line more))
(defn wizard-dialogue [entities] (defn wizard-dialogue [entities]
(do-dialogue entities :ego "Hello there Mr. Fangald!" :wizard "Oh no, not you again!")
(actions/present-choices entities
{:choices ["What do you mean, \"Not you again?\"" {:choices ["What do you mean, \"Not you again?\""
{:run #(respond entities % :wizard "I mean, you've wrecked my life and I never want to see you again.") {:run #(respond entities % :wizard "I mean, you've wrecked my life and I never want to see you again.")
:choices ["You mean the time I set your house on fire with a fire mint?" :choices ["You mean the time I set your house on fire with a fire mint?"
@@ -215,27 +223,27 @@
:wizard "'Worthy in courage, wisdom and might,' ..." :wizard "'Worthy in courage, wisdom and might,' ..."
:wizard "... 'only then with sword he'll fight.'" :wizard "... 'only then with sword he'll fight.'"
:wizard "'But a hero should he prove not be,' ..." :wizard "'But a hero should he prove not be,' ..."
:wizard "... 'Only ruin will fall on thee.'" :wizard "... 'Only ruin will fall on he.'"
:wizard "'I'll fall neither for guile nor guise'..." :wizard "'Should he use guile or guise'..."
) )
:choices ["Is this almost over?" :choices ["Is this almost over?"
{:run #(do (respond entities % {:run #(do (actions/update-state (fn [state] (assoc state :convinced-wizard? true)))
(respond entities %
:wizard "Patience, boy." :wizard "Patience, boy."
:wizard "... 'Such a man will have great surprise.'" :wizard "... 'Such a man will have great surprise.'"
:wizard "If this is truely your quest, boy, then I will help you in your quest. " :wizard "If this is truely your quest, boy, then I will help you in your quest. "
:wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh." :wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
:ego "No cheating." :ego "No cheating."
:ego "Check.") :ego "Check."))}
(swap! entities (fn [e] (assoc-in e [:state :convinced-wizard?] true))))}
"*cough* *cough* *ahem*" "*cough* *cough* *ahem*"
{:run #(do (respond entities % {:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
:wizard "Excuse you." (respond entities %
:wizard "Excuse you. Moving on..."
:wizard "... 'Such a man will have great surprise.'" :wizard "... 'Such a man will have great surprise.'"
:wizard "If this is truely your quest, boy, then I will help you in your quest. " :wizard "If this is truely your quest, boy, then I will help you in your quest. "
:wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh." :wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
:ego "No cheating." :ego "No cheating."
:ego "Check.") :ego "Check."))}]}
(swap! entities (fn [e] (assoc-in e [:state :convinced-wizard?] true))))}]}
"By besting swamp, foe, and the occasional bizarre conversation tree." "By besting swamp, foe, and the occasional bizarre conversation tree."
{:run #(do (respond entities % {:run #(do (respond entities %
:wizard "While your goal sounds noble, no amount of bizarre conversation tree searching will earn my respect." :wizard "While your goal sounds noble, no amount of bizarre conversation tree searching will earn my respect."
@@ -247,7 +255,7 @@
"Good bye, Mr. Fangald!" "Good bye, Mr. Fangald!"
{:run #(do {:run #(do
(respond entities % :wizard "Now scram!") (respond entities % :wizard "Now scram!")
(actions/transition-background entities :outside-house [262 88]))}]}) (actions/transition-background entities :outside-house [262 88]))}]}))
(defn backgrounds [screen] (defn backgrounds [screen]
(let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21) (let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
@@ -270,10 +278,7 @@
(actions/walk-to entities :ego [237 1]) (actions/walk-to entities :ego [237 1])
(actions/transition-background entities :outside-house [262 88])) (actions/transition-background entities :outside-house [262 88]))
:cursor :down} :cursor :down}
:wizard {:box [228 80 248 126] :wizard {:box [228 80 248 126]}}
:script (actions/get-script entities
(do-dialogue entities :ego "Hello there Mr. Fangald!" :wizard "Oh no, not you again!")
(actions/present-choices entities (wizard-dialogue entities)))}}
:layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0) :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) (assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200)
(assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)] (assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)]
@@ -293,7 +298,10 @@
entities entities
(actions/walk-to entities :ego [262 88]) (actions/walk-to entities :ego [262 88])
(actions/talk entities :ego (str "Anyone home?")) (actions/talk entities :ego (str "Anyone home?"))
(actions/transition-background entities :inside-house [237 0]))} (actions/transition-background entities :inside-house [237 0])
(if (get-in @entities [:state :convinced-wizard?])
(actions/talk entities :wizard (str "Oh, hello there boy."))
(wizard-dialogue entities)))}
:sword {:box [274 55 305 88] :sword {:box [274 55 305 88]
:script (actions/get-script :script (actions/get-script
entities entities