picking up the teddy and portait add and remove entities.

This commit is contained in:
Bryce Covert
2016-10-06 22:21:25 -07:00
parent 55fd9495eb
commit 1ac2a2ef3a
2 changed files with 70 additions and 44 deletions

View File

@@ -10,18 +10,20 @@
(merge entity (merge entity
{:id id {:id id
:mouse-in? (fn [entities x y] :mouse-in? (fn [entities x y]
(let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id]) (if-let [box (get-in entities [:room :entities id :box])]
((apply zone/box box) x y)
width (or width (if (instance? TextureRegion region ) (.getRegionWidth ^TextureRegion region) 0)) (let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id])
height (or height (if (instance? TextureRegion region ) (.getRegionHeight ^TextureRegion region) 0))
entity-x (- entity-x (* (or origin-x 0) width (or width (if (instance? TextureRegion region ) (.getRegionWidth ^TextureRegion region) 0))
(or scale-x 1))) height (or height (if (instance? TextureRegion region ) (.getRegionHeight ^TextureRegion region) 0))
entity-y (- entity-y (* (or origin-y 0) entity-x (- entity-x (* (or origin-x 0)
(or scale-y 1)))] (or scale-x 1)))
entity-y (- entity-y (* (or origin-y 0)
((zone/box entity-x entity-y (or scale-y 1)))]
(+ entity-x (* width (or scale-x 1)))
(+ entity-y (* height (or scale-y 1)))) x y)))} ((zone/box entity-x entity-y
(+ entity-x (* width (or scale-x 1)))
(+ entity-y (* height (or scale-y 1)))) x y))))}
(when (or script scripts only-script) (when (or script scripts only-script)
{:get-script (fn [cursor [x y]] {:get-script (fn [cursor [x y]]
(cond only-script (cond only-script

View File

@@ -159,20 +159,25 @@
(actions/walk-to entities :ego [143 58] :face :left) (actions/walk-to entities :ego [143 58] :face :left)
(actions/play-animation entities :ego :reach) (actions/play-animation entities :ego :reach)
(actions/add-entity entities :portrait (get-in @entities [:room :portrait])) (actions/add-entity entities :portrait (get-in @entities [:room :portrait]))
(actions/remove-item entities :portrait)) (actions/remove-item entities :portrait)
(actions/remove-entity entities :return-portrait)
(actions/remove-entity entities :return-portrait-2))
(defn get-portrait [entities] (defn get-portrait [entities]
(actions/walk-to entities :ego [140 58] :face :left) (actions/walk-to entities :ego [140 58] :face :left)
(actions/play-animation entities :ego :reach) (actions/play-animation entities :ego :reach)
(actions/remove-entity entities :portrait) (actions/remove-entity entities :portrait)
(actions/give entities :portrait) (actions/give entities :portrait)
(actions/talk entities :ego "It's a portrait. There's something on the back but it's too dim to read.")) (actions/talk entities :ego "It's a portrait. There's something on the back but it's too dim to read.")
(actions/add-entity entities :return-portrait-2 (get-in @entities [:room :return-portrait-2]))
(actions/add-entity entities :return-portrait (get-in @entities [:room :return-portrait])))
(defn return-teddy [entities] (defn return-teddy [entities]
(actions/walk-to entities :ego [242 49] :face :right) (actions/walk-to entities :ego [242 49] :face :right)
(actions/play-animation entities :ego :reach) (actions/play-animation entities :ego :reach)
(actions/add-entity entities :teddy (get-in @entities [:room :teddy])) (actions/add-entity entities :teddy (get-in @entities [:room :teddy]))
(actions/remove-item entities :teddy)) (actions/remove-item entities :teddy)
(actions/remove-entity entities :return-teddy))
(defn has-to-return-teddy? [entities] (defn has-to-return-teddy? [entities]
(and (actions/has-item? entities :teddy) (and (actions/has-item? entities :teddy)
@@ -209,6 +214,7 @@
:script (actions/get-script entities :script (actions/get-script entities
(actions/walk-to entities :ego [242 49] :face :right) (actions/walk-to entities :ego [242 49] :face :right)
(actions/play-animation entities :ego :reach) (actions/play-animation entities :ego :reach)
(actions/add-entity entities :return-teddy (get-in @entities [:room :return-teddy]))
(actions/give entities :teddy) (actions/give entities :teddy)
(actions/remove-entity entities :teddy) (actions/remove-entity entities :teddy)
(when (not (get-in @entities [:state :allowed-to-keep-teddy?])) (when (not (get-in @entities [:state :allowed-to-keep-teddy?]))
@@ -223,6 +229,39 @@
:fire-2 (utils/load-sound "inside-antique/fire-2.ogg") :fire-2 (utils/load-sound "inside-antique/fire-2.ogg")
:fire-3 (utils/load-sound "inside-antique/fire-3.ogg") :fire-3 (utils/load-sound "inside-antique/fire-3.ogg")
} }
:return-portrait (rooms/make-entity :return-portrait {:box [103 70 206 116]
:label "Desk"
:baseline 0
:cursor :look
:script (actions/get-script entities (actions/talk entities :ego "It's the shopkeep's desk."))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}})
:return-portrait-2 (rooms/make-entity :return-portrait-2
{:box [103 116 131 131]
:label "Desk"
:baseline 0
:cursor :look
:script (actions/get-script entities (if (actions/has-item? entities :portrait)
(actions/talk entities :ego "The shopkeep's portrait used to sit there.")
(get-portrait entities)
))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}})
:return-teddy (rooms/make-entity :return-teddy {:box [227 90 301 105]
:baseline 0
:cursor :look
:label "Shelf"
:script (actions/get-script entities
(actions/talk entities :ego "It's a shelf."))
:scripts {:teddy (actions/get-script entities
(return-teddy entities))
:portrait (actions/get-script entities
(return-portrait entities))}})
:interactions :interactions
{:right {:box [250 0 320 75] {:right {:box [250 0 320 75]
:cursor :right :cursor :right
@@ -240,35 +279,9 @@
(actions/walk-straight-to entities :ego [320 -5]) (actions/walk-straight-to entities :ego [320 -5])
(actions/transition-background entities :inside-castle [182 90]) (actions/transition-background entities :inside-castle [182 90])
(actions/walk-to entities :ego [187 75]))} (actions/walk-to entities :ego [187 75]))}
:return-portrait-2 {:box [103 116 131 131]
:label "Desk"
:cursor :look
:script (actions/get-script entities (if (actions/has-item? entities :portrait)
(actions/talk entities :ego "The shopkeep's portrait used to sit there.")
(get-portrait entities)
))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}}
:return-portrait {:box [103 70 206 116]
:label "Desk"
:cursor :look
:script (actions/get-script entities (actions/talk entities :ego "It's the shopkeep's desk."))
:scripts {:portrait (actions/get-script entities
(return-portrait entities))
:teddy (actions/get-script entities
(return-teddy entities))}}
:return-teddy {:box [227 90 301 105]
:cursor :look
:label "Shelf"
:script (actions/get-script entities
(actions/talk entities :ego "It's a shelf."))
:scripts {:teddy (actions/get-script entities
(return-teddy entities))
:portrait (actions/get-script entities
(return-portrait entities))}}
:window {:box [195 121 256 190] :window {:box [195 121 256 190]
:label "Window" :label "Window"
:cursor :hand :cursor :hand
@@ -455,6 +468,17 @@
(update-in entities [:room :entities] #(dissoc % :teddy)) (update-in entities [:room :entities] #(dissoc % :teddy))
entities) entities)
(if (actions/has-item? entities :portrait)
(update-in entities [:room :entities] assoc
:return-portrait (get-in entities [:room :return-portrait])
:return-portrait-2 (get-in entities [:room :return-portrait-2]))
entities)
(if (actions/has-item? entities :teddy)
(update-in entities [:room :entities] assoc
:return-teddy (get-in entities [:room :return-teddy]))
entities)
(update-in entities (update-in entities
[:room :entities :bowl] [:room :entities :bowl]
(fn [b] (fn [b]