implementing simple cat puzzle.
This commit is contained in:
@@ -32,11 +32,12 @@
|
|||||||
(thread ~@forms))))
|
(thread ~@forms))))
|
||||||
|
|
||||||
|
|
||||||
(defn jump-to [screen entities entity [x y]]
|
(defn jump-to [screen entities entity [x y] update-baseline?]
|
||||||
(let [scale-fn (-> entities :room :scale-fn)
|
(let [scale-fn (-> entities :room :scale-fn)
|
||||||
entity (assoc entity :x x
|
entity (assoc entity :x x :y y)
|
||||||
:y y
|
entity (if update-baseline?
|
||||||
:baseline (- 240 y))]
|
(assoc entity :baseline (- 240 y))
|
||||||
|
entity)]
|
||||||
(if (:scaled entity)
|
(if (:scaled entity)
|
||||||
(assoc entity :scale-x (scale-fn [x y]) :scale-y (scale-fn [x y]))
|
(assoc entity :scale-x (scale-fn [x y]) :scale-y (scale-fn [x y]))
|
||||||
entity)))
|
entity)))
|
||||||
@@ -68,10 +69,11 @@
|
|||||||
~@forms))
|
~@forms))
|
||||||
(reset! ~entities (<!! c#)))))
|
(reset! ~entities (<!! c#)))))
|
||||||
|
|
||||||
(defn walk-straight-to [entities target-id [final-x final-y]]
|
(defn walk-straight-to [entities target-id [final-x final-y] & {:keys [update-baseline? face]}]
|
||||||
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
|
(let [{start-x :x start-y :y} (get-in @entities [:room :entities target-id])
|
||||||
final-x (int final-x)
|
final-x (int final-x)
|
||||||
final-y (int final-y)]
|
final-y (int final-y)
|
||||||
|
update-baseline? (if (nil? update-baseline?) true update-baseline?)]
|
||||||
(run-action entities
|
(run-action entities
|
||||||
(begin [this screen entities]
|
(begin [this screen entities]
|
||||||
entities)
|
entities)
|
||||||
@@ -94,7 +96,7 @@
|
|||||||
(assoc-in [:room :entities target-id :y] final-y))
|
(assoc-in [:room :entities target-id :y] final-y))
|
||||||
(update-in entities [:room :entities target-id]
|
(update-in entities [:room :entities target-id]
|
||||||
#(start-animation screen
|
#(start-animation screen
|
||||||
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
|
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)] update-baseline?)
|
||||||
:facing (cond (< delta-x 0) :left
|
:facing (cond (< delta-x 0) :left
|
||||||
(> delta-x 0) :right
|
(> delta-x 0) :right
|
||||||
:else (:facing %)))
|
:else (:facing %)))
|
||||||
@@ -106,7 +108,7 @@
|
|||||||
(< (utils/dist final-x final-y from-x from-y) 1)))
|
(< (utils/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 :face face))
|
||||||
(can-skip? [this screen entities]
|
(can-skip? [this screen entities]
|
||||||
false))))
|
false))))
|
||||||
|
|
||||||
@@ -178,7 +180,7 @@
|
|||||||
(assoc-in [:room :entities target-id :y] target-y)))
|
(assoc-in [:room :entities target-id :y] target-y)))
|
||||||
(update-in entities [:room :entities target-id]
|
(update-in entities [:room :entities target-id]
|
||||||
#(start-animation screen
|
#(start-animation screen
|
||||||
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
|
(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)] true)
|
||||||
:facing (cond (< delta-x 0) :left
|
:facing (cond (< delta-x 0) :left
|
||||||
(> delta-x 0) :right
|
(> delta-x 0) :right
|
||||||
:else (:facing %)))
|
:else (:facing %)))
|
||||||
@@ -354,6 +356,20 @@
|
|||||||
|
|
||||||
(terminate [this screen entities] entities)
|
(terminate [this screen entities] entities)
|
||||||
|
|
||||||
|
(can-skip? [this screen entities]
|
||||||
|
false)))
|
||||||
|
|
||||||
|
(defn add-entity [entities id entity]
|
||||||
|
(run-action entities
|
||||||
|
(begin [this screen entities]
|
||||||
|
(update-in entities [:room :entities] #(assoc % id entity)))
|
||||||
|
|
||||||
|
(continue [this screen entities] entities)
|
||||||
|
|
||||||
|
(done? [this screen entities] true)
|
||||||
|
|
||||||
|
(terminate [this screen entities] entities)
|
||||||
|
|
||||||
(can-skip? [this screen entities]
|
(can-skip? [this screen entities]
|
||||||
false)))
|
false)))
|
||||||
|
|
||||||
@@ -400,7 +416,7 @@
|
|||||||
(music! (get-in entities [:musics new-music]) :set-volume 0)
|
(music! (get-in entities [:musics new-music]) :set-volume 0)
|
||||||
(music! (get-in entities [:musics new-music]) :play)))
|
(music! (get-in entities [:musics new-music]) :play)))
|
||||||
(-> entities
|
(-> entities
|
||||||
(update-in [:room :entities :ego] #(jump-to screen entities % [x y])))))
|
(update-in [:room :entities :ego] #(jump-to screen entities % [x y] true)))))
|
||||||
|
|
||||||
(continue [this screen entities]
|
(continue [this screen entities]
|
||||||
(when music-changed?
|
(when music-changed?
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
(ns advent.screens.rooms
|
(ns advent.screens.rooms
|
||||||
(:require [advent.zone :as zone]))
|
(:require [advent.zone :as zone]))
|
||||||
|
|
||||||
|
(defn make-entity [id entity]
|
||||||
|
(merge entity
|
||||||
|
{:mouse-in? (fn [entities x y]
|
||||||
|
(let [{entity-x :x entity-y :y width :width height :height region :object} (get-in entities [:room :entities id])
|
||||||
|
width (or width (.getRegionWidth region))
|
||||||
|
height (or height (.getRegionHeight region))]
|
||||||
|
((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y)))}
|
||||||
|
(when (:script entity)
|
||||||
|
{:get-script (fn [cursor [x y]]
|
||||||
|
(if (= :main cursor)
|
||||||
|
(:script entity)
|
||||||
|
(when-let [scripts (:scripts entity)]
|
||||||
|
(scripts (:value cursor)))))})))
|
||||||
(defn make [& {:keys [collision interactions entities] :as params}]
|
(defn make [& {:keys [collision interactions entities] :as params}]
|
||||||
(let [interactions-as-list (for [[id spec] interactions]
|
(let [interactions-as-list (for [[id spec] interactions]
|
||||||
(merge spec {:mouse-in? (fn [_ x y]
|
(merge spec {:mouse-in? (fn [_ x y]
|
||||||
@@ -11,18 +24,7 @@
|
|||||||
(when-let [scripts (:scripts spec)]
|
(when-let [scripts (:scripts spec)]
|
||||||
(scripts (:value cursor)))))}))
|
(scripts (:value cursor)))))}))
|
||||||
entities (into {} (for [[id entity] entities]
|
entities (into {} (for [[id entity] entities]
|
||||||
[id (merge entity
|
[id (make-entity id entity)]))]
|
||||||
{:mouse-in? (fn [entities x y]
|
|
||||||
(let [{entity-x :x entity-y :y region :object} (get-in entities [:room :entities id])
|
|
||||||
width (.getRegionWidth region)
|
|
||||||
height (.getRegionHeight region)]
|
|
||||||
((zone/box entity-x entity-y (+ entity-x width) (+ entity-y height)) x y)))}
|
|
||||||
(when (:script entity)
|
|
||||||
{:get-script (fn [cursor [x y]]
|
|
||||||
(if (= :main cursor)
|
|
||||||
(:script entity)
|
|
||||||
(when-let [scripts (:scripts entity)]
|
|
||||||
(scripts (:value cursor)))))}))]))]
|
|
||||||
(merge params {:collision (advent.pathfind/map-from-resource collision)
|
(merge params {:collision (advent.pathfind/map-from-resource collision)
|
||||||
:interactions interactions-as-list
|
:interactions interactions-as-list
|
||||||
:entities entities})))
|
:entities entities})))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
(ns advent.screens.rooms.cat-tree
|
(ns advent.screens.rooms.cat-tree
|
||||||
(:require [advent.screens.rooms :as rooms]
|
(:require [advent.screens.rooms :as rooms]
|
||||||
[advent.actions :as actions]
|
[advent.actions :as actions]
|
||||||
|
[advent.screens.items :as items]
|
||||||
[advent.utils :as utils]
|
[advent.utils :as utils]
|
||||||
[clojure.zip :as zip]
|
[clojure.zip :as zip]
|
||||||
[play-clj.core :refer :all]
|
[play-clj.core :refer :all]
|
||||||
@@ -11,7 +12,8 @@
|
|||||||
(defn make [screen]
|
(defn make [screen]
|
||||||
(let [cat-stand-sheet (texture! (texture "cat-tree/cat-stand.png") :split 22 10)
|
(let [cat-stand-sheet (texture! (texture "cat-tree/cat-stand.png") :split 22 10)
|
||||||
cat-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0 0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0])]
|
cat-stand (animation 0.15 (for [i (flatten [(repeat 10 0) 1 1 (repeat 10 0) 2 3 4 3 0 0 2 3 4 3 (repeat 10 0) 1 1 (repeat 10 0) 5 5 6 6 7 (repeat 10 [7 8]) 6 5 0])]
|
||||||
(aget cat-stand-sheet 0 i)))]
|
(aget cat-stand-sheet 0 i)))
|
||||||
|
ladder-entity (assoc (texture "inside-cafeteria/ladder.png") :x 120 :y 60 :baseline 162)]
|
||||||
(rooms/make :music :town-2
|
(rooms/make :music :town-2
|
||||||
:interactions
|
:interactions
|
||||||
{:down-dir {:box [150 0 270 20]
|
{:down-dir {:box [150 0 270 20]
|
||||||
@@ -19,13 +21,27 @@
|
|||||||
(actions/walk-to entities :ego [203 1])
|
(actions/walk-to entities :ego [203 1])
|
||||||
(actions/transition-background entities :outside-house [137 204])
|
(actions/transition-background entities :outside-house [137 204])
|
||||||
(actions/walk-to entities :ego [195 140]))
|
(actions/walk-to entities :ego [195 140]))
|
||||||
:cursor :down}}
|
:cursor :down}
|
||||||
|
:ladder-area {:box [46 40 265 190]
|
||||||
|
:scripts {:ladder (actions/get-script entities
|
||||||
|
(actions/talk entities :ego "I'll just set this up.")
|
||||||
|
(actions/walk-to entities :ego [151 50] :face :left)
|
||||||
|
(actions/play-animation entities :ego :reach)
|
||||||
|
(actions/remove-item entities items/ladder)
|
||||||
|
(actions/add-entity entities :ladder ladder-entity)
|
||||||
|
(actions/walk-straight-to entities :ego [140 85] :face :right :update-baseline? false)
|
||||||
|
(actions/add-entity entities :blank (rooms/make-entity :blank
|
||||||
|
{:object nil :x 0 :y 0 :width 320 :height 240 :baseline 240
|
||||||
|
:script (actions/get-script entities
|
||||||
|
(when (get-in @entities [:room :entities :ladder])
|
||||||
|
(actions/talk entities :ego "I'll get down."))) }))
|
||||||
|
)}}}
|
||||||
:layers [(assoc (texture "cat-tree/background.png") :x 0 :y 0 :baseline 0)
|
: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/tree-and-rock.png") :x 0 :y 0 :baseline 161)
|
||||||
(assoc (texture "cat-tree/sillhoute.png") :x 0 :y 0 :baseline 240)]
|
(assoc (texture "cat-tree/sillhoute.png") :x 0 :y 0 :baseline 240)]
|
||||||
:entities { :cat (actions/start-animation screen
|
:entities {:cat (actions/start-animation screen
|
||||||
(assoc (animation->texture screen cat-stand)
|
(assoc (animation->texture screen cat-stand)
|
||||||
:x 184 :y 173 :baseline 240
|
:x 184 :y 173 :baseline 1000
|
||||||
:script (actions/get-script entities
|
:script (actions/get-script entities
|
||||||
(actions/talk entities :ego "Here kitty, kitty, kitty.")
|
(actions/talk entities :ego "Here kitty, kitty, kitty.")
|
||||||
(actions/talk entities :ego "Kitty's not so interested in me."))
|
(actions/talk entities :ego "Kitty's not so interested in me."))
|
||||||
|
|||||||
@@ -52,10 +52,10 @@
|
|||||||
(open-inventory screen entities)
|
(open-inventory screen entities)
|
||||||
(let [interaction (first (filter #((:mouse-in? %) entities x y)
|
(let [interaction (first (filter #((:mouse-in? %) entities x y)
|
||||||
(get-in entities [:room :interactions])))
|
(get-in entities [:room :interactions])))
|
||||||
interacting-entity (first (filter #(and (:mouse-in? %)
|
interacting-entity (first (sort-by (comp - :baseline) (filter #(and (:mouse-in? %)
|
||||||
(:get-script %)
|
(:get-script %)
|
||||||
((:mouse-in? %) entities x y))
|
((:mouse-in? %) entities x y))
|
||||||
(vals (get-in entities [:room :entities]))))
|
(vals (get-in entities [:room :entities])))))
|
||||||
|
|
||||||
current-action (get-in entities [:actions :current])
|
current-action (get-in entities [:actions :current])
|
||||||
;; TODO - hacky way of resetting queue
|
;; TODO - hacky way of resetting queue
|
||||||
@@ -226,7 +226,7 @@
|
|||||||
:inside-fangald (make-music "inside-fangald.ogg")}
|
:inside-fangald (make-music "inside-fangald.ogg")}
|
||||||
:state {:object nil
|
:state {:object nil
|
||||||
:active? true
|
:active? true
|
||||||
:inventory [items/grass items/flask-1-strength]
|
:inventory [items/grass items/ladder]
|
||||||
:clues #{}
|
:clues #{}
|
||||||
:mints-eaten 0}
|
:mints-eaten 0}
|
||||||
:actions {:object nil
|
:actions {:object nil
|
||||||
@@ -264,7 +264,7 @@
|
|||||||
|
|
||||||
:on-mouse-moved
|
:on-mouse-moved
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
#_(when (get-in entities [:state :active?])
|
(when (get-in entities [:state :active?])
|
||||||
(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)})]
|
||||||
(if-let [mouse-override (find-override screen entities [x y])]
|
(if-let [mouse-override (find-override screen entities [x y])]
|
||||||
(assoc-in entities [:cursor :override] (:cursor mouse-override))
|
(assoc-in entities [:cursor :override] (:cursor mouse-override))
|
||||||
|
|||||||
Reference in New Issue
Block a user