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