improving start page.

This commit is contained in:
2015-02-08 11:38:32 -08:00
parent 78479885b3
commit 0658616453
3 changed files with 58 additions and 21 deletions

View File

@@ -6,6 +6,7 @@
[clojure.pprint] [clojure.pprint]
[clojure.set :as set] [clojure.set :as set]
[advent.pathfind] [advent.pathfind]
[advent.utils :as utils]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]] [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]
@@ -65,13 +66,10 @@
(def choice-height 30) (def choice-height 30)
(defn intersects? [e [x y]]
(and (:object e)
(< (:x e) x (+ (:x e) (.getWidth (:object e))))
(< (:y e) y (+ (:y e) (:height e)))))
(defn get-color [e mouse-pos] (defn get-color [e mouse-pos]
(if (intersects? e mouse-pos) (if (utils/intersects? e mouse-pos)
(color :yellow) (color :yellow)
(color 0.6 1.0 1.0 1.0) (color 0.6 1.0 1.0 1.0)
)) ))
@@ -121,7 +119,7 @@
:on-touch-up (fn [screen [entities]] :on-touch-up (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 (get-in entities [:state :choices])) (when (seq (get-in entities [:state :choices]))
(when-let [choice (first (filter #(intersects? % [x y]) (vals entities)))] (when-let [choice (first (filter #(utils/intersects? % [x y]) (vals entities)))]
((get-in entities [:state :callback]) (:index choice)) ((get-in entities [:state :callback]) (:index choice))
(-> entities (-> entities
(assoc-in [:state :callback] nil) (assoc-in [:state :callback] nil)

View File

@@ -17,12 +17,27 @@
InputMultiplexer InputProcessor Net Preferences Screen])) InputMultiplexer InputProcessor Net Preferences Screen]))
(defn get-color [e mouse-pos]
(if (utils/intersects? e mouse-pos)
(color :yellow)
(color 0.6 1.0 1.0 1.0)))
(defn style-label [e font mouse-pos]
(label! e :set-style (style :label font (get-color e mouse-pos)))
e)
(defn center [e]
(assoc e :x (- (/ 1280 2) (/ (.getWidth (:object e)) 2))))
(defscreen title-screen (defscreen title-screen
:on-show :on-show
(fn [screen entities] (fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic)) (update! screen :renderer (stage) :camera (orthographic))
(let [start-playing (assoc (label "Start Game" (style :label (utils/get-font "ego/font.fnt") (color :red))) :x 0 :y 850 :width 1280) (let [font (utils/get-font "ego/font.fnt")
start-playing (assoc (label "Embark on thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 100)
start-playing (center start-playing)
quit (assoc (label "Quit thy adventure" (style :label font (color 0.6 1.0 1.0 1.0))) :x 0 :y 50)
quit (center quit)
music (utils/make-music "intro.ogg")] music (utils/make-music "intro.ogg")]
(label! start-playing :set-alignment Align/center) (label! start-playing :set-alignment Align/center)
@@ -31,10 +46,12 @@
:scale-x 80 :scale-x 80
:scale-y 80 :scale-y 80
:opacity 1.0) :opacity 1.0)
:font font
:music music :music music
:volume 1.0 :volume 1.0
:start-showing? false :start-showing? false
:start-playing start-playing :start-playing start-playing
:quit quit
:tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0 :tweens {:fade-in (utils/tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0
:finish #(do (utils/play-sound (:music %)) %) :finish #(do (utils/play-sound (:music %)) %)
:power 10.0)} :power 10.0)}
@@ -44,16 +61,22 @@
(fn [screen [entities]] (fn [screen [entities]]
(let [entities (utils/apply-tweens screen entities (:tweens entities))] (let [entities (utils/apply-tweens screen entities (:tweens entities))]
(music! (:music entities) :set-volume (:volume entities)) (music! (:music entities) :set-volume (:volume entities))
(render! screen [(:overlay entities) (:start-playing entities) (:fade entities)]) (render! screen [(:overlay entities) (:start-playing entities) (:quit entities) (:fade entities)])
entities)) entities))
:show-screen (fn [entities] :show-screen (fn [entities]
entities) entities)
:on-mouse-moved (fn [screen [entities]] :on-mouse-moved (fn [screen [entities]]
nil) (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(style-label (:start-playing entities) (get-in entities [:font]) [x y])
(style-label (:quit entities) (get-in entities [:font]) [x y])
entities))
:on-touch-up (fn [screen [entities]] :on-touch-up (fn [screen [entities]]
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
(cond
(utils/intersects? (:start-playing entities) [x y])
(-> entities (-> entities
(assoc-in [:tweens :fade-out] (assoc-in [:tweens :fade-out]
(utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0 (utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0
@@ -63,7 +86,18 @@
entities) entities)
:power 3.0)) :power 3.0))
(assoc-in [:tweens :fade-out-music] (assoc-in [:tweens :fade-out-music]
(utils/tween :fade-out-music screen [:volume] 1.0 0.0 1.8)))) (utils/tween :fade-out-music screen [:volume] 1.0 0.0 1.8)))
(utils/intersects? (:quit entities) [x y])
(-> entities
(assoc-in [:tweens :fade-out]
(utils/tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0
:finish (fn [entities]
(System/exit 0)
entities)
:power 3.0)))
:else
nil)))
:on-resize (fn [screen entities] :on-resize (fn [screen entities]
(size! screen 1280 960))) (size! screen 1280 960)))

View File

@@ -145,3 +145,8 @@
(f e (:total-time screen))) (f e (:total-time screen)))
entities entities
(vals tweens))) (vals tweens)))
(defn intersects? [e [x y]]
(and (:object e)
(< (:x e) x (+ (:x e) (or (:width e) (.getWidth (:object e)))))
(< (:y e) y (+ (:y e) (or (:height e) (.getHeight (:object e)))))))