first step in large refactoring to extract rooms.

This commit is contained in:
2014-10-03 20:00:09 -07:00
parent d672c7ab39
commit 098891dd42
9 changed files with 433 additions and 375 deletions

View File

@@ -0,0 +1,47 @@
(ns advent.screens.rooms.behind-house
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.utils :as utils]
[clojure.zip :as zip]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn make [screen]
(rooms/make :interactions
{:left-dir {:box [0 131 20 224]
:script (actions/get-script
entities
(actions/walk-to entities :ego [122 140])
(actions/transition-background entities :outside-house [244 150])
(actions/walk-to entities :ego [195 140]))
:cursor :left}
:crack {:box [68 100 73 114]
:script (actions/get-script
entities
(actions/walk-to entities :ego [70 80])
(actions/talk entities :ego "I can see Fangald, the wizard inside.")
(actions/talk entities :ego "It looks like he's opening his Magi-safe.")
(actions/talk entities :ego "[todo: sounds play.]")
(actions/talk entities :ego "A lot of good it'll do me to know his password while he's still there."))}
:mushrooms {:box [247 59 269 76]
:script (actions/get-script
entities
(if ((get-in @entities [:state :inventory]) :mushrooms)
(actions/talk entities :ego "I've already got a junk ton of mushrooms.")
(do
(actions/walk-to entities :ego [242 75])
(actions/give entities :mushrooms)
(actions/talk entities :ego "Perfectly ripe mushrooms!"))))}
:window {:box [103 44 130 140]
:script (actions/get-script
entities
(actions/walk-to entities :ego [128 100])
(actions/talk entities :ego "I can see Fangald moving around in there but it's hard to see at this angle."))}}
:layers [(assoc (texture "behindhouse/background.png") :x 0 :y 0 :baseline 0)
(assoc (texture "behindhouse/house.png") :x 0 :y 0 :baseline 122)
(assoc (texture "behindhouse/brush.png") :x 0 :y 0 :baseline 240)]
:entities {}
:collision "behindhouse/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00)))

View File

@@ -0,0 +1,24 @@
(ns advent.screens.rooms.cat-tree
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.utils :as utils]
[clojure.zip :as zip]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn make [screen]
(rooms/make :interactions
{:down-dir {:box [150 0 270 20]
:script (actions/get-script entities
(actions/walk-to entities :ego [203 1])
(actions/transition-background entities :outside-house [137 204])
(actions/walk-to entities :ego [195 140]))
:cursor :down}}
:layers [(assoc (texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
(assoc (texture "cat-tree/tree-and-rock.png") :x 0 :y 0 :baseline 161)
(assoc (texture "cat-tree/sillhoute.png") :x 0 :y 0 :baseline 240)]
:entities {}
:collision "cat-tree/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.20)))

View File

@@ -0,0 +1,34 @@
(ns advent.screens.rooms.inside-house
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.utils :as utils]
[clojure.zip :as zip]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn make [screen]
(let [wizard-sheet (texture! (texture "wizard/talk.png") :split 20 46)
wizard-stand (animation 0.2 (for [i (flatten [(repeat 10 0) 1])]
(aget wizard-sheet 0 i)))
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)))]
(rooms/make :interactions {:down-dir {:box [151 0 320 20]
:script (actions/get-script entities
(actions/walk-to entities :ego [237 1])
(actions/transition-background entities :outside-house [262 88]))
:cursor :down}
:wizard {:box [228 80 248 126]}}
: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/sillhoute.png") :x 0 :y 0 :baseline 240)]
:entities {:wizard (actions/start-animation screen (assoc (animation->texture screen wizard-stand) :x 228 :y 80 :baseline 160 :scale-x 1.75 :scale-y 1.75
:left {:talk (utils/flip wizard-talk)
:stand (utils/flip wizard-stand)}
:right {:talk wizard-talk
:stand wizard-stand}
:facing :left)
:stand)}
:collision "inside-house/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.75))))

View File

@@ -0,0 +1,57 @@
(ns advent.screens.rooms.outside-castle
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.utils :as utils]
[clojure.zip :as zip]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn make [screen]
(let [peddler-sheet (texture! (texture "outside-castle/peddler-talk.png" ) :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 5 0) 6])]
(aget peddler-sheet 0 i)))]
(rooms/make :interactions
{:right-dir {:box [300 40 320 140]
:script (actions/get-script
entities
(actions/walk-to entities :ego [310 80])
(actions/transition-background entities :outside-house [0 80]))
:cursor :right}
:garden {:box [103 170 178 200]
:script (actions/get-script
entities
(if ((get-in @entities [:state :inventory]) :carrot)
(actions/talk entities :ego "If I steal any more, I might get caught.")
(do
(actions/walk-to entities :ego [128 180])
(actions/talk entities :ego "Hey! Carrots. No one will notice one missing.")
(actions/give entities :carrot))))}
:peddler {:box [110 90 128 146]
:script (actions/get-script
entities
(actions/walk-to entities :ego [191 90])
(actions/talk entities :ego "Hello there, peddler.")
(actions/talk entities :peddler "Good day sir! Care to see any of my wares?" :stop? false)
(actions/talk entities :peddler "I have only the choicest of wares.")
(actions/talk entities :ego "What 'wares' are you selling?")
(actions/talk entities :peddler "I have the choicest of all types of wares..." :stop? false)
(actions/talk entities :peddler "...I'm well stocked on used earplugs..." :stop? false)
(actions/talk entities :peddler "...glass eyes, motivational tapes... " :stop? false)
(actions/talk entities :peddler "...and useful books like this:" :stop? false)
(actions/talk entities :peddler "'Checkers Mastery in Less Than 10 Seconds'")
(actions/talk entities :ego "I sure am interested on that book on checkers.")
(actions/talk entities :peddler "An excellent selection! It is the choicest of checkers book you'll ever find." :stop? false)
(actions/talk entities :peddler "This book will only set you back 75 sheckels.")
(actions/talk entities :ego "But I haven't got any money!")
(actions/talk entities :peddler "Then you won't have the choicest of checkers books."))}}
:layers [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)]
:entities {:peddler (actions/start-animation screen
(assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil
:talk peddler-talk :stand peddler-stand)
:stand)}
:collision "outside-castle/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00))))

