dialogue tree improvements.
This commit is contained in:
@@ -10,7 +10,8 @@
|
|||||||
[advent.screens.dialogue :as dialogue]
|
[advent.screens.dialogue :as dialogue]
|
||||||
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
|
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
|
||||||
(: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]
|
||||||
|
[com.badlogic.gdx Screen]))
|
||||||
|
|
||||||
(defprotocol IAction
|
(defprotocol IAction
|
||||||
(begin [this screen entities])
|
(begin [this screen entities])
|
||||||
@@ -148,17 +149,17 @@
|
|||||||
entities)))))
|
entities)))))
|
||||||
|
|
||||||
(defn present-choices [entities & pairs]
|
(defn present-choices [entities & pairs]
|
||||||
(let [pairs (partition 2 pairs)]
|
(run-action entities
|
||||||
(run-action entities
|
(begin [this screen entities]
|
||||||
(begin [this screen entities]
|
(run! dialogue/choice-screen :on-present-choices :pairs pairs)
|
||||||
(run! dialogue/choice-screen :on-present-choices :pairs pairs)
|
(run! @(resolve 'advent.screens.scene/scene) :on-pause)
|
||||||
entities)
|
entities)
|
||||||
|
|
||||||
(continue [this screen entities] entities)
|
(continue [this screen entities] entities)
|
||||||
|
|
||||||
(done? [this screen entities] true)
|
(done? [this screen entities] true)
|
||||||
|
|
||||||
(terminate [this screen entities] entities))))
|
(terminate [this screen entities] entities)))
|
||||||
|
|
||||||
|
|
||||||
(defn give [entities target-id item]
|
(defn give [entities target-id item]
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
[play-clj.g2d :refer :all]
|
[play-clj.g2d :refer :all]
|
||||||
[clojure.pprint]
|
[clojure.pprint]
|
||||||
[advent.pathfind]
|
[advent.pathfind]
|
||||||
|
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]]
|
||||||
#_[advent.screens.scene :as scene])
|
#_[advent.screens.scene :as scene])
|
||||||
(: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]
|
||||||
[com.badlogic.gdx.scenes.scene2d.utils Align]))
|
[com.badlogic.gdx.scenes.scene2d.utils Align]
|
||||||
|
[com.badlogic.gdx Screen]))
|
||||||
|
|
||||||
(defn ensure-on-screen [talk]
|
(defn ensure-on-screen [talk]
|
||||||
(let [margin-width (* 0.05 (game :width))
|
(let [margin-width (* 0.05 (game :width))
|
||||||
@@ -34,7 +36,7 @@
|
|||||||
(fn [{:keys [create-talk target-id text x y scale]} [entities]]
|
(fn [{:keys [create-talk target-id text x y scale]} [entities]]
|
||||||
(let [font (bitmap-font "ego/font.fnt" )
|
(let [font (bitmap-font "ego/font.fnt" )
|
||||||
tr (bitmap-font! font :get-region)
|
tr (bitmap-font! font :get-region)
|
||||||
scale (or (max scale 0.75) 1)
|
scale (or (min (max scale 0.75) 1) 1)
|
||||||
width (/ (game :width) 1.5)
|
width (/ (game :width) 1.5)
|
||||||
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)
|
||||||
@@ -70,18 +72,17 @@
|
|||||||
(let [font (bitmap-font "ego/font.fnt" )
|
(let [font (bitmap-font "ego/font.fnt" )
|
||||||
tr (bitmap-font! font :get-region)
|
tr (bitmap-font! font :get-region)
|
||||||
scale 1
|
scale 1
|
||||||
width (/ (game :width) 1.5)
|
|
||||||
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)]
|
||||||
(into entities (for [[[text result-script] i] (map vector pairs (range))]
|
(into entities (for [[[text result-script] i] (map vector pairs (range))]
|
||||||
(do (println result-script)
|
[i (assoc (label text (style :label font (color :white))) :x 30 :y (* 30 i) :result-script result-script)]))))
|
||||||
[i (assoc (label text (style :label font (color :white))) :x 0 :y (* 20 i) :result-script result-script)])))))
|
|
||||||
|
|
||||||
:on-touch-down (fn [screen [entities]]
|
:on-touch-down (fn [screen [entities]]
|
||||||
(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)})]
|
||||||
(when (seq entities)
|
(when (seq entities)
|
||||||
(when (< y (* 20 (count entities)))
|
(when (< y (* 30 (count entities)))
|
||||||
(run! @(resolve 'advent.screens.scene/scene) :on-start-script :script (:result-script (entities (int (/ y 20)))))
|
(run! @(resolve 'advent.screens.scene/scene) :on-resume)
|
||||||
|
(run! @(resolve 'advent.screens.scene/scene) :on-start-script :script (:result-script (entities (int (/ y 30)))))
|
||||||
{}))))
|
{}))))
|
||||||
|
|
||||||
:on-resize (fn [screen entities]
|
:on-resize (fn [screen entities]
|
||||||
|
|||||||
@@ -145,6 +145,17 @@
|
|||||||
(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})))
|
||||||
|
|
||||||
|
(defn make-dialogue-tree [entities target-id tree]
|
||||||
|
(let [[e-line t-line options] tree
|
||||||
|
option-scripts (when options (for [option options]
|
||||||
|
[(first option) (actions/get-script entities
|
||||||
|
(make-dialogue-tree entities target-id option))]))]
|
||||||
|
(actions/talk entities :ego e-line)
|
||||||
|
(if (string? t-line)
|
||||||
|
(actions/talk entities target-id t-line)
|
||||||
|
(t-line))
|
||||||
|
(apply actions/present-choices entities option-scripts)))
|
||||||
|
|
||||||
(defn backgrounds [screen]
|
(defn backgrounds [screen]
|
||||||
(let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21)
|
(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)])]
|
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)])]
|
||||||
@@ -168,26 +179,18 @@
|
|||||||
:cursor :down}
|
:cursor :down}
|
||||||
:wizard {:box [228 80 248 126]
|
:wizard {:box [228 80 248 126]
|
||||||
:script (actions/get-script entities
|
:script (actions/get-script entities
|
||||||
(actions/talk entities :ego "Hello there Fangald!")
|
(make-dialogue-tree entities :wizard ["Hello there Mr. Fangald!"
|
||||||
(actions/talk entities :wizard "Oh no, not you again!")
|
"Oh no, not you again!"
|
||||||
(actions/present-choices entities "You're not my friend, Mr. Fangald?"
|
[["You're not my friend, Mr. Fangald?"
|
||||||
(actions/get-script entities
|
"No, you are a rascally little boy who is nothing but a cheat!"
|
||||||
(actions/talk entities :ego "You're not my friend, Mr. Fangald?")
|
[["Oh come on, I'm not that bad."
|
||||||
(actions/talk entities :wizard "No, you are a rascally little boy who is nothing but a cheat!")
|
"Yes you are. Shoo!"]
|
||||||
(actions/present-choices entities
|
["I'm sorry I stole your magic cowboy hat."
|
||||||
"Oh, come on, I'm not that bad."
|
#(do (actions/talk entities :wizard "Go.")
|
||||||
(actions/get-script entities
|
(actions/talk entities :wizard "Away.")
|
||||||
(actions/talk entities :ego "Oh, come on, I'm not that bad.")
|
(actions/transition-background entities :outside-house [262 88]))]]]
|
||||||
(actions/talk entities :wizard "Yes you are. Shoo!"))
|
["What do you mean, 'not you again'?"
|
||||||
"I'm sorry."
|
"I mean get lost kid."]]]))}}
|
||||||
(actions/get-script entities
|
|
||||||
(actions/talk entities :ego "I'm sorry")
|
|
||||||
(actions/talk entities :wizard "That's better. Now scram."))
|
|
||||||
))
|
|
||||||
"Yes, it's me!"
|
|
||||||
(actions/get-script entities
|
|
||||||
(actions/talk entities :ego "Yes, it's me!")
|
|
||||||
(actions/talk entities :wizard "Great, just great. Leave me alone."))))}}
|
|
||||||
:layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0)
|
:layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0)
|
||||||
(assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200)
|
(assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200)
|
||||||
(assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)]
|
(assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)]
|
||||||
@@ -343,9 +346,11 @@
|
|||||||
(update! screen :renderer (stage) :camera (orthographic))
|
(update! screen :renderer (stage) :camera (orthographic))
|
||||||
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
|
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
|
||||||
music (sound "town-music.mp3")
|
music (sound "town-music.mp3")
|
||||||
;; _ (sound! music :loop 0.20)
|
_ (sound! music :loop 0.20)
|
||||||
backgrounds (backgrounds screen)]
|
backgrounds (backgrounds screen)]
|
||||||
{:backgrounds backgrounds
|
{:backgrounds backgrounds
|
||||||
|
:state {:object nil
|
||||||
|
:active? true}
|
||||||
:actions {:object nil
|
:actions {:object nil
|
||||||
:channel (chan)
|
:channel (chan)
|
||||||
:current nil
|
:current nil
|
||||||
@@ -358,7 +363,7 @@
|
|||||||
[:entities :ego] (get-ego screen))
|
[:entities :ego] (get-ego screen))
|
||||||
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
|
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
|
||||||
:mouse-in? (zone/box 278 0 320 42))
|
:mouse-in? (zone/box 278 0 320 42))
|
||||||
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 9000)}))
|
:fps (assoc (label "0" (color :white) ) :x 5 :baseline 0)}))
|
||||||
|
|
||||||
:on-render
|
:on-render
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
@@ -383,17 +388,25 @@
|
|||||||
|
|
||||||
:on-mouse-moved
|
:on-mouse-moved
|
||||||
(fn [screen [entities]]
|
(fn [screen [entities]]
|
||||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
|
(when (get-in entities [:state :active?])
|
||||||
(if-let [mouse-override (find-override screen entities [x y])]
|
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
|
||||||
(assoc-in entities [:cursor :override] (cursor-override mouse-override))
|
(if-let [mouse-override (find-override screen entities [x y])]
|
||||||
(assoc-in entities [:cursor :override] nil))))
|
(assoc-in entities [:cursor :override] (cursor-override mouse-override))
|
||||||
|
(assoc-in entities [:cursor :override] nil)))))
|
||||||
|
|
||||||
:on-touch-down (fn [screen [entities]]
|
:on-touch-down (fn [screen [entities]]
|
||||||
(if (= (button-code :right)
|
(when (get-in entities [:state :active?])
|
||||||
(:button screen))
|
(if (= (button-code :right)
|
||||||
(assoc-in entities [:cursor :current] :main)
|
(:button screen))
|
||||||
(left-click screen entities)))
|
(assoc-in entities [:cursor :current] :main)
|
||||||
|
(left-click screen entities))))
|
||||||
|
|
||||||
:on-start-script (fn [{:keys [script]} [entities] ]
|
:on-pause (fn [screen [entities]]
|
||||||
|
(assoc-in entities [:state :active?] false))
|
||||||
|
|
||||||
|
:on-resume (fn [screen [entities]]
|
||||||
|
(assoc-in entities [:state :active?] true))
|
||||||
|
|
||||||
|
:on-start-script (fn [{:keys [script]} [entities]]
|
||||||
(script entities)
|
(script entities)
|
||||||
entities))
|
entities))
|
||||||
|
|||||||
Reference in New Issue
Block a user