lots of improvements.

This commit is contained in:
2014-10-01 13:26:56 -07:00
parent 4bd400dff3
commit d235017423
4 changed files with 77 additions and 26 deletions

View File

@@ -67,7 +67,7 @@
~@forms)) ~@forms))
(reset! ~entities (<!! c#))))) (reset! ~entities (<!! c#)))))
(defn walk-to [entities target-id [final-x final-y]] (defn walk-to [entities target-id [final-x final-y] & [can-skip?]]
(let [{start-x :x start-y :y} (get-in @entities [:background :entities target-id]) (let [{start-x :x start-y :y} (get-in @entities [:background :entities target-id])
final-x (int final-x) final-x (int final-x)
final-y (int final-y) final-y (int final-y)
@@ -118,7 +118,7 @@
(terminate [this screen entities] (terminate [this screen entities]
(stop screen entities target-id)) (stop screen entities target-id))
(can-skip? [this screen entities] (can-skip? [this screen entities]
false)) (or can-skip? false)))
@entities))) @entities)))
(defn get-text-duration [text] (defn get-text-duration [text]
@@ -214,13 +214,13 @@
(can-skip? [this screen entities] (can-skip? [this screen entities]
false))) false)))
(defn give [entities target-id item] (defn give [entities item]
(run-action entities (run-action entities
(begin [this screen entities] (begin [this screen entities]
(sound! (sound "pickup.mp3") :play) (sound! (sound "pickup.mp3") :play)
(-> entities (-> entities
(update-in [:background :entities target-id :inventory] #(conj % item)) (update-in [:state :inventory] #(conj % item))
(assoc-in [:cursor :current] item))) (assoc-in [:cursor :current] item)))
(continue [this screen entities] entities) (continue [this screen entities] entities)

View File

@@ -4,7 +4,9 @@
[play-clj.utils :refer :all] [play-clj.utils :refer :all]
[play-clj.g2d :refer :all] [play-clj.g2d :refer :all]
[clojure.pprint] [clojure.pprint]
[advent.pathfind]) [advent.pathfind]
[advent.zone :as zone]
[advent.utils :as utils])
(: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]
@@ -12,17 +14,24 @@
InputMultiplexer InputProcessor Net Preferences Screen])) InputMultiplexer InputProcessor Net Preferences Screen]))
(defscreen inventory-screen (defscreen inventory-screen
:on-show :on-show
(fn [screen entities] (fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic)) (update! screen :renderer (stage) :camera (orthographic))
{:overlay (assoc (texture "inventory-overlay.png" ) :x 0 :y 0) (let [highlighted-text (assoc (label "Hello" (style :label (utils/get-font "ego/font.fnt") (color :white))) :x 0 :y 850 :width 1280)]
:fade (assoc (texture "black.png") (label! highlighted-text :set-alignment Align/center)
:scale-x 20 {:overlay (assoc (texture "inventory-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
:scale-y 20 :fade (assoc (texture "black.png")
:opacity 0.7) :scale-x 80
:shown? false :scale-y 80
:start-showing? false}) :opacity 0.7)
:all-items (texture! (texture "cursor.png") :split 16 16)
:items []
:shown? false
:start-showing? false
:highlighted-item nil
:highlighted-text highlighted-text}))
:on-render :on-render
(fn [screen [entities]] (fn [screen [entities]]
@@ -33,18 +42,47 @@
entities)] entities)]
(when (:shown? entities) (when (:shown? entities)
(render! screen [(:fade entities) (:overlay entities)])) (render! screen [(:fade entities) (:overlay entities)])
(render! screen (:items entities))
(if-let [item (:highlighted-item entities)]
(label! (:highlighted-text entities) :set-text (name item))
(label! (:highlighted-text entities) :set-text ""))
(render! screen [(:highlighted-text entities)]))
entities)) entities))
:show-screen (fn [screen [entities]] :show-screen (fn [{items :items} [entities]]
(assoc entities :start-showing? true)) (assoc entities :start-showing? true
:items (for [[item index] (map vector items (range))
:let [x (+ (* 79 4) (* index (* 24 4)))
y (* 4 180)
item-width 16
offset-x (+ x (/ item-width 2))
offset-y (+ y (/ item-width 2))
padding (/ item-width 2)
padding (* 4 padding)]]
(assoc (texture (aget (:all-items entities) 0 (.indexOf utils/+all-cursors+ item)))
:x x :y y
:scale-x 4
:scale-y 4
:item item
:box (zone/box (- offset-x padding) (- offset-y padding) (+ offset-x item-width padding) (+ offset-y item-width padding))))))
:on-mouse-moved (fn [screen [entities]]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})
selected-entity (first (filter #((:box %) x y) (:items entities)))]
(if selected-entity
(assoc entities :highlighted-item (:item selected-entity))
(assoc entities :highlighted-item nil))))
:on-touch-down (fn [screen [entities]] :on-touch-down (fn [screen [entities]]
(when (:shown? entities) (when (:shown? entities)
(run! @(resolve 'advent.screens.scene/scene) :on-reactivate)
(when-let [{:keys [highlighted-item]} entities]
(run! @(resolve 'advent.screens.scene/scene) :on-chose-item :item highlighted-item))
(-> entities (-> entities
(assoc :shown? false) (assoc :shown? false)
(assoc :start-showing? false)))) (assoc :start-showing? false))))
:on-resize (fn [screen entities] :on-resize (fn [screen entities]
(size! screen 320 240) (height! screen 960)
entities)) entities))

View File

@@ -34,7 +34,7 @@
IInteractable IInteractable
(get-script [_ [x y]] (get-script [_ [x y]]
(actions/get-script entities (actions/get-script entities
(actions/walk-to entities :ego [x y]))))) (actions/walk-to entities :ego [x y] true)))))
(defn find-override [screen entities [x y]] (defn find-override [screen entities [x y]]
@@ -43,7 +43,8 @@
(get-in entities [:background :interactions])))) (get-in entities [:background :interactions]))))
(defn open-inventory [screen entities] (defn open-inventory [screen entities]
(run! inventory-screen :show-screen)) (run! inventory-screen :show-screen :items (get-in entities [:state :inventory]))
(assoc-in entities [:state :active?] false))
(defn left-click [screen entities] (defn left-click [screen entities]
@@ -103,7 +104,7 @@
:origin-x 9 :origin-x 9
:origin-y 0 :origin-y 0
:scaled true :scaled true
:inventory #{}
:x 150 :y 95 :x 150 :y 95
:id "ego"}] :id "ego"}]
(actions/start-animation screen (actions/start-animation screen
@@ -227,7 +228,7 @@
:wizard "'Should he use guile or guise'..." :wizard "'Should he use guile or guise'..."
) )
:choices ["Is this almost over?" :choices ["Is this almost over?"
{:run #(do (actions/update-state (fn [state] (assoc state :convinced-wizard? true))) {:run #(do (actions/update-state entities (fn [state] (assoc state :convinced-wizard? true)))
(respond entities % (respond entities %
:wizard "Patience, boy." :wizard "Patience, boy."
:wizard "... 'Such a man will have great surprise.'" :wizard "... 'Such a man will have great surprise.'"
@@ -311,9 +312,9 @@
:sheep {:box [38 160 71 181] :sheep {:box [38 160 71 181]
:script (actions/get-script :script (actions/get-script
entities entities
(if ((get-in @entities [:background :entities :ego :inventory]) :wool) (if ((get-in @entities [:state :inventory]) :wool)
(actions/talk entities :ego "The sheep has given me enough wool.") (actions/talk entities :ego "The sheep has given me enough wool.")
(do (actions/give entities :ego :wool) (do (actions/give entities :wool)
(actions/talk entities :ego "I guess his wool is shedding."))))} (actions/talk entities :ego "I guess his wool is shedding."))))}
:right-dir {:box [300 131 320 224] :right-dir {:box [300 131 320 224]
:script (actions/get-script :script (actions/get-script
@@ -363,11 +364,11 @@
:mushrooms {:box [247 59 269 76] :mushrooms {:box [247 59 269 76]
:script (actions/get-script :script (actions/get-script
entities entities
(if ((get-in @entities [:background :entities :ego :inventory]) :mushrooms) (if ((get-in @entities [:state :inventory]) :mushrooms)
(actions/talk entities :ego "I've already got a junk ton of mushrooms.") (actions/talk entities :ego "I've already got a junk ton of mushrooms.")
(do (do
(actions/walk-to entities :ego [242 75]) (actions/walk-to entities :ego [242 75])
(actions/give entities :ego :mushrooms) (actions/give entities :mushrooms)
(actions/talk entities :ego "Perfectly ripe mushrooms!"))))} (actions/talk entities :ego "Perfectly ripe mushrooms!"))))}
:window {:box [103 44 130 140] :window {:box [103 44 130 140]
:script (actions/get-script :script (actions/get-script
@@ -437,11 +438,12 @@
(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 :state {:object nil
:active? true} :active? true
:inventory (sorted-set)}
:actions {:object nil :actions {:object nil
:channel (chan) :channel (chan)
:current nil :current nil
@@ -498,6 +500,9 @@
:on-reactivate (fn [screen [entities]] :on-reactivate (fn [screen [entities]]
(assoc-in entities [:state :active?] true)) (assoc-in entities [:state :active?] true))
:on-chose-item (fn [{:keys [item]} [entities]]
(assoc-in entities [:cursor :current] item))
:on-start-script (fn [{:keys [script]} [entities]] :on-start-script (fn [{:keys [script]} [entities]]
(script entities) (script entities)
entities)) entities))

View File

@@ -24,3 +24,11 @@
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16 (pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
0 0 target-width target-height) 0 0 target-width target-height)
resized )) resized ))
(defn get-font [filename]
(let [font (bitmap-font filename)
tr (bitmap-font! font :get-region)
tx (.getTexture tr)]
(texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
font))