View File

@@ -0,0 +1,163 @@
(ns advent.screens.rooms.outside-house
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.utils :as utils]
[clojure.zip :as zip]
[play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]))
(defn wizard-dialogue [entities]
(actions/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?\""
{:run #(actions/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?"
{:run #(do
(actions/respond entities %
:wizard "That was you!?"
:wizard "My house was nearly destroyed!"
:wizard "I spent weeks rebuilding my home!"
:wizard "Leave, now, or I'll turn you into a ..."
:wizard "... a ..."
:wizard "... a frog!"
:ego "Okay, okay! I'm leaving.")
(actions/transition-background entities :outside-house [262 88])
(actions/talk entities :ego "I guess he's really upset with me."))}
"You're still cross about my stealing your magic cowboy hat?"
{:run #(do (actions/respond entities %
:wizard "Of course I'm cross! It's irreplaceable!"
:wizard "That cowboy hat accented my facial physique."
:wizard "And complemented my skin color."
:wizard "And you little cheat stole it from me!"
:wizard "That's why I bought my MagiSafe 5000, to keep out intruders like you."
:wizard "Now leave.")
(actions/transition-background entities :outside-house [262 88]))}
"Even an old hoot like you needs a kick in the pants every now and again."
{:run #(actions/respond entities % :wizard "What gives you the right to try to teach me a lesson?")
:choices ["My good looks?"
{:run #(do (actions/respond entities %
:wizard "You know, handsome looks aren't all they're chocked up to be."
:wizard "Take me for example."
:wizard "When you have a bod like man, you can hardly go to the grocery store without being noticed."
:wizard "But no. Your looks, however good they may be, don't give you the right to teach me a lesson."
:wizard "Now please leave me in peace.")
(actions/transition-background entities :outside-house [262 88]))}
"My good standing within the community?"
{:run #(do (actions/respond entities %
:wizard "Ha! Good standing?"
:wizard "You're the neighborhood cheat and everyone knows it."
:wizard "Now please leave me in peace.")
(actions/transition-background entities :outside-house [262 88]))}
"I'm going to be a knight! That counts for something doesn't it?"
{:run #(do (actions/respond entities %
:wizard "You are, are you?"
:wizard "Pray tell, how do you, a mere wreckless youth, plan on becoming a knight?"))
:choices ["By pulling the Sword of Blergh from its stone!"
{:run #(actions/respond entities %
:wizard "Well, well. It sounds I was wrong about you."
:wizard "Indeed, you are on the path of setting your destructive past behind you."
:wizard "But know this, the stone cannot be cheated easily."
:wizard "You must fulfill the age-old prophecy."
:wizard "'The Sword of Blergh with magic sting,' ..."
:wizard "... 'Shall yield to no earthly king.'"
:wizard "'To draw from hardened, weathered stone,' ..."
:wizard "... 'One must have valor, right to the bone.'"
:wizard "'Worthy in courage, wisdom and might,' ..."
:wizard "... 'only then with sword he'll fight.'"
:wizard "'But a hero should he prove not be,' ..."
:wizard "... 'Only ruin will fall on he.'"
:wizard "'Should he use guile or guise'..."
)
:choices ["Is this almost over?"
{:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
(actions/respond entities %
:wizard "Patience, boy."
: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 "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
:ego "No cheating."
:ego "Check."))}
"*cough* *cough* *ahem*"
{:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
(actions/respond entities %
:wizard "Excuse you. Moving on..."
: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 "But heed the warning from the prophecy: No cheat can pull the Sword of Blergh."
:ego "No cheating."
:ego "Check."))}]}
"By besting swamp, foe, and the occasional bizarre conversation tree."
{:run #(do (actions/respond entities %
:wizard "While your goal sounds noble, no amount of bizarre conversation tree searching will earn my respect."
:wizard "Now please leave.")
(actions/transition-background entities :outside-house [262 88]))}]}]}]}
"You're not happy to see me, Mr. Fangald?"
{:run #(actions/respond entities % :wizard "Of course not, you little brat. You've made my life a living hell!")
:choices #(-> % zip/left)}
"Good bye, Mr. Fangald!"
{:run #(do
(actions/respond entities % :wizard "Now scram!")
(actions/transition-background entities :outside-house [262 88]))}]}))
(defn make [screen]
(let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])]
(aget sheep-sheet 0 i)))]
(rooms/make :interactions
{:door {:box [258 100 281 160]
:script (actions/get-script
entities
(actions/walk-to entities :ego [262 88])
(actions/talk entities :ego (str "Anyone home?"))
(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]
:script (actions/get-script
entities
(actions/talk entities :ego (str "It's the coolest sword I've ever seen!"))
(actions/walk-to entities :ego [290 66])
(actions/talk entities :ego "Maybe I can pull it out."))}
:right-dir {:box [300 131 320 224]
:script (actions/get-script
entities
(actions/walk-to entities :ego [244 150])
(actions/transition-background entities :behind-house [122 140])
(actions/walk-to entities :ego [172 122]))
:cursor :right}
:up-dir {:box [60 180 224 240]
:script (actions/get-script
entities
(actions/walk-to entities :ego [137 204])
(actions/transition-background entities :cat-tree [203 1]))
:cursor :up}
:left-dir {:box [0 40 20 140]
:script (actions/get-script
entities
(actions/walk-to entities :ego [0 80])
(actions/transition-background entities :outside-castle [310 80]))
:cursor :left}}
:layers [(assoc (texture "bg5.png") :x 0 :y 0 :baseline 0)
(assoc (texture "house.png") :x 0 :y 0 :baseline 122)
(assoc (texture "overdirt.png") :x 0 :y 0 :baseline 240)
(assoc (texture "background-trees.png") :x 0 :y 0 :baseline 44)]
:entities {:sheep (actions/start-animation screen
(assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160
:box [38 160 71 181]
:script (actions/get-script
entities
(if ((get-in @entities [:state :inventory]) :wool)
(actions/talk entities :ego "The sheep has given me enough wool.")
(do (actions/give entities :wool)
(actions/talk entities :ego "I guess her wool is shedding."))))
:scripts {:wool (actions/get-script entities
(actions/talk entities :ego "She doesn't need it back."))
:carrot (actions/get-script entities
(actions/walk-to entities :ego [132 140])
(actions/talk entities :ego "Come on girl, get the carrot!")
(actions/walk-straight-to entities :sheep [100 150]))})
sheep)}
:collision "outsidehouse/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00))))