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,95 +165,97 @@
(apply do-dialogue entities :ego line more)) (apply do-dialogue entities :ego line more))
(defn wizard-dialogue [entities] (defn wizard-dialogue [entities]
{:choices ["What do you mean, \"Not you again?\"" (do-dialogue entities :ego "Hello there Mr. Fangald!" :wizard "Oh no, not you again!")
{:run #(respond entities % :wizard "I mean, you've wrecked my life and I never want to see you again.") (actions/present-choices entities
:choices ["You mean the time I set your house on fire with a fire mint?" {:choices ["What do you mean, \"Not you again?\""
{:run #(do {:run #(respond entities % :wizard "I mean, you've wrecked my life and I never want to see you again.")
(respond entities % :choices ["You mean the time I set your house on fire with a fire mint?"
:wizard "That was you!?" {:run #(do
:wizard "My house was nearly destroyed!" (respond entities %
:wizard "I spent weeks rebuilding my home!" :wizard "That was you!?"
:wizard "Leave, now, or I'll turn you into a ..." :wizard "My house was nearly destroyed!"
:wizard "... a ..." :wizard "I spent weeks rebuilding my home!"
:wizard "... a frog!" :wizard "Leave, now, or I'll turn you into a ..."
:ego "Okay, okay! I'm leaving.") :wizard "... a ..."
(actions/transition-background entities :outside-house [262 88]) :wizard "... a frog!"
(actions/talk entities :ego "I guess he's really upset with me."))} :ego "Okay, okay! I'm leaving.")
"You're still cross about my stealing your magic cowboy hat?" (actions/transition-background entities :outside-house [262 88])
{:run #(do (respond entities % (actions/talk entities :ego "I guess he's really upset with me."))}
:wizard "Of course I'm cross! It's irreplaceable!" "You're still cross about my stealing your magic cowboy hat?"
:wizard "That cowboy hat accented my facial physique." {:run #(do (respond entities %
:wizard "And complemented my skin color." :wizard "Of course I'm cross! It's irreplaceable!"
:wizard "And you little cheat stole it from me!" :wizard "That cowboy hat accented my facial physique."
:wizard "That's why I bought my MagiSafe 5000, to keep out intruders like you." :wizard "And complemented my skin color."
:wizard "Now leave.") :wizard "And you little cheat stole it from me!"
(actions/transition-background entities :outside-house [262 88]))} :wizard "That's why I bought my MagiSafe 5000, to keep out intruders like you."
"Even an old hoot like you needs a kick in the pants every now and again." :wizard "Now leave.")
{:run #(respond entities % :wizard "What gives you the right to try to teach me a lesson?") (actions/transition-background entities :outside-house [262 88]))}
:choices ["My good looks?" "Even an old hoot like you needs a kick in the pants every now and again."
{:run #(do (respond entities % {:run #(respond entities % :wizard "What gives you the right to try to teach me a lesson?")
:wizard "You know, handsome looks aren't all they're chocked up to be." :choices ["My good looks?"
:wizard "Take me for example." {:run #(do (respond entities %
:wizard "When you have a bod like man, you can hardly go to the grocery store without being noticed." :wizard "You know, handsome looks aren't all they're chocked up to be."
:wizard "But no. Your looks, however good they may be, don't give you the right to teach me a lesson." :wizard "Take me for example."
:wizard "Now please leave me in peace.") :wizard "When you have a bod like man, you can hardly go to the grocery store without being noticed."
(actions/transition-background entities :outside-house [262 88]))} :wizard "But no. Your looks, however good they may be, don't give you the right to teach me a lesson."
"My good standing within the community?" :wizard "Now please leave me in peace.")
{:run #(do (respond entities % (actions/transition-background entities :outside-house [262 88]))}
:wizard "Ha! Good standing?" "My good standing within the community?"
:wizard "You're the neighborhood cheat and everyone knows it." {:run #(do (respond entities %
:wizard "Now please leave me in peace.") :wizard "Ha! Good standing?"
(actions/transition-background entities :outside-house [262 88]))} :wizard "You're the neighborhood cheat and everyone knows it."
"I'm going to be a knight! That counts for something doesn't it?" :wizard "Now please leave me in peace.")
{:run #(do (respond entities % (actions/transition-background entities :outside-house [262 88]))}
:wizard "You are, are you?" "I'm going to be a knight! That counts for something doesn't it?"
:wizard "Pray tell, how do you, a mere wreckless youth, plan on becoming a knight?")) {:run #(do (respond entities %
:choices ["By pulling the Sword of Blergh from its stone!" :wizard "You are, are you?"
{:run #(respond entities % :wizard "Pray tell, how do you, a mere wreckless youth, plan on becoming a knight?"))
:wizard "Well, well. It sounds I was wrong about you." :choices ["By pulling the Sword of Blergh from its stone!"
:wizard "Indeed, you are on the path of setting your destructive past behind you." {:run #(respond entities %
:wizard "But know this, the stone cannot be cheated easily." :wizard "Well, well. It sounds I was wrong about you."
:wizard "You must fulfill the age-old prophecy." :wizard "Indeed, you are on the path of setting your destructive past behind you."
:wizard "'The Sword of Blergh with magic sting,' ..." :wizard "But know this, the stone cannot be cheated easily."
:wizard "... 'Shall yield to no earthly king.'" :wizard "You must fulfill the age-old prophecy."
:wizard "'To draw from hardened, weathered stone,' ..." :wizard "'The Sword of Blergh with magic sting,' ..."
:wizard "... 'One must have valor, right to the bone.'" :wizard "... 'Shall yield to no earthly king.'"
:wizard "'Worthy in courage, wisdom and might,' ..." :wizard "'To draw from hardened, weathered stone,' ..."
:wizard "... 'only then with sword he'll fight.'" :wizard "... 'One must have valor, right to the bone.'"
:wizard "'But a hero should he prove not be,' ..." :wizard "'Worthy in courage, wisdom and might,' ..."
:wizard "... 'Only ruin will fall on thee.'" :wizard "... 'only then with sword he'll fight.'"
:wizard "'I'll fall neither for guile nor guise'..." :wizard "'But a hero should he prove not be,' ..."
) :wizard "... 'Only ruin will fall on he.'"
:choices ["Is this almost over?" :wizard "'Should he use guile or guise'..."
{:run #(do (respond entities % )
:wizard "Patience, boy." :choices ["Is this almost over?"
:wizard "... 'Such a man will have great surprise.'" {:run #(do (actions/update-state (fn [state] (assoc state :convinced-wizard? true)))
:wizard "If this is truely your quest, boy, then I will help you in your quest. " (respond entities %
:wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh." :wizard "Patience, boy."
:ego "No cheating." :wizard "... 'Such a man will have great surprise.'"
:ego "Check.") :wizard "If this is truely your quest, boy, then I will help you in your quest. "
(swap! entities (fn [e] (assoc-in e [:state :convinced-wizard?] true))))} :wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
"*cough* *cough* *ahem*" :ego "No cheating."
{:run #(do (respond entities % :ego "Check."))}
:wizard "Excuse you." "*cough* *cough* *ahem*"
:wizard "... 'Such a man will have great surprise.'" {:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
:wizard "If this is truely your quest, boy, then I will help you in your quest. " (respond entities %
:wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh." :wizard "Excuse you. Moving on..."
:ego "No cheating." :wizard "... 'Such a man will have great surprise.'"
:ego "Check.") :wizard "If this is truely your quest, boy, then I will help you in your quest. "
(swap! entities (fn [e] (assoc-in e [:state :convinced-wizard?] true))))}]} :wizard "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
"By besting swamp, foe, and the occasional bizarre conversation tree." :ego "No cheating."
{:run #(do (respond entities % :ego "Check."))}]}
:wizard "While your goal sounds noble, no amount of bizarre conversation tree searching will earn my respect." "By besting swamp, foe, and the occasional bizarre conversation tree."
:wizard "Now please leave.") {:run #(do (respond entities %
(actions/transition-background entities :outside-house [262 88]))}]}]}]} :wizard "While your goal sounds noble, no amount of bizarre conversation tree searching will earn my respect."
"You're not happy to see me, Mr. Fangald?" :wizard "Now please leave.")
{:run #(respond entities % :wizard "Of course not, you little brat. You've made my life a living hell!") (actions/transition-background entities :outside-house [262 88]))}]}]}]}
:choices #(-> % zip/left)} "You're not happy to see me, Mr. Fangald?"
"Good bye, Mr. Fangald!" {:run #(respond entities % :wizard "Of course not, you little brat. You've made my life a living hell!")
{:run #(do :choices #(-> % zip/left)}
(respond entities % :wizard "Now scram!") "Good bye, Mr. Fangald!"
(actions/transition-background entities :outside-house [262 88]))}]}) {:run #(do
(respond entities % :wizard "Now scram!")
(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