From ed7d6c457e624a77605c7c3dfc65916ee46e3921 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 25 Jul 2015 12:08:41 -0700 Subject: [PATCH] flying ego. --- desktop/src-common/advent/screens/title.clj | 34 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/desktop/src-common/advent/screens/title.clj b/desktop/src-common/advent/screens/title.clj index da8fa6b6..11f0362e 100644 --- a/desktop/src-common/advent/screens/title.clj +++ b/desktop/src-common/advent/screens/title.clj @@ -1,5 +1,6 @@ (ns advent.screens.title (:require [play-clj.core :refer :all] + [play-clj.math :refer :all] [play-clj.ui :refer :all] [play-clj.utils :refer :all] [play-clj.g2d :refer :all] @@ -39,6 +40,29 @@ (defn center [e] (assoc e :x (- (/ 1280 2) (/ (or (:width e) (.getWidth (:object e))) 2)))) + +(defn get-dir [old-x new-x] + (if (< old-x new-x) + :right + :left)) + +(defn fly-ego [screen entities] + (let [speed 0.07 + pos-f (- (* (:total-time screen) speed) (int (* (:total-time screen) speed))) + v (vector-2 0 0) + a (catmull-rom-spline! (:path (:flying-ego entities)) :value-at v pos-f) + direction (get-dir (get-in entities [:flying-ego :x]) (vector-2! v :x))] + (merge (update-in entities [:flying-ego] + merge {:x (vector-2! v :x) + :y (vector-2! v :y)} + (get-in entities [:flying-ego direction]) + )))) + +(defn flip [t] + (let [flipped (texture t)] + (texture! flipped :flip true false) + flipped)) + (defscreen title-screen :on-show (fn [screen entities] @@ -64,8 +88,13 @@ :origin-x 0 :origin-y 0) :flying-ego (assoc (texture "ego/flying.png") + :left (flip (texture "ego/flying.png")) + :right (texture "ego/flying.png") :scale-x 5 :scale-y 5 + :origin-x 2 + :origin-y 0 + :path (catmull-rom-spline (map #(apply vector-2* %) [[-800 450] [1280 450] [2000 100] [0 100] [-800 300] [1280 300] [2000 450]]) true) :x 450 :y 650) :clouds (assoc (particle-effect "titleclouds" :reset :start) :x 640 :y 480 ) @@ -108,9 +137,10 @@ (fn [screen [entities]] (clear!) - (let [entities (utils/apply-tweens screen entities (:tweens entities))] + (let [entities (utils/apply-tweens screen entities (:tweens entities)) + entities (fly-ego screen entities)] (music! (:music entities) :set-volume (utils/current-music-volume (:volume entities))) - () + (render! screen [(:overlay entities) (:clouds entities) (:flying-ego entities) (:toolbox entities) (:start-playing entities) (:quit entities) (:music-label entities) (:music-volume-slider entities) (:sound-label entities) (:sound-volume-slider entities) (:fade entities) ]) entities))