dialogue tree improvements.

This commit is contained in:
2014-09-24 18:39:07 -07:00
parent f90ae6b7c3
commit 240af5dcf0
3 changed files with 62 additions and 47 deletions

View File

@@ -10,7 +10,8 @@
[advent.screens.dialogue :as dialogue]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]])
(: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
(begin [this screen entities])
@@ -148,17 +149,17 @@
entities)))))
(defn present-choices [entities & pairs]
(let [pairs (partition 2 pairs)]
(run-action entities
(begin [this screen entities]
(run! dialogue/choice-screen :on-present-choices :pairs pairs)
entities)
(run-action entities
(begin [this screen entities]
(run! dialogue/choice-screen :on-present-choices :pairs pairs)
(run! @(resolve 'advent.screens.scene/scene) :on-pause)
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]

View File

@@ -5,10 +5,12 @@
[play-clj.g2d :refer :all]
[clojure.pprint]
[advent.pathfind]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]]
#_[advent.screens.scene :as scene])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[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]
(let [margin-width (* 0.05 (game :width))
@@ -34,7 +36,7 @@
(fn [{:keys [create-talk target-id text x y scale]} [entities]]
(let [font (bitmap-font "ego/font.fnt" )
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)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
@@ -70,18 +72,17 @@
(let [font (bitmap-font "ego/font.fnt" )
tr (bitmap-font! font :get-region)
scale 1
width (/ (game :width) 1.5)
tx (.getTexture tr)
_ (texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)]
(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 0 :y (* 20 i) :result-script result-script)])))))
[i (assoc (label text (style :label font (color :white))) :x 30 :y (* 30 i) :result-script result-script)]))))
:on-touch-down (fn [screen [entities]]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(when (seq entities)
(when (< y (* 20 (count entities)))
(run! @(resolve 'advent.screens.scene/scene) :on-start-script :script (:result-script (entities (int (/ y 20)))))
(when (< y (* 30 (count entities)))
(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]

View File

@@ -145,6 +145,17 @@
(merge params {:collision (advent.pathfind/map-from-resource collision)
: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]
(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)])]
@@ -168,26 +179,18 @@
:cursor :down}
:wizard {:box [228 80 248 126]
:script (actions/get-script entities
(actions/talk entities :ego "Hello there Fangald!")
(actions/talk entities :wizard "Oh no, not you again!")
(actions/present-choices entities "You're not my friend, Mr. Fangald?"
(actions/get-script entities
(actions/talk entities :ego "You're not my friend, Mr. Fangald?")
(actions/talk entities :wizard "No, you are a rascally little boy who is nothing but a cheat!")
(actions/present-choices entities
"Oh, come on, I'm not that bad."
(actions/get-script entities
(actions/talk entities :ego "Oh, come on, I'm not that bad.")
(actions/talk entities :wizard "Yes you are. Shoo!"))
"I'm sorry."
(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."))))}}
(make-dialogue-tree entities :wizard ["Hello there Mr. Fangald!"
"Oh no, not you again!"
[["You're not my friend, Mr. Fangald?"
"No, you are a rascally little boy who is nothing but a cheat!"
[["Oh come on, I'm not that bad."
"Yes you are. Shoo!"]
["I'm sorry I stole your magic cowboy hat."
#(do (actions/talk entities :wizard "Go.")
(actions/talk entities :wizard "Away.")
(actions/transition-background entities :outside-house [262 88]))]]]
["What do you mean, 'not you again'?"
"I mean get lost kid."]]]))}}
: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/sillhoute.png") :x 0 :y 0 :baseline 240)]
@@ -343,9 +346,11 @@
(update! screen :renderer (stage) :camera (orthographic))
(let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0)
music (sound "town-music.mp3")
;; _ (sound! music :loop 0.20)
_ (sound! music :loop 0.20)
backgrounds (backgrounds screen)]
{:backgrounds backgrounds
:state {:object nil
:active? true}
:actions {:object nil
:channel (chan)
:current nil
@@ -358,7 +363,7 @@
[:entities :ego] (get-ego screen))
:inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000
: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
(fn [screen [entities]]
@@ -383,17 +388,25 @@
:on-mouse-moved
(fn [screen [entities]]
(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])]
(assoc-in entities [:cursor :override] (cursor-override mouse-override))
(assoc-in entities [:cursor :override] nil))))
(when (get-in entities [:state :active?])
(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])]
(assoc-in entities [:cursor :override] (cursor-override mouse-override))
(assoc-in entities [:cursor :override] nil)))))
:on-touch-down (fn [screen [entities]]
(if (= (button-code :right)
(:button screen))
(assoc-in entities [:cursor :current] :main)
(left-click screen entities)))
(when (get-in entities [:state :active?])
(if (= (button-code :right)
(:button screen))
(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)
entities))