Files
gitea-docker/desktop/src-common/advent/screens/rooms/inside_jail.clj
2014-12-27 12:52:21 -08:00

167 lines
13 KiB
Clojure

(ns advent.screens.rooms.inside-jail
(:require [advent.screens.rooms :as rooms]
[advent.actions :as actions]
[advent.screens.items :as items]
[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 do-warden-dialogue [entities]
(actions/do-dialogue entities :ego "Hey, who are you? Why am I in this cell?"
:warden "You're under arrest for theft of public property."
:ego "Under arrest? But I'm the good guy!\nThe game is named after me!"
:warden "Sorry chap. The law's the law.")
(actions/present-choices entities
{:choices ["But I'm just a kid."
{:run #(actions/respond entities %
:warden "The Duke of Remington is a very stern chap."
:warden "He doesn't bend the rules, even for young thieves.")
:choices actions/previous-choices}
"But I was going to teach Blergh a lesson!"
{:run #(actions/respond entities %
:warden "Sure you were. If he even exists."
:ego "He does! He's going to come destroy the town first thing in the morning!"
:warden "Uh huh."
:warden "As if I have heard the 'bad guy is coming to destroy the town' 1000 times already."
:warden "You could try coming up with something creative, chap."
:ego "Creative?"
:warden "Yeah, like, 'My mother is in the hospital.'"
:warden "Or, 'I have a highly contagious case of the lizard-pox.'")
:choices actions/previous-choices}
"But the whole town will die if I don't do something!"
{:run #(actions/respond entities %
:warden "The whole town will have a thief on the loose if I don't keep you here."
:warden "We don't want that either, do we?"
:ego "This is life and death we're talking about here!"
:warden "And this is my job. A chap's got to do his job, am I right?"
:warden "You've got to steal, and I've got to lock you up."
:warden "It's how it works.")
:choices actions/previous-choices}
"Nevermind."
{:run #(do (actions/respond entities %
:warden "This conversation has got me very tired."
:warden "Be a good chap and let me rest.")
(actions/play-animation entities :warden :fall-asleep :stop? false)
(actions/begin-animation entities :warden :sleep)
(actions/update-state entities (fn [s] (assoc s :warden-sleeping? true))))}]}))
(defn get-key [ entities]
(actions/walk-to entities :ego [71 82] :face :left)
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities :ego "He's got something clutched in his hand!")
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities :ego "What's this?"
:ego "Hello hello!"
:ego "It's the key!")
(let [had-key-before? (actions/has-obtained? entities :key)]
(actions/give entities :key)
(when (not had-key-before?)
(actions/do-dialogue entities :ego "Come on! It's that easy to escape?"
:ego "We're not going to at least do that dog and bone scenario?"
:ego "I get to just take the key and leave?"
:ego "Seems like a pretty sorry excuse for a puzzle."))))
(defn search-hay [entities]
(actions/walk-to entities :ego [144 86] :face :right)
(let [hay-searches (get-in @entities [:state :hay-searches] 0)]
(condp = hay-searches
0 (do
(actions/talk entities :ego "Maybe there's a needle or something in here.")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "No. Nothing at all!"))
1 (do
(actions/talk entities :ego "Maybe I missed something. I'll check again.")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "Nope. Still nothing."))
2 (do (actions/talk entities :ego "There's got to be something in here!")
(actions/play-animation entities :ego :squat)
(actions/talk entities :ego "Nope. Still nothing."))
(do (actions/talk entities :ego "One more try.")
(actions/play-animation entities :ego :squat)
(actions/do-dialogue entities
:ego "You know, in some games, you have to try multiple times."
:ego "But I have a feeling each time you click on this hay, I'm going to find nothing."
:ego "Maybe you should give it a rest.")))
(actions/update-state entities #(assoc % :hay-searches (inc hay-searches)))))
(defn make [screen]
(let [warden-sheet (texture! (texture "inside-jail/warden.png") :split 43 58)
warden-talk (animation 0.2 (for [i [1 0 1 0 1 0 1 0 0 0 2 0]]
(aget warden-sheet 0 i)))
warden-stand (animation 0.1 (for [i (flatten [(repeat 30 0) 2 (repeat 20 0) 2])]
(aget warden-sheet 0 i)))
warden-fall-asleep (animation 0.1 (for [i (flatten [(repeat 10 0) 2 2 (repeat 10 0) 2 2 2 2 2 2 2 (repeat 10 0) 2 2 2 2 2 2 2 ])]
(aget warden-sheet 0 i)))
warden-sleep (animation 0.5 (for [i (flatten [(repeat 5 2) 3])]
(aget warden-sheet 0 i)))]
(rooms/make :music :inside-antique
:interactions {
:lock {:box [178 102 184 124]
:script (actions/get-script entities
(actions/walk-to entities :ego [174 80] :face :right)
(actions/play-animation entities :ego :reach)
(actions/talk entities :ego "There's no helping it. It's locked."))
:scripts {:key (actions/get-script entities
(actions/walk-to entities :ego [174 80] :face :right)
(actions/play-animation entities :ego :reach)
(actions/talk entities :ego "Yes, that's it!"))}}
:window {:box [98 110 118 140]
:script (actions/get-script entities
(actions/walk-to entities :ego [102 88] :face :right)
(actions/do-dialogue entities
:ego "What a peaceful night."
:ego "Oh my sweet Georgia McGorgeous. How will I ever save you now?"
:ego "I have to find a way out of here!"))}
:hay {:box [130 86 177 102]
:script (actions/get-script entities
(search-hay entities)
)}}
:layers [(assoc (texture "inside-jail/background.png") :x 0 :y 0 :baseline 0)
(assoc (texture "inside-jail/bars.png") :x 0 :y 0 :baseline 165)
(assoc (texture "inside-jail/glow.png") :x 0 :y 0 :baseline 240)]
:entities {:warden (assoc (texture "inside-jail/warden.png" )
:x 40 :y 60 :baseline 166
:stand warden-stand
:talk warden-talk
:sleep warden-sleep
:fall-asleep warden-fall-asleep
:anim warden-stand
:anim-start 0
:talk-color (color 0.9 0.3 0.9 1.0)
:script (actions/get-script entities
(cond
(actions/has-item? entities :key) (actions/talk entities :ego "Shh! It's best not to wake him now.")
(get-in @entities [:state :warden-fast-asleep?]) (get-key entities)
(get-in @entities [:state :warden-sleeping?]) (do (actions/walk-to entities :ego [103 82])
(actions/do-dialogue entities
:ego "You-hoo! Mr. Warden?"
:ego "I guess he's really fast asleep!")
(actions/update-state entities #(assoc % :warden-fast-asleep? true)))
:else (do (actions/walk-to entities :ego [103 82])
(do-warden-dialogue entities)))))
:ball-n-chain (assoc (texture "inside-jail/ball-n-chain.png")
:x 80 :y 80 :baseline 160
:script (actions/get-script entities
(actions/walk-to entities :ego [103 83] :face :left)
(actions/play-animation entities :ego :squat)
(actions/remove-entity entities :ball-n-chain)
(actions/give entities :ball-n-chain)))}
:collision "inside-jail/collision.png"
:scale-fn (utils/scaler-fn-with-baseline 0 0.50 1.5)
:start-pos [130 85]
:apply-state (fn [entities]
(as-> entities entities
(if (actions/has-item? entities :ball-n-chain)
(update-in entities [:room :entities] #(dissoc % :ball-n-chain))
entities)
(if (get-in entities [:state :warden-sleeping?])
(update-in entities [:room :entities :warden] #(actions/start-animation % :sleep))
entities))))))