first step at dialogue trees.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 43 KiB |
BIN
desktop/resources/wizard/stand.png
Normal file
BIN
desktop/resources/wizard/stand.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
desktop/resources/wizard/talk.png
Normal file
BIN
desktop/resources/wizard/talk.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
BIN
desktop/resources/wizard/talk.pxa/0.pxi
Normal file
BIN
desktop/resources/wizard/talk.pxa/0.pxi
Normal file
Binary file not shown.
BIN
desktop/resources/wizard/talk.pxa/1.pxi
Normal file
BIN
desktop/resources/wizard/talk.pxa/1.pxi
Normal file
Binary file not shown.
BIN
desktop/resources/wizard/talk.pxa/2.pxi
Normal file
BIN
desktop/resources/wizard/talk.pxa/2.pxi
Normal file
Binary file not shown.
BIN
desktop/resources/wizard/talk.pxa/3.pxi
Normal file
BIN
desktop/resources/wizard/talk.pxa/3.pxi
Normal file
Binary file not shown.
22
desktop/resources/wizard/talk.pxa/CelData.plist
Normal file
22
desktop/resources/wizard/talk.pxa/CelData.plist
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array>
|
||||
<dict>
|
||||
<key>duration</key>
|
||||
<real>0.20000000298023224</real>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>duration</key>
|
||||
<real>0.20000000298023224</real>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>duration</key>
|
||||
<real>0.20000000298023224</real>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>duration</key>
|
||||
<real>0.20000000298023224</real>
|
||||
</dict>
|
||||
</array>
|
||||
</plist>
|
||||
@@ -1,93 +0,0 @@
|
||||
(ns advent.action-test)
|
||||
|
||||
(defprotocol IAction
|
||||
(begin [this state])
|
||||
(done? [this state])
|
||||
(continue [this state]))
|
||||
|
||||
|
||||
(defmacro do-actions [name & forms]
|
||||
`(vector ~@(for [form forms]
|
||||
`(fn [~name]
|
||||
~form))))
|
||||
|
||||
(defn walk-to [who & targets ]
|
||||
(for [[target-x target-y] targets]
|
||||
(fn [state]
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state] (println "Starting Walking") state)
|
||||
(continue [this {:keys [x y] :as state}]
|
||||
(println "Continue Walking from" x y)
|
||||
(Thread/sleep 500)
|
||||
(assoc state :x (inc x) :y (inc y)))
|
||||
(done? [this {:keys [x y]} ]
|
||||
(and (= x target-x)
|
||||
(= y target-y)))))))
|
||||
|
||||
(defn talk [who text]
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state]
|
||||
(println "Speaking:" text)
|
||||
(assoc state :time 0))
|
||||
(continue [this state]
|
||||
(Thread/sleep 200)
|
||||
(assoc state :time (inc (:time state))))
|
||||
(done? [this {:keys [time]}]
|
||||
(< 3 time))))
|
||||
|
||||
(defn give-item [item]
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state]
|
||||
(println "Receiving item:" item)
|
||||
(update-in state [:items] #(conj % item)))
|
||||
(continue [this state]
|
||||
state)
|
||||
(done? [this state]
|
||||
true)))
|
||||
|
||||
|
||||
(defn walk-to [who & targets ]
|
||||
(for [[target-x target-y] targets]
|
||||
(fn [state]
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state] (println "Starting Walking to" target-x target-y) state)
|
||||
(continue [this {:keys [x y] :as state}]
|
||||
(println "Continue Walking from" x y)
|
||||
(Thread/sleep 500)
|
||||
(assoc state :x (inc x) :y (inc y)))
|
||||
(done? [this {:keys [x y]} ]
|
||||
(and (>= x target-x)
|
||||
(>= y target-y)))))))
|
||||
|
||||
(defn get-script []
|
||||
(let [random-loc (+ 3 (rand-int 10))]
|
||||
(do-actions state
|
||||
(if (= 1 (rand-int 2))
|
||||
(give-item :gold)
|
||||
(give-item :candy))
|
||||
(walk-to :ego [3 3] [random-loc random-loc] )
|
||||
(if ((:items state) :gold)
|
||||
(talk :ego "I have enough money to buy something")
|
||||
(talk :ego "I'm broke.")))))
|
||||
|
||||
(defn test-run []
|
||||
(let [state {:x 0 :y 0 :time 0 :items #{}}
|
||||
actions (get-script)]
|
||||
(loop [actions actions
|
||||
state state
|
||||
started? false]
|
||||
(when (seq actions)
|
||||
(let [step ((first actions) state)]
|
||||
(if (sequential? step)
|
||||
(recur (concat step (rest actions)) state false)
|
||||
(let [state (if started?
|
||||
state
|
||||
(begin step state))
|
||||
state (continue step state)]
|
||||
(if (done? step state)
|
||||
(recur (rest actions) state false)
|
||||
(recur actions state true)))))))))
|
||||
@@ -1,99 +0,0 @@
|
||||
(ns advent.action-test2
|
||||
(:require [clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!!]]))
|
||||
|
||||
(defprotocol IAction
|
||||
(begin [this state])
|
||||
(done? [this state])
|
||||
(continue [this state])
|
||||
(terminate [this state]))
|
||||
|
||||
|
||||
|
||||
(defn talk [action-channel who text]
|
||||
(let [c (chan)]
|
||||
(put! action-channel
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state]
|
||||
(println "Speaking:" text)
|
||||
(assoc state :time 0))
|
||||
(continue [this state]
|
||||
(Thread/sleep 200)
|
||||
(assoc state :time (inc (:time state))))
|
||||
(done? [this {:keys [time]}]
|
||||
(< 3 time))
|
||||
(terminate [this state]
|
||||
(put! c state)
|
||||
state)))
|
||||
(<!! c)))
|
||||
|
||||
(defn give-item [action-channel item]
|
||||
(let [c (chan)]
|
||||
(put! action-channel
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state]
|
||||
(println "Receiving item:" item)
|
||||
(update-in state [:items] #(conj % item)))
|
||||
(continue [this state]
|
||||
state)
|
||||
(done? [this state]
|
||||
true)
|
||||
(terminate [this state]
|
||||
(put! c state)
|
||||
state)))
|
||||
(<!! c)))
|
||||
|
||||
|
||||
(defn walk-to [action-channel who & targets ]
|
||||
(let [c (chan)]
|
||||
(doseq [[target-x target-y] targets]
|
||||
(put! action-channel
|
||||
(reify
|
||||
IAction
|
||||
(begin [this state] (println "Starting Walking to" target-x target-y) state)
|
||||
(continue [this {:keys [x y] :as state}]
|
||||
(println "Continue Walking from" x y)
|
||||
(Thread/sleep 500)
|
||||
(assoc state :x (inc x) :y (inc y)))
|
||||
(done? [this {:keys [x y]} ]
|
||||
(and (>= x target-x)
|
||||
(>= y target-y)))
|
||||
(terminate [this state]
|
||||
(put! c state)
|
||||
state))))
|
||||
(<!! c)))
|
||||
|
||||
(defmacro get-script [& forms]
|
||||
`(fn [action-channel#] (thread ~@forms (put! action-channel# :end))))
|
||||
|
||||
(defn run-script [state action-channel]
|
||||
(let [random-loc (+ 3 (rand-int 10))]
|
||||
(get-script
|
||||
(if (= 1 (rand-int 2))
|
||||
(give-item action-channel :gold)
|
||||
(give-item action-channel :candy))
|
||||
(let [state (walk-to action-channel :ego [3 3] [random-loc random-loc] )]
|
||||
(if ((:items state) :gold)
|
||||
(talk action-channel :ego "I have enough money to buy something")
|
||||
(talk action-channel :ego "I'm broke."))))))
|
||||
|
||||
(defn test-run []
|
||||
(let [state {:x 0 :y 0 :time 0 :items #{} :current-action nil}
|
||||
action-channel (chan)
|
||||
script (run-script state action-channel)]
|
||||
(script action-channel)
|
||||
(loop [state state
|
||||
current-action nil
|
||||
started? false]
|
||||
(if (= :end current-action)
|
||||
nil
|
||||
(if current-action
|
||||
(let [state (if started? state (begin current-action state))
|
||||
state (continue current-action state)]
|
||||
(if (done? current-action state)
|
||||
(recur (terminate current-action state) nil false)
|
||||
(recur state current-action true)))
|
||||
(let [[current-action _] (alts!! [action-channel] :default nil)]
|
||||
(do (Thread/sleep 50)
|
||||
(recur state current-action false))))))))
|
||||
@@ -147,6 +147,20 @@
|
||||
(stop screen entities target-id)
|
||||
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)
|
||||
|
||||
(continue [this screen entities] entities)
|
||||
|
||||
(done? [this screen entities] true)
|
||||
|
||||
(terminate [this screen entities] entities))))
|
||||
|
||||
|
||||
(defn give [entities target-id item]
|
||||
(run-action entities
|
||||
(begin [this screen entities]
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
(defgame advent
|
||||
:on-create
|
||||
(fn [this]
|
||||
(set-screen! this scene/scene dialogue/talking-screen inventory/inventory-screen)))
|
||||
(set-screen! this scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen)))
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
[play-clj.utils :refer :all]
|
||||
[play-clj.g2d :refer :all]
|
||||
[clojure.pprint]
|
||||
[advent.pathfind])
|
||||
[advent.pathfind]
|
||||
#_[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]))
|
||||
@@ -52,3 +53,36 @@
|
||||
|
||||
:on-resize (fn [screen entities]
|
||||
(size! screen 1280 960)))
|
||||
|
||||
(defscreen choice-screen
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
(update! screen :renderer (stage) :camera (orthographic))
|
||||
{})
|
||||
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
(render! screen (vals entities))
|
||||
entities)
|
||||
|
||||
:on-present-choices
|
||||
(fn [{:keys [pairs]} [entities]]
|
||||
(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)])))))
|
||||
|
||||
: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)))))
|
||||
{}))))
|
||||
|
||||
:on-resize (fn [screen entities]
|
||||
(size! screen 1280 960)))
|
||||
|
||||
@@ -155,18 +155,49 @@
|
||||
(aget peddler-sheet 0 i)))
|
||||
peddler-stand (animation 0.2 (for [i (flatten [(repeat 5 0) 6])]
|
||||
(aget peddler-sheet 0 i)))
|
||||
wizard (texture "wizard.png")
|
||||
_ (texture! wizard :flip true false)]
|
||||
wizard-sheet (texture! (texture "wizard/talk.png") :split 20 46)
|
||||
wizard-stand (animation 0.2 (for [i (flatten [(repeat 10 0) 1])]
|
||||
(aget wizard-sheet 0 i)))
|
||||
wizard-talk (animation 0.2 (for [i [0 2 0 2 1 2 0 3 0 2 0 1 0 2]]
|
||||
(aget wizard-sheet 0 i)))]
|
||||
{:inside-house
|
||||
(make-background :interactions {:down-dir {:box [151 0 320 20]
|
||||
:script (actions/get-script entities
|
||||
(actions/walk-to entities :ego [237 1])
|
||||
(actions/transition-background entities :outside-house [262 88]))
|
||||
:cursor :down}}
|
||||
: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."))))}}
|
||||
: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)]
|
||||
:entities {:wizard (assoc wizard :x 228 :y 80 :baseline 160 :scale-x 1.75 :scale-y 1.75)}
|
||||
:entities {:wizard (actions/start-animation screen (assoc (animation->texture screen wizard-stand) :x 228 :y 80 :baseline 160 :scale-x 1.75 :scale-y 1.75
|
||||
:left {:talk (flip wizard-talk)
|
||||
:stand (flip wizard-stand)}
|
||||
:right {:talk wizard-talk
|
||||
:stand wizard-stand}
|
||||
:facing :left)
|
||||
:stand)}
|
||||
:collision "inside-house/collision.png"
|
||||
:scale-fn (scaler-fn-with-baseline 110 0.10 1.75))
|
||||
:outside-house
|
||||
@@ -312,7 +343,7 @@
|
||||
(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
|
||||
:actions {:object nil
|
||||
@@ -361,4 +392,8 @@
|
||||
(if (= (button-code :right)
|
||||
(:button screen))
|
||||
(assoc-in entities [:cursor :current] :main)
|
||||
(left-click screen entities))))
|
||||
(left-click screen entities)))
|
||||
|
||||
:on-start-script (fn [{:keys [script]} [entities] ]
|
||||
(script entities)
|
||||
entities))
|
||||
|
||||
Reference in New Issue
Block a user