moving ego into background.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@@ -35,10 +35,10 @@
|
||||
entity)))
|
||||
|
||||
(defn stop [screen entities target-id]
|
||||
(update-in entities [target-id] #(merge %
|
||||
{:anim nil}
|
||||
(when (:anim %)
|
||||
(texture (animation! (:anim %) :get-key-frame 0.25))))))
|
||||
(update-in entities [:background :entities target-id] #(merge %
|
||||
{:anim nil}
|
||||
(when (:anim %)
|
||||
(texture (animation! (:anim %) :get-key-frame 0.25))))))
|
||||
|
||||
|
||||
(defn dist [x1 y1 x2 y2]
|
||||
@@ -56,7 +56,7 @@
|
||||
(reset! ~entities (<!! c#)))))
|
||||
|
||||
(defn walk-to [entities target-id [final-x final-y]]
|
||||
(let [{start-x :x start-y :y} (@entities target-id)
|
||||
(let [{start-x :x start-y :y} (get-in @entities [:background :entities target-id])
|
||||
final-x (int final-x)
|
||||
final-y (int final-y)
|
||||
path (vec (take-nth 5 (advent.pathfind/visit-all
|
||||
@@ -73,7 +73,7 @@
|
||||
entities)
|
||||
|
||||
(continue [this screen entities]
|
||||
(let [{from-x :x from-y :y :keys [left right] :as target-entity} (entities target-id)
|
||||
(let [{from-x :x from-y :y :keys [left right] :as target-entity} (get-in entities [:background :entities target-id])
|
||||
[[target-x target-y] remainder] @targets-left]
|
||||
(let [delta-x (- target-x from-x)
|
||||
delta-y (- target-y from-y)
|
||||
@@ -87,14 +87,14 @@
|
||||
(if (< distance 1)
|
||||
(do (swap! targets-left rest)
|
||||
entities)
|
||||
(update-in entities [target-id]
|
||||
(update-in entities [:background :entities target-id]
|
||||
#(assoc (jump-to screen entities % [(+ moved-x from-x) (+ moved-y from-y)])
|
||||
:anim (cond (< delta-x 0) left
|
||||
(> delta-x 0) right
|
||||
:else (:anim %))))))))
|
||||
|
||||
(done? [this screen entities]
|
||||
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (entities target-id)]
|
||||
(let [{from-x :x from-y :y :keys [left right anim] :as target-entity} (get-in entities [:background :entities target-id])]
|
||||
(< (dist final-x final-y from-x from-y) 1)))
|
||||
|
||||
(terminate [this screen entities]
|
||||
@@ -109,15 +109,15 @@
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(let [_ (swap! initial-time #(or % (:total-time screen)))
|
||||
target-y (get-in entities [target-id :y])
|
||||
target-y (get-in entities [:background :entities target-id :y])
|
||||
scale-fn (get-in entities [:background :scale-fn])
|
||||
scale (scale-fn target-y)
|
||||
height (* scale 36)]
|
||||
(run! dialogue/talking-screen :on-talk :text text
|
||||
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height)
|
||||
:x (get-in entities [:background :entities target-id :x]) :y (+ (get-in entities [:background :entities target-id :y]) height)
|
||||
:target-id target-id
|
||||
:scale scale)
|
||||
(assoc-in entities [target-id :anim] (get-in entities [target-id :talk]))))
|
||||
(assoc-in entities [:background :entities target-id :anim] (get-in entities [:background :entities target-id :talk]))))
|
||||
|
||||
(continue [this screen entities] entities)
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
(sound! (sound "pickup.mp3") :play)
|
||||
|
||||
(-> entities
|
||||
(update-in [target-id :inventory] #(conj % item))
|
||||
(update-in [:background :entities target-id :inventory] #(conj % item))
|
||||
(assoc-in [:cursor :current] item)))
|
||||
|
||||
(continue [this screen entities] entities)
|
||||
@@ -168,10 +168,12 @@
|
||||
entities))
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
(-> entities
|
||||
(assoc-in [:background] (get-in entities [:backgrounds new-background]))
|
||||
(assoc-in [:ego :x] x)
|
||||
(assoc-in [:ego :y] y)))
|
||||
(let [ego (get-in entities [:background :entities :ego])]
|
||||
(-> entities
|
||||
(assoc-in [:background] (get-in entities [:backgrounds new-background]))
|
||||
(assoc-in [:background :entities :ego] ego)
|
||||
(assoc-in [:background :entities :ego :x] x)
|
||||
(assoc-in [:background :entities :ego :y] y))))
|
||||
|
||||
(continue [this screen entities]
|
||||
(update-in entities [:transition :opacity] - 0.075))
|
||||
|
||||
@@ -120,7 +120,11 @@
|
||||
(defn backgrounds [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)))]
|
||||
(aget sheep-sheet 0 i)))
|
||||
|
||||
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)))]
|
||||
{:outside-house
|
||||
(make-background :interactions
|
||||
{:door {:box [258 100 281 160]
|
||||
@@ -137,7 +141,7 @@
|
||||
:sheep {:box [38 160 71 181]
|
||||
:script (actions/get-script
|
||||
entities
|
||||
(if ((get-in @entities [:ego :inventory]) :wool)
|
||||
(if ((get-in @entities [:background :entities :ego :inventory]) :wool)
|
||||
(actions/talk entities :ego "The sheep has given me enough wool.")
|
||||
(do (actions/give entities :ego :wool)
|
||||
(actions/talk entities :ego "I guess his wool is shedding."))))}
|
||||
@@ -161,7 +165,7 @@
|
||||
(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 [(assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)]
|
||||
:entities {:sheep (assoc (animation->texture screen sheep) :x 38 :y 160 :baseline 160 :anim sheep)}
|
||||
:collision "outsidehouse/collision.png"
|
||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
|
||||
|
||||
@@ -177,9 +181,17 @@
|
||||
:script (actions/get-script
|
||||
entities
|
||||
(actions/walk-to entities :ego [191 90])
|
||||
(actions/talk entities :ego "Hello there."))}}
|
||||
(actions/talk entities :ego "Hello there, peddler.")
|
||||
(actions/talk entities :peddler "Good day sir! Care to see any of my wares?")
|
||||
(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 all types of wares...")
|
||||
(actions/talk entities :peddler "...I'm well stocked on used earplugs...")
|
||||
(actions/talk entities :peddler "...glass eyes, motivational tapes... ")
|
||||
(actions/talk entities :peddler "...and useful books like this:")
|
||||
(actions/talk entities :peddler "'Checkers Mastery in Less Than 10 Seconds'"))}}
|
||||
:layers [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)]
|
||||
:entities [(assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150)]
|
||||
:entities {:peddler (assoc (texture "outside-castle/peddler.png") :x 110 :y 90 :baseline 150 :anim nil :talk peddler-talk)}
|
||||
:collision "outside-castle/collision.png"
|
||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))}))
|
||||
|
||||
@@ -205,8 +217,8 @@
|
||||
:current :main
|
||||
:last :main
|
||||
:override nil}
|
||||
:background (:outside-house backgrounds)
|
||||
:ego (get-ego screen)
|
||||
:background (assoc-in (:outside-house backgrounds)
|
||||
[:entities :ego] (get-ego screen))
|
||||
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)
|
||||
}))
|
||||
|
||||
@@ -217,9 +229,13 @@
|
||||
#_(.glEnable (.getGL30 Gdx/graphics) GL30/GL_BLEND)
|
||||
(let [entities (update-cursor screen entities)
|
||||
entities (update-from-script screen entities)
|
||||
entities (update-in entities [:background :entities] (fn [entities] (map #(animate % screen) entities)))
|
||||
entities (update-in entities [:ego] #(animate % screen))
|
||||
all-entities (concat (vals entities) (get-in entities [:background :layers]) (get-in entities [:background :entities]))]
|
||||
entities (update-in entities [:background :entities] (fn [entities]
|
||||
(into entities
|
||||
(for [[id entity] entities]
|
||||
(if (:anim entity)
|
||||
[id (animate entity screen)]
|
||||
[id entity])))))
|
||||
all-entities (concat (vals entities) (get-in entities [:background :layers]) (vals (get-in entities [:background :entities])))]
|
||||
(label! (:fps entities) :set-text (str (game :fps)))
|
||||
(render! screen (sort-by :baseline all-entities))
|
||||
entities))
|
||||
|
||||
Reference in New Issue
Block a user