cleanup.
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
[play-clj.g2d :refer :all]
|
[play-clj.g2d :refer :all]
|
||||||
[clojure.pprint]
|
[clojure.pprint]
|
||||||
[advent.pathfind]
|
[advent.pathfind]
|
||||||
[advent.actions :as actions])
|
[advent.actions :as actions]
|
||||||
|
[advent.screens.dialogue :as dialogue])
|
||||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
||||||
[com.badlogic.gdx.graphics.g2d TextureRegion] ))
|
[com.badlogic.gdx.graphics.g2d TextureRegion] ))
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
(assoc entity :scale-x (scale-fn y) :scale-y (scale-fn y))
|
(assoc entity :scale-x (scale-fn y) :scale-y (scale-fn y))
|
||||||
entity)))
|
entity)))
|
||||||
|
|
||||||
(defn walk-to-fn [[target-x target-y] target-id]
|
(defn walk-to [[target-x target-y] target-id]
|
||||||
(fn [screen entities]
|
(fn [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} (entities target-id)]
|
||||||
(let [delta-x (- target-x from-x)
|
(let [delta-x (- target-x from-x)
|
||||||
@@ -32,9 +33,10 @@
|
|||||||
(assoc (jump-to screen entities target-entity [(+ moved-x from-x) (+ moved-y from-y)])
|
(assoc (jump-to screen entities target-entity [(+ moved-x from-x) (+ moved-y from-y)])
|
||||||
:anim (if (< moved-x 0) left right))))))))
|
:anim (if (< moved-x 0) left right))))))))
|
||||||
|
|
||||||
(defn stop-fn [target-id]
|
(defn stop [target-id]
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(let [target (target-id entities)]
|
(let [target (target-id entities)]
|
||||||
|
(run! dialogue/talking-screen :stop-talk :target-id target-id)
|
||||||
(assoc-in entities [target-id] (merge target
|
(assoc-in entities [target-id] (merge target
|
||||||
{:anim nil
|
{:anim nil
|
||||||
:actions (rest (:actions target))}
|
:actions (rest (:actions target))}
|
||||||
@@ -48,7 +50,16 @@
|
|||||||
[(int (:x entity)) (int (:y entity))]
|
[(int (:x entity)) (int (:y entity))]
|
||||||
[(int x) (int y)])))
|
[(int x) (int y)])))
|
||||||
actions (when (seq path)
|
actions (when (seq path)
|
||||||
(conj
|
(concat
|
||||||
(vec (map #(walk-to-fn % target-id) (conj path [x y])))
|
[(stop target-id)]
|
||||||
(stop-fn target-id)))]
|
(map #(walk-to % target-id) (conj path [x y]))
|
||||||
|
[(stop target-id)]))]
|
||||||
actions))
|
actions))
|
||||||
|
|
||||||
|
(defn talk [target-id text]
|
||||||
|
(fn [screen entities]
|
||||||
|
(run! dialogue/talking-screen :on-talk :text text
|
||||||
|
:x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) 25)
|
||||||
|
:target-id target-id)
|
||||||
|
(-> entities
|
||||||
|
(update-in [target-id :actions] rest))))
|
||||||
|
|||||||
@@ -11,21 +11,27 @@
|
|||||||
(defscreen talking-screen
|
(defscreen talking-screen
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(update! screen :renderer (stage) :camera (orthographic)) [])
|
(update! screen :renderer (stage) :camera (orthographic))
|
||||||
|
{})
|
||||||
:on-render
|
:on-render
|
||||||
(fn [screen entities]
|
(fn [screen [entities]]
|
||||||
(render! screen entities)
|
(render! screen (vals entities))
|
||||||
entities)
|
entities)
|
||||||
|
|
||||||
:on-talk
|
:on-talk
|
||||||
(fn [{:keys [create-talk text x y]} entities]
|
(fn [{:keys [create-talk target-id text x y]} [entities]]
|
||||||
[(let [font (bitmap-font "mainfont.fnt" )
|
(let [font (bitmap-font "mainfont.fnt" )
|
||||||
tr (bitmap-font! font :get-region)
|
tr (bitmap-font! font :get-region)
|
||||||
tx (.getTexture tr)
|
tx (.getTexture tr)
|
||||||
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||||
talk (assoc (label text (style :label font (color :white)) ) :x (* 4 x) :y (* 4 y))]
|
talk (assoc (label text (style :label font (color :white)) ) :x (* 4 x) :y (* 4 y))]
|
||||||
(label! talk :set-font-scale 1)
|
(label! talk :set-font-scale 1)
|
||||||
talk)])
|
(assoc entities target-id talk)))
|
||||||
|
|
||||||
|
:stop-talk
|
||||||
|
(fn [{:keys [target-id] } [entities]]
|
||||||
|
(dissoc entities target-id))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:on-resize (fn [screen entities]
|
:on-resize (fn [screen entities]
|
||||||
|
|||||||
@@ -99,48 +99,40 @@
|
|||||||
]
|
]
|
||||||
{
|
{
|
||||||
:cursor {:id "cursor" :cursor-index 0 }
|
:cursor {:id "cursor" :cursor-index 0 }
|
||||||
:background (assoc background
|
:background (assoc {}
|
||||||
:id "background" :x 0 :y 0
|
|
||||||
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
:collision (advent.pathfind/map-from-resource "pathfind-test-big.png")
|
||||||
:baseline 0
|
:baseline 0
|
||||||
:mouse-overrides [{:mouse-in? (zone/box 290 131 320 224)
|
:mouse-overrides [{:mouse-in? (zone/box 300 131 320 224)
|
||||||
:cursor-override 4
|
:cursor-override 4
|
||||||
:go-to [319 160]}
|
:go-to [319 160]}
|
||||||
{:mouse-in? (zone/box 60 180 224 240)
|
{:mouse-in? (zone/box 60 180 224 240)
|
||||||
:cursor-override 7
|
:cursor-override 7
|
||||||
:go-to [137 204]}
|
:go-to [137 204]}
|
||||||
{:mouse-in? (zone/box 0 40 30 140)
|
{:mouse-in? (zone/box 0 40 20 140)
|
||||||
:cursor-override 6
|
:cursor-override 6
|
||||||
:go-to [0 80]}]
|
:go-to [0 80]}]
|
||||||
:interactions [{:mouse-in? (zone/box 258 100 281 160)
|
:interactions [{:mouse-in? (zone/box 258 100 281 160)
|
||||||
:click-fn (fn [screen entities [x y]]
|
:click-fn (fn [screen entities [x y]]
|
||||||
(assoc-in entities [:ego :actions] [(fn [screen entities]
|
(assoc-in entities [:ego :actions] [(actions/stop :ego)
|
||||||
(run! talking-screen :on-talk :text "It's the door to Merlin's house."
|
(actions/talk :ego "Looking at the house.")]))}]
|
||||||
:x (get-in entities [:ego :x]) :y (+ (get-in entities [:ego :y]) 25) )
|
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00)
|
||||||
(-> entities
|
:layers [(assoc background :x 0 :y 0 :baseline 0)
|
||||||
(update-in [:ego :actions] rest)))]))}]
|
(assoc house :x 0 :y 0 :baseline 122)
|
||||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.00))
|
(assoc overdirt :x 0 :y 0 :baseline 240)
|
||||||
:house (assoc house
|
(assoc background-trees :x 0 :y 0 :baseline 44)])
|
||||||
:x 0 :y 0
|
|
||||||
:baseline 122)
|
|
||||||
:overdirt (assoc overdirt
|
|
||||||
:x 0 :y 0
|
|
||||||
:baseline 240)
|
|
||||||
:background-trees (assoc background-trees
|
|
||||||
:x 0 :y 0
|
|
||||||
:baseline 44)
|
|
||||||
:ego (get-ego screen)
|
:ego (get-ego screen)
|
||||||
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)
|
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
:on-render
|
:on-render
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
|
(clear!)
|
||||||
(let [entities (update-ego screen entities (:ego entities))
|
(let [entities (update-ego screen entities (:ego entities))
|
||||||
_ (label! (:fps entities) :set-text (str (game :fps)))
|
_ (label! (:fps entities) :set-text (str (game :fps)))
|
||||||
entities (if (get-in entities [:ego :anim])
|
entities (if (get-in entities [:ego :anim])
|
||||||
(update-in entities [:ego] #(merge % (animation->texture screen (:anim %))))
|
(update-in entities [:ego] #(merge % (animation->texture screen (:anim %))))
|
||||||
entities)]
|
entities)]
|
||||||
(render! screen (sort-by :baseline (vals entities)))
|
(render! screen (sort-by :baseline (concat (vals entities) (get-in entities [:background :layers]))))
|
||||||
entities))
|
entities))
|
||||||
|
|
||||||
:on-resize (fn [screen entities]
|
:on-resize (fn [screen entities]
|
||||||
|
|||||||
Reference in New Issue
Block a user