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))
(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])
final-x (int final-x)
final-y (int final-y)
@@ -118,7 +118,7 @@
(terminate [this screen entities]
(stop screen entities target-id))
(can-skip? [this screen entities]
false))
(or can-skip? false)))
@entities)))
(defn get-text-duration [text]
@@ -214,13 +214,13 @@
(can-skip? [this screen entities]
false)))
(defn give [entities target-id item]
(defn give [entities item]
(run-action entities
(begin [this screen entities]
(sound! (sound "pickup.mp3") :play)
(-> entities
(update-in [:background :entities target-id :inventory] #(conj % item))
(update-in [:state :inventory] #(conj % item))
(assoc-in [:cursor :current] item)))
(continue [this screen entities] entities)

View File

@@ -4,7 +4,9 @@
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[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]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.scenes.scene2d.utils Align]
@@ -12,17 +14,24 @@
InputMultiplexer InputProcessor Net Preferences Screen]))
(defscreen inventory-screen
:on-show
(fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic))
{:overlay (assoc (texture "inventory-overlay.png" ) :x 0 :y 0)
:fade (assoc (texture "black.png")
:scale-x 20
:scale-y 20
:opacity 0.7)
:shown? false
:start-showing? false})
(let [highlighted-text (assoc (label "Hello" (style :label (utils/get-font "ego/font.fnt") (color :white))) :x 0 :y 850 :width 1280)]
(label! highlighted-text :set-alignment Align/center)
{:overlay (assoc (texture "inventory-overlay.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0)
:fade (assoc (texture "black.png")
:scale-x 80
:scale-y 80
: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
(fn [screen [entities]]
@@ -33,18 +42,47 @@
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))
:show-screen (fn [screen [entities]]
(assoc entities :start-showing? true))
:show-screen (fn [{items :items} [entities]]
(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]]
(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
(assoc :shown? false)
(assoc :start-showing? false))))
:on-resize (fn [screen entities]
(size! screen 320 240)
(height! screen 960)
entities))

View File

@@ -34,7 +34,7 @@
IInteractable
(get-script [_ [x y]]
(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]]
@@ -43,7 +43,8 @@
(get-in entities [:background :interactions]))))
(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]
@@ -103,7 +104,7 @@
:origin-x 9
:origin-y 0
:scaled true
:inventory #{}
:x 150 :y 95
:id "ego"}]
(actions/start-animation screen
@@ -227,7 +228,7 @@
:wizard "'Should he use guile or guise'..."
)
: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 %
:wizard "Patience, boy."
:wizard "... 'Such a man will have great surprise.'"
@@ -311,9 +312,9 @@
:sheep {:box [38 160 71 181]
:script (actions/get-script
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.")
(do (actions/give entities :ego :wool)
(do (actions/give entities :wool)
(actions/talk entities :ego "I guess his wool is shedding."))))}
:right-dir {:box [300 131 320 224]
:script (actions/get-script
@@ -363,11 +364,11 @@
:mushrooms {:box [247 59 269 76]
:script (actions/get-script
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.")
(do
(actions/walk-to entities :ego [242 75])
(actions/give entities :ego :mushrooms)
(actions/give entities :mushrooms)
(actions/talk entities :ego "Perfectly ripe mushrooms!"))))}
:window {:box [103 44 130 140]
:script (actions/get-script
@@ -437,11 +438,12 @@
(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}
:active? true
:inventory (sorted-set)}
:actions {:object nil
:channel (chan)
:current nil
@@ -498,6 +500,9 @@
:on-reactivate (fn [screen [entities]]
(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]]
(script entities)
entities))

View File

@@ -24,3 +24,11 @@
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
0 0 target-width target-height)
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))