diff --git a/README.md b/README.md
index 0649200..e413694 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Kiwi.js is the world's easiest to use Open Source HTML5 game framework for makin
 
 Our focus is blazingly fast WebGL rendering and complementary tools to make professional quality serious games. We use [CocoonJS](https://www.ludei.com/) for publishing games and App creation.
 
-Version: 1.2.2 "Williams"
+Version: 1.2.3 "Williams"
 
 - Visit the [Official Website](http://www.kiwijs.org/documentation/getting-started/)
 - Follow us on [Twitter](http://www.twitter.com/kiwijsengine)
@@ -37,6 +37,19 @@ Our [Official Documentation Codex](http://www.kiwijs.org/documentation/getting-s
 
 Number tags refer to [GitHub issues](https://github.com/gamelab/kiwi.js/issues).
 
+### v1.2.3 "Williams"
+
+### Bug Fixes
+
+* `Clock.elapsed()` now resets to 0 after `start()` is called. (#177)
+* `Geom.Intersect.lineToLineSegment` and `lineSegmentToLineSegment` now work correctly. (#172)
+
+### Deprecations
+
+* `Entity.inputEnabled` wasn't used by anything, and is now officially deprecated.
+
+More details can be found on the [Kiwi.JS repo](https://github.com/gamelab/kiwi.js) under the [1.2.3 milestone](https://github.com/gamelab/kiwi.js/issues?q=milestone%3Av1.2.3)
+
 ### v1.2.2 "Williams"
 
 ### Bug Fixes
diff --git a/build/kiwi.d.ts b/build/kiwi.d.ts
index 50eb3f8..ce34653 100644
--- a/build/kiwi.d.ts
+++ b/build/kiwi.d.ts
@@ -2065,6 +2065,7 @@ declare module Kiwi {
         * @property _inputEnabled
         * @type boolean
         * @private
+        * @deprecated As of 1.2.3, nothing was found to use this.
         */
         private _inputEnabled;
         /**
@@ -2073,6 +2074,7 @@ declare module Kiwi {
         * @property inputEnabled
         * @type boolean
         * @public
+        * @deprecated As of 1.2.3, nothing was found to use this.
         */
         inputEnabled: boolean;
         /**
@@ -6137,10 +6139,13 @@ declare module Kiwi.Components {
         */
         parent: Kiwi.Entity;
         /**
-        * Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
+        * Sets the parent's rotation to be equal to the trajectory of the
+        * velocity of the physics component. Note that rotation 0 corresponds
+        * to pointing directly to the right.
         * @method rotateToVelocity
-        * @return { Number }
+        * @return {number} New rotation value
         * @public
+        * @since 1.3.0
         */
         rotateToVelocity(): number;
         /**
@@ -14986,14 +14991,20 @@ declare module Kiwi.Geom {
         static lineToLine(line1: Line, line2: Line, output?: IntersectResult): IntersectResult;
         /**
         * Check to see if a Line and a Line Segment intersect at any point.
-        * Note: The first line passed is treated as if it extends infinately though space,
-        * The second is treated as if it only exists between its two points.
+        * Note: The first line passed is treated as if it extends infinitely
+        * though space. The second is treated as if it only exists between
+        * its two points.
         *
         * @method lineToLineSegment
-        * @param line1 {Kiwi.Geom.Line} The first line to check. This is the one that will extend through space infinately.
-        * @param seg {Kiwi.Geom.Line} The second line to check. This is the one that will only exist between its two coordinates.
-        * @param [output] {Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-        * @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection.
+        * @param line1 {Kiwi.Geom.Line} The first line to check.
+            This is the one that will extend through space infinately.
+        * @param seg {Kiwi.Geom.Line} The second line to check.
+            This is the one that will only exist between its two coordinates.
+        * @param [output] {Kiwi.Geom.IntersectResult} An optional
+            IntersectResult object to store the intersection values in. One is
+            created if none given.
+        * @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+            containing the results of this intersection.
         * @public
         * @static
         */
@@ -15071,19 +15082,23 @@ declare module Kiwi.Geom {
         */
         static lineToRectangle(line: any, rect: Rectangle, output?: IntersectResult): IntersectResult;
         /**
-        * -------------------------------------------------------------------------------------------
+        * ---------------------------------------------------------------------
         * Line Segment
-        * -------------------------------------------------------------------------------------------
+        * ---------------------------------------------------------------------
         **/
         /**
         * Checks to see if two Line Segments intersect at any point in space.
-        * Note: Both lines are treated as if they only exist between their two line coordinates.
+        * Note: Both lines are treated as if they only exist between their two
+        * line coordinates.
         *
         * @method lineSegmentToLineSegment
         * @param line1 {Kiwi.Geom.Line} The first line object to check.
         * @param line2 {Kiwi.Geom.Line} The second line object to check.
-        * @param [output]{Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-        * @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection in x/y.
+        * @param [output]{Kiwi.Geom.IntersectResult} An optional
+            IntersectResult object to store the intersection values in.
+            One is created if none given.
+        * @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+            containing the results of this intersection in x/y.
         * @public
         * @static
         */
@@ -19405,48 +19420,60 @@ declare module Kiwi.Sound {
     }
 }
 /**
-*
 * @module Kiwi
 * @submodule Time
-*
 */
 declare module Kiwi.Time {
     /**
-    * The Clock class offers a way of tracking time within a game. When creating a new Clock you should NOT directly instantiate this class but instead use the addClock method on a ClockManager.
-    * - The MasterClock is a property of the Kiwi.Time.Manager class and tracks real world time in milliseconds elapsed since the application started. This happens automatically and there is no need to do anything to set this up.
-    * - An instance of a clock is used to track time in arbitrary units (milliseconds by default)
-    * - A clock can be started, paused, unpaused and stopped. Once stopped, re-starting the clock again will reset it. It can also have its time scale freely transformed.
-    * - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer class for timer details.
-    * - If the clock is paused, any timers attached to the clock will take this into account and not continue to fire events until the clock is unpaused. (Note that this is not the same as pausing timers, which can be done manually and needs to be undone manually.)
+    * The Clock class offers a way of tracking time within a game.
+    * When creating a new Clock you should NOT directly instantiate this class
+    * but instead use the addClock method on a ClockManager.
+    * - The MasterClock is a property of the Kiwi.Time.Manager class and tracks
+    *   real world time in milliseconds elapsed since the application started.
+    *   This happens automatically and there is no need to do anything to set
+    *   this up.
+    * - An instance of a clock is used to track time in arbitrary units
+    *   (milliseconds by default)
+    * - A clock can be started, paused, unpaused and stopped. Once stopped,
+    *   re-starting the clock again will reset it. It can also have its time
+    *   scale freely transformed.
+    * - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer
+    *   class for timer details.
+    * - If the clock is paused, any timers attached to the clock will take this
+    *   into account and not continue to fire events until the clock is
+    *   unpaused. (Note that this is not the same as pausing timers, which can
+    *   be done manually and needs to be undone manually.)
     * - Animations and TweenManagers can use any Clock.
     *
     * @class Clock
     * @namespace Kiwi.Time
     * @constructor
-    * @param manager {ClockManager} The ClockManager that this clock belongs to.
-    * @param master {Kiwi.Time.MasterClock} The MasterClock that it is getting the time in relation to.
-    * @param name {String} The name of the clock.
-    * @param [units=1000] {Number} The units that this clock is to operate in per second.
-    * @return {Kiwi.Time.Clock} This Clock object.
+    * @param manager {ClockManager} ClockManager that this clock belongs to
+    * @param master {Kiwi.Time.MasterClock} MasterClock that this is getting
+    *	the time in relation to
+    * @param name {String} Name of the clock
+    * @param [units=1000] {Number} Units that this clock is to operate in
+    *	per second
+    * @return {Kiwi.Time.Clock} This Clock object
     */
     class Clock {
         constructor(manager: Kiwi.Time.ClockManager, master: Kiwi.Time.MasterClock, name: string, units?: number);
         /**
-        * The type of object that this is.
+        * The type of object that this is
         * @method objType
         * @return {String} "Clock"
         * @public
         */
         objType(): string;
         /**
-        * A collection of Timer objects using this clock.
+        * Collection of Timer objects using this clock
         * @property timers
         * @type Timer[]
         * @private
         */
         private timers;
         /**
-        * The time the clock was first started relative to the master clock.
+        * Time the clock was first started relative to the master clock
         * @property _timeFirstStarted
         * @type Number
         * @default null
@@ -19454,14 +19481,14 @@ declare module Kiwi.Time {
         */
         private _timeFirstStarted;
         /**
-        * The number of clock units elapsed since the clock was first started.
-        * @method elapsedSinceFirstStarted.
-        * @return {Number} number of clock units.
+        * Number of clock units elapsed since the clock was first started
+        * @method elapsedSinceFirstStarted
+        * @return {Number} Number of clock units elapsed
         * @public
         */
         elapsedSinceFirstStarted(): number;
         /**
-        * The time the clock was most recently started relative to the master clock.
+        * Most recent time the clock was started relative to the master clock
         * @property _timeLastStarted
         * @type Number
         * @default null
@@ -19469,15 +19496,15 @@ declare module Kiwi.Time {
         */
         private _timeLastStarted;
         /**
-        * Get the most recent time the clock was started relative to the master clock.
+        * Most recent time the clock was started relative to the master clock
         * @method started
-        * @return {Number} milliseconds.
+        * @return {Number} Milliseconds
         * @public
         */
         started(): number;
         /**
         * Rate at which time passes on this clock.
-        * 1 is normal speed. 0 is no speed. -1 is backwards.
+        * 1 is normal speed. 1.5 is faster. 0 is no speed. -1 is backwards.
         * This mostly affects timers, animations and tweens.
         * @property timeScale
         * @type number
@@ -19545,14 +19572,16 @@ declare module Kiwi.Time {
         */
         maxFrameDuration: number;
         /**
-        * The number of clock units elapsed since the clock was most recently started (not including time spent paused)
+        * Number of clock units elapsed since the clock was most recently
+        * started (not including time spent paused)
         * @method elapsed
-        * @return {Number} number of clock units.
+        * @return {Number} Number of clock units
         * @public
         */
         elapsed(): number;
         /**
-        * The time the clock was most recently stopped relative to the master clock.
+        * Time the clock was most recently stopped relative to the
+        * master clock.
         * @property _timeLastStopped
         * @type Number
         * @default null
@@ -19560,14 +19589,16 @@ declare module Kiwi.Time {
         */
         private _timeLastStopped;
         /**
-        * The number of clock units elapsed since the clock was most recently stopped.
-        * @method elapsedSinceLastStopped.
-        * @return {Number} number of clock units.
+        * Number of clock units elapsed since the clock was most recently
+        * stopped.
+        * @method elapsedSinceLastStopped
+        * @return {Number} Number of clock units
         * @public
         */
         elapsedSinceLastStopped(): number;
         /**
-        * The time the clock was most receently paused relative to the master clock.
+        * Time the clock was most receently paused relative to the
+        * master clock.
         * @property _timeLastPaused
         * @private
         * @type Number
@@ -19576,14 +19607,15 @@ declare module Kiwi.Time {
         */
         private _timeLastPaused;
         /**
-        * The number of clock units elapsed since the clock was most recently paused.
-        * @method elapsedSinceLastPaused.
-        * @return {Number} number of clock units.
+        * Number of clock units elapsed since the clock was most recently paused.
+        * @method elapsedSinceLastPaused
+        * @return {Number} Number of clock units
         * @public
         */
         elapsedSinceLastPaused(): number;
         /**
-        * The time the clock was most recently unpaused relative to the master clock.
+        * Time the clock was most recently unpaused relative to the
+        * master clock.
         * @property _timeLastUnpaused
         * @private
         * @type Number
@@ -19592,14 +19624,16 @@ declare module Kiwi.Time {
         */
         private _timeLastUnpaused;
         /**
-        * The number of clock units elapsed since the clock was most recently unpaused.
-        * @method elapsedSinceLastUnpaused.
-        * @return {Number} number of clock units.
+        * Number of clock units elapsed since the clock was most recently
+        * unpaused.
+        * @method elapsedSinceLastUnpaused
+        * @return {Number} Number of clock units
         * @public
         */
         elapsedSinceLastUnpaused(): number;
         /**
-        * The total number of milliseconds the clock has been paused since it was last started.
+        * Total number of milliseconds the clock has been paused
+        * since it was last started
         * @property _totalPaused
         * @private
         * @type Number
@@ -19608,7 +19642,7 @@ declare module Kiwi.Time {
         */
         private _totalPaused;
         /**
-        * Whether the clock is in a running state.
+        * Whether the clock is in a running state
         * @property _isRunning
         * @type boolean
         * @default false
@@ -19616,14 +19650,14 @@ declare module Kiwi.Time {
         */
         private _isRunning;
         /**
-        * Check if the clock is currently running.
+        * Check if the clock is currently running
         * @method isRunning
-        * @return {boolean} true if running.
+        * @return {boolean} `true` if running
         * @public
         */
         isRunning(): boolean;
         /**
-        * Whether the clock is in a stopped state.
+        * Whether the clock is in a stopped state
         * @property _isStopped
         * @type boolean
         * @default true
@@ -19631,14 +19665,14 @@ declare module Kiwi.Time {
         */
         private _isStopped;
         /**
-        * Check if the clock is in the stopped state.
+        * Check if the clock is in the stopped state
         * @method isStopped
-        * @return {boolean} true if stopped.
+        * @return {boolean} `true` if stopped
         * @public
         */
         isStopped(): boolean;
         /**
-        * Whether the clock is in a paused state.
+        * Whether the clock is in a paused state
         * @property _isPaused
         * @type boolean
         * @default false
@@ -19646,28 +19680,28 @@ declare module Kiwi.Time {
         */
         private _isPaused;
         /**
-        * Check if the clock is in the paused state.
+        * Check if the clock is in the paused state
         * @method isPaused
-        * @return {boolean} true if paused.
+        * @return {boolean} `true` if paused
         * @public
         */
         isPaused(): boolean;
         /**
-        * An internal reference to the state of the elapsed timer
+        * Internal reference to the state of the elapsed timer
         * @property _elapsedState
         * @type Number
         * @private
         */
         private _elapsedState;
         /**
-        * The time manager that this clock belongs to.
+        * Time manager that this clock belongs to
         * @property manager
         * @type ClockManager
         * @public
         */
         manager: Kiwi.Time.ClockManager;
         /**
-        * The master clock.
+        * Master clock from which time is derived
         * @property master
         * @type Kiwi.Time.MasterClock
         * @public
@@ -19681,7 +19715,7 @@ declare module Kiwi.Time {
         */
         name: string;
         /**
-        * The number of milliseconds counted as one unit of time by the clock.
+        * Number of milliseconds counted as one unit of time by the clock
         * @property units
         * @type Number
         * @default 0
@@ -19729,56 +19763,60 @@ declare module Kiwi.Time {
         /**
         * Add an existing Timer to the Clock.
         * @method addTimer
-        * @param timer {Timer} Timer object instance to be added to this Clock.
-        * @return {Kiwi.Time.Clock} This Clock object.
+        * @param timer {Timer} Timer object instance to be added to this Clock
+        * @return {Kiwi.Time.Clock} This Clock object
         * @public
         */
         addTimer(timer: Timer): Clock;
         /**
-        * Creates a new Timer and adds it to this Clock.
+        * Create a new Timer and add it to this Clock.
         * @method createTimer
-        * @param name {string} The name of the Timer (must be unique on this Clock).
-        * @param [delay=1] {Number} The number of clock units to wait between firing events (default 1)
-        * @param [repeatCount=0] {Number} The number of times to repeat this Timer (default 0)
-        * @param [start=true] {Boolean} If the timer should start.
-        * @return {Kiwi.Time.Timer} The newly created Timer.
+        * @param name {string} Name of the Timer (must be unique on this Clock)
+        * @param [delay=1] {Number} Number of clock units to wait between
+        *	firing events
+        * @param [repeatCount=0] {Number} Number of times to repeat the Timer
+        *	(default 0)
+        * @param [start=true] {Boolean} If the timer should start
+        * @return {Kiwi.Time.Timer} The newly created Timer
         * @public
         */
         createTimer(name: string, delay?: number, repeatCount?: number, start?: boolean): Timer;
         /**
-        * Remove a Timer from this Clock based on either the Timer object or its name.
+        * Remove a Timer from this Clock based on either the Timer object
+        * or its name.
         * @method removeTimer
-        * @param [timer=null] {Timer} The Timer object you wish to remove. If you wish to delete by Timer Name set this to null.
-        * @param [timerName=''] {string} The name of the Timer object to remove.
-        * @return {boolean} True if the Timer was successfully removed, false if not.
+        * @param [timer=null] {Timer} Timer object you wish to remove.
+        *	If you wish to delete by Timer Name set this to null.
+        * @param [timerName=''] {string} Name of the Timer object to remove
+        * @return {boolean} `true` if the Timer was successfully removed
         * @public
         */
         removeTimer(timer?: Timer, timerName?: string): boolean;
         /**
-        * Check if the Timer already exists on this Clock
+        * Check if the Timer already exists on this Clock.
         * @method checkExists
-        * @param name {string} The name of the Timer.
-        * @return {boolean} true if the Timer exists, false if not.
+        * @param name {string} Name of the Timer
+        * @return {boolean} `true` if the Timer exists
         * @public
         */
         checkExists(name: string): boolean;
         /**
         * Stop all timers attached to the clock.
         * @method stopAllTimers
-        * @return {Clock} This Clock object.
+        * @return {Clock} This Clock object
         * @public
         */
         stopAllTimers(): Clock;
         /**
         * Convert a number to milliseconds based on clock units.
-        * @method toMilliseconds.
-        * @param time {number} seconds
-        * @return {Number} milliseconds.
+        * @method toMilliseconds
+        * @param time {number} Seconds
+        * @return {Number} Milliseconds
         * @public
         */
         convertToMilliseconds(time: number): number;
         /**
-        * Updates all Timers linked to this Clock.
+        * Update all Timers linked to this Clock.
         * @method update
         * @public
         */
@@ -19786,79 +19824,80 @@ declare module Kiwi.Time {
         /**
         * Start the clock. This resets the clock and starts it running.
         * @method start
-        * @return {Clock} This Clock object.
+        * @return {Clock} This Clock object
         * @public
         */
         start(): Clock;
         /**
-        * Pause the clock. The clock can only be paused if it is already running.
+        * Pause the clock. This can only be paused if it is already running.
         * @method pause
-        * @return {Kiwi.Time.Clock} This Clock object.
+        * @return {Kiwi.Time.Clock} This Clock object
         * @public
         */
         pause(): Clock;
         /**
-        * Resume the clock. The clock can only be resumed if it is already paused.
+        * Resume the clock. This can only be resumed if it is already paused.
         * @method resume
-        * @return {Kiwi.Time.Clock} This Clock object.
+        * @return {Kiwi.Time.Clock} This Clock object
         * @public
         */
         resume(): Clock;
         /**
-        * Stop the clock. Clock can only be stopped if it is already running or is paused.
+        * Stop the clock. This can only be stopped if it is already running
+        *	or is paused.
         * @method stop
-        * @return {Kiwi.Time.Clock} This Clock object.
+        * @return {Kiwi.Time.Clock} This Clock object
         * @public
         */
         stop(): Clock;
         /**
-        * Returns a string representation of this object.
+        * Return a string representation of this object.
         * @method toString
-        * @return {string} a string representation of the instance.
+        * @return {string} String representation of the instance
         * @public
         */
         toString(): string;
         /**
         * Set a function to execute after a certain time interval.
-        * Emulates window.setTimeout, except attached to a Kiwi.Time.Clock.
-        * This allows you to pause and manipulate time, and the timeout will respect
-        * the clock on which it is created.
+        * Emulates `window.setTimeout`, except attached to a `Kiwi.Time.Clock`.
+        * This allows you to pause and manipulate time, and the timeout will
+        * respect the clock on which it is created.
         *
-        * No clearTimeout is provided; you should use Kiwi.Time.Timer functions
-        * to achieve further control.
+        * No `clearTimeout` is provided; you should use `Kiwi.Time.Timer`
+        * functions to achieve further control.
         *
-        * Any parameters after "context" will be passed as parameters to the
-        * callback function. Note that you must specify "context" in order for
-        * this to work. You may specify "null", in which case it will default
-        * to the global scope "window".
+        * Any parameters after `context` will be passed as parameters to the
+        * callback function. Note that you must specify `context` in order for
+        * this to work. You may specify `null`, in which case it will default
+        * to the global scope `window`.
         *
         * @method setTimeout
         * @param callback {function} Function to execute
         * @param timeout {number} Milliseconds before execution
-        * @param [context] {object} Object to be "this" for the callback
-        * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used to further
-        *   manipulate the timer
+        * @param [context] {object} Object to be `this` for the callback
+        * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used
+        *	to further manipulate the timer
         * @public
         */
         setTimeout(callback: any, timeout: number, context: any, ...args: any[]): Timer;
         /**
         * Set a function to repeatedly execute at fixed time intervals.
-        * Emulates window.setInterval, except attached to a Kiwi.Time.Clock.
-        * This allows you to pause and manipulate time, and the timeout will respect
-        * the clock on which it is created.
+        * Emulates `window.setInterval`, except attached to a `Kiwi.Time.Clock`.
+        * This allows you to pause and manipulate time, and the timeout will
+        * respect the clock on which it is created.
         *
-        * No clearInterval is provided; you should use Kiwi.Time.Timer functions
-        * to achieve further control.
+        * No `clearInterval` is provided; you should use `Kiwi.Time.Timer`
+        * functions to achieve further control.
         *
-        * Any parameters after "context" will be passed as parameters to the
-        * callback function. Note that you must specify "context" in order for
-        * this to work. You may specify "null", in which case it will default
-        * to the global scope "window".
+        * Any parameters after `context` will be passed as parameters to the
+        * callback function. Note that you must specify `context` in order for
+        * this to work. You may specify `null`, in which case it will default
+        * to the global scope `window`.
         *
         * @method setInterval
         * @param callback {function} Function to execute
         * @param timeout {number} Milliseconds between executions
-        * @param [context=window] {object} Object to be "this" for the callback
+        * @param [context=window] {object} Object to be `this` for the callback
         * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object
         *   which can be used to further manipulate the timer
         * @public
diff --git a/build/kiwi.js b/build/kiwi.js
index d6e0e1e..e147a0b 100644
--- a/build/kiwi.js
+++ b/build/kiwi.js
@@ -2811,6 +2811,7 @@ var Kiwi;
             * @property inputEnabled
             * @type boolean
             * @public
+            * @deprecated As of 1.2.3, nothing was found to use this.
             */
             set: function (value) {
                 this._inputEnabled = value;
@@ -8659,10 +8660,13 @@ var Kiwi;
                 this._callbackContext = callbackContext;
             };
             /**
-            * Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
+            * Sets the parent's rotation to be equal to the trajectory of the
+            * velocity of the physics component. Note that rotation 0 corresponds
+            * to pointing directly to the right.
             * @method rotateToVelocity
-            * @return { Number }
+            * @return {number} New rotation value
             * @public
+            * @since 1.3.0
             */
             ArcadePhysics.prototype.rotateToVelocity = function () {
                 var result = Math.atan2(this.velocity.y, this.velocity.x);
@@ -21317,14 +21321,20 @@ var Kiwi;
             };
             /**
             * Check to see if a Line and a Line Segment intersect at any point.
-            * Note: The first line passed is treated as if it extends infinately though space,
-            * The second is treated as if it only exists between its two points.
+            * Note: The first line passed is treated as if it extends infinitely
+            * though space. The second is treated as if it only exists between
+            * its two points.
             *
             * @method lineToLineSegment
-            * @param line1 {Kiwi.Geom.Line} The first line to check. This is the one that will extend through space infinately.
-            * @param seg {Kiwi.Geom.Line} The second line to check. This is the one that will only exist between its two coordinates.
-            * @param [output] {Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection.
+            * @param line1 {Kiwi.Geom.Line} The first line to check.
+                This is the one that will extend through space infinately.
+            * @param seg {Kiwi.Geom.Line} The second line to check.
+                This is the one that will only exist between its two coordinates.
+            * @param [output] {Kiwi.Geom.IntersectResult} An optional
+                IntersectResult object to store the intersection values in. One is
+                created if none given.
+            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+                containing the results of this intersection.
             * @public
             * @static
             */
@@ -21339,8 +21349,7 @@ var Kiwi;
                     var minX = Math.min(seg.x1, seg.x2);
                     var maxY = Math.max(seg.y1, seg.y2);
                     var minY = Math.min(seg.y1, seg.y2);
-                    //if (!(output.x <= maxX && output.x >= minX) || !(output.y <= maxY && output.y >= minY))
-                    if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true) {
+                    if ((output.x <= maxX && output.x >= minX) === true && (output.y <= maxY && output.y >= minY) === true) {
                         output.result = true;
                     }
                 }
@@ -21495,19 +21504,23 @@ var Kiwi;
                 return output;
             };
             /**
-            * -------------------------------------------------------------------------------------------
+            * ---------------------------------------------------------------------
             * Line Segment
-            * -------------------------------------------------------------------------------------------
+            * ---------------------------------------------------------------------
             **/
             /**
             * Checks to see if two Line Segments intersect at any point in space.
-            * Note: Both lines are treated as if they only exist between their two line coordinates.
+            * Note: Both lines are treated as if they only exist between their two
+            * line coordinates.
             *
             * @method lineSegmentToLineSegment
             * @param line1 {Kiwi.Geom.Line} The first line object to check.
             * @param line2 {Kiwi.Geom.Line} The second line object to check.
-            * @param [output]{Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection in x/y.
+            * @param [output]{Kiwi.Geom.IntersectResult} An optional
+                IntersectResult object to store the intersection values in.
+                One is created if none given.
+            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+                containing the results of this intersection in x/y.
             * @public
             * @static
             */
@@ -27894,38 +27907,50 @@ var Kiwi;
     })(Sound = Kiwi.Sound || (Kiwi.Sound = {}));
 })(Kiwi || (Kiwi = {}));
 /**
-*
 * @module Kiwi
 * @submodule Time
-*
 */
 var Kiwi;
 (function (Kiwi) {
     var Time;
     (function (Time) {
         /**
-        * The Clock class offers a way of tracking time within a game. When creating a new Clock you should NOT directly instantiate this class but instead use the addClock method on a ClockManager.
-        * - The MasterClock is a property of the Kiwi.Time.Manager class and tracks real world time in milliseconds elapsed since the application started. This happens automatically and there is no need to do anything to set this up.
-        * - An instance of a clock is used to track time in arbitrary units (milliseconds by default)
-        * - A clock can be started, paused, unpaused and stopped. Once stopped, re-starting the clock again will reset it. It can also have its time scale freely transformed.
-        * - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer class for timer details.
-        * - If the clock is paused, any timers attached to the clock will take this into account and not continue to fire events until the clock is unpaused. (Note that this is not the same as pausing timers, which can be done manually and needs to be undone manually.)
+        * The Clock class offers a way of tracking time within a game.
+        * When creating a new Clock you should NOT directly instantiate this class
+        * but instead use the addClock method on a ClockManager.
+        * - The MasterClock is a property of the Kiwi.Time.Manager class and tracks
+        *   real world time in milliseconds elapsed since the application started.
+        *   This happens automatically and there is no need to do anything to set
+        *   this up.
+        * - An instance of a clock is used to track time in arbitrary units
+        *   (milliseconds by default)
+        * - A clock can be started, paused, unpaused and stopped. Once stopped,
+        *   re-starting the clock again will reset it. It can also have its time
+        *   scale freely transformed.
+        * - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer
+        *   class for timer details.
+        * - If the clock is paused, any timers attached to the clock will take this
+        *   into account and not continue to fire events until the clock is
+        *   unpaused. (Note that this is not the same as pausing timers, which can
+        *   be done manually and needs to be undone manually.)
         * - Animations and TweenManagers can use any Clock.
         *
         * @class Clock
         * @namespace Kiwi.Time
         * @constructor
-        * @param manager {ClockManager} The ClockManager that this clock belongs to.
-        * @param master {Kiwi.Time.MasterClock} The MasterClock that it is getting the time in relation to.
-        * @param name {String} The name of the clock.
-        * @param [units=1000] {Number} The units that this clock is to operate in per second.
-        * @return {Kiwi.Time.Clock} This Clock object.
+        * @param manager {ClockManager} ClockManager that this clock belongs to
+        * @param master {Kiwi.Time.MasterClock} MasterClock that this is getting
+        *	the time in relation to
+        * @param name {String} Name of the clock
+        * @param [units=1000] {Number} Units that this clock is to operate in
+        *	per second
+        * @return {Kiwi.Time.Clock} This Clock object
         */
         var Clock = (function () {
             function Clock(manager, master, name, units) {
                 if (units === void 0) { units = 1000; }
                 /**
-                * The time the clock was first started relative to the master clock.
+                * Time the clock was first started relative to the master clock
                 * @property _timeFirstStarted
                 * @type Number
                 * @default null
@@ -27933,7 +27958,7 @@ var Kiwi;
                 */
                 this._timeFirstStarted = null;
                 /**
-                * The time the clock was most recently started relative to the master clock.
+                * Most recent time the clock was started relative to the master clock
                 * @property _timeLastStarted
                 * @type Number
                 * @default null
@@ -27942,7 +27967,7 @@ var Kiwi;
                 this._timeLastStarted = null;
                 /**
                 * Rate at which time passes on this clock.
-                * 1 is normal speed. 0 is no speed. -1 is backwards.
+                * 1 is normal speed. 1.5 is faster. 0 is no speed. -1 is backwards.
                 * This mostly affects timers, animations and tweens.
                 * @property timeScale
                 * @type number
@@ -27983,7 +28008,8 @@ var Kiwi;
                 */
                 this._maxFrameDuration = -1;
                 /**
-                * The time the clock was most recently stopped relative to the master clock.
+                * Time the clock was most recently stopped relative to the
+                * master clock.
                 * @property _timeLastStopped
                 * @type Number
                 * @default null
@@ -27991,7 +28017,8 @@ var Kiwi;
                 */
                 this._timeLastStopped = null;
                 /**
-                * The time the clock was most receently paused relative to the master clock.
+                * Time the clock was most receently paused relative to the
+                * master clock.
                 * @property _timeLastPaused
                 * @private
                 * @type Number
@@ -28000,7 +28027,8 @@ var Kiwi;
                 */
                 this._timeLastPaused = null;
                 /**
-                * The time the clock was most recently unpaused relative to the master clock.
+                * Time the clock was most recently unpaused relative to the
+                * master clock.
                 * @property _timeLastUnpaused
                 * @private
                 * @type Number
@@ -28009,7 +28037,8 @@ var Kiwi;
                 */
                 this._timeLastUnpaused = null;
                 /**
-                * The total number of milliseconds the clock has been paused since it was last started.
+                * Total number of milliseconds the clock has been paused
+                * since it was last started
                 * @property _totalPaused
                 * @private
                 * @type Number
@@ -28018,7 +28047,7 @@ var Kiwi;
                 */
                 this._totalPaused = 0;
                 /**
-                * Whether the clock is in a running state.
+                * Whether the clock is in a running state
                 * @property _isRunning
                 * @type boolean
                 * @default false
@@ -28026,7 +28055,7 @@ var Kiwi;
                 */
                 this._isRunning = false;
                 /**
-                * Whether the clock is in a stopped state.
+                * Whether the clock is in a stopped state
                 * @property _isStopped
                 * @type boolean
                 * @default true
@@ -28034,7 +28063,7 @@ var Kiwi;
                 */
                 this._isStopped = true;
                 /**
-                * Whether the clock is in a paused state.
+                * Whether the clock is in a paused state
                 * @property _isPaused
                 * @type boolean
                 * @default false
@@ -28042,21 +28071,21 @@ var Kiwi;
                 */
                 this._isPaused = false;
                 /**
-                * An internal reference to the state of the elapsed timer
+                * Internal reference to the state of the elapsed timer
                 * @property _elapsedState
                 * @type Number
                 * @private
                 */
                 this._elapsedState = Kiwi.Time.Clock._RUNNING;
                 /**
-                * The time manager that this clock belongs to.
+                * Time manager that this clock belongs to
                 * @property manager
                 * @type ClockManager
                 * @public
                 */
                 this.manager = null;
                 /**
-                * The master clock.
+                * Master clock from which time is derived
                 * @property master
                 * @type Kiwi.Time.MasterClock
                 * @public
@@ -28070,7 +28099,7 @@ var Kiwi;
                 */
                 this.name = null;
                 /**
-                * The number of milliseconds counted as one unit of time by the clock.
+                * Number of milliseconds counted as one unit of time by the clock
                 * @property units
                 * @type Number
                 * @default 0
@@ -28089,7 +28118,7 @@ var Kiwi;
                 this._currentMasterElapsed = this.master.elapsed();
             }
             /**
-            * The type of object that this is.
+            * The type of object that this is
             * @method objType
             * @return {String} "Clock"
             * @public
@@ -28098,18 +28127,18 @@ var Kiwi;
                 return "Clock";
             };
             /**
-            * The number of clock units elapsed since the clock was first started.
-            * @method elapsedSinceFirstStarted.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was first started
+            * @method elapsedSinceFirstStarted
+            * @return {Number} Number of clock units elapsed
             * @public
             */
             Clock.prototype.elapsedSinceFirstStarted = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeFirstStarted) / this.units : null;
             };
             /**
-            * Get the most recent time the clock was started relative to the master clock.
+            * Most recent time the clock was started relative to the master clock
             * @method started
-            * @return {Number} milliseconds.
+            * @return {Number} Milliseconds
             * @public
             */
             Clock.prototype.started = function () {
@@ -28136,63 +28165,66 @@ var Kiwi;
                 configurable: true
             });
             /**
-            * The number of clock units elapsed since the clock was most recently started (not including time spent paused)
+            * Number of clock units elapsed since the clock was most recently
+            * started (not including time spent paused)
             * @method elapsed
-            * @return {Number} number of clock units.
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsed = function () {
                 return this._elapsed;
             };
             /**
-            * The number of clock units elapsed since the clock was most recently stopped.
-            * @method elapsedSinceLastStopped.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was most recently
+            * stopped.
+            * @method elapsedSinceLastStopped
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsedSinceLastStopped = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeLastStopped) / this.units : null;
             };
             /**
-            * The number of clock units elapsed since the clock was most recently paused.
-            * @method elapsedSinceLastPaused.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was most recently paused.
+            * @method elapsedSinceLastPaused
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsedSinceLastPaused = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeLastPaused) / this.units : null;
             };
             /**
-            * The number of clock units elapsed since the clock was most recently unpaused.
-            * @method elapsedSinceLastUnpaused.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was most recently
+            * unpaused.
+            * @method elapsedSinceLastUnpaused
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsedSinceLastUnpaused = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeLastUnpaused) / this.units : null;
             };
             /**
-            * Check if the clock is currently running.
+            * Check if the clock is currently running
             * @method isRunning
-            * @return {boolean} true if running.
+            * @return {boolean} `true` if running
             * @public
             */
             Clock.prototype.isRunning = function () {
                 return this._isRunning;
             };
             /**
-            * Check if the clock is in the stopped state.
+            * Check if the clock is in the stopped state
             * @method isStopped
-            * @return {boolean} true if stopped.
+            * @return {boolean} `true` if stopped
             * @public
             */
             Clock.prototype.isStopped = function () {
                 return this._isStopped;
             };
             /**
-            * Check if the clock is in the paused state.
+            * Check if the clock is in the paused state
             * @method isPaused
-            * @return {boolean} true if paused.
+            * @return {boolean} `true` if paused
             * @public
             */
             Clock.prototype.isPaused = function () {
@@ -28201,8 +28233,8 @@ var Kiwi;
             /**
             * Add an existing Timer to the Clock.
             * @method addTimer
-            * @param timer {Timer} Timer object instance to be added to this Clock.
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @param timer {Timer} Timer object instance to be added to this Clock
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.addTimer = function (timer) {
@@ -28210,13 +28242,15 @@ var Kiwi;
                 return this;
             };
             /**
-            * Creates a new Timer and adds it to this Clock.
+            * Create a new Timer and add it to this Clock.
             * @method createTimer
-            * @param name {string} The name of the Timer (must be unique on this Clock).
-            * @param [delay=1] {Number} The number of clock units to wait between firing events (default 1)
-            * @param [repeatCount=0] {Number} The number of times to repeat this Timer (default 0)
-            * @param [start=true] {Boolean} If the timer should start.
-            * @return {Kiwi.Time.Timer} The newly created Timer.
+            * @param name {string} Name of the Timer (must be unique on this Clock)
+            * @param [delay=1] {Number} Number of clock units to wait between
+            *	firing events
+            * @param [repeatCount=0] {Number} Number of times to repeat the Timer
+            *	(default 0)
+            * @param [start=true] {Boolean} If the timer should start
+            * @return {Kiwi.Time.Timer} The newly created Timer
             * @public
             */
             Clock.prototype.createTimer = function (name, delay, repeatCount, start) {
@@ -28230,11 +28264,13 @@ var Kiwi;
                 return this.timers[this.timers.length - 1];
             };
             /**
-            * Remove a Timer from this Clock based on either the Timer object or its name.
+            * Remove a Timer from this Clock based on either the Timer object
+            * or its name.
             * @method removeTimer
-            * @param [timer=null] {Timer} The Timer object you wish to remove. If you wish to delete by Timer Name set this to null.
-            * @param [timerName=''] {string} The name of the Timer object to remove.
-            * @return {boolean} True if the Timer was successfully removed, false if not.
+            * @param [timer=null] {Timer} Timer object you wish to remove.
+            *	If you wish to delete by Timer Name set this to null.
+            * @param [timerName=''] {string} Name of the Timer object to remove
+            * @return {boolean} `true` if the Timer was successfully removed
             * @public
             */
             Clock.prototype.removeTimer = function (timer, timerName) {
@@ -28260,10 +28296,10 @@ var Kiwi;
                 return false;
             };
             /**
-            * Check if the Timer already exists on this Clock
+            * Check if the Timer already exists on this Clock.
             * @method checkExists
-            * @param name {string} The name of the Timer.
-            * @return {boolean} true if the Timer exists, false if not.
+            * @param name {string} Name of the Timer
+            * @return {boolean} `true` if the Timer exists
             * @public
             */
             Clock.prototype.checkExists = function (name) {
@@ -28277,7 +28313,7 @@ var Kiwi;
             /**
             * Stop all timers attached to the clock.
             * @method stopAllTimers
-            * @return {Clock} This Clock object.
+            * @return {Clock} This Clock object
             * @public
             */
             Clock.prototype.stopAllTimers = function () {
@@ -28288,16 +28324,16 @@ var Kiwi;
             };
             /**
             * Convert a number to milliseconds based on clock units.
-            * @method toMilliseconds.
-            * @param time {number} seconds
-            * @return {Number} milliseconds.
+            * @method toMilliseconds
+            * @param time {number} Seconds
+            * @return {Number} Milliseconds
             * @public
             */
             Clock.prototype.convertToMilliseconds = function (time) {
                 return time * this.units;
             };
             /**
-            * Updates all Timers linked to this Clock.
+            * Update all Timers linked to this Clock.
             * @method update
             * @public
             */
@@ -28330,7 +28366,7 @@ var Kiwi;
             /**
             * Start the clock. This resets the clock and starts it running.
             * @method start
-            * @return {Clock} This Clock object.
+            * @return {Clock} This Clock object
             * @public
             */
             Clock.prototype.start = function () {
@@ -28343,12 +28379,15 @@ var Kiwi;
                 this._isPaused = false;
                 this._isStopped = false;
                 this._elapsedState = Kiwi.Time.Clock._RUNNING;
+                this._elapsed = 0;
+                this._lastMasterElapsed = this.master.elapsed();
+                this._currentMasterElapsed = this.master.elapsed();
                 return this;
             };
             /**
-            * Pause the clock. The clock can only be paused if it is already running.
+            * Pause the clock. This can only be paused if it is already running.
             * @method pause
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.pause = function () {
@@ -28362,9 +28401,9 @@ var Kiwi;
                 return this;
             };
             /**
-            * Resume the clock. The clock can only be resumed if it is already paused.
+            * Resume the clock. This can only be resumed if it is already paused.
             * @method resume
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.resume = function () {
@@ -28379,9 +28418,10 @@ var Kiwi;
                 return this;
             };
             /**
-            * Stop the clock. Clock can only be stopped if it is already running or is paused.
+            * Stop the clock. This can only be stopped if it is already running
+            *	or is paused.
             * @method stop
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.stop = function () {
@@ -28398,9 +28438,9 @@ var Kiwi;
                 return this;
             };
             /**
-            * Returns a string representation of this object.
+            * Return a string representation of this object.
             * @method toString
-            * @return {string} a string representation of the instance.
+            * @return {string} String representation of the instance
             * @public
             */
             Clock.prototype.toString = function () {
@@ -28408,24 +28448,24 @@ var Kiwi;
             };
             /**
             * Set a function to execute after a certain time interval.
-            * Emulates window.setTimeout, except attached to a Kiwi.Time.Clock.
-            * This allows you to pause and manipulate time, and the timeout will respect
-            * the clock on which it is created.
+            * Emulates `window.setTimeout`, except attached to a `Kiwi.Time.Clock`.
+            * This allows you to pause and manipulate time, and the timeout will
+            * respect the clock on which it is created.
             *
-            * No clearTimeout is provided; you should use Kiwi.Time.Timer functions
-            * to achieve further control.
+            * No `clearTimeout` is provided; you should use `Kiwi.Time.Timer`
+            * functions to achieve further control.
             *
-            * Any parameters after "context" will be passed as parameters to the
-            * callback function. Note that you must specify "context" in order for
-            * this to work. You may specify "null", in which case it will default
-            * to the global scope "window".
+            * Any parameters after `context` will be passed as parameters to the
+            * callback function. Note that you must specify `context` in order for
+            * this to work. You may specify `null`, in which case it will default
+            * to the global scope `window`.
             *
             * @method setTimeout
             * @param callback {function} Function to execute
             * @param timeout {number} Milliseconds before execution
-            * @param [context] {object} Object to be "this" for the callback
-            * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used to further
-            *   manipulate the timer
+            * @param [context] {object} Object to be `this` for the callback
+            * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used
+            *	to further manipulate the timer
             * @public
             */
             Clock.prototype.setTimeout = function (callback, timeout, context) {
@@ -28446,22 +28486,22 @@ var Kiwi;
             };
             /**
             * Set a function to repeatedly execute at fixed time intervals.
-            * Emulates window.setInterval, except attached to a Kiwi.Time.Clock.
-            * This allows you to pause and manipulate time, and the timeout will respect
-            * the clock on which it is created.
+            * Emulates `window.setInterval`, except attached to a `Kiwi.Time.Clock`.
+            * This allows you to pause and manipulate time, and the timeout will
+            * respect the clock on which it is created.
             *
-            * No clearInterval is provided; you should use Kiwi.Time.Timer functions
-            * to achieve further control.
+            * No `clearInterval` is provided; you should use `Kiwi.Time.Timer`
+            * functions to achieve further control.
             *
-            * Any parameters after "context" will be passed as parameters to the
-            * callback function. Note that you must specify "context" in order for
-            * this to work. You may specify "null", in which case it will default
-            * to the global scope "window".
+            * Any parameters after `context` will be passed as parameters to the
+            * callback function. Note that you must specify `context` in order for
+            * this to work. You may specify `null`, in which case it will default
+            * to the global scope `window`.
             *
             * @method setInterval
             * @param callback {function} Function to execute
             * @param timeout {number} Milliseconds between executions
-            * @param [context=window] {object} Object to be "this" for the callback
+            * @param [context=window] {object} Object to be `this` for the callback
             * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object
             *   which can be used to further manipulate the timer
             * @public
diff --git a/build/kiwi.min.js b/build/kiwi.min.js
index 5a2352e..227b928 100644
--- a/build/kiwi.min.js
+++ b/build/kiwi.min.js
@@ -4,8 +4,8 @@ l.orientation=this.orientation,l.visible=void 0==i.visible?!0:i.visible,l.alpha=
 }return __extends(c,b),c.prototype.isTouching=function(a){return(this.touching&a)==a},c.prototype.solid=function(a){return void 0!==a&&(this.allowCollisions=a?c.ANY:c.NONE),(this.allowCollisions&c.ANY)>c.NONE},c.prototype.setCallback=function(a,b){this._callbackFunction=a,this._callbackContext=b},c.prototype.rotateToVelocity=function(){var a=Math.atan2(this.velocity.y,this.velocity.x);return this.transform.rotation=a,a},c.separate=function(a,b){var c=this.separateX(a,b),d=this.separateY(a,b);return c||d},c.separateX=function(b,d){var e=b.components.getComponent("ArcadePhysics"),f=d.components.getComponent("ArcadePhysics");if(e.immovable&&f.immovable)return!1;var g=0,h=e.transform.worldX-e.last.x,i=f.transform.worldX-f.last.x;if(h==i)return!1;var j=h>0?h:-h,k=i>0?i:-i,l=e.box.worldHitbox,m=f.box.worldHitbox,n=new a.Geom.Rectangle(l.x-(h>0?h:0),e.last.y+e.box.hitboxOffset.y,l.width+(h>0?h:-h),l.height),o=new a.Geom.Rectangle(m.x-(i>0?i:0),f.last.y+f.box.hitboxOffset.y,m.width+(i>0?i:-i),m.height);if(n.x+n.width>o.x&&n.x<o.x+o.width&&n.y+n.height>o.y&&n.y<o.y+o.height){var p=j+k+c.OVERLAP_BIAS;h>i?(g=l.x+l.width-m.x,!(g>p)&&e.allowCollisions&c.RIGHT&&f.allowCollisions&c.LEFT?(e.touching|=c.RIGHT,f.touching|=c.LEFT):g=0):(g=l.x-m.width-m.x,!(-g>p)&&e.allowCollisions&c.LEFT&&f.allowCollisions&c.RIGHT?(e.touching|=c.LEFT,f.touching|=c.RIGHT):g=0)}if(0!=g){var q=e.velocity.x,r=f.velocity.x;if(e.immovable||f.immovable)e.immovable?f.immovable||(f.transform.x=f.transform.x+g,f.velocity.x=q-r*f.elasticity):(e.transform.x=e.transform.x-g,e.velocity.x=r-q*e.elasticity);else{g*=.5,e.transform.x=e.transform.x-g,f.transform.x=f.transform.x+g;var s=Math.sqrt(r*r*f.mass/e.mass)*(r>0?1:-1),t=Math.sqrt(q*q*e.mass/f.mass)*(q>0?1:-1),u=.5*(s+t);s-=u,t-=u,e.velocity.x=u+s*e.elasticity,f.velocity.x=u+t*f.elasticity}return!0}return!1},c.separateY=function(b,d){var e=b.components.getComponent("ArcadePhysics"),f=d.components.getComponent("ArcadePhysics");if(e.immovable&&f.immovable)return!1;var g=0,h=e.transform.worldY-e.last.y,i=f.transform.worldY-f.last.y;if(h==i)return!1;var j=h>0?h:-h,k=i>0?i:-i,l=e.box.worldHitbox,m=f.box.worldHitbox,n=new a.Geom.Rectangle(l.x,l.y-(h>0?h:0),l.width,l.height+j),o=new a.Geom.Rectangle(m.x,m.y-(i>0?i:0),m.width,m.height+k);if(n.x+n.width>o.x&&n.x<o.x+o.width&&n.y+n.height>o.y&&n.y<o.y+o.height){var p=j+k+c.OVERLAP_BIAS;if(h>i?(g=l.y+l.height-m.y,!(g>p)&&e.allowCollisions&c.DOWN&&f.allowCollisions&c.UP?(e.touching|=c.DOWN,f.touching|=c.UP):g=0):(g=l.y-m.height-m.y,!(-g>p)&&e.allowCollisions&c.UP&&f.allowCollisions&c.DOWN?(e.touching|=c.UP,f.touching|=c.DOWN):g=0),0!=g){var q=e.velocity.y,r=f.velocity.y;if(e.immovable||f.immovable)e.immovable?f.immovable||(f.transform.y=f.transform.y+g,f.velocity.y=q-r*f.elasticity,b.active&&e.moves&&i>h&&(f.transform.x=f.transform.worldX+b.transform.worldX-e.last.x)):(e.transform.y=e.transform.y-g,e.velocity.y=r-q*e.elasticity,d.active&&f.moves&&h>i&&(e.transform.x=e.transform.worldX+d.transform.worldX-f.last.x));else{g*=.5,e.transform.y=e.transform.y-g,f.transform.y=f.transform.y+g;var s=Math.sqrt(r*r*f.mass/e.mass)*(r>0?1:-1),t=Math.sqrt(q*q*e.mass/f.mass)*(q>0?1:-1),u=.5*(s+t);s-=u,t-=u,e.velocity.y=u+s*e.elasticity,f.velocity.y=u+t*f.elasticity}return!0}}return!1},c.separateTiles=function(a,b,c){if(0==a.components.hasComponent("ArcadePhysics"))return!1;if(a.components.getComponent("ArcadePhysics").immovable)return!1;for(var d=!1,e=!1,f=0;f<c.length;f++){var g=c[f];d||(d=this.separateTilesX(a,b,g)),e||(e=this.separateTilesY(a,b,g))}return d||e},c.separateTilesX=function(b,d,e){var f=b.components.getComponent("ArcadePhysics"),g=d.components.getComponent("ArcadePhysics"),h=f.transform.worldX-f.last.x,i=g.transform.worldX-g.last.x;if(h==i)return!1;var j=h>0?h:-h,k=i>0?i:-i,l=0,m=j+k+c.OVERLAP_BIAS,n=f.box.worldHitbox,o=d.tilemap.tileTypes,p=d.tileData,q=g.transform.worldX+e.x,r=new a.Geom.Rectangle(n.x-(h>0?h:0),f.last.y+f.box.hitboxOffset.y,n.width+(h>0?h:-h),n.height),s=new a.Geom.Rectangle(q-(i>0?i:0),g.last.y+e.y,d.tileWidth+(i>0?i:-i),d.tileHeight);if(r.x+r.width>s.x&&r.x<s.x+s.width&&r.y+r.height>s.y&&r.y<s.y+s.height&&(h>i?(l=n.x+n.width-q,!(l>m)&&f.allowCollisions&c.RIGHT&&o[p[e.index]].allowCollisions&c.LEFT?f.touching|=c.RIGHT:l=0):(l=n.x-d.tileWidth-q,!(-l>m)&&f.allowCollisions&c.LEFT&&o[p[e.index]].allowCollisions&c.RIGHT?f.touching|=c.LEFT:l=0),0!=l)){var t=f.velocity.x,u=g.velocity.x;return f.transform.x=f.transform.x-l,f.velocity.x=u-t*f.elasticity,!0}return!1},c.separateTilesY=function(b,d,e){var f=b.components.getComponent("ArcadePhysics"),g=d.components.getComponent("ArcadePhysics"),h=f.transform.worldY-f.last.y,i=g.transform.worldY-g.last.y;if(h==i)return!1;var j=h>0?h:-h,k=i>0?i:-i,l=0,m=j+k+c.OVERLAP_BIAS,n=f.box.worldHitbox,o=d.tilemap.tileTypes,p=d.tileData,q=d.transform.worldY+e.y,r=new a.Geom.Rectangle(n.x,n.y-(h>0?h:0),n.width,n.height+j),s=new a.Geom.Rectangle(g.transform.worldX+e.x,q-(i>0?i:0),d.tileWidth,d.tileHeight+k);if(r.x+r.width>s.x&&r.x<s.x+s.width&&r.y+r.height>s.y&&r.y<s.y+s.height&&(h>i?(l=n.y+n.height-q,!(l>m)&&f.allowCollisions&c.DOWN&&o[p[e.index]].allowCollisions&c.UP?f.touching|=c.DOWN:l=0):(l=n.y-d.tileHeight-q,!(-l>m)&&f.allowCollisions&c.UP&&o[p[e.index]].allowCollisions&c.DOWN?f.touching|=c.UP:l=0),0!=l)){var t=f.velocity.y,u=g.velocity.y;return f.transform.y=f.transform.y-l,f.velocity.y=u-t*f.elasticity,!0}return!1},c.prototype.overlapsTiles=function(b,d,e){if(void 0===d&&(d=!1),void 0===e&&(e=a.Components.ArcadePhysics.ANY),this.parent.childType()!==a.TILE_LAYER)return!1;var f=this.parent.getOverlappingTiles(b,e);return f.length>0?(d&&c.separateTiles(b,this.parent,f),!0):!1},c.prototype.overlaps=function(a,b){if(void 0===b&&(b=!1),0!=a.components.hasComponent("Box")){var d=a.components.getComponent("Box"),e=d.worldHitbox.x+d.worldHitbox.width>this.box.worldHitbox.x&&d.worldHitbox.x<this.box.worldHitbox.x+this.box.worldHitbox.width&&d.worldHitbox.y+d.worldHitbox.height>this.box.worldHitbox.y&&d.worldHitbox.y<this.box.worldHitbox.y+this.box.worldHitbox.height;return e&&(b&&c.separate(this.owner,a),null!==this._callbackFunction&&null!==this._callbackContext&&this._callbackFunction.call(this._callbackContext,this.owner,a)),e}},c.prototype.overlapsGroup=function(b,c){void 0===c&&(c=!1);for(var d=!1,e=0;e<b.members.length;e++)b.members[e].childType()===a.GROUP?this.overlapsGroup(b.members[e],c):this.overlaps(b.members[e],c)&&(null!==this._callbackContext&&null!==this._callbackFunction&&this._callbackFunction.call(this._callbackContext,this.owner,b.members[e]),d=!0);return d},c.prototype.overlapsArray=function(b,c){void 0===c&&(c=!1);for(var d=!1,e=0;e<b.length;e++)"undefined"!=typeof b[e].childType&&(b[e].childType()==a.GROUP?this.overlapsGroup(b[e],c):this.overlaps(b[e],c)&&(null!==this._callbackFunction&&null!==this._callbackContext&&this._callbackFunction.call(this._callbackContext,this.owner,b[e]),d=!0));return d},c.computeVelocity=function(a,b,d,e){return void 0===b&&(b=0),void 0===d&&(d=0),void 0===e&&(e=1e4),0!=b?a+=b*c.updateInterval:0!=d&&(d*=c.updateInterval,a-d>0?a-=d:0>a+d?a+=d:a=0),0!=a&&1e4!=e&&(a>e?a=e:-e>a&&(a=-e)),a},c.prototype.updateMotion=function(){var a,b;b=(c.computeVelocity(this.angularVelocity,this.angularAcceleration,this.angularDrag,this.maxAngular)-this.angularVelocity)/2,this.angularVelocity+=b,this.transform.rotation+=this.angularVelocity*c.updateInterval,this.angularVelocity+=b,b=(c.computeVelocity(this.velocity.x,this.acceleration.x,this.drag.x,this.maxVelocity.x)-this.velocity.x)/2,this.velocity.x+=b,a=this.velocity.x*c.updateInterval,this.velocity.x+=b,this.transform.x=this.transform.x+a,b=(c.computeVelocity(this.velocity.y,this.acceleration.y,this.drag.y,this.maxVelocity.y)-this.velocity.y)/2,this.velocity.y+=b,a=this.velocity.y*c.updateInterval,this.velocity.y+=b,this.transform.y=this.transform.y+a},c.prototype.update=function(){this.last.x=this.transform.worldX,this.last.y=this.transform.worldY,this.moves&&this.updateMotion(),this.wasTouching=this.touching,this.touching=c.NONE},c.prototype.destroy=function(){b.prototype.destroy.call(this),delete this.transform,delete this.owner,delete this._callbackContext,delete this._callbackFunction},c.prototype.objType=function(){return"ArcadePhysics"},c.collide=function(a,b,d){return void 0===d&&(d=!0),c.overlaps(a,b,d)},c.collideGroup=function(a,b,d){return void 0===d&&(d=!0),c.overlapsObjectGroup(a,b,d)},c.collideGroupGroup=function(a,b,d){return void 0===d&&(d=!0),c.overlapsGroupGroup(a,b,d)},c.overlaps=function(a,b,c){void 0===c&&(c=!0);var d=a.components.getComponent("ArcadePhysics");return d.overlaps(b,c)},c.overlapsObjectGroup=function(a,b,c){void 0===c&&(c=!0);var d=a.components.getComponent("ArcadePhysics");return d.overlapsGroup(b,c)},c.overlapsGroupGroup=function(b,d,e){void 0===e&&(e=!0);for(var f=!1,g=b.members,h=0;h<b.members.length;)g[h].childType()==a.GROUP?c.overlapsGroupGroup(g[h++],d,e)&&(f=!0):c.overlapsObjectGroup(g[h++],d,e)&&(f=!0);return f},c.overlapsArrayGroup=function(b,d,e){void 0===e&&(e=!0);for(var f=!1,g=0;g<b.length;g++)"undefined"!=typeof b[g].childType&&(b[g].childType()===a.GROUP?c.overlapsGroupGroup(b[g],d,e)&&(f=!0):c.overlapsObjectGroup(b[g],d,e)&&(f=!0));return f},c.updateInterval=.1,c.LEFT=1,c.RIGHT=16,c.UP=256,c.DOWN=4096,c.NONE=0,c.CEILING=c.UP,c.FLOOR=c.DOWN,c.WALL=c.LEFT|c.RIGHT,c.ANY=c.LEFT|c.RIGHT|c.UP|c.DOWN,c.OVERLAP_BIAS=4,c}(a.Component);b.ArcadePhysics=c}(b=a.Components||(a.Components={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._queueLoading=!1,this.percentLoaded=0,this.enableParallelLoading=!1,this._completedFiles=0,this._calculateBytes=!1,this._currentFileIndex=0,this._bytesTotal=0,this._bytesLoaded=0,this.game=a}return b.prototype.objType=function(){return"Loader"},Object.defineProperty(b.prototype,"queueLoading",{get:function(){return this._queueLoading},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._loadingList=[],this._loadingParallel=[],this._loadingQueue=[],this.onQueueComplete=new a.Signal,this.onQueueProgress=new a.Signal},b.prototype.start=function(b){return void 0===b&&(b=null),null!==b&&(this._calculateBytes=b),this._queueLoading?void a.Log.warn("Kiwi.Files.Loader: Files in the queue are already being loaded"):(this._bytesLoaded=0,this._bytesTotal=0,this.percentLoaded=0,void(this._calculateBytes?this.calculateQueuedSize(this._startLoading,this):this._startLoading()))},b.prototype._startLoading=function(){if(this._loadingList.length<=0)return a.Log.log("Kiwi.Files.Loader: No files are to load have been found.","#loading"),this.onQueueProgress.dispatch(100,0,null),void this.onQueueComplete.dispatch();for(var b=0;b<this._loadingList.length;)this._calculateBytes&&this._loadingList[b].onProgress.add(this._updateFileListInformation,this),this._sortFile(this._loadingList[b]),this._loadingList[b].onComplete.addOnce(this._fileQueueUpdate,this),b++;this._queueLoading=!0,this._bytesLoaded=0,this._startLoadingQueue(),this._startLoadingAllParallel(),this._fileQueueUpdate(null,!0)},b.prototype.addFileToQueue=function(b){return this._queueLoading?(a.Log.warn("Kiwi.Files.Loader: File cannot be added to the queue whilst the queue is currently loading.","#loading","#filequeue"),!1):b.loading||b.complete?(a.Log.warn("Kiwi.Files.Loader: File could not be added as it is currently loading or has already loaded.","#loading","#filequeue"),!1):(this._loadingList.push(b),!0)},b.prototype.removeFileFromQueue=function(b){if(this._queueLoading)return a.Log.warn("Kiwi.Files.Loader: File cannot be remove from the queue whilst the queue is currently loading.","#loading","#filequeue"),!1;var c=this._loadingList.indexOf(b);return-1===c?!1:b.loading?(a.Log.warn("Kiwi.Files.Loader: Cannot remove the file from the list as it is currently loading.","#loading","#filequeue"),!1):(this._loadingList.splice(c,1),!0)},b.prototype.clearQueue=function(){this._queueLoading?a.Log.error("Kiwi.Files.Loader: Cannot clear the file queue whilst the files are being loaded.","#loading","#filequeue"):this._loadingList.length=0},b.prototype.loadFile=function(b){return b.loading||b.complete?void a.Log.error("Kiwi.Files.Loader: Could not add file. File is already loading or has completed loading."):void this._sortFile(b,!0)},b.prototype._sortFile=function(a,b){void 0===b&&(b=!1),this.enableParallelLoading&&a.loadInParallel?(this._loadingParallel.push(a),b&&this._startLoadingParallel(a)):(this._loadingQueue.push(a),b&&this._startLoadingQueue())},b.prototype._updateFileListInformation=function(){var a=0;for(this._completedFiles=0,this._bytesLoaded=0;a<this._loadingList.length;)this._bytesLoaded+=0===this._loadingList[a].bytesLoaded&&this._loadingList[a].success&&this._loadingList[a].detailsReceived?this._loadingList[a].size:this._loadingList[a].bytesLoaded,this._loadingList[a].complete&&this._completedFiles++,a++;this.percentLoaded=this._calculateBytes?this._bytesLoaded/this._bytesTotal*100:this._completedFiles/this._loadingList.length*100},b.prototype._fileQueueUpdate=function(a,b){void 0===b&&(b=!1),(b||-1!==this._loadingList.indexOf(a))&&(this._updateFileListInformation(),this.onQueueProgress.dispatch(this.percentLoaded,this.bytesLoaded,a),this._completedFiles>=this._loadingList.length&&(this._queueLoading=!1,this.clearQueue(),this.onQueueComplete.dispatch()))},b.prototype._startLoadingQueue=function(){return this._loadingQueue.length<=0?(a.Log.log("Kiwi.Files.Loader: No queued files to load.","#loading"),!1):this._loadingQueue[0].loading?!1:(this._loadingQueue[0].onComplete.addOnce(this._queueFileComplete,this,1),this._loadingQueue[0].load(),!0)},b.prototype._queueFileComplete=function(b){var c=this._loadingQueue.indexOf(b);return-1===c?void a.Log.warn("Something has gone wrong? The file which executed this method doesn't exist in the loadingQueue.","#loading","#error"):(this._loadingQueue.splice(c,1),void this._startLoadingQueue())},b.prototype._startLoadingParallel=function(a){a.loading||(a.onComplete.add(this._parallelFileComplete,this,1),a.load())},b.prototype._startLoadingAllParallel=function(){for(var a=0;a<this._loadingParallel.length;)this._startLoadingParallel(this._loadingParallel[a]),a++},b.prototype._parallelFileComplete=function(b){var c=this._loadingParallel.indexOf(b);return-1===c?void a.Log.warn("Something has gone wrong? The file which executed this method doesn't exist in the loadingParallel.","#loading","#error"):void this._loadingParallel.splice(c,1)},Object.defineProperty(b.prototype,"bytesTotal",{get:function(){return this._bytesTotal},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"bytesLoaded",{get:function(){return this._bytesLoaded},enumerable:!0,configurable:!0}),b.prototype.calculateQueuedSize=function(b,c){return void 0===c&&(c=null),this._queueLoading?void a.Log.warn("Kiwi.Files.Loader: Cannot calculate the size of the files in the filequeue whilst they are loading. "):(this.onSizeCallback=b,this.onSizeContext=c,this._currentFileIndex=0,this._bytesTotal=0,this._queueLoading=!0,void this._calculateNextFileSize())},b.prototype._calculateNextFileSize=function(){if(this._currentFileIndex>=this._loadingList.length)return this._queueLoading=!1,void this.onSizeCallback.call(this.onSizeContext,this._bytesTotal);var a=this._loadingList[this._currentFileIndex];if(a.detailsReceived)this._detailsReceived();else{var b=a.loadDetails(this._detailsReceived,this);b||this._detailsReceived()}},b.prototype._detailsReceived=function(){var a=this._loadingList[this._currentFileIndex];a.detailsReceived&&(this._bytesTotal+=a.size),this._currentFileIndex++,this._calculateNextFileSize()},b.prototype.addImage=function(b,c,d,e,f,g,h){void 0===h&&(h=!0);var i={type:a.Files.File.IMAGE,key:null,url:null,fileStore:this.game.fileStore,metadata:{}};if(a.Utils.Common.isObject(b)){var j=b;i.key=j.key,i.url=j.url,i.metadata={width:j.width,height:j.height,offsetX:j.offsetX,offsetY:j.offsetY},j.xhrLoading&&(i.xhrLoading=j.xhrLoading),j.state&&(i.state=j.state),j.tags&&(i.tags=j.tags)}else!h&&this.game.states.current&&(i.state=this.game.states.current),i.key=b,i.url=c,i.metadata={width:d,height:e,offsetX:f,offsetY:g};var k=new a.Files.TextureFile(this.game,i);return this.addFileToQueue(k),k},b.prototype.addSpriteSheet=function(b,c,d,e,f,g,h,i,j,k,l,m){void 0===m&&(m=!0);var n={type:a.Files.File.SPRITE_SHEET,key:null,url:null,fileStore:this.game.fileStore,metadata:{}};if(a.Utils.Common.isObject(b)){var o=b;n.key=o.key,n.url=o.url,n.metadata={frameWidth:o.frameWidth,frameHeight:o.frameHeight,numCells:o.numCells,rows:o.rows,cols:o.cols,sheetOffsetX:o.sheetOffsetX,sheetOffsetY:o.sheetOffsetY,cellOffsetX:o.cellOffsetX,cellOffsetY:o.cellOffsetY},o.xhrLoading&&(n.xhrLoading=o.xhrLoading),o.state&&(n.state=o.state),o.tags&&(n.tags=o.tags)}else!m&&this.game.states.current&&(n.state=this.game.states.current),n.key=b,n.url=c,n.metadata={frameWidth:d,frameHeight:e,numCells:f,rows:g,cols:h,sheetOffsetX:i,sheetOffsetY:j,cellOffsetX:k,cellOffsetY:l};var p=new a.Files.TextureFile(this.game,n);return this.addFileToQueue(p),p},b.prototype.addTextureAtlas=function(b,c,d,e,f){void 0===f&&(f=!0);var g={type:a.Files.File.TEXTURE_ATLAS,key:b,url:c,fileStore:this.game.fileStore,metadata:{jsonID:d}},h={type:a.Files.File.JSON,key:d,url:e,fileStore:this.game.fileStore,metadata:{imageID:b}};if(!f&&this.game.states.current&&(g.state=this.game.states.current,h.state=this.game.states.current),a.Utils.Common.isObject(b)){var i=b;g.key=i.textureAtlasKey,g.url=i.textureAtlasURL,h.key=i.jsonKey,h.url=i.jsonURL,g.metadata.jsonID=h.key,h.metadata.imageID=g.key,i.state&&(g.state=i.state,h.state=i.state),i.xhrLoading&&(g.xhrLoading=i.xhrLoading),i.tags&&(h.tags=i.tags,g.tags=i.tags)}var j=new a.Files.TextureFile(this.game,g),k=new a.Files.DataFile(this.game,h);return this.addFileToQueue(j),this.addFileToQueue(k),j},b.prototype.addAudio=function(b,c,d,e){void 0===d&&(d=!0),void 0===e&&(e=!0);var f={type:a.Files.File.AUDIO,key:null,url:null,state:null,fileStore:this.game.fileStore};a.Utils.Common.isObject(b)?(f=b,f.fileStore=this.game.fileStore):(f.key=b,f.url=c,!d&&this.game.states.current&&(f.state=this.game.states.current));var g,h,i=0;for(g=a.Utils.Common.isString(f.url)?[f.url]:f.url;i<g.length;){if(f.url=g[i],h=this._attemptToAddAudio(f,e))return h;i++}return null},b.prototype._attemptToAddAudio=function(b,c){var d=new a.Files.AudioFile(this.game,b),e=!1;switch(d.extension){case"mp3":e=a.DEVICE.mp3;break;case"ogg":case"oga":e=a.DEVICE.ogg;break;case"m4a":e=a.DEVICE.m4a;break;case"wav":case"wave":e=a.DEVICE.wav}return 1==e||0==c?(this.addFileToQueue(d),d):(a.Log.error("Kiwi.Loader: Audio Format not supported on this Device/Browser.","#audio","#unsupported"),null)},b.prototype.addJSON=function(b,c,d){void 0===d&&(d=!0);var e={type:a.Files.File.JSON,key:b,url:c,fileStore:this.game.fileStore};if(a.Utils.Common.isObject(b)){var f=b;e.key=f.key,e.url=f.url,f.parse&&(e.parse=f.parse),f.state&&(e.state=f.state),f.tags&&(e.tags=f.tags)}else!d&&this.game.states.current&&(e.state=this.game.states.current);var g=new a.Files.DataFile(this.game,e);return this.addFileToQueue(g),g},b.prototype.addXML=function(b,c,d){void 0===d&&(d=!0);var e={type:a.Files.File.XML,key:b,url:c,fileStore:this.game.fileStore};if(a.Utils.Common.isObject(b)){var f=b;e.key=f.key,e.url=f.url,f.parse&&(e.parse=f.parse),f.state&&(e.state=f.state),f.tags&&(e.tags=f.tags)}else!d&&this.game.states.current&&(e.state=this.game.states.current);var g=new a.Files.DataFile(this.game,e);return this.addFileToQueue(g),g},b.prototype.addBinaryFile=function(b,c,d){void 0===d&&(d=!0);var e={type:a.Files.File.BINARY_DATA,key:b,url:c,fileStore:this.game.fileStore};if(a.Utils.Common.isObject(b)){var f=b;e.key=f.key,e.url=f.url,f.parse&&(e.parse=f.parse),f.state&&(e.state=f.state),f.tags&&(e.tags=f.tags)}else!d&&this.game.states.current&&(e.state=this.game.states.current);var g=new a.Files.DataFile(this.game,e);return this.addFileToQueue(g),g},b.prototype.addTextFile=function(b,c,d){void 0===d&&(d=!0);var e={type:a.Files.File.TEXT_DATA,key:b,url:c,fileStore:this.game.fileStore};if(a.Utils.Common.isObject(b)){var f=b;e.key=f.key,e.url=f.url,f.parse&&(e.parse=f.parse),f.state&&(e.state=f.state),f.tags&&(e.tags=f.tags)}else!d&&this.game.states.current&&(e.state=this.game.states.current);var g=new a.Files.DataFile(this.game,e);return this.addFileToQueue(g),g},b.prototype.destroy=function(){this.onQueueComplete.dispose(),this.onQueueProgress.dispose(),delete this.game,delete this.onQueueComplete,delete this.onQueueProgress;for(var a=0;a<this._loadingList.length;)this._loadingList[a].destroy(),a++;this._loadingList=[];for(var a=0;a<this._loadingQueue.length;)this._loadingQueue[a].destroy(),a++;this._loadingQueue=[];for(var a=0;a<this._loadingParallel.length;)this._loadingParallel[a].destroy(),a++;this._loadingParallel=[]},b.prototype.init=function(a,b,c){void 0===a&&(a=null),void 0===b&&(b=null),void 0===c&&(c=null),null!==c&&(this._calculateBytes=c),null!==a&&this.onQueueProgress.addOnce(a),null!==b&&this.onQueueComplete.addOnce(b)},b.prototype.startLoad=function(){this.start()},b.prototype.getPercentLoaded=function(){return this.percentLoaded},b.prototype.complete=function(){return 100===this.percentLoaded},b.prototype.calculateBytes=function(a){return"undefined"!=typeof a&&(this._calculateBytes=a),this._calculateBytes},b.prototype.getBytesLoaded=function(){return this.bytesLoaded},b}();b.Loader=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._game=a,this.data={}}return b.prototype.objType=function(){return"DataLibrary"},b.prototype.clear=function(){for(var a in this.data)delete this.data[a]},b.prototype.add=function(b){switch(b.dataType){case a.Files.File.JSON:case a.Files.File.XML:case a.Files.File.BINARY_DATA:case a.Files.File.TEXT_DATA:this.data[b.key]=b}},b.prototype.rebuild=function(b,c){this.clear(),a.Log.log("Kiwi.DataLibrary: Rebuilding Data Library","#rebuild");for(var d=b.keys,e=0;e<d.length;e++){var f=this._game.fileStore.getFile(d[e]);f.isData&&(a.Log.log("  Kiwi.DataLibrary: Adding Data: "+f.name,"#rebuild","#adding"),c.dataLibrary.add(f))}},b}();b.DataLibrary=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c){this._loadInParallel=!1,this.useTagLoader=!1,this.size=0,this.timeOutDelay=a.Files.File.TIMEOUT_DELAY,this.attemptCounter=0,this.maxLoadAttempts=a.Files.File.MAX_LOAD_ATTEMPTS,this.timeStarted=0,this.lastProgress=0,this.timeFinished=0,this.duration=0,this.hasError=!1,this.success=!1,this.loading=!1,this.complete=!1,this.percentLoaded=0,this.bytesLoaded=0,this.bytesTotal=0,this.detailsReceived=!1,this.ETag="",this.lastModified="",this.status=0,this.statusText="",this.readyState=0,this.hasTimedOut=!1,this.timedOut=0,this.game=b,this.onComplete=new a.Signal,this.onProgress=new a.Signal,a.Utils.Common.isNumeric(c)?this._parseParamsOld(c,arguments[2],arguments[3],arguments[4],arguments[5]):(this.key=c.key,this._assignFileDetails(c.url),this.parseParams(c))}return b.prototype._parseParamsOld=function(a,b,c,d,e){void 0===c&&(c=""),void 0===d&&(d=!0),void 0===e&&(e=!0),this.dataType=a,this._assignFileDetails(b),d&&(this.fileStore=this.game.fileStore),this.game.states.current&&!e&&(this.ownerState=this.game.states.current)},b.prototype.parseParams=function(c){if(this.fileStore=c.fileStore||null,this.ownerState=c.state||null,this.metadata=c.metadata||{},this.dataType=a.Utils.Common.isUndefined(c.type)?b.UNKNOWN:c.type,c.tags&&a.Utils.Common.isArray(c.tags))for(var d=0;d<c.tags.length;d++)this.addTag(c.tags[d])},b.prototype._assignFileDetails=function(a){this.URL=a,a.lastIndexOf("/")>-1?(this.name=a.substr(a.lastIndexOf("/")+1),this.path=a.substr(0,a.lastIndexOf("/")+1)):(this.path="",this.name=a),this.extension=a.substr(a.lastIndexOf(".")+1).toLowerCase()},b.prototype.objType=function(){return"File"},Object.defineProperty(b.prototype,"loadInParallel",{get:function(){return this._loadInParallel},enumerable:!0,configurable:!0}),b.prototype.load=function(b,c,d,e,f){return this.loading?void a.Log.error("Kiwi.Files.File: File loading is in progress. Cannot be told to load again.","#loading"):(a.Log.log("Kiwi.Files.File: Starting to load '"+this.name+"'","#file","#loading"),b&&this.onComplete.add(b),c&&this.onProgress.add(c),d&&(this.fileStore=d),"undefined"!=typeof e&&(this.maxLoadAttempts=e),"undefined"!=typeof f&&(this.timeOutDelay=f),this._start(),void this._load())},b.prototype._load=function(){this.attemptCounter++,this.xhrLoader("GET","text")},b.prototype.loadProgress=function(){this.onProgress.dispatch(this)},b.prototype.loadSuccess=function(){this.complete||(this.success=!0,this.hasError=!1,this._stop(),this.fileStore&&this.fileStore.addFile(this.key,this),this.onComplete.dispatch(this))},b.prototype.loadError=function(b){this.attemptCounter>=this.maxLoadAttempts?(a.Log.log("Kiwi.Files.File: Failed to load file '"+this.name+"'. Trying Again","#loading"),this.hasError=!0,this.success=!1,this.error=b,this._stop(),this.onComplete.dispatch(this)):(a.Log.log("Kiwi.Files.File: Failed to load file '"+this.name+"'","#loading"),this._load())},b.prototype.xhrLoader=function(a,b,c){var d=this;void 0===a&&(a="GET"),void 0===b&&(b="text"),void 0===c&&(c=this.timeOutDelay),this._xhr=new XMLHttpRequest,this._xhr.open("GET",this.URL,!0),null!==c&&(this._xhr.timeout=c),this._xhr.responseType=b,this._xhr.onload=function(a){return d.xhrOnLoad(a)},this._xhr.onerror=function(a){return d.loadError(a)},this._xhr.onprogress=function(a){return d.xhrOnProgress(a)},this._xhr.onreadystatechange=function(){return function(){this.readyState=this._xhr.readyState}},this._xhr.onloadstart=function(){return function(a){this.timeStarted=a.timeStamp,this.lastProgress=a.timeStamp}},this._xhr.ontimeout=function(){return function(){this.hasTimedOut=!0}},this._xhr.send()},b.prototype.xhrOnProgress=function(a){this.bytesLoaded=parseInt(a.loaded),this.bytesTotal=parseInt(a.total),this.percentLoaded=Math.round(this.bytesLoaded/this.bytesTotal*100),this.onProgress.dispatch(this)},b.prototype.xhrOnLoad=function(a){this.status=this._xhr.status,this.statusText=this._xhr.statusText,this._xhr.response?(this._getXhrHeaderInfo(),this.buffer=this._xhr.response,this.processXhr(this._xhr.response)):this.loadError(a)},b.prototype.processXhr=function(a){this.data=a,this.loadSuccess()},b.prototype._start=function(){this.attemptCounter=0,this.loading=!0,this.timeStarted=Date.now(),this.percentLoaded=0},b.prototype._stop=function(){this.loading=!1,this.complete=!0,this.percentLoaded=100,this.timeFinished=Date.now(),this.duration=this.timeFinished-this.timeStarted},b.prototype.loadDetails=function(b,c){return void 0===b&&(b=null),void 0===c&&(c=null),this.loading?(a.Log.error("Kiwi.Files.File: Cannot get the file details whilst the file is already loading"),!1):(b&&(this.headCompleteCallback=b),c&&(this.headCompleteContext=c),this.xhrHeadRequest(),!0)},b.prototype._getXhrHeaderInfo=function(){this._xhr&&(this.status=this._xhr.status,this.statusText=this._xhr.statusText,this.type=this._xhr.getResponseHeader("Content-Type"),this.size=parseInt(this._xhr.getResponseHeader("Content-Length")),this.lastModified=this._xhr.getResponseHeader("Last-Modified"),this.ETag=this._xhr.getResponseHeader("ETag"),this.detailsReceived=!0)},b.prototype.xhrHeadRequest=function(){var a=this;this._xhr=new XMLHttpRequest,this._xhr.open("HEAD",this.fileURL,!0),null!==this.timeOutDelay&&(this._xhr.timeout=this.timeOutDelay),this._xhr.onload=function(b){return a.xhrHeadOnLoad(b)},this._xhr.onerror=function(b){return a.xhrHeadOnError(b)},this._xhr.send()},b.prototype.xhrHeadOnError=function(){this.headCompleteCallback&&this.headCompleteCallback.call(this.headCompleteContext,!1)},b.prototype.xhrHeadOnLoad=function(){200===this._xhr.status?(this._getXhrHeaderInfo(),this.headCompleteCallback&&this.headCompleteCallback.call(this.headCompleteContext,!0)):this.xhrHeadOnError(null)},b.prototype.addTag=function(a){-1==this._tags.indexOf(a)&&this._tags.push(a)},b.prototype.removeTag=function(a){var b=this._tags.indexOf(a);-1!=b&&this._tags.splice(b,1)},b.prototype.hasTag=function(a){return-1==this._tags.indexOf(a)?!1:!0},Object.defineProperty(b.prototype,"isTexture",{get:function(){return a.Files.TextureFile.prototype.objType.call(this)===this.objType()},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"isAudio",{get:function(){return a.Files.AudioFile.prototype.objType.call(this)===this.objType()},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"isData",{get:function(){return a.Files.DataFile.prototype.objType.call(this)===this.objType()},enumerable:!0,configurable:!0}),b.prototype.destroy=function(){this.fileStore&&this.fileStore.removeFile(this.key),this.onComplete.dispose(),this.onProgress.dispose(),delete this.fileStore,delete this._xhr,delete this.data,delete this.buffer,delete this.game,delete this.error,delete this.headCompleteCallback,delete this.headCompleteContext,delete this.onComplete,delete this.onProgress,delete this.ownerState},Object.defineProperty(b.prototype,"fileName",{get:function(){return this.name},set:function(a){this.name=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"filePath",{get:function(){return this.path},set:function(a){this.path=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"fileExtension",{get:function(){return this.extension},set:function(a){this.extension=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"fileURL",{get:function(){return this.URL},set:function(a){this.URL=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"fileType",{get:function(){return this.type},set:function(a){this.type=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"fileSize",{get:function(){return this.size},set:function(a){this.size=a},enumerable:!0,configurable:!0}),b.prototype.getFileDetails=function(a,b,c){void 0===a&&(a=null),void 0===c&&(c=null),c&&(this.timeOutDelay=c),this.loadDetails(a,null)},b.TIMEOUT_DELAY=4e3,b.MAX_LOAD_ATTEMPTS=2,b.IMAGE=0,b.SPRITE_SHEET=1,b.TEXTURE_ATLAS=2,b.AUDIO=3,b.JSON=4,b.XML=5,b.BINARY_DATA=6,b.TEXT_DATA=7,b.UNKNOWN=8,b}();b.File=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a){this._size=0,this._game=a,this._files={}}return a.prototype.objType=function(){return"FileStore"},a.prototype.boot=function(){},a.prototype.getFile=function(a){return this._files[a]},a.prototype.getFilesByTag=function(a){var b={};for(var c in this._files)this._files[c].hasTag(a)&&(b[c]=this._files[c]);return b},a.prototype.removeFilesByTag=function(a){var b=0;for(var c in this._files)this._files[c].hasTag(a)&&(this.removeFile(c),b++);return b},Object.defineProperty(a.prototype,"keys",{get:function(){var a=new Array;for(var b in this._files)a.push(b);return a},enumerable:!0,configurable:!0}),a.prototype.size=function(){return this._size},a.prototype.addFile=function(a,b){return this._files[a]?!1:(this._files[a]=b,this._size++,!0)},a.prototype.exists=function(a){return this._files[a]?!0:!1},a.prototype.removeStateFiles=function(a){for(var b in this._files)this._files[b].ownerState===a&&this.removeFile(b)},a.prototype.removeFile=function(a,b){void 0===b&&(b=!1);var c=this._files[a];return c?(this._files[a]=null,delete this._files[a],b&&this._files[a].destroy(),!0):!1},a}();a.FileStore=b}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){this.isReady=!1,this.container=null,this.input=null}return b.prototype.objType=function(){return"Bootstrap"},b.prototype.boot=function(a,b,c){var d=this;void 0===b&&(b=null),void 0===c&&(c=!0),this._callback=b,this._domParent=a,this._createContainer=c,"complete"===document.readyState||"interactive"===document.readyState?this.ready():(document.addEventListener("DOMContentLoaded",function(){return d.ready()
 },!1),window.addEventListener("load",function(){return d.ready()},!1))},b.prototype.ready=function(){var b=this;this.isReady!==!0&&(document.body?(this.isReady=!0,this._createContainer===!0&&(""===this._domParent?(a.Log.log("  Kiwi.Game: No DOM parent specified. Appending the game to the body.","#dom"),this.container=document.createElement("div"),this._setupContainer("KiwiGame"+Date.now().toString()),document.body.appendChild(this.container)):document.querySelector(this._domParent)?(a.Log.log("  Kiwi.Game: Game being created inside '"+this._domParent+"'.","#dom"),this.container=document.querySelector(this._domParent),this._setupContainer()):document.getElementById(this._domParent)?(a.Log.log("  Kiwi.Game: Game being created inside '"+this._domParent+"'.","#dom"),this.container=document.getElementById(this._domParent),this._setupContainer()):(a.Log.log("  Kiwi.Game: The element '"+this._domParent+"' could not be found. Appending the game to the body.","#dom"),this.container=document.createElement("div"),this._setupContainer(this._domParent),document.body.appendChild(this.container))),null!==this._callback&&this._callback()):window.setTimeout(function(){return b.ready()},13))},b.prototype._setupContainer=function(b){void 0===b&&(b=""),b&&(this.container.id=b),this.container.style.width=a.Stage.DEFAULT_WIDTH+"px",this.container.style.height=a.Stage.DEFAULT_HEIGHT+"px",this.container.style.position="relative",this.container.style.overflow="hidden"},b}();b.Bootstrap=c}(b=a.System||(a.System={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){this.iOS=!1,this.android=!1,this.chromeOS=!1,this.linux=!1,this.macOS=!1,this.windows=!1,this.windowsPhone=!1,this.canvas=!1,this.file=!1,this.fileSystem=!1,this.localStorage=!1,this.webGL=!1,this.worker=!1,this.blob=!1,this.touch=!1,this.pointerEnabled=!1,this.arora=!1,this.chrome=!1,this.epiphany=!1,this.firefox=!1,this.ie=!1,this.ieVersion=0,this.ieMobile=!1,this.mobileSafari=!1,this.midori=!1,this.opera=!1,this.safari=!1,this.webApp=!1,this.audioData=!1,this.webaudio=!1,this.ogg=!1,this.mp3=!1,this.wav=!1,this.m4a=!1,this.iPhone=!1,this.iPhone4=!1,this.iPad=!1,this.pixelRatio=0,this._checkAudio(),this._checkBrowser(),this._checkDevice(),this._checkFeatures(),this._checkOS()}return a.prototype.objType=function(){return"Device"},a.prototype._checkOS=function(){var a=navigator.userAgent;/Android/.test(a)?this.android=!0:/CrOS/.test(a)?this.chromeOS=!0:/iP[ao]d|iPhone/i.test(a)?this.iOS=!0:/Linux/.test(a)?this.linux=!0:/Mac OS/.test(a)?this.macOS=!0:/Windows Phone/.test(a)?this.windowsPhone=!0:/Windows/.test(a)&&(this.windows=!0)},a.prototype._checkFeatures=function(){"undefined"!=typeof window.Blob&&(this.blob=!0),this.canvas=!!window.CanvasRenderingContext2D,this.webGL=!!window.WebGLRenderingContext;try{this.localStorage=!!localStorage.getItem}catch(a){this.localStorage=!1}this.file=!!(window.File&&window.FileReader&&window.FileList&&window.Blob),this.fileSystem=!!window.requestFileSystem,this.worker=!!window.Worker,("ontouchstart"in document.documentElement||window.navigator.msPointerEnabled&&window.navigator.msMaxTouchPoints>0||window.navigator.pointerEnabled&&window.navigator.maxTouchPoints>0)&&(this.touch=!0),(window.navigator.pointerEnabled||window.navigator.msPointerEnabled)&&(this.pointerEnabled=!0)},a.prototype._checkBrowser=function(){{var a=navigator.userAgent;navigator.appName}/Arora/.test(a)?this.arora=!0:/Chrome/.test(a)?this.chrome=!0:/Epiphany/.test(a)?this.epiphany=!0:/Firefox/.test(a)?this.firefox=!0:/Mobile Safari/.test(a)?this.mobileSafari=!0:/MSIE (\d+\.\d+);/.test(a)?(this.ie=!0,this.ieVersion=parseInt(RegExp.$1),/IEMobile/.test(a)&&(this.ieMobile=!0)):/Trident/.test(a)?(this.ie=!0,/rv:(\d+\.\d+)\)/.test(a),this.ieVersion=parseInt(RegExp.$1)):/Midori/.test(a)?this.midori=!0:/Opera/.test(a)?this.opera=!0:/Safari/.test(a)&&(this.safari=!0),navigator.standalone&&(this.webApp=!0)},a.prototype._checkAudio=function(){this.audioData=!!window.Audio,this.webaudio=!(!window.webkitAudioContext&&!window.AudioContext);var a=document.createElement("audio"),b=!1;try{(b=!!a.canPlayType)&&(a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,"")&&(this.ogg=!0),a.canPlayType("audio/mpeg;").replace(/^no$/,"")&&(this.mp3=!0),a.canPlayType('audio/wav; codecs="1"').replace(/^no$/,"")&&(this.wav=!0),(a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;").replace(/^no$/,""))&&(this.m4a=!0))}catch(c){}},a.prototype._checkDevice=function(){this.pixelRatio=window.devicePixelRatio||1,this.iPhone=-1!=navigator.userAgent.toLowerCase().indexOf("iphone"),this.iPhone4=2==this.pixelRatio&&this.iPhone,this.iPad=-1!=navigator.userAgent.toLowerCase().indexOf("ipad")},a.prototype.getAll=function(){var a="";return a=a.concat("Device\n"),a=a.concat("iPhone : "+this.iPhone+"\n"),a=a.concat("iPhone4 : "+this.iPhone4+"\n"),a=a.concat("iPad : "+this.iPad+"\n"),a=a.concat("\n"),a=a.concat("Operating System\n"),a=a.concat("iOS: "+this.iOS+"\n"),a=a.concat("Android: "+this.android+"\n"),a=a.concat("ChromeOS: "+this.chromeOS+"\n"),a=a.concat("Linux: "+this.linux+"\n"),a=a.concat("MacOS: "+this.macOS+"\n"),a=a.concat("Windows: "+this.windows+"\n"),a=a.concat("\n"),a=a.concat("Browser\n"),a=a.concat("Arora: "+this.arora+"\n"),a=a.concat("Chrome: "+this.chrome+"\n"),a=a.concat("Epiphany: "+this.epiphany+"\n"),a=a.concat("Firefox: "+this.firefox+"\n"),a=a.concat("Internet Explorer: "+this.ie+" ("+this.ieVersion+")\n"),a=a.concat("Mobile Safari: "+this.mobileSafari+"\n"),a=a.concat("Midori: "+this.midori+"\n"),a=a.concat("Opera: "+this.opera+"\n"),a=a.concat("Safari: "+this.safari+"\n"),a=a.concat("\n"),a=a.concat("Features\n"),a=a.concat("Blob: "+this.blob+"\n"),a=a.concat("Canvas: "+this.canvas+"\n"),a=a.concat("File: "+this.file+"\n"),a=a.concat("FileSystem: "+this.fileSystem+"\n"),a=a.concat("LocalStorage: "+this.localStorage+"\n"),a=a.concat("WebGL: "+this.webGL+"\n"),a=a.concat("Worker: "+this.worker+"\n"),a=a.concat("Touch: "+this.touch+"\n"),a=a.concat("\n"),a=a.concat("Audio\n"),a=a.concat("Audio Data: "+this.canvas+"\n"),a=a.concat("Web Audio: "+this.canvas+"\n"),a=a.concat("Can play OGG: "+this.canvas+"\n"),a=a.concat("Can play MP3: "+this.canvas+"\n"),a=a.concat("Can play M4A: "+this.canvas+"\n"),a=a.concat("Can play WAV: "+this.canvas+"\n")},a}();a.Device=b}(b=a.System||(a.System={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c,d,e){this.dirty=!1,this.cellIndex=0,this.name=a,this.cells=c||new Array,this.sequences=e||new Array,this.image=d,this._type=b}return b.prototype.objType=function(){return"TextureAtlas"},Object.defineProperty(b.prototype,"type",{get:function(){return this._type},enumerable:!0,configurable:!0}),b.prototype.createGLTextureWrapper=function(b,c){this.glTextureWrapper=new a.Renderers.GLTextureWrapper(b,this),c.registerTextureWrapper(b,this.glTextureWrapper)},b.prototype.enableGL=function(a,b,c){b.updateTextureSize(a,new Float32Array([this.image.width,this.image.height])),c.useTexture(a,this.glTextureWrapper),this.dirty&&this.refreshTextureGL(a)},b.prototype.refreshTextureGL=function(a){this.glTextureWrapper&&this.glTextureWrapper.refreshTexture(a),this.dirty=!1},b.prototype.readJSON=function(b){var c=JSON.parse(b);void 0!==c.name&&(this.name=c.name);for(var d=0;d<c.cells.length;d++)this.cells.push(c.cells[d]),void 0===c.cells[d].hitboxes&&(this.cells[d].hitboxes=new Array,this.cells[d].hitboxes.push({x:0,y:0,w:this.cells[d].w,h:this.cells[d].h}));if(c.sequences)for(var d=0;d<c.sequences.length;d++){var e=new a.Animations.Sequence(c.sequences[d].name,c.sequences[d].cells);void 0!==c.sequences[d].speed&&(e.speed=c.sequences[d].speed),void 0!==c.sequences[d].loop&&(e.loop=c.sequences[d].loop),this.sequences.push(e)}},b.SINGLE_IMAGE=0,b.SPRITE_SHEET=1,b.TEXTURE_ATLAS=2,b}();b.TextureAtlas=c}(b=a.Textures||(a.Textures={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._game=a,this.textures=new Object}return b.prototype.objType=function(){return"TextureLibrary"},b.prototype.clear=function(){for(var a in this.textures)delete this.textures[a]},b.prototype.add=function(b){if(this.textures[b.name]=b,this._game.renderOption===a.RENDERER_WEBGL){(-1==a.Utils.Common.base2Sizes.indexOf(b.image.width)||-1==a.Utils.Common.base2Sizes.indexOf(b.image.height))&&a.Log.log("Kiwi.TextureLibrary: Warning:Image is not of base2 size and may not render correctly.","#texture","#base2");var c=this._game.renderer;c.addTexture(this._game.stage.gl,b)}},b.prototype.addFromFile=function(b){switch(this._game.renderOption===a.RENDERER_WEBGL&&this._game.deviceTargetOption!=a.TARGET_COCOON&&(b=this._rebuildImage(b)),b.dataType){case a.Files.File.SPRITE_SHEET:this.textures[b.key]=this._buildSpriteSheet(b);break;case a.Files.File.IMAGE:this.textures[b.key]=this._buildImage(b);break;case a.Files.File.TEXTURE_ATLAS:this.textures[b.key]=this._buildTextureAtlas(b)}},b.prototype._rebuildImage=function(b){var c=a.Utils.Common.convertToBase2(b.data);return(b.data.width!==c.width||b.data.height!==c.height)&&(b.dataType===a.Files.File.SPRITE_SHEET?(b.metadata.rows||(b.metadata.rows=b.data.height/b.metadata.frameHeight),b.metadata.cols||(b.metadata.cols=b.data.width/b.metadata.frameWidth)):b.dataType===a.Files.File.IMAGE&&(b.metadata.width||(b.metadata.width=b.data.width),b.metadata.height||(b.metadata.height=b.data.height)),a.Log.log("Kiwi.TextureLibrary: "+b.name+" has been rebuilt to be base2.","#texture","#base2"),b.data=c),b},b.prototype._buildTextureAtlas=function(b){var c=new a.Textures.TextureAtlas(b.key,a.Textures.TextureAtlas.TEXTURE_ATLAS,null,b.data),d=b.metadata,e=this._game.fileStore.getFile(d.jsonID).data;return e.trim(),c.readJSON(e),c},b.prototype._buildSpriteSheet=function(b){var c=b.metadata,d=new a.Textures.SpriteSheet(b.key,b.data,c.frameWidth,c.frameHeight,c.numCells,c.rows,c.cols,c.sheetOffsetX,c.sheetOffsetY,c.cellOffsetX,c.cellOffsetY);return d},b.prototype._buildImage=function(b){var c=b.metadata;return new a.Textures.SingleImage(b.key,b.data,c.width,c.height,c.offsetX,c.offsetY)},b.prototype.rebuild=function(b,c){this.clear(),a.Log.log("Kiwi.TextureLibrary: Rebuilding Texture Library","#texture","#rebuild");for(var d=b.keys,e=0;e<d.length;e++){var f=this._game.fileStore.getFile(d[e]);f.isTexture&&(a.Log.log("  Kiwi.TextureLibrary: Adding Texture: "+f.name,"#texture","#added"),c.textureLibrary.addFromFile(f))}},b}();b.TextureLibrary=c}(b=a.Textures||(a.Textures={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(c,d,e,f,g,h,i,j,k,l,m){this.cellWidth=e,this.cellHeight=f,this._cols=i||d.width/e,this._rows=h||d.height/f,this.numCells=g||this.cols*this.rows,this.sheetOffsetX=j||0,this.sheetOffsetY=k||0,this.cellOffsetX=l||0,this.cellOffsetY=m||0,b.call(this,c,a.Textures.TextureAtlas.SPRITE_SHEET,this.generateAtlasCells(),d,this.sequences)}return __extends(c,b),c.prototype.objType=function(){return"SpriteSheet"},Object.defineProperty(c.prototype,"rows",{get:function(){return this._rows},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"cols",{get:function(){return this._cols},enumerable:!0,configurable:!0}),c.prototype.generateAtlasCells=function(){for(var b=new Array,c=new Array,d=this.sheetOffsetX,e=this.sheetOffsetY,f=0,g=0;g<this.rows;g++){for(var h=0;h<this.cols;h++)f>=this.numCells||(b.push({x:d,y:e,w:this.cellWidth,h:this.cellHeight,hitboxes:[{x:0,y:0,w:this.cellWidth,h:this.cellHeight}]}),c.push(f++),d+=this.cellOffsetX+this.cellWidth);d=this.sheetOffsetX,e+=this.cellOffsetY+this.cellHeight}return this.sequences=new Array,this.sequences.push(new a.Animations.Sequence("default",c)),b},c}(b.TextureAtlas);b.SpriteSheet=c}(b=a.Textures||(a.Textures={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(c,d,e,f,g,h){this.width=e||d.width,this.height=f||d.height,this.offsetX=g||0,this.offsetY=h||0,b.call(this,c,a.Textures.TextureAtlas.SINGLE_IMAGE,this.generateAtlasCells(),d)}return __extends(c,b),c.prototype.objType=function(){return"SingleImage"},c.prototype.generateAtlasCells=function(){return[{x:this.offsetX,y:this.offsetY,w:this.width,h:this.height,hitboxes:[{x:0,y:0,w:this.width,h:this.height}]}]},c}(b.TextureAtlas);b.SingleImage=c}(b=a.Textures||(a.Textures={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Back"},a.In=function(a){var b=1.70158;return a*a*((b+1)*a-b)},a.Out=function(a){var b=1.70158;return--a*a*((b+1)*a+b)+1},a.InOut=function(a){var b=2.5949095;return(a*=2)<1?.5*a*a*((b+1)*a-b):.5*((a-=2)*a*((b+1)*a+b)+2)},a}();a.Back=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c;!function(b){var c=function(){function b(){}return b.prototype.objType=function(){return"Bounce"},b.In=function(b){return 1-a.Animations.Tweens.Easing.Bounce.Out(1-b)},b.Out=function(a){return 1/2.75>a?7.5625*a*a:2/2.75>a?7.5625*(a-=1.5/2.75)*a+.75:2.5/2.75>a?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375},b.InOut=function(b){return.5>b?.5*a.Animations.Tweens.Easing.Bounce.In(2*b):.5*a.Animations.Tweens.Easing.Bounce.Out(2*b-1)+.5},b}();b.Bounce=c}(c=b.Easing||(b.Easing={}))}(c=b.Tweens||(b.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Circular"},a.In=function(a){return 1-Math.sqrt(1-a*a)},a.Out=function(a){return Math.sqrt(1- --a*a)},a.InOut=function(a){return(a*=2)<1?-.5*(Math.sqrt(1-a*a)-1):.5*(Math.sqrt(1-(a-=2)*a)+1)},a}();a.Circular=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Cubic"},a.In=function(a){return a*a*a},a.Out=function(a){return--a*a*a+1},a.InOut=function(a){return(a*=2)<1?.5*a*a*a:.5*((a-=2)*a*a+2)},a}();a.Cubic=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Elastic"},a.In=function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),-(c*Math.pow(2,10*(a-=1))*Math.sin(2*(a-b)*Math.PI/d)))},a.Out=function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),c*Math.pow(2,-10*a)*Math.sin(2*(a-b)*Math.PI/d)+1)},a.InOut=function(a){var b,c=.1,d=.4;return 0===a?0:1===a?1:(!c||1>c?(c=1,b=d/4):b=d*Math.asin(1/c)/(2*Math.PI),(a*=2)<1?-.5*c*Math.pow(2,10*(a-=1))*Math.sin(2*(a-b)*Math.PI/d):c*Math.pow(2,-10*(a-=1))*Math.sin(2*(a-b)*Math.PI/d)*.5+1)},a}();a.Elastic=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Exponential"},a.In=function(a){return 0===a?0:Math.pow(1024,a-1)},a.Out=function(a){return 1===a?1:1-Math.pow(2,-10*a)},a.InOut=function(a){return 0===a?0:1===a?1:(a*=2)<1?.5*Math.pow(1024,a-1):.5*(-Math.pow(2,-10*(a-1))+2)},a}();a.Exponential=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Linear"},a.None=function(a){return a},a}();a.Linear=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Quadratic"},a.In=function(a){return a*a},a.Out=function(a){return a*(2-a)},a.InOut=function(a){return(a*=2)<1?.5*a*a:-.5*(--a*(a-2)-1)},a}();a.Quadratic=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Quartic"},a.In=function(a){return a*a*a*a},a.Out=function(a){return 1- --a*a*a*a},a.InOut=function(a){return(a*=2)<1?.5*a*a*a*a:-.5*((a-=2)*a*a*a-2)},a}();a.Quartic=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Quintic"},a.In=function(a){return a*a*a*a*a},a.Out=function(a){return--a*a*a*a*a+1},a.InOut=function(a){return(a*=2)<1?.5*a*a*a*a*a:.5*((a-=2)*a*a*a*a+2)},a}();a.Quintic=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Sinusoidal"},a.In=function(a){return 1-Math.cos(a*Math.PI/2)},a.Out=function(a){return Math.sin(a*Math.PI/2)},a.InOut=function(a){return.5*(1-Math.cos(Math.PI*a))},a}();a.Sinusoidal=b}(b=a.Easing||(a.Easing={}))}(b=a.Tweens||(a.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(){function b(a,b){this._game=a,this._tweens=[],this.clock=b||this._game.time.clock}return b.prototype.objType=function(){return"TweenManager"},b.prototype.getAll=function(){return this._tweens},b.prototype.removeAll=function(){this._tweens.length=0},b.prototype.create=function(b){var c=new a.Animations.Tween(b,this._game);return this.validateClock(),c.manager=this,c},b.prototype.add=function(a){return a.setParent(this._game),a.manager=this,this.validateClock(),this._tweens.push(a),a},b.prototype.remove=function(a){var b=this._tweens.indexOf(a);return-1!==b&&this._tweens.splice(b,1),a},b.prototype.update=function(){var a=0,b=this._tweens.length;if(0===this._tweens.length)return!1;for(;b>a;)this._tweens[a].update(1e3*this.clock.elapsed())?a++:(this._tweens.splice(a,1),b--);return!0},b.prototype.validateClock=function(){this.clock||(this.clock=this._game.time.clock,this.clock||a.Log.error("Tween manager could not find valid clock!"))},b}();b.TweenManager=c}(c=b.Tweens||(b.Tweens={}))}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c){void 0===c&&(c=null),this._game=null,this._manager=null,this._object=null,this._valuesStart={},this._valuesEnd={},this._duration=1e3,this._delayTime=0,this._startTime=null,this._easingFunction=a.Animations.Tweens.Easing.Linear.None,this._interpolationFunction=a.Utils.GameMath.linearInterpolation,this._chainedTweens=[],this._onStartCallback=null,this._onStartContext=null,this._onStartCallbackFired=!1,this._onUpdateCallback=null,this._onUpdateContext=null,this._onCompleteCallback=null,this._onCompleteCalled=!1,this._onCompleteContext=null,this.isRunning=!1,this._object=b,null!==c&&(this._game=c,this._manager=this._game.tweens),this.isRunning=!1}return b.prototype.objType=function(){return"Tween"},Object.defineProperty(b.prototype,"manager",{get:function(){return this._manager},set:function(a){this._manager=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"object",{get:function(){return this._object},set:function(a){var b,c={};this._object=a;for(b in this._valuesEnd)a[b]&&(c[b]=this._valuesEnd[b]);this._valuesEnd=c},enumerable:!0,configurable:!0}),b.prototype.to=function(a,b,c,d){return void 0===b&&(b=1e3),void 0===c&&(c=null),void 0===d&&(d=!1),this._duration=b,this._valuesEnd=a,null!==c&&(this._easingFunction=c),d===!0?this.start():this},b.prototype.start=function(){var a;if(null!==this._game&&null!==this._object){this.isRunning=!0,this._manager.add(this),this._onStartCallbackFired=!1,this._onCompleteCalled=!1,this._startTime=1e3*this._manager.clock.elapsed()+this._delayTime;for(var a in this._valuesEnd)if(null!==this._object[a]&&a in this._object){if(this._valuesEnd[a]instanceof Array){if(0===this._valuesEnd[a].length)continue;this._valuesEnd[a]=[this._object[a]].concat(this._valuesEnd[a])}this._valuesStart[a]="function"==typeof this._object[a]?this._object[a]():this._object[a]}return this}},b.prototype.stop=function(){return null!==this._manager&&this._manager.remove(this),this.isRunning=!1,this},b.prototype.setParent=function(a){this._game=a,this._manager=this._game.tweens},b.prototype.delay=function(a){return this._delayTime=a,this},b.prototype.easing=function(a){return this._easingFunction=a,this},b.prototype.interpolation=function(a){return this._interpolationFunction=a,this},b.prototype.chain=function(a){return this._chainedTweens.push(a),this},b.prototype.onStart=function(a,b){return this._onStartCallback=a,this._onStartContext=b,this},b.prototype.onUpdate=function(a,b){return this._onUpdateCallback=a,this._onUpdateContext=b,this},b.prototype.onComplete=function(a,b){return this._onCompleteCallback=a,this._onCompleteContext=b,this},b.prototype.update=function(a){if(a<this._startTime-this._delayTime)return!1;this._onStartCallbackFired===!1&&(null!==this._onStartCallback&&this._onStartCallback.call(this._onStartContext,this._object),this._onStartCallbackFired=!0);var b=(a-this._startTime)/this._duration;b=b>1?1:0>b?0:b;var c=this._easingFunction(b);for(var d in this._valuesStart){var e=this._valuesStart[d],f=this._valuesEnd[d];f instanceof Array?this._object[d]=this._interpolationFunction(f,c):"function"==typeof this._object[d]?this._object[d](e+(f-e)*c):this._object[d]=e+(f-e)*c}if(null!==this._onUpdateCallback&&this._onUpdateCallback.call(this._onUpdateContext,this._object,c),1===b){this.isRunning=!1,null!==this._onCompleteCallback&&this._onCompleteCalled===!1&&(this._onCompleteCalled=!0,this._onCompleteCallback.call(this._onCompleteContext,this._object));for(var g=0;g<this._chainedTweens.length;g++)this._chainedTweens[g].start();return!1}return!0},b}();b.Tween=c}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this.numDrawCalls=0,this._game=a}return b.prototype.boot=function(){},b.prototype.objType=function(){return"CanvasRenderer"},b.prototype._recurse=function(b){if(b.visible)if(b.childType()===a.GROUP)for(var c=0;c<b.members.length;c++)this._recurse(b.members[c]);else this.numDrawCalls++,b.render(this._currentCamera)},b.prototype.requestRendererInstance=function(a,b){return void 0===b&&(b=null),null},b.prototype.requestSharedRenderer=function(a,b){return void 0===b&&(b=null),null},b.prototype.initState=function(){},b.prototype.endState=function(){},b.prototype.render=function(a){var b=this._game.states.current.members,c=this._game.stage.rgbaColor;if(c.a<255&&this._game.stage.ctx.clearRect(0,0,this._game.stage.canvas.width,this._game.stage.canvas.height),this._game.stage.ctx.fillStyle="rgba("+c.r+","+c.g+","+c.b+","+c.a/255+")",this._game.stage.ctx.fillRect(0,0,this._game.stage.canvas.width,this._game.stage.canvas.height),0!=b.length){this.numDrawCalls=0,this._currentCamera=a;var d=a.transform.getConcatenatedMatrix(),e=a.transform;this._game.stage.ctx.save(),this._game.stage.ctx.setTransform(d.a,d.b,d.c,d.d,d.tx,d.ty),this._game.stage.ctx.transform(1,0,0,1,-e.rotPointX,-e.rotPointY);for(var f=0;f<b.length;f++)this._recurse(b[f]);this._game.stage.ctx.restore()}},b}();b.CanvasRenderer=c}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(b){if(this._currentRenderer=null,this._entityCount=0,this.numDrawCalls=0,this._maxItems=1e3,this._currentTextureAtlas=null,this._sharedRenderers={},this._game=b,"undefined"==typeof mat4)throw"ERROR: gl-matrix.js is missing";this._currentBlendMode=new a.Renderers.GLBlendMode(this._game.stage.gl,{mode:"DEFAULT"})}return c.prototype.boot=function(){this._textureManager=new b.GLTextureManager,this._shaderManager=new a.Shaders.ShaderManager,this._init()},c.prototype.objType=function(){return"GLRenderManager"},c.prototype.addTexture=function(a,b){this._textureManager.uploadTexture(a,b)},c.prototype.addSharedRenderer=function(b,c){return void 0===c&&(c=null),!a.Renderers[b]||b in this._sharedRenderers?!1:(this._sharedRenderers[b]=new a.Renderers[b](this._game.stage.gl,this._shaderManager,c),!0)},c.prototype.addSharedRendererClone=function(b,c,d){return void 0===d&&(d=null),"undefined"==typeof d&&(d=null),!a.Renderers[b]||c in this._sharedRenderers?!1:(this._sharedRenderers[c]=new a.Renderers[b](this._game.stage.gl,this._shaderManager,d),!0)},c.prototype.requestSharedRenderer=function(b,c){void 0===c&&(c=null);var d=this._sharedRenderers[b];return d?d:this.addSharedRenderer(b,c)?this._sharedRenderers[b]:(a.Log.log("No renderer called "+b,"#renderer","#webgl"),null)},c.prototype.requestRendererInstance=function(b,c){if(void 0===c&&(c=null),b in a.Renderers){var d=new a.Renderers[b](this._game.stage.gl,this._shaderManager,c);return d}return a.Log.log("No renderer with id "+b+" exists","#renderer","#webgl"),null},c.prototype._init=function(){a.Log.log("Initialising WebGL","#renderer","#webgl");var b=this._game.stage.gl;this._stageResolution=new Float32Array([this._game.stage.width,this._game.stage.height]),this._game.deviceTargetOption===a.TARGET_COCOON?this.scaleViewport(b,this._game.stage.scaleType,window.innerWidth,window.innerHeight):this.scaleViewport(b,a.Stage.SCALE_NONE,this._game.stage.width,this._game.stage.height),b.enable(b.BLEND),this._switchBlendMode(b,this._currentBlendMode),this._shaderManager.init(b,"TextureAtlasShader"),this.camMatrix=mat3.create(),this._game.stage.onResize.add(function(c,d){this._stageResolution=new Float32Array([c,d]),this.currentRenderer&&this._currentRenderer.updateStageResolution(b,this._stageResolution),this._game.deviceTargetOption===a.TARGET_COCOON?this.scaleViewport(b,this._game.stage.scaleType,window.innerWidth,window.innerHeight):this.scaleViewport(b,a.Stage.SCALE_NONE,c,d)},this)},c.prototype.scaleViewport=function(b,c,d,e){var f=new a.Geom.Point(0,0);switch(c){case a.Stage.SCALE_FIT:var g=this._game.stage.width/this._game.stage.height,h=d/e;if(h>g){var i=e*g;f.x=(d-i)/2,d=i}else{var j=d/g;f.y=(e-j)/2,e=j}break;case a.Stage.SCALE_STRETCH:break;case a.Stage.SCALE_NONE:d=this._game.stage.width,e=this._game.stage.height}b.viewport(f.x,f.y,d,e)},c.prototype.initState=function(a){this._textureManager.clearTextures(this._game.stage.gl),this._textureManager.uploadTextureLibrary(this._game.stage.gl,a.textureLibrary)},c.prototype.endState=function(){this._textureManager.clearTextures(this._game.stage.gl),a.Log.log("Ending WebGL on State","#renderer","#webgl")},c.prototype.render=function(b){var c=this._game.stage.gl,d=this._game.stage.normalizedColor;if(c.clearColor(d.r*d.a,d.g*d.a,d.b*d.a,d.a),c.clear(c.COLOR_BUFFER_BIT),0!=this._game.states.current.members.length){this.numDrawCalls=0,this._textureManager.numTextureWrites=0,this._entityCount=0;var e=b.transform.getConcatenatedMatrix(),f=b.transform,g=vec2.create(),h=vec2.create(),i=vec2.create();vec2.set(h,f.scaleX,f.scaleY),vec2.set(g,-f.rotPointX,-f.rotPointY),vec2.set(i,e.tx,e.ty),mat3.identity(this.camMatrix),mat3.translate(this.camMatrix,this.camMatrix,i),mat3.rotate(this.camMatrix,this.camMatrix,f.rotation),mat3.scale(this.camMatrix,this.camMatrix,h),mat3.translate(this.camMatrix,this.camMatrix,g),this._game.deviceTargetOption==a.TARGET_COCOON&&this._switchBlendMode(c,this._currentBlendMode),this.collateRenderSequence(),this.collateBatches(),this.renderBatches(c,b)}},c.prototype.collateRenderSequence=function(){this._sequence=[];var a=this._game.states.current;this.collateChild(a)},c.prototype.collateChild=function(b){if(b.visible)if(b.childType()===a.GROUP)for(var c=0;c<b.members.length;c++)this.collateChild(b.members[c]);else{var d=b;this._sequence.push({entity:d,renderer:d.glRenderer,shader:d.glRenderer.shaderPair,isBatchRenderer:d.glRenderer.isBatchRenderer,texture:d.atlas})}},c.prototype.collateBatches=function(){var a=null,b=null,c=null;this._batches=[];for(var d,e=0;e<this._sequence.length;e++){if(!this._sequence[e].isBatchRenderer||this._sequence[e].renderer!==a||this._sequence[e].shader!==b||this._sequence[e].texture!==c){var d=this._batches.push(new Array)-1;a=this._sequence[e].renderer,b=this._sequence[e].shader,c=this._sequence[e].texture}this._batches[d].push(this._sequence[e])}},c.prototype.renderBatches=function(a,b){for(var c=0;c<this._batches.length;c++)this.renderBatch(a,this._batches[c],b)},c.prototype.renderBatch=function(b,c,d){var e=!1;c[0].entity.glRenderer!==this._currentRenderer&&(e=!0,this._switchRenderer(b,c[0].entity)),this._currentRenderer.clear(b,{camMatrix:this.camMatrix});for(var f=0;f<c.length;f++)c[f].entity.renderGL(b,d);(c[0].entity.atlas!==this._currentTextureAtlas||c[0].entity.atlas.dirty||e&&c[0].entity.atlas==this._currentTextureAtlas)&&this._switchTexture(b,c[0].entity),(!this._currentBlendMode.isIdentical(c[0].entity.glRenderer.blendMode)||this._currentBlendMode.dirty||this._game.deviceTargetOption===a.TARGET_COCOON)&&this._switchBlendMode(b,c[0].entity.glRenderer.blendMode),this._currentRenderer.draw(b)},c.prototype.renderEntity=function(a,b,c){this.renderBatch(a,[b],c)},c.prototype.setupGLState=function(a,b){b.atlas!==this._currentTextureAtlas&&this._switchTexture(a,b),b.glRenderer!==this._currentRenderer&&this._switchRenderer(a,b)},c.prototype._switchRenderer=function(a,b){this._currentRenderer&&this._currentRenderer.disable(a),this._currentRenderer=b.glRenderer,this._currentRenderer.enable(a,{camMatrix:this.camMatrix,stageResolution:this._stageResolution})},c.prototype._switchTexture=function(a,b){this._currentTextureAtlas=b.atlas,b.atlas.enableGL(a,this._currentRenderer,this._textureManager)},c.prototype._switchBlendMode=function(a,b){this._currentBlendMode=b,this._currentBlendMode.apply(a)},c}();b.GLRenderManager=c}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){this._shaderPairs={}}return Object.defineProperty(b.prototype,"currentShader",{get:function(){return this._currentShader},enumerable:!0,configurable:!0}),b.prototype.init=function(a,b){this._currentShader=this.requestShader(a,b)},b.prototype.requestShader=function(b,c,d){void 0===d&&(d=!0);var e;return c in this._shaderPairs?(e=this._shaderPairs[c],e.loaded||this._loadShader(b,e),d&&this._useShader(b,e),e):this.shaderExists(b,c)?(e=this._addShader(b,c),this._loadShader(b,e),d&&this._useShader(b,e),e):(a.Log.log("Shader "+c+" does not exist.","#renderer","#webgl"),null)},b.prototype.shaderExists=function(b,c){return c in a.Shaders},b.prototype._addShader=function(b,c){return this._shaderPairs[c]=new a.Shaders[c],this._shaderPairs[c]},b.prototype._loadShader=function(a,b){b.init(a)},b.prototype._useShader=function(a,b){b!==this._currentShader&&(this._currentShader=b),a.useProgram(b.shaderProgram)},b}();b.ShaderManager=c}(b=a.Shaders||(a.Shaders={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c){void 0===c&&(c=!1),this._created=!1,this._uploaded=!1,this.textureAtlas=b,this._image=b.image,this._numBytes=this._image.width*this._image.height*4,this.createTexture(a),c&&this.uploadTexture(a)}return Object.defineProperty(b.prototype,"numBytes",{get:function(){return this._numBytes},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"created",{get:function(){return this._created
 },enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"uploaded",{get:function(){return this._uploaded},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"image",{get:function(){return this._image},set:function(a){this._image=a,this._numBytes=this._image.width*this._image.height*4,this._uploaded=!1},enumerable:!0,configurable:!0}),b.prototype.createTexture=function(a){return this.texture=a.createTexture(),this._created=!0,!0},b.prototype.uploadTexture=function(b){var c=!1;return this.created||this.createTexture(b),this.uploaded?a.Log.log("...not uploading:the image is already uploaded.","#renderer","#webgl"):(b.bindTexture(b.TEXTURE_2D,this.texture),b.pixelStorei(b.UNPACK_PREMULTIPLY_ALPHA_WEBGL,0),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,this._image),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE),b.bindTexture(b.TEXTURE_2D,null),this._uploaded=!0,c=!0),c},b.prototype.refreshTexture=function(a){this.numBytes=this._image.width*this._image.height*4,a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this._image)},b.prototype.deleteTexture=function(a){return a.deleteTexture(this.texture),this._uploaded=!1,this._created=!1,!0},b}();b.GLTextureWrapper=c}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){this.numTextureWrites=0,this._numTexturesUsed=0,this._usedTextureMem=0,this.maxTextureMem=1024*b.DEFAULT_MAX_TEX_MEM_MB*1024,this._textureWrapperCache=new Array}return Object.defineProperty(b.prototype,"usedTextureMem",{get:function(){return this._usedTextureMem},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"numTexturesUsed",{get:function(){return this._numTexturesUsed},enumerable:!0,configurable:!0}),b.prototype._addTextureToCache=function(a){this._textureWrapperCache.push(a)},b.prototype._deleteTexture=function(a,b){this._textureWrapperCache[b].deleteTexture(a),this._usedTextureMem-=this._textureWrapperCache[b].numBytes,this._numTexturesUsed--},b.prototype._uploadTexture=function(a,b){return b.numBytes+this._usedTextureMem<=this.maxTextureMem?(b.uploadTexture(a),this._usedTextureMem+=b.numBytes,this._numTexturesUsed++,!0):!1},b.prototype.uploadTextureLibrary=function(a,b){this._textureWrapperCache=new Array;for(var c in b.textures)b.textures[c].createGLTextureWrapper(a,this)},b.prototype.uploadTexture=function(a,b){b.createGLTextureWrapper(a,this)},b.prototype.registerTextureWrapper=function(b,c){this._addTextureToCache(c),this._uploadTexture(b,c)||a.Log.log("...skipped uploading texture due to allocated texture memory exceeded.","#renderer","#webgl")},b.prototype.clearTextures=function(a){for(var b=0;b<this._textureWrapperCache.length;b++)this._deleteTexture(a,b),this._textureWrapperCache[b].textureAtlas.glTextureWrapper=null;this._textureWrapperCache=new Array},b.prototype.useTexture=function(b,c,d){if(void 0===d&&(d=0),d=a.Utils.GameMath.clamp(a.Utils.GameMath.truncate(d),31),c.created&&c.uploaded||(this._uploadTexture(b,c)||(this._freeSpace(b,c.numBytes),this._uploadTexture(b,c)),this.numTextureWrites++),c.created&&c.uploaded){var e=b.TEXTURE0+d;return b.activeTexture(e),b.bindTexture(b.TEXTURE_2D,c.texture),!0}return!1},b.prototype._freeSpace=function(a,b){for(var c=0,d=0;d<this._textureWrapperCache.length;d++)if(this._textureWrapperCache[d].uploaded&&(c+=this._textureWrapperCache[d].numBytes,this._deleteTexture(a,d)),c>=b)return!0;return!1},b.DEFAULT_MAX_TEX_MEM_MB=1024,b}();b.GLTextureManager=c}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(b,c,d,e){void 0===e&&(e=!0),this._created=!1,this._uploaded=!1,this.items=d||a.squareVertices,this.itemSize=c||2,this.numItems=this.items.length/this.itemSize,this.createBuffer(b),e&&this.uploadBuffer(b,this.items)}return Object.defineProperty(a.prototype,"created",{get:function(){return this._created},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"uploaded",{get:function(){return this._uploaded},enumerable:!0,configurable:!0}),a.prototype.clear=function(){this.items=new Array},a.prototype.createBuffer=function(a){return this.buffer=a.createBuffer(),this._created=!0,!0},a.prototype.uploadBuffer=function(a,b){this.items=b,this.numItems=this.items.length/this.itemSize;var c=new Float32Array(this.items);return a.bindBuffer(a.ARRAY_BUFFER,this.buffer),a.bufferData(a.ARRAY_BUFFER,c,a.DYNAMIC_DRAW),this._uploaded=!0,!0},a.prototype.deleteBuffer=function(a){return a.bindBuffer(a.ARRAY_BUFFER,this.buffer),a.deleteBuffer(this.buffer),this.uploaded=!1,this.created=!1,!0},a.squareVertices=[0,0,100,0,100,100,0,100],a.squareUVs=[0,0,.1,0,.1,.1,0,.1],a.squareCols=[1,1,1,1],a}();a.GLArrayBuffer=b}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b){this.gl=a,this.dirty=!0,this._srcRGB=a.SRC_ALPHA,this._dstRGB=a.ONE_MINUS_SRC_ALPHA,this._srcAlpha=a.ONE,this._dstAlpha=a.ONE,this._modeRGB=a.FUNC_ADD,this._modeAlpha=a.FUNC_ADD,"undefined"==typeof b&&(b=null),b&&this.readConfig(b)}return a.prototype.readConfig=function(a){void 0!==a.mode?this.setMode(a.mode):(a.srcRGB=this.makeConstant(a.srcRGB),"undefined"!=typeof a.srcRGB&&(this._srcRGB=a.srcRGB),a.dstRGB=this.makeConstant(a.dstRGB),"undefined"!=typeof a.dstRGB&&(this._dstRGB=a.dstRGB),a.srcAlpha=this.makeConstant(a.srcAlpha),"undefined"!=typeof a.srcAlpha&&(this._srcAlpha=a.srcAlpha),a.dstAlpha=this.makeConstant(a.dstAlpha),"undefined"!=typeof a.dstAlpha&&(this._dstAlpha=a.dstAlpha),a.modeRGB=this.makeConstant(a.modeRGB),"undefined"!=typeof a.modeRGB&&(this._modeRGB=a.modeRGB),a.modeAlpha=this.makeConstant(a.modeAlpha),"undefined"!=typeof a.modeAlpha&&(this._modeAlpha=a.modeAlpha)),this.dirty=!0},a.prototype.makeConstant=function(a){if("number"==typeof a)return a;switch("string"==typeof a&&(a=a.toUpperCase()),a){case"ZERO":a=this.gl.ZERO;break;case"ONE":a=this.gl.ONE;break;case"SRC_COLOR":case"SRC_COLOUR":a=this.gl.SRC_COLOR;break;case"ONE_MINUS_SRC_COLOR":case"ONE_MINUS_SRC_COLOUR":a=this.gl.ONE_MINUS_SRC_COLOR;break;case"DST_COLOR":case"DST_COLOUR":a=this.gl.DST_COLOR;break;case"ONE_MINUS_DST_COLOR":case"ONE_MINUS_DST_COLOUR":a=this.gl.ONE_MINUS_DST_COLOR;break;case"SRC_ALPHA":a=this.gl.SRC_ALPHA;break;case"ONE_MINUS_SRC_ALPHA":a=this.gl.ONE_MINUS_SRC_ALPHA;break;case"DST_ALPHA":a=this.gl.DST_ALPHA;break;case"ONE_MINUS_DST_ALPHA":a=this.gl.ONE_MINUS_DST_ALPHA;break;case"SRC_ALPHA_SATURATE":a=this.gl.SRC_ALPHA_SATURATE;break;case"CONSTANT_COLOR":case"CONSTANT_COLOUR":a=this.gl.CONSTANT_COLOR;break;case"ONE_MINUS_CONSTANT_COLOR":case"ONE_MINUS_CONSTANT_COLOUR":a=this.gl.ONE_MINUS_CONSTANT_COLOR;break;case"CONSTANT_ALPHA":a=this.gl.CONSTANT_ALPHA;break;case"ONE_MINUS_CONSTANT_ALPHA":a=this.gl.ONE_MINUS_CONSTANT_ALPHA;break;case"FUNC_ADD":a=this.gl.FUNC_ADD;break;case"FUNC_SUBTRACT":a=this.gl.FUNC_SUBTRACT;break;case"FUNC_REVERSE_SUBTRACT":a=this.gl.FUNC_REVERSE_SUBTRACT;break;default:a=void 0}return a},a.prototype.setMode=function(a){switch(a=a.toUpperCase()){case"ADDITIVE":case"ADD":this._srcRGB=this.gl.SRC_ALPHA,this._dstRGB=this.gl.ONE,this._srcAlpha=this.gl.ONE,this._dstAlpha=this.gl.ONE,this._modeRGB=this.gl.FUNC_ADD,this._modeAlpha=this.gl.FUNC_ADD;break;case"SUBTRACT":case"SUBTRACTIVE":this._srcRGB=this.gl.SRC_ALPHA,this._dstRGB=this.gl.ONE,this._srcAlpha=this.gl.ONE,this._dstAlpha=this.gl.ONE,this._modeRGB=this.gl.FUNC_REVERSE_SUBTRACT,this._modeAlpha=this.gl.FUNC_ADD;break;case"ERASE":case"ERASER":this._srcRGB=this.gl.SRC_ALPHA,this._dstRGB=this.gl.ONE_MINUS_SRC_ALPHA,this._srcAlpha=this.gl.ONE,this._dstAlpha=this.gl.ONE,this._modeRGB=this.gl.FUNC_REVERSE_SUBTRACT,this._modeAlpha=this.gl.FUNC_REVERSE_SUBTRACT;break;case"BLACK":case"BLACKEN":this._srcRGB=this.gl.ZERO,this._dstRGB=this.gl.ONE_MINUS_SRC_ALPHA,this._srcAlpha=this.gl.ONE,this._dstAlpha=this.gl.ONE,this._modeRGB=this.gl.FUNC_ADD,this._modeAlpha=this.gl.FUNC_ADD;break;case"NORMAL":default:this._srcRGB=this.gl.SRC_ALPHA,this._dstRGB=this.gl.ONE_MINUS_SRC_ALPHA,this._srcAlpha=this.gl.ONE,this._dstAlpha=this.gl.ONE,this._modeRGB=this.gl.FUNC_ADD,this._modeAlpha=this.gl.FUNC_ADD}this.dirty=!0},a.prototype.isIdentical=function(a){return this==a?!0:this._srcRGB==a._srcRGB&&this._dstRGB==a._dstRGB&&this._srcAlpha==a._srcAlpha&&this._dstAlpha==a._dstAlpha&&this._modeRGB==a._modeRGB&&this._modeAlpha==a._modeAlpha?!0:!1},a.prototype.apply=function(a){a.blendEquationSeparate(this._modeRGB,this._modeAlpha),a.blendFuncSeparate(this._srcRGB,this._dstRGB,this._srcAlpha,this._dstAlpha),this.dirty=!1},a}();a.GLBlendMode=b}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(b,c,d,e){void 0===e&&(e=!0),this.indices=d||a.square,this.itemSize=c||1,this.numItems=this.indices.length/this.itemSize,e&&(this.buffer=this.init(b))}return a.prototype.clear=function(){this.indices=new Array},a.prototype.init=function(a){var b=a.createBuffer();return a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,b),a.bufferData(a.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),a.STATIC_DRAW),b},a.prototype.refresh=function(a){return this.numItems=this.indices.length/this.itemSize,a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.buffer),a.bufferData(a.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),a.STATIC_DRAW),this.buffer},a.square=[0,1,2,0,2,3],a}();a.GLElementArrayBuffer=b}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c,d){void 0===d&&(d=!1),this.loaded=!1,this._isBatchRenderer=!1,this.shaderManager=c,this._isBatchRenderer=d,this.loaded=!0,this.blendMode=new a.Renderers.GLBlendMode(b,{mode:"NORMAL"})}return b.prototype.enable=function(a,b){void 0===b&&(b=null)},b.prototype.disable=function(){},b.prototype.clear=function(){},b.prototype.draw=function(){},b.prototype.updateStageResolution=function(){},b.prototype.updateTextureSize=function(){},Object.defineProperty(b.prototype,"isBatchRenderer",{get:function(){return this._isBatchRenderer},enumerable:!0,configurable:!0}),b.RENDERER_ID="Renderer",b}();b.Renderer=c}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(c){function d(a,d,e){void 0===e&&(e=null),c.call(this,a,d,!0),this._shaderPairName="TextureAtlasShader",this._maxItems=1e3;var f=5;this._vertexBuffer=new b.GLArrayBuffer(a,f);var g=6;this._indexBuffer=new b.GLElementArrayBuffer(a,1,this._generateIndices(this._maxItems*g)),this.shaderPair=this.shaderManager.requestShader(a,this._shaderPairName)}return __extends(d,c),d.prototype.enable=function(a,b){void 0===b&&(b=null),this.shaderPair=this.shaderManager.requestShader(a,this._shaderPairName,!0),a.uniform1i(this.shaderPair.uniforms.uSampler.location,0),a.uniform2fv(this.shaderPair.uniforms.uResolution.location,b.stageResolution),a.uniformMatrix3fv(this.shaderPair.uniforms.uCamMatrix.location,!1,b.camMatrix)},d.prototype.disable=function(a){a.disableVertexAttribArray(this.shaderPair.attributes.aXYUV),a.disableVertexAttribArray(this.shaderPair.attributes.aAlpha)},d.prototype.clear=function(a,b){this._vertexBuffer.clear(),a.uniformMatrix3fv(this.shaderPair.uniforms.uCamMatrix.location,!1,b.camMatrix)},d.prototype.draw=function(a){this._vertexBuffer.uploadBuffer(a,this._vertexBuffer.items),a.enableVertexAttribArray(this.shaderPair.attributes.aXYUV),a.vertexAttribPointer(this.shaderPair.attributes.aXYUV,4,a.FLOAT,!1,20,0),a.enableVertexAttribArray(this.shaderPair.attributes.aAlpha),a.vertexAttribPointer(this.shaderPair.attributes.aAlpha,1,a.FLOAT,!1,20,16),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBuffer.buffer),a.drawElements(a.TRIANGLES,this._vertexBuffer.items.length/20*6,a.UNSIGNED_SHORT,0)},d.prototype._generateIndices=function(a){for(var b=new Array,c=0;a>c;c++)b.push(4*c+0,4*c+1,4*c+2,4*c+0,4*c+2,4*c+3);return b},d.prototype.updateStageResolution=function(a,b){a.uniform2fv(this.shaderPair.uniforms.uResolution.location,b)},d.prototype.updateTextureSize=function(a,b){a.uniform2fv(this.shaderPair.uniforms.uTextureSize.location,b)},d.prototype.setShaderPair=function(a){"string"==typeof a&&(this._shaderPairName=a)},d.prototype.addToBatch=function(b,c){if(!(c.alpha<=0)){var d=c.transform,e=d.getConcatenatedMatrix(),f=c.atlas.cells[c.cellIndex],g=new a.Geom.Point(0-d.rotPointX,0-d.rotPointY),h=new a.Geom.Point(f.w-d.rotPointX,0-d.rotPointY),i=new a.Geom.Point(f.w-d.rotPointX,f.h-d.rotPointY),j=new a.Geom.Point(0-d.rotPointX,f.h-d.rotPointY);g=e.transformPoint(g),h=e.transformPoint(h),i=e.transformPoint(i),j=e.transformPoint(j),this._vertexBuffer.items.push(g.x,g.y,f.x,f.y,c.alpha,h.x,h.y,f.x+f.w,f.y,c.alpha,i.x,i.y,f.x+f.w,f.y+f.h,c.alpha,j.x,j.y,f.x,f.y+f.h,c.alpha)}},d.prototype.concatBatch=function(a){this._vertexBuffer.items=this._vertexBuffer.items.concat(a)},d.RENDERER_ID="TextureAtlasRenderer",d}(b.Renderer);b.TextureAtlasRenderer=c}(b=a.Renderers||(a.Renderers={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){this.loaded=!1}return a.prototype.init=function(a){this.vertShader=this.compile(a,this.vertSource.join("\n"),a.VERTEX_SHADER),this.fragShader=this.compile(a,this.fragSource.join("\n"),a.FRAGMENT_SHADER),this.shaderProgram=this.attach(a,this.vertShader,this.fragShader),this.loaded=!0},a.prototype.attach=function(a,b,c){var d=a.createProgram();return a.attachShader(d,c),a.attachShader(d,b),a.linkProgram(d),d},a.prototype.compile=function(a,b,c){var d=a.createShader(c);return a.shaderSource(d,b),a.compileShader(d),a.getShaderParameter(d,a.COMPILE_STATUS)?d:null},a.prototype.setParam=function(a,b){this.uniforms[a].value=b,this.uniforms[a].dirty=!0},a.prototype.applyUniforms=function(a){for(var b in this.uniforms)this.applyUniform(a,b)},a.prototype.applyUniform=function(a,b){var c=this.uniforms[b];this.uniforms[b].dirty&&(a["uniform"+c.type](c.location,c.value),this.uniforms[b].dirty=!1)},a.prototype.initUniforms=function(a){for(var b in this.uniforms){var c=this.uniforms[b];c.location=a.getUniformLocation(this.shaderProgram,b),c.dirty=!0,c.value=null}},a.RENDERER_ID="ShaderPair",a}();a.ShaderPair=b}(b=a.Shaders||(a.Shaders={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(a){function b(){a.call(this),this.attributes={aXYUV:null,aAlpha:null},this.uniforms={uCamMatrix:{type:"mat3"},uResolution:{type:"2fv"},uTextureSize:{type:"2fv"},uSampler:{type:"1i"}},this.fragSource=["precision mediump float;","varying vec2 vTextureCoord;","varying float vAlpha;","uniform sampler2D uSampler;","void main(void) {","gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));","gl_FragColor.a *= vAlpha;","}"],this.vertSource=["attribute vec4 aXYUV;","attribute float aAlpha;","uniform mat3 uCamMatrix;","uniform vec2 uResolution;","uniform vec2 uTextureSize;","varying vec2 vTextureCoord;","varying float vAlpha;","void main(void) {","   vec2 pos = (uCamMatrix * vec3(aXYUV.xy,1)).xy; ","   gl_Position = vec4((pos / uResolution * 2.0 - 1.0) * vec2(1, -1), 0, 1);","   vTextureCoord = aXYUV.zw / uTextureSize;","   vAlpha = aAlpha;","}"]}return __extends(b,a),b.prototype.init=function(b){a.prototype.init.call(this,b),this.attributes.aXYUV=b.getAttribLocation(this.shaderProgram,"aXYUV"),this.attributes.aAlpha=b.getAttribLocation(this.shaderProgram,"aAlpha"),this.initUniforms(b)},b}(a.ShaderPair);a.TextureAtlasShader=b}(b=a.Shaders||(a.Shaders={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c,d){this._frameIndex=0,this._startTime=null,this._reverse=!1,this._isPlaying=!1,this._onStop=null,this._onPlay=null,this._onUpdate=null,this._onLoop=null,this._onComplete=null,this.name=a,this._sequence=b,this._speed=b.speed,this._loop=b.loop,this._parent=d,this._clock=c,this._lastFrameElapsed=this.clock.elapsed()}return b.prototype.objType=function(){return"Animation"},Object.defineProperty(b.prototype,"loop",{get:function(){return this._loop},set:function(a){this._loop=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"frameIndex",{get:function(){return this._frameIndex},set:function(a){this._validateFrame(a)&&(this._frameIndex=a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"currentCell",{get:function(){return this._sequence.cells[this.frameIndex]},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"speed",{get:function(){return this._speed},set:function(a){this._speed=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"clock",{get:function(){return this._clock?this._clock:this._parent.entity.clock},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"reverse",{get:function(){return this._reverse},set:function(a){this._reverse=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"isPlaying",{get:function(){return this._isPlaying},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onStop",{get:function(){return null==this._onStop&&(this._onStop=new a.Signal),this._onStop},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onPlay",{get:function(){return null==this._onPlay&&(this._onPlay=new a.Signal),this._onPlay},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onUpdate",{get:function(){return null==this._onUpdate&&(this._onUpdate=new a.Signal),this._onUpdate},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onLoop",{get:function(){return null==this._onLoop&&(this._onLoop=new a.Signal),this._onLoop},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onComplete",{get:function(){return null==this._onComplete&&(this._onComplete=new a.Signal),this._onComplete},enumerable:!0,configurable:!0}),b.prototype._start=function(a){void 0===a&&(a=null),null!==a&&(this.frameIndex=a),this._isPlaying=!0,this._startTime=this.clock.elapsed(),this._lastFrameElapsed=this.clock.elapsed(),null!==this._onPlay&&this._onPlay.dispatch()},b.prototype.play=function(){this._frameIndex>=this.length-1&&(this.frameIndex=0),this.playAt(this._frameIndex)},b.prototype.playAt=function(a){this._start(a)},b.prototype.pause=function(){this.stop()},b.prototype.resume=function(){null!==this._startTime&&(this._isPlaying=!0)},b.prototype.stop=function(){this._isPlaying&&(this._isPlaying=!1,null!==this._onStop&&this._onStop.dispatch())},b.prototype.nextFrame=function(){this._frameIndex++,this._frameIndex>=this.length&&(this.frameIndex=0)},b.prototype.prevFrame=function(){this._frameIndex--,this._frameIndex<0&&(this.frameIndex=this.length-1)},b.prototype.update=function(){var a;if(this._isPlaying&&(a=(this.clock.elapsed()-this._lastFrameElapsed)/this._speed%(this.length+1),this._reverse&&(a*=-1),a=a>0?Math.floor(a):Math.ceil(a),0!==a)){if(this._frameIndex+=a,this._lastFrameElapsed=this.clock.elapsed(),this._loop){if(this._frameIndex>=this.length)for(;this._frameIndex>=this.length;)this._frameIndex-=this.length,null!=this._onLoop&&this._onLoop.dispatch();else if(this._frameIndex<0)for(;this._frameIndex<0;)this._frameIndex+=this.length,null!=this._onLoop&&this._onLoop.dispatch()}else if(this._frameIndex<0||this._frameIndex>=this.length)return null!=this._onComplete&&this._onComplete.dispatch(),void this._parent.stop();this._parent.updateCellIndex(),null!==this._onUpdate&&this._onUpdate.dispatch()}},b.prototype._validateFrame=function(a){return a<this.length&&a>=0},Object.defineProperty(b.prototype,"length",{get:function(){return this._sequence.cells.length},enumerable:!0,configurable:!0}),b.prototype.destroy=function(){this._isPlaying=!1,delete this._clock,delete this._sequence,delete this._parent,this._onLoop&&this._onLoop.dispose(),this._onStop&&this._onStop.dispose(),this._onPlay&&this._onPlay.dispose(),this._onUpdate&&this._onUpdate.dispose(),delete this._onLoop,delete this._onStop,delete this._onPlay,delete this._onUpdate,delete this.frameIndex,delete this.loop,delete this._reverse,delete this._tick},b}();b.Animation=c}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b,c,d){void 0===c&&(c=.1),void 0===d&&(d=!0),this.name=a,this.cells=b,this.speed=c,this.loop=d}return a}();a.Sequence=b}(b=a.Animations||(a.Animations={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b,c){this.preventDefault=!1,this.isDown=!1,this.isUp=!0,this.altKey=!1,this.ctrlKey=!1,this.shiftKey=!1,this.timeDown=0,this.timeUp=0,this.repeats=0,this._manager=a,this.game=this._manager.game,this.keyCode=b,c&&this.update(c)}return a.prototype.objType=function(){return"Key"},Object.defineProperty(a.prototype,"duration",{get:function(){return this.isDown&&(this.timeDown=this.game.time.now()),this.timeDown<this.timeUp?0:this.timeDown-this.timeUp},enumerable:!0,configurable:!0}),a.prototype.update=function(a){this.keyCode=a.keyCode,this.preventDefault&&a.preventDefault(),"keydown"===a.type?(this.altKey=a.altKey,this.ctrlKey=a.ctrlKey,this.shiftKey=a.shiftKey,this.isDown===!0?(this.repeats++,this.timeDown=this.game.time.now()):(this.isDown=!0,this.isUp=!1,this.timeDown=this.game.time.now(),this.repeats=0)):"keyup"===a.type&&(this.isDown=!1,this.isUp=!0,this.timeUp=this.game.time.now())},a.prototype.justPressed=function(a){return void 0===a&&(a=this._manager.justPressedRate),this.isDown===!0&&this.timeDown+a>this.game.time.now()?!0:!1},a.prototype.justReleased=function(a){return void 0===a&&(a=this._manager.justReleasedRate),this.isUp===!0&&this.timeUp+a>this.game.time.now()?!0:!1},a.prototype.reset=function(){this.isDown=!1,this.isUp=!0,this.timeUp=0,this.timeDown=0,this.repeats=0,this.altKey=!1,this.shiftKey=!1,this.ctrlKey=!1},a}();a.Key=b}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._keys=[],this.justPressedRate=200,this.justReleasedRate=200,this.game=a}return b.prototype.objType=function(){return"Keyboard"},Object.defineProperty(b.prototype,"keys",{get:function(){return this._keys},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this.onKeyUp=new a.Signal,this.onKeyDown=new a.Signal,this.onKeyDownOnce=new a.Signal,this.start()},b.prototype.update=function(){},b.prototype.start=function(){var b=this;this.game.deviceTargetOption===a.TARGET_BROWSER&&(document.body.addEventListener("keydown",function(a){return b._keyPressed(a)},!1),document.body.addEventListener("keyup",function(a){return b._keyReleased(a)},!1))},b.prototype.stop=function(){var b=this;this.game.deviceTargetOption===a.TARGET_BROWSER&&(document.body.removeEventListener("keydown",function(a){return b._keyPressed(a)},!1),document.body.removeEventListener("keyup",function(a){return b._keyReleased(a)},!1))},b.prototype._keyPressed=function(b){this._keys[b.keyCode]?this._keys[b.keyCode].update(b):this._keys[b.keyCode]=new a.Input.Key(this,b.keyCode,b),0==this._keys[b.keyCode].repeats&&this.onKeyDownOnce.dispatch(b.keyCode,this._keys[b.keyCode]),this.onKeyDown.dispatch(b.keyCode,this._keys[b.keyCode])},b.prototype._keyReleased=function(b){this._keys[b.keyCode]?this._keys[b.keyCode].update(b):this._keys[b.keyCode]=new a.Input.Key(this,b.keyCode,b),this.onKeyUp.dispatch(b.keyCode,this._keys[b.keyCode])},b.prototype.addKey=function(b,c){void 0===c&&(c=!1);var d=new a.Input.Key(this,b);return d.preventDefault=c,this._keys[b]=d},b.prototype.justPressed=function(a,b){return void 0===b&&(b=this.justPressedRate),this._keys[a]?this._keys[a].justPressed(b):!1},b.prototype.justReleased=function(a,b){return void 0===b&&(b=this.justReleasedRate),this._keys[a]?this._keys[a].justReleased(b):!1},b.prototype.isDown=function(a){return this._keys[a]?this._keys[a].isDown:!1},b.prototype.isUp=function(a){return this._keys[a]?this._keys[a].isUp:!1},b.prototype.reset=function(){for(var a in this._keys)this._keys[a].reset()},b}();b.Keyboard=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){}return a.prototype.objType=function(){return"Keycodes"},a.A="A".charCodeAt(0),a.B="B".charCodeAt(0),a.C="C".charCodeAt(0),a.D="D".charCodeAt(0),a.E="E".charCodeAt(0),a.F="F".charCodeAt(0),a.G="G".charCodeAt(0),a.H="H".charCodeAt(0),a.I="I".charCodeAt(0),a.J="J".charCodeAt(0),a.K="K".charCodeAt(0),a.L="L".charCodeAt(0),a.M="M".charCodeAt(0),a.N="N".charCodeAt(0),a.O="O".charCodeAt(0),a.P="P".charCodeAt(0),a.Q="Q".charCodeAt(0),a.R="R".charCodeAt(0),a.S="S".charCodeAt(0),a.T="T".charCodeAt(0),a.U="U".charCodeAt(0),a.V="V".charCodeAt(0),a.W="W".charCodeAt(0),a.X="X".charCodeAt(0),a.Y="Y".charCodeAt(0),a.Z="Z".charCodeAt(0),a.ZERO="0".charCodeAt(0),a.ONE="1".charCodeAt(0),a.TWO="2".charCodeAt(0),a.THREE="3".charCodeAt(0),a.FOUR="4".charCodeAt(0),a.FIVE="5".charCodeAt(0),a.SIX="6".charCodeAt(0),a.SEVEN="7".charCodeAt(0),a.EIGHT="8".charCodeAt(0),a.NINE="9".charCodeAt(0),a.NUMPAD_0=96,a.NUMPAD_1=97,a.NUMPAD_2=98,a.NUMPAD_3=99,a.NUMPAD_4=100,a.NUMPAD_5=101,a.NUMPAD_6=102,a.NUMPAD_7=103,a.NUMPAD_8=104,a.NUMPAD_9=105,a.NUMPAD_MULTIPLY=106,a.NUMPAD_ADD=107,a.NUMPAD_ENTER=108,a.NUMPAD_SUBTRACT=109,a.NUMPAD_DECIMAL=110,a.NUMPAD_DIVIDE=111,a.F1=112,a.F2=113,a.F3=114,a.F4=115,a.F5=116,a.F6=117,a.F7=118,a.F8=119,a.F9=120,a.F10=121,a.F11=122,a.F12=123,a.F13=124,a.F14=125,a.F15=126,a.COLON=186,a.EQUALS=187,a.UNDERSCORE=189,a.QUESTION_MARK=191,a.TILDE=192,a.OPEN_BRACKET=219,a.BACKWARD_SLASH=220,a.CLOSED_BRACKET=221,a.QUOTES=222,a.BACKSPACE=8,a.TAB=9,a.CLEAR=12,a.ENTER=13,a.SHIFT=16,a.CONTROL=17,a.ALT=18,a.CAPS_LOCK=20,a.ESC=27,a.SPACEBAR=32,a.PAGE_UP=33,a.PAGE_DOWN=34,a.END=35,a.HOME=36,a.LEFT=37,a.UP=38,a.RIGHT=39,a.DOWN=40,a.INSERT=45,a.DELETE=46,a.HELP=47,a.NUM_LOCK=144,a}();a.Keycodes=b}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this.game=a}return b.prototype.objType=function(){return"InputManager"},Object.defineProperty(b.prototype,"pointers",{get:function(){return this._pointers},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._pointers=[],this.mouse=new a.Input.Mouse(this.game),this.mouse.boot(),this.keyboard=new a.Input.Keyboard(this.game),this.keyboard.boot(),this.touch=new a.Input.Touch(this.game),this.touch.boot(),this.mouse.onDown.add(this._onDownEvent,this),this.mouse.onUp.add(this._onUpEvent,this),this.touch.touchDown.add(this._onDownEvent,this),this.touch.touchUp.add(this._onUpEvent,this),this._pointers=this.touch.fingers.slice(),this._pointers.push(this.mouse.cursor),this.isDown=!1,this.position=new a.Geom.Point,this.onDown=new a.Signal,this.onUp=new a.Signal},b.prototype._onDownEvent=function(a,b,c,d,e,f){this.onDown.dispatch(a,b,c,d,e,f)},b.prototype._onUpEvent=function(a,b,c,d,e,f){this.onUp.dispatch(a,b,c,d,e,f)},Object.defineProperty(b.prototype,"onPressed",{get:function(){return this.onDown},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onReleased",{get:function(){return this.onUp},enumerable:!0,configurable:!0}),b.prototype.update=function(){this.mouse.update(),this.keyboard.update(),this.touch.update(),this.touch.touchEnabled?this.position.setTo(this.touch.x,this.touch.y):this.position.setTo(this.mouse.x,this.mouse.y),this.isDown=this.mouse.isDown||this.touch.isDown},b.prototype.reset=function(){this.mouse.reset(),this.keyboard.reset(),this.touch.reset()},Object.defineProperty(b.prototype,"x",{get:function(){return this.position.x},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"y",{get:function(){return this.position.y},enumerable:!0,configurable:!0}),b}();b.InputManager=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._domElement=null,this._game=a}return b.prototype.objType=function(){return"Mouse"},Object.defineProperty(b.prototype,"cursor",{get:function(){return this._cursor},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._domElement=this._game.stage.container,this._cursor=new a.Input.MouseCursor(this._game),this._cursor.active=!0,this._cursor.id=1,this.onDown=new a.Signal,this.onUp=new a.Signal,this.onWheel=new a.Signal,this.start()},Object.defineProperty(b.prototype,"isDown",{get:function(){return this._cursor.isDown},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"isUp",{get:function(){return this._cursor.isUp},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"duration",{get:function(){return this._cursor.duration},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"x",{get:function(){return this._cursor.x},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"y",{get:function(){return this._cursor.y},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"wheelDeltaX",{get:function(){return this._cursor.wheelDeltaX},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"wheelDeltaY",{get:function(){return this._cursor.wheelDeltaY},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"ctrlKey",{get:function(){return this._cursor.ctrlKey},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"shiftKey",{get:function(){return this._cursor.shiftKey},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"altKey",{get:function(){return this._cursor.altKey},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"button",{get:function(){return this._cursor.button},enumerable:!0,configurable:!0}),b.prototype.update=function(){this._cursor.update()},b.prototype.start=function(){var b=this;this._game.deviceTargetOption===a.TARGET_BROWSER?a.DEVICE.ie&&a.DEVICE.ieVersion<9?(this._domElement.attachEvent("onmousedown",function(a){return b.onMouseDown(a)}),this._domElement.attachEvent("onmousemove",function(a){return b.onMouseMove(a)}),this._domElement.attachEvent("onmouseup",function(a){return b.onMouseUp(a)}),this._domElement.attachEvent("onmousewheel",function(a){return b.onMouseWheel(a)})):(this._domElement.addEventListener("mousedown",function(a){return b.onMouseDown(a)},!0),this._domElement.addEventListener("mousemove",function(a){return b.onMouseMove(a)},!0),this._domElement.addEventListener("mouseup",function(a){return b.onMouseUp(a)},!0),this._domElement.addEventListener("mousewheel",function(a){return b.onMouseWheel(a)},!0),this._domElement.addEventListener("DOMMouseScroll",function(a){return b.onMouseWheel(a)},!0)):this._game.deviceTargetOption===a.TARGET_COCOON&&(this._game.stage.canvas.addEventListener("mousedown",function(a){return b.onMouseDown(a)},!0),this._game.stage.canvas.addEventListener("mousemove",function(a){return b.onMouseMove(a)},!0),this._game.stage.canvas.addEventListener("mouseup",function(a){return b.onMouseUp(a)},!0),this._game.stage.canvas.addEventListener("mousewheel",function(a){return b.onMouseWheel(a)},!0),this._game.stage.canvas.addEventListener("DOMMouseScroll",function(a){return b.onMouseWheel(a)},!0))},b.prototype.stop=function(){var b=this;this._game.deviceTargetOption===a.TARGET_BROWSER&&(this._domElement.removeEventListener("mousedown",function(a){return b.onMouseDown(a)},!1),this._domElement.removeEventListener("mousedown",this.onMouseDown,!1),this._domElement.removeEventListener("mousemove",this.onMouseMove,!1),this._domElement.removeEventListener("mouseup",this.onMouseUp,!1),this._domElement.removeEventListener("mousewheel",this.onMouseWheel,!1),this._domElement.removeEventListener("DOMMouseScroll",this.onMouseWheel,!1))},b.prototype.onMouseDown=function(a){this._cursor.start(a),this.onDown.dispatch(this._cursor.x,this._cursor.y,this._cursor.timeDown,this._cursor.timeUp,this.duration,this._cursor)},b.prototype.onMouseMove=function(a){a.preventDefault(),this._cursor.move(a)
-},b.prototype.onMouseUp=function(a){this._cursor.stop(a),this.onUp.dispatch(this._cursor.x,this._cursor.y,this._cursor.timeDown,this._cursor.timeUp,this.duration,this._cursor)},b.prototype.onMouseWheel=function(a){this._cursor.wheel(a),this.onWheel.dispatch(this._cursor.wheelDeltaX,this._cursor.wheelDeltaY,this._cursor)},b.prototype.justPressed=function(a){return void 0===a&&(a=this._cursor.justPressedRate),this._cursor.justPressed(a)},b.prototype.justReleased=function(a){return void 0===a&&(a=this._cursor.justReleasedRate),this._cursor.justReleased(a)},b.prototype.reset=function(){this._cursor.reset()},b.LEFT_BUTTON=0,b.MIDDLE_BUTTON=1,b.RIGHT_BUTTON=2,b}();b.Mouse=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._domElement=null,this.isDown=!1,this.isUp=!0,this._maxPointers=10,this._game=a}return b.prototype.objType=function(){return"TouchManager"},Object.defineProperty(b.prototype,"fingers",{get:function(){return this._fingers},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onDown",{get:function(){return this.touchDown},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onUp",{get:function(){return this.touchUp},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onCancel",{get:function(){return this.touchCancel},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._domElement=this._game.stage.container,this.finger1=new a.Input.Finger(this._game),this.finger2=new a.Input.Finger(this._game),this.finger3=new a.Input.Finger(this._game),this.finger4=new a.Input.Finger(this._game),this.finger5=new a.Input.Finger(this._game),this.finger6=new a.Input.Finger(this._game),this.finger7=new a.Input.Finger(this._game),this.finger8=new a.Input.Finger(this._game),this.finger9=new a.Input.Finger(this._game),this.finger10=new a.Input.Finger(this._game),this._fingers=[this.finger1,this.finger2,this.finger3,this.finger4,this.finger5,this.finger6,this.finger7,this.finger8,this.finger9,this.finger10],this.latestFinger=this.finger1,this.touchDown=new a.Signal,this.touchUp=new a.Signal,this.touchCancel=new a.Signal,this.start()},b.prototype.start=function(){var b=this;if(a.DEVICE.touch)if(this.touchEnabled=!0,this._game.deviceTargetOption===a.TARGET_BROWSER)if(a.DEVICE.pointerEnabled){var c="pointerup",d="pointerdown",e="pointerenter",f="pointerleave",g="pointercancel",h="pointermove";if(window.navigator.msPointerEnabled)var c="MSPointerUp",d="MSPointerDown",e="MSPointerEnter",f="MSPointerLeave",g="MSPointerCancel",h="MSPointerMove";this._domElement.addEventListener(c,function(a){return b.onPointerStart(a)},!1),this._domElement.addEventListener(d,function(a){return b.onPointerEnd(a)},!1),this._domElement.addEventListener(e,function(a){return b.onPointerEnter(a)},!1),this._domElement.addEventListener(f,function(a){return b.onPointerLeave(a)},!1),this._domElement.addEventListener(g,function(a){return b.onPointerCancel(a)},!1),this._domElement.addEventListener(h,function(a){return b.onPointerMove(a)},!1)}else this._domElement.addEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._domElement.addEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._domElement.addEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._domElement.addEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._domElement.addEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._domElement.addEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1),document.addEventListener("touchmove",function(a){return b.consumeTouchMove(a)},!1);else this._game.deviceTargetOption===a.TARGET_COCOON&&(this._game.stage.canvas.addEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._game.stage.canvas.addEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._game.stage.canvas.addEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._game.stage.canvas.addEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._game.stage.canvas.addEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._game.stage.canvas.addEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1));else this.touchEnabled=!1},b.prototype.consumeTouchMove=function(a){a.preventDefault()},Object.defineProperty(b.prototype,"x",{get:function(){return this.latestFinger.x},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"y",{get:function(){return this.latestFinger.y},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"maximumPointers",{get:function(){return this._maxPointers},set:function(a){0>a&&(a=1),a>this._fingers.length&&(a=this._fingers.length),this._maxPointers=a},enumerable:!0,configurable:!0}),b.prototype._registerFinger=function(a,b){for(var c=0;c<this._maxPointers;c++)if(this._fingers[c].active===!1){this._fingers[c].id=b,this._fingers[c].start(a),this.latestFinger=this._fingers[c],this.touchDown.dispatch(this._fingers[c].x,this._fingers[c].y,this._fingers[c].timeDown,this._fingers[c].timeUp,this._fingers[c].duration,this._fingers[c]),this.isDown=!0,this.isUp=!1;break}},b.prototype._deregisterFinger=function(a,b){for(var c=null,d=0;d<this._fingers.length;d++)if(this._fingers[d].active&&this._fingers[d].id===b){this._fingers[d].stop(a),this.latestFinger=this._fingers[d],c=this._fingers[d],this.isDown=!1,this.isUp=!0;break}for(var e=0;e<this._fingers.length;e++)this._fingers[e].active===!0&&(this.isDown=!0,this.isUp=!1);null!==c&&this.touchUp.dispatch(c.x,c.y,c.timeDown,c.timeUp,c.duration,c)},b.prototype._cancelFinger=function(a,b){for(var c=0;c<this._fingers.length;c++)if(this._fingers[c].active&&this._fingers[c].id===b){this._fingers[c].stop(a),this.touchCancel.dispatch(this._fingers[c].x,this._fingers[c].y,this._fingers[c].timeDown,this._fingers[c].timeUp,this._fingers[c].duration,this._fingers[c]);break}for(var d=0;d<this._fingers.length;d++)this._fingers[d].active&&(this.isDown=!0,this.isUp=!1)},b.prototype._enterFinger=function(a,b){for(var c=0;c<this._maxPointers;c++)if(this._fingers[c].active===!1){this._fingers[c].id=b,this._fingers[c].start(a),this.latestFinger=this._fingers[c],this.isDown=!0,this.isUp=!1;break}},b.prototype._leaveFinger=function(a,b){for(var c=0;c<this._fingers.length;c++)if(this._fingers[c].active&&this._fingers[c].id===b){this._fingers[c].leave(a);break}},b.prototype._moveFinger=function(a,b){for(var c=0;c<this._fingers.length;c++)if(this._fingers[c].active&&this._fingers[c].id===b){this._fingers[c].move(a),this.latestFinger=this._fingers[c];break}},b.prototype.onTouchStart=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._registerFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchCancel=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._cancelFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchEnter=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._enterFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchLeave=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._leaveFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchMove=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._moveFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchEnd=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._deregisterFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onPointerStart=function(a){"touch"===a.type&&this._registerFinger(a,a.pointerId)},b.prototype.onPointerCancel=function(a){"touch"===a.type&&this._cancelFinger(a,a.pointerId)},b.prototype.onPointerEnter=function(a){"touch"===a.type&&this._enterFinger(a,a.pointerId)},b.prototype.onPointerLeave=function(a){"touch"===a.type&&this._leaveFinger(a,a.pointerId)},b.prototype.onPointerMove=function(a){"touch"===a.type&&this._moveFinger(a,a.pointerId)},b.prototype.onPointerEnd=function(a){"touch"===a.type&&this._deregisterFinger(a,a.pointerId)},b.prototype.update=function(){if(this.touchEnabled&&this.isDown)for(var a=0;a<this._fingers.length;a++)this._fingers[a].active&&this._fingers[a].update()},b.prototype.stop=function(){var b=this;this.touchEnabled&&(this._game.deviceTargetOption===a.TARGET_BROWSER?(this._domElement.removeEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._domElement.removeEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._domElement.removeEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._domElement.removeEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._domElement.removeEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._domElement.removeEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1)):this._game.deviceTargetOption===a.TARGET_COCOON&&(this._game.stage.canvas.removeEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._game.stage.canvas.removeEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._game.stage.canvas.removeEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._game.stage.canvas.removeEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._game.stage.canvas.removeEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._game.stage.canvas.removeEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1)))},b.prototype.reset=function(){for(var a=0;a<this._fingers.length;a++)this._fingers[a].reset()},b}();b.Touch=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b){this.x=-1,this.y=-1,this.clientX=-1,this.clientY=-1,this.pageX=-1,this.pageY=-1,this.screenX=-1,this.screenY=-1,this.isDown=!1,this.isUp=!0,this.withinGame=!1,this.active=!1,this.timeDown=0,this.timeUp=0,this.duration=0,this.frameDuration=0,this.justPressedRate=200,this.justReleasedRate=200,this._game=b,this.point=new a.Geom.Point,this.circle=new a.Geom.Circle(0,0,1),this.startPoint=new a.Geom.Point,this.endPoint=new a.Geom.Point}return b.prototype.objType=function(){return"Pointer"},Object.defineProperty(b.prototype,"game",{get:function(){return this._game},enumerable:!0,configurable:!0}),b.prototype.start=function(a){this.move(a),this.startPoint.setTo(this.x,this.y),this.frameDuration=0,this.withinGame=!0,this.isDown=!0,this.isUp=!1,this.timeDown=this.game.time.now()},b.prototype.stop=function(){this.withinGame=!1,this.endPoint.setTo(this.x,this.y),this.isDown=!1,this.isUp=!0,this.timeUp=this.game.time.now(),this.duration=this.timeUp-this.timeDown},b.prototype.move=function(a){this.clientX=a.clientX,this.clientY=a.clientY,this.pageX=a.pageX,this.pageY=a.pageY,this.screenX=a.screenX,this.screenY=a.screenY,this.x=(this.pageX-this.game.stage.offset.x)*this.game.stage.scaleX,this.y=(this.pageY-this.game.stage.offset.y)*this.game.stage.scaleY,this.point.setTo(this.x,this.y),this.circle.x=this.x,this.circle.y=this.y,this.duration=this.game.time.now()-this.timeDown},b.prototype.justPressed=function(a){return void 0===a&&(a=this.justPressedRate),this.isDown===!0&&this.timeDown+a>this._game.time.now()?!0:!1},b.prototype.justReleased=function(a){return void 0===a&&(a=this.justReleasedRate),this.isUp===!0&&this.timeUp+a>this._game.time.now()?!0:!1},Object.defineProperty(b.prototype,"pressed",{get:function(){return this.timeDown>=this._game.time.now()-this._game.time.delta()},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"released",{get:function(){return this.timeUp>=this._game.time.now()-this._game.time.delta()},enumerable:!0,configurable:!0}),b.prototype.reset=function(){this.isDown=!1,this.isUp=!0,this.timeDown=0,this.timeUp=0,this.duration=0,this.frameDuration=0},b.prototype.update=function(){this.isDown===!0&&(this.frameDuration++,this.duration=this._game.time.now()-this.timeDown)},b}();b.Pointer=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(a){function b(){a.apply(this,arguments),this.wheelDeltaX=0,this.wheelDeltaY=0,this.preventDown=!0,this.preventUp=!0,this.preventWheel=!0}return __extends(b,a),b.prototype.objType=function(){return"MouseCursor"},b.prototype.start=function(b){this.preventDown&&b.preventDefault(),this.ctrlKey=b.ctrlKey,this.shiftKey=b.shiftKey,this.altKey=b.altKey,this.button=b.button,a.prototype.start.call(this,b)},b.prototype.stop=function(b){this.preventUp&&b.preventDefault(),this.move(b),a.prototype.stop.call(this,b)},b.prototype.wheel=function(a){this.preventWheel&&a.preventDefault(),this.wheelDeltaX=a.wheelDeltaX?a.wheelDeltaX:a.deltaX,this.wheelDeltaY=a.wheelDeltaY?a.wheelDeltaY:a.deltaY},b}(a.Pointer);a.MouseCursor=b}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(a){function b(b){a.call(this,b),this.circle.diameter=44}return __extends(b,a),b.prototype.objType=function(){return"Finger"},b.prototype.start=function(b){this.active=!0,a.prototype.start.call(this,b)},b.prototype.stop=function(b){this.active=!1,a.prototype.stop.call(this,b)},b.prototype.leave=function(a){this.withinGame=!1,this.move(a)},b.prototype.reset=function(){this.active=!1,a.prototype.reset.call(this)},b}(a.Pointer);a.Finger=b}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(a,b,c,d){this.cx=0,this.cy=0,this.halfWidth=0,this.halfHeight=0,this.cx=a||0,this.cy=b||0,this.halfWidth=c/2||0,this.halfHeight=d/2||0}return b.prototype.objType=function(){return"AABB"},Object.defineProperty(b.prototype,"height",{get:function(){return 2*this.halfHeight},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"width",{get:function(){return 2*this.halfWidth},enumerable:!0,configurable:!0}),b.prototype.draw=function(a){return a.beginPath(),a.moveTo(this.cx-this.halfWidth,this.cy),a.lineTo(this.cx+this.halfWidth,this.cy),a.moveTo(this.cx,this.cy-this.halfHeight),a.lineTo(this.cx,this.cy+this.halfHeight),a.stroke(),this},b.prototype.setPosition=function(a,b){return this.cx=a,this.cy=b,this},b.prototype.setPositionPoint=function(a){return this.cx=a.x,this.cy=a.y,this},b.prototype.toRect=function(){return new a.Rectangle(this.cx-this.halfWidth,this.cy-this.halfHeight,2*this.halfWidth,2*this.halfHeight)},b.prototype.fromRect=function(a){return this.halfWidth=a.width/2,this.halfHeight=a.height/2,this.cx=a.x+this.halfWidth,this.cy=a.y+this.halfHeight,this},b}();a.AABB=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(a,b,c){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),this._diameter=0,this._radius=0,this.x=0,this.y=0,this.setTo(a,b,c)}return b.prototype.objType=function(){return"Circle"},Object.defineProperty(b.prototype,"diameter",{get:function(){return this._diameter},set:function(a){a>0&&(this._diameter=a,this._radius=.5*a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"radius",{get:function(){return this._radius},set:function(a){a>0&&(this._radius=a,this._diameter=2*a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"circumference",{get:function(){return 2*Math.PI*this._radius},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"bottom",{get:function(){return this.y+this._radius},set:function(a){isNaN(a)||(a<this.y?(this._radius=0,this._diameter=0):this.radius=a-this.y)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"left",{get:function(){return this.x-this._radius},set:function(a){isNaN(a)||(a<this.x?this.radius=this.x-a:(this._radius=0,this._diameter=0))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"right",{get:function(){return this.x+this._radius},set:function(a){a&&!isNaN(a)&&(a>this.x?this.radius=a-this.x:(this._radius=0,this._diameter=0))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"top",{get:function(){return this.y-this._radius},set:function(a){a&&!isNaN(a)&&(a>this.y?(this._radius=0,this._diameter=0):this.radius=this.y-a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"area",{get:function(){return this._radius>0?Math.PI*this._radius*this._radius:0},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"isEmpty",{get:function(){return this._diameter<=0?!0:!1},enumerable:!0,configurable:!0}),b.prototype.clone=function(a){return void 0===a&&(a=new b),a.setTo(this.x,this.y,this._diameter)},b.prototype.copyFrom=function(a){return this.setTo(a.x,a.y,a.diameter)},b.prototype.copyTo=function(a){return a.copyFrom(this)},b.prototype.distanceTo=function(a,b){void 0===b&&(b=!1);var c=this.x-a.x,d=this.y-a.y;return b===!0?Math.round(Math.sqrt(c*c+d*d)):Math.sqrt(c*c+d*d)},b.prototype.equals=function(a){return this.x===a.x&&this.y===a.y&&this.diameter===a.diameter?!0:!1},b.prototype.intersects=function(a){return this.distanceTo(a,!1)<this._radius+a._radius?!0:!1},b.prototype.circumferencePoint=function(b,c,d){return void 0===c&&(c=!1),void 0===d&&(d=new a.Point),c===!0&&(b*=Math.PI/180),d.x=this.x+this._radius*Math.cos(b),d.y=this.y+this._radius*Math.sin(b),d},b.prototype.offset=function(a,b){return isNaN(a)||isNaN(b)||(this.x+=a,this.y+=b),this},b.prototype.offsetPoint=function(a){return this.offset(a.x,a.y)},b.prototype.setTo=function(a,b,c){return this.x=a,this.y=b,this._diameter=c,this._radius=.5*c,this},b.prototype.toString=function(){return"[{Circle (x="+this.x+" y="+this.y+" diameter="+this.diameter+" radius="+this.radius+")}]"},b}();a.Circle=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b,c,d){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=0,this.y1=0,this.x2=0,this.y2=0,this.setTo(a,b,c,d)}return a.prototype.objType=function(){return"Ray"},a.prototype.clone=function(b){return void 0===b&&(b=new a),b.setTo(this.x1,this.y1,this.x2,this.y2)},a.prototype.copyFrom=function(a){return this.setTo(a.x1,a.y1,a.x2,a.y2)},a.prototype.copyTo=function(a){return a.copyFrom(this)},a.prototype.setTo=function(a,b,c,d){return void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=a,this.y1=b,this.x2=c,this.y2=d,this},Object.defineProperty(a.prototype,"angle",{get:function(){return Math.atan2(this.y2-this.y1,this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"slope",{get:function(){return(this.y2-this.y1)/(this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"yIntercept",{get:function(){return this.y1-this.slope*this.x1},enumerable:!0,configurable:!0}),a.prototype.isPointOnRay=function(a,b){return(a-this.x1)*(this.y2-this.y1)===(this.x2-this.x1)*(b-this.y1)&&Math.atan2(b-this.y1,a-this.x1)==Math.atan2(this.y2-this.y1,this.x2-this.x1)?!0:!1},a.prototype.toString=function(){return"[{Ray (x1="+this.x1+" y1="+this.y1+" x2="+this.x2+" y2="+this.y2+")}]"},a}();a.Ray=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(){}return b.prototype.objType=function(){return"Intersect"},b.distance=function(a,b,c,d){return Math.sqrt((c-a)*(c-a)+(d-b)*(d-b))},b.distanceSquared=function(a,b,c,d){return(c-a)*(c-a)+(d-b)*(d-b)},b.lineToLine=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=(b.x1-b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1-c.x2);return 0!==e&&(d.result=!0,d.x=((b.x1*b.y2-b.y1*b.x2)*(c.x1-c.x2)-(b.x1-b.x2)*(c.x1*c.y2-c.y1*c.x2))/e,d.y=((b.x1*b.y2-b.y1*b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1*c.y2-c.y1*c.x2))/e),d},b.lineToLineSegment=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=(b.x1-b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1-c.x2);if(0!==e){d.x=((b.x1*b.y2-b.y1*b.x2)*(c.x1-c.x2)-(b.x1-b.x2)*(c.x1*c.y2-c.y1*c.x2))/e,d.y=((b.x1*b.y2-b.y1*b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1*c.y2-c.y1*c.x2))/e;var f=Math.max(c.x1,c.x2),g=Math.min(c.x1,c.x2),h=Math.max(c.y1,c.y2),i=Math.min(c.y1,c.y2);((d.x<=f&&d.x>=g)==!0||(d.y<=h&&d.y>=i)==!0)&&(d.result=!0)}return d},b.lineToRawSegment=function(b,c,d,e,f,g){void 0===g&&(g=new a.IntersectResult),g.result=!1;var h=(b.x1-b.x2)*(d-f)-(b.y1-b.y2)*(c-e);if(0!==h){g.x=((b.x1*b.y2-b.y1*b.x2)*(c-e)-(b.x1-b.x2)*(c*f-d*e))/h,g.y=((b.x1*b.y2-b.y1*b.x2)*(d-f)-(b.y1-b.y2)*(c*f-d*e))/h;var i=Math.max(c,e),j=Math.min(c,e),k=Math.max(d,f),l=Math.min(d,f);g.x<=i&&g.x>=j&&g.y<=k&&g.y>=l&&(g.result=!0)}return g},b.lineSegmentToRawSegment=function(c,d,e,f,g,h){void 0===h&&(h=new a.IntersectResult),h=b.lineToRawSegment(c,d,e,f,g,h);var i=Math.max(c.x1,c.x2),j=Math.min(c.x1,c.x2),k=Math.max(c.y1,c.y2),l=Math.min(c.y1,c.y2);return h.x<=i&&h.x>=j&&h.y<=k&&h.y>=l?h:(h.result=!1,h)},b.lineToRay=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=(b.x1-b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1-c.x2);return 0!==e&&(d.x=((b.x1*b.y2-b.y1*b.x2)*(c.x1-c.x2)-(b.x1-b.x2)*(c.x1*c.y2-c.y1*c.x2))/e,d.y=((b.x1*b.y2-b.y1*b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1*c.y2-c.y1*c.x2))/e,d.result=!0,!(c.x1>=c.x2)&&d.x<c.x1&&(d.result=!1),!(c.y1>=c.y2)&&d.y<c.y1&&(d.result=!1)),d},b.lineToCircle=function(b,c,d){return void 0===d&&(d=new a.IntersectResult),d.result=!1,b.perp(c.x,c.y).length<=c.radius&&(d.result=!0),d},b.lineToRectangle=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToRawSegment(c,d.x,d.y,d.right,d.y,e),e.result===!0?e:(b.lineToRawSegment(c,d.x,d.y,d.x,d.bottom,e),e.result===!0?e:(b.lineToRawSegment(c,d.x,d.bottom,d.right,d.bottom,e),e.result===!0?e:(b.lineToRawSegment(c,d.right,d.y,d.right,d.bottom,e),e)))},b.lineSegmentToLineSegment=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToLineSegment(c,d,e),e.result===!0&&(e.x>=Math.min(c.x1,c.x2)&&e.x<=Math.max(c.x1,c.x2)&&e.y>=Math.min(c.y1,c.y2)&&e.y<=Math.max(c.y1,c.y2)||(e.result=!1)),e},b.lineSegmentToRay=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToRay(c,d,e),e.result===!0&&(e.x>=Math.min(c.x1,c.x2)&&e.x<=Math.max(c.x1,c.x2)&&e.y>=Math.min(c.y1,c.y2)&&e.y<=Math.max(c.y1,c.y2)||(e.result=!1)),e},b.lineSegmentToCircle=function(c,d,e){void 0===e&&(e=new a.IntersectResult),e.result=!1;var f=c.perp(d.x,d.y);if(f.length<=d.radius){var g=Math.max(c.x1,c.x2),h=Math.min(c.x1,c.x2),i=Math.max(c.y1,c.y2),j=Math.min(c.y1,c.y2);f.x2<=g&&f.x2>=h&&f.y2<=i&&f.y2>=j?e.result=!0:(b.circleContainsPoint(d,{x:c.x1,y:c.y1}).result||b.circleContainsPoint(d,{x:c.x2,y:c.y2}).result)&&(e.result=!0)}return e},b.lineSegmentToRectangle=function(c,d,e){if(void 0===e&&(e=new a.IntersectResult),e.result=!1,d.contains(c.x1,c.y1)&&d.contains(c.x2,c.y2))e.x=(c.x1+c.x2)/2,e.y=(c.y1+c.y2)/2,e.result=!0;else{if(b.lineSegmentToRawSegment(c,d.x,d.y,d.right,d.y,e),e.result===!0)return e;if(b.lineSegmentToRawSegment(c,d.x,d.y,d.x,d.bottom,e),e.result===!0)return e;if(b.lineSegmentToRawSegment(c,d.x,d.bottom,d.right,d.bottom,e),e.result===!0)return e;b.lineSegmentToRawSegment(c,d.right,d.y,d.right,d.bottom,e)}return e},b.rayToRectangle=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToRectangle(c,d,e),e},b.rayToLineSegment=function(b,c,d,e,f,g,h,i,j){void 0===j&&(j=new a.IntersectResult),j.result=!1;var k,l,m;return(e-c)/(d-b)!=(i-g)/(h-f)&&(m=(d-b)*(i-g)-(e-c)*(h-f),0!=m&&(k=((c-g)*(h-f)-(b-f)*(i-g))/m,l=((c-g)*(d-b)-(b-f)*(e-c))/m,k>=0&&l>=0&&1>=l&&(j.result=!0,j.x=b+k*(d-b),c+k*(e-c)))),j},b.circleToCircle=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,e.result=(c.radius+d.radius)*(c.radius+d.radius)>=b.distanceSquared(c.x,c.y,d.x,d.y),e},b.circleToRectangle=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e,f,g,h,i,j,k,l;return i=c.width/2,g=Math.abs(b.x-c.x-i),k=b.radius+i,g>k?(d.result=!1,d):(j=c.height/2,h=Math.abs(b.y-c.y-j),l=b.radius+j,h>l?(d.result=!1,d):i>=g||h<=c.height/2?(d.result=!0,d):(e=g-i,f=h-j,d.result=e*e+f*f<=b.radius*b.radius,d))},b.circleContainsPoint=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,e.result=c.radius*c.radius>=b.distanceSquared(c.x,c.y,d.x,d.y),e},b.pointToRectangle=function(b,c,d){return void 0===d&&(d=new a.IntersectResult),d.result=!1,d.setTo(b.x,b.y),d.result=c.containsPoint(b),d},b.rectangleToRectangle=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=Math.max(b.x,c.x),f=Math.min(b.right,c.right),g=Math.max(b.y,c.y),h=Math.min(b.bottom,c.bottom);d.setTo(e,g,f-e,h-g,f-e,h-g);var i=d.x+.5*d.width,j=d.y+.5*d.height;return i>b.x&&i<b.right&&j>b.y&&j<b.bottom&&(d.result=!0),d},b}();a.Intersect=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){this.result=!1}return a.prototype.objType=function(){return"IntersectResult"},a.prototype.setTo=function(a,b,c,d,e,f){void 0===c&&(c=0),void 0===d&&(d=0),void 0===e&&(e=0),void 0===f&&(f=0),this.x=a,this.y=b,this.x1=a,this.y1=b,this.x2=c,this.y2=d,this.width=e,this.height=f},a}();a.IntersectResult=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c,d){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=0,this.y1=0,this.x2=0,this.y2=0,this.setTo(a,b,c,d)}return b.prototype.objType=function(){return"Line"},b.prototype.clone=function(a){return void 0===a&&(a=new b),a.setTo(this.x1,this.y1,this.x2,this.y2)},b.prototype.copyFrom=function(a){return this.setTo(a.x1,a.y1,a.x2,a.y2)},b.prototype.copyTo=function(a){return a.copyFrom(this)},b.prototype.setTo=function(a,b,c,d){return void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=a,this.y1=b,this.x2=c,this.y2=d,this},Object.defineProperty(b.prototype,"length",{get:function(){return Math.sqrt((this.x2-this.x1)*(this.x2-this.x1)+(this.y2-this.y1)*(this.y2-this.y1))},enumerable:!0,configurable:!0}),b.prototype.getY=function(a){return this.x1==this.x2?null:this.slope*a+this.yIntercept},Object.defineProperty(b.prototype,"angle",{get:function(){return Math.atan2(this.y2-this.y1,this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"slope",{get:function(){return(this.y2-this.y1)/(this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"perpSlope",{get:function(){return-((this.x2-this.x1)/(this.y2-this.y1))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"yIntercept",{get:function(){return this.y1-this.slope*this.x1},enumerable:!0,configurable:!0}),b.prototype.isPointOnLine=function(a,b){return(a-this.x1)*(this.y2-this.y1)===(this.x2-this.x1)*(b-this.y1)?!0:!1},b.prototype.isPointOnLineSegment=function(a,b){var c=Math.min(this.x1,this.x2),d=Math.max(this.x1,this.x2),e=Math.min(this.y1,this.y2),f=Math.max(this.y1,this.y2);return this.isPointOnLine(a,b)&&a>=c&&d>=a&&b>=e&&f>=b?!0:!1},b.prototype.intersectLineLine=function(b){return a.Geom.Intersect.lineToLine(this,b)},b.prototype.perp=function(a,c,d){void 0===d&&(d=new b);var e;if(this.y1===this.y2)return d.setTo(a,c,a,this.y1),d;if(this.x1===this.x2)return d.setTo(a,c,this.x1,c),d;var f=c-this.perpSlope*a;return e=this.intersectLineLine(0!==a?{x1:a,y1:c,x2:0,y2:f}:{x1:a,y1:c,x2:1,y2:f+this.perpSlope}),d.setTo(a,c,e.x,e.y),d},b.prototype.toString=function(){return"[{Line (x1="+this.x1+" y1="+this.y1+" x2="+this.x2+" y2="+this.y2+")}]"},b}();b.Line=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c,d,e,f){void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0),this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this.setTo(a,b,c,d,e,f)}return b.prototype.objType=function(){return"Matrix"},b.prototype.setTo=function(a,b,c,d,e,f){return void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0),this.a=a,this.b=b,this.c=c,this.d=d,this.tx=e,this.ty=f,this},b.prototype.setFromTransform=function(a,b,c,d,e){this.identity();var f=Math.cos(e),g=Math.sin(e);return this.append(f*c,g*c,-g*d,f*d,a,b),this},b.prototype.setFromOffsetTransform=function(a,b,c,d,e,f,g){this.identity();var h=Math.cos(e),i=Math.sin(e);return this.append(h*c,i*c,-i*d,h*d,a+f,b+g),this},b.prototype.prepend=function(a,b,c,d,e,f){void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0);var g=this.tx,h=this.a,i=this.c;return this.a=h*a+this.b*c,this.b=h*b+this.b*d,this.c=i*a+this.d*c,this.d=i*b+this.d*d,this.tx=g*a+this.ty*c+e,this.ty=g*b+this.ty*d+f,this},b.prototype.prependMatrix=function(a){var b=this.tx,c=this.a,d=this.c;return this.a=c*a.a+this.b*a.c,this.b=c*a.b+this.b*a.d,this.c=d*a.a+this.d*a.c,this.d=d*a.b+this.d*a.d,this.tx=b*a.a+this.ty*a.c+a.tx,this.ty=b*a.b+this.ty*a.d+a.ty,this},b.prototype.append=function(a,b,c,d,e,f){void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0);var g=this.a,h=this.b,i=this.c,j=this.d;return this.a=a*g+b*i,this.b=a*h+b*j,this.c=c*g+d*i,this.d=c*h+d*j,this.tx=e*g+f*i+this.tx,this.ty=e*h+f*j+this.ty,this},b.prototype.appendMatrix=function(a){var b=this.a,c=this.b,d=this.c,e=this.d;return this.a=a.a*b+a.b*d,this.b=a.a*c+a.b*e,this.c=a.c*b+a.d*d,this.d=a.c*c+a.d*e,this.tx=a.tx*b+a.ty*d+this.tx,this.ty=a.tx*c+a.ty*e+this.ty,this},b.prototype.setPosition=function(a,b){return this.tx=a,this.ty=b,this},b.prototype.setPositionPoint=function(a){return this.tx=a.x,this.ty=a.y,this},b.prototype.getPosition=function(b){return void 0===b&&(b=new a.Geom.Point),b.setTo(this.tx,this.ty)},b.prototype.identity=function(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this},b.prototype.rotate=function(a){var b=Math.cos(a),c=Math.sin(a),d=this.a,e=this.c,f=this.tx;return this.a=d*b-this.b*c,this.b=d*c+this.b*b,this.c=e*b-this.d*c,this.d=e*c+this.d*b,this.tx=f*b-this.ty*c,this.ty=f*c+this.ty*b,this},b.prototype.translate=function(a,b){return this.tx+=a,this.ty+=b,this},b.prototype.scale=function(a,b){return this.a*=a,this.d*=b,this},b.prototype.transformPoint=function(a){var b=a.x,c=a.y;return a.x=this.a*b+this.c*c+this.tx,a.y=this.b*b+this.d*c+this.ty,a},b.prototype.invert=function(){var a=this.a,b=this.b,c=this.c,d=this.d,e=this.tx,f=a*d-b*c;return this.a=d/f,this.b=-b/f,this.c=-c/f,this.d=a/f,this.tx=(c*this.ty-d*e)/f,this.ty=-(a*this.ty-b*e)/f,this},b.prototype.copyFrom=function(a){return this.a=a.a,this.b=a.b,this.c=a.c,this.d=a.d,this.tx=a.tx,this.ty=a.ty,this},b.prototype.copyTo=function(a){return a.a=this.a,a.b=this.b,a.c=this.c,a.d=this.d,a.tx=this.tx,a.ty=this.ty,this},b.prototype.clone=function(){return new a.Geom.Matrix(this.a,this.b,this.c,this.d,this.tx,this.ty)},Object.defineProperty(b.prototype,"toString",{get:function(){return"[{Matrix (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")}]"},enumerable:!0,configurable:!0}),b}();b.Matrix=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b){void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(a,b)}return a.prototype.objType=function(){return"Point"},a.prototype.polar=function(a,b){return this.x=a*Math.cos(b),this.y=a*Math.sin(b),this},a.prototype.add=function(b,c){return void 0===c&&(c=new a),c.setTo(this.x+b.x,this.y+b.y)},a.prototype.addTo=function(a,b){return void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(this.x+a,this.y+b)},a.prototype.subtractFrom=function(a,b){return void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(this.x-a,this.y-b)},a.prototype.invert=function(){return this.setTo(this.y,this.x)},a.prototype.clamp=function(a,b){return this.clampX(a,b),this.clampY(a,b),this},a.prototype.clampX=function(a,b){return this.x=Math.max(Math.min(this.x,b),a),this
+},b.prototype.onMouseUp=function(a){this._cursor.stop(a),this.onUp.dispatch(this._cursor.x,this._cursor.y,this._cursor.timeDown,this._cursor.timeUp,this.duration,this._cursor)},b.prototype.onMouseWheel=function(a){this._cursor.wheel(a),this.onWheel.dispatch(this._cursor.wheelDeltaX,this._cursor.wheelDeltaY,this._cursor)},b.prototype.justPressed=function(a){return void 0===a&&(a=this._cursor.justPressedRate),this._cursor.justPressed(a)},b.prototype.justReleased=function(a){return void 0===a&&(a=this._cursor.justReleasedRate),this._cursor.justReleased(a)},b.prototype.reset=function(){this._cursor.reset()},b.LEFT_BUTTON=0,b.MIDDLE_BUTTON=1,b.RIGHT_BUTTON=2,b}();b.Mouse=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._domElement=null,this.isDown=!1,this.isUp=!0,this._maxPointers=10,this._game=a}return b.prototype.objType=function(){return"TouchManager"},Object.defineProperty(b.prototype,"fingers",{get:function(){return this._fingers},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onDown",{get:function(){return this.touchDown},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onUp",{get:function(){return this.touchUp},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"onCancel",{get:function(){return this.touchCancel},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._domElement=this._game.stage.container,this.finger1=new a.Input.Finger(this._game),this.finger2=new a.Input.Finger(this._game),this.finger3=new a.Input.Finger(this._game),this.finger4=new a.Input.Finger(this._game),this.finger5=new a.Input.Finger(this._game),this.finger6=new a.Input.Finger(this._game),this.finger7=new a.Input.Finger(this._game),this.finger8=new a.Input.Finger(this._game),this.finger9=new a.Input.Finger(this._game),this.finger10=new a.Input.Finger(this._game),this._fingers=[this.finger1,this.finger2,this.finger3,this.finger4,this.finger5,this.finger6,this.finger7,this.finger8,this.finger9,this.finger10],this.latestFinger=this.finger1,this.touchDown=new a.Signal,this.touchUp=new a.Signal,this.touchCancel=new a.Signal,this.start()},b.prototype.start=function(){var b=this;if(a.DEVICE.touch)if(this.touchEnabled=!0,this._game.deviceTargetOption===a.TARGET_BROWSER)if(a.DEVICE.pointerEnabled){var c="pointerup",d="pointerdown",e="pointerenter",f="pointerleave",g="pointercancel",h="pointermove";if(window.navigator.msPointerEnabled)var c="MSPointerUp",d="MSPointerDown",e="MSPointerEnter",f="MSPointerLeave",g="MSPointerCancel",h="MSPointerMove";this._domElement.addEventListener(c,function(a){return b.onPointerStart(a)},!1),this._domElement.addEventListener(d,function(a){return b.onPointerEnd(a)},!1),this._domElement.addEventListener(e,function(a){return b.onPointerEnter(a)},!1),this._domElement.addEventListener(f,function(a){return b.onPointerLeave(a)},!1),this._domElement.addEventListener(g,function(a){return b.onPointerCancel(a)},!1),this._domElement.addEventListener(h,function(a){return b.onPointerMove(a)},!1)}else this._domElement.addEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._domElement.addEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._domElement.addEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._domElement.addEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._domElement.addEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._domElement.addEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1),document.addEventListener("touchmove",function(a){return b.consumeTouchMove(a)},!1);else this._game.deviceTargetOption===a.TARGET_COCOON&&(this._game.stage.canvas.addEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._game.stage.canvas.addEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._game.stage.canvas.addEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._game.stage.canvas.addEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._game.stage.canvas.addEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._game.stage.canvas.addEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1));else this.touchEnabled=!1},b.prototype.consumeTouchMove=function(a){a.preventDefault()},Object.defineProperty(b.prototype,"x",{get:function(){return this.latestFinger.x},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"y",{get:function(){return this.latestFinger.y},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"maximumPointers",{get:function(){return this._maxPointers},set:function(a){0>a&&(a=1),a>this._fingers.length&&(a=this._fingers.length),this._maxPointers=a},enumerable:!0,configurable:!0}),b.prototype._registerFinger=function(a,b){for(var c=0;c<this._maxPointers;c++)if(this._fingers[c].active===!1){this._fingers[c].id=b,this._fingers[c].start(a),this.latestFinger=this._fingers[c],this.touchDown.dispatch(this._fingers[c].x,this._fingers[c].y,this._fingers[c].timeDown,this._fingers[c].timeUp,this._fingers[c].duration,this._fingers[c]),this.isDown=!0,this.isUp=!1;break}},b.prototype._deregisterFinger=function(a,b){for(var c=null,d=0;d<this._fingers.length;d++)if(this._fingers[d].active&&this._fingers[d].id===b){this._fingers[d].stop(a),this.latestFinger=this._fingers[d],c=this._fingers[d],this.isDown=!1,this.isUp=!0;break}for(var e=0;e<this._fingers.length;e++)this._fingers[e].active===!0&&(this.isDown=!0,this.isUp=!1);null!==c&&this.touchUp.dispatch(c.x,c.y,c.timeDown,c.timeUp,c.duration,c)},b.prototype._cancelFinger=function(a,b){for(var c=0;c<this._fingers.length;c++)if(this._fingers[c].active&&this._fingers[c].id===b){this._fingers[c].stop(a),this.touchCancel.dispatch(this._fingers[c].x,this._fingers[c].y,this._fingers[c].timeDown,this._fingers[c].timeUp,this._fingers[c].duration,this._fingers[c]);break}for(var d=0;d<this._fingers.length;d++)this._fingers[d].active&&(this.isDown=!0,this.isUp=!1)},b.prototype._enterFinger=function(a,b){for(var c=0;c<this._maxPointers;c++)if(this._fingers[c].active===!1){this._fingers[c].id=b,this._fingers[c].start(a),this.latestFinger=this._fingers[c],this.isDown=!0,this.isUp=!1;break}},b.prototype._leaveFinger=function(a,b){for(var c=0;c<this._fingers.length;c++)if(this._fingers[c].active&&this._fingers[c].id===b){this._fingers[c].leave(a);break}},b.prototype._moveFinger=function(a,b){for(var c=0;c<this._fingers.length;c++)if(this._fingers[c].active&&this._fingers[c].id===b){this._fingers[c].move(a),this.latestFinger=this._fingers[c];break}},b.prototype.onTouchStart=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._registerFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchCancel=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._cancelFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchEnter=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._enterFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchLeave=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._leaveFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchMove=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._moveFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onTouchEnd=function(a){a.preventDefault();for(var b=0;b<a.changedTouches.length;b++)this._deregisterFinger(a.changedTouches[b],a.changedTouches[b].identifier)},b.prototype.onPointerStart=function(a){"touch"===a.type&&this._registerFinger(a,a.pointerId)},b.prototype.onPointerCancel=function(a){"touch"===a.type&&this._cancelFinger(a,a.pointerId)},b.prototype.onPointerEnter=function(a){"touch"===a.type&&this._enterFinger(a,a.pointerId)},b.prototype.onPointerLeave=function(a){"touch"===a.type&&this._leaveFinger(a,a.pointerId)},b.prototype.onPointerMove=function(a){"touch"===a.type&&this._moveFinger(a,a.pointerId)},b.prototype.onPointerEnd=function(a){"touch"===a.type&&this._deregisterFinger(a,a.pointerId)},b.prototype.update=function(){if(this.touchEnabled&&this.isDown)for(var a=0;a<this._fingers.length;a++)this._fingers[a].active&&this._fingers[a].update()},b.prototype.stop=function(){var b=this;this.touchEnabled&&(this._game.deviceTargetOption===a.TARGET_BROWSER?(this._domElement.removeEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._domElement.removeEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._domElement.removeEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._domElement.removeEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._domElement.removeEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._domElement.removeEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1)):this._game.deviceTargetOption===a.TARGET_COCOON&&(this._game.stage.canvas.removeEventListener("touchstart",function(a){return b.onTouchStart(a)},!1),this._game.stage.canvas.removeEventListener("touchmove",function(a){return b.onTouchMove(a)},!1),this._game.stage.canvas.removeEventListener("touchend",function(a){return b.onTouchEnd(a)},!1),this._game.stage.canvas.removeEventListener("touchenter",function(a){return b.onTouchEnter(a)},!1),this._game.stage.canvas.removeEventListener("touchleave",function(a){return b.onTouchLeave(a)},!1),this._game.stage.canvas.removeEventListener("touchcancel",function(a){return b.onTouchCancel(a)},!1)))},b.prototype.reset=function(){for(var a=0;a<this._fingers.length;a++)this._fingers[a].reset()},b}();b.Touch=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b){this.x=-1,this.y=-1,this.clientX=-1,this.clientY=-1,this.pageX=-1,this.pageY=-1,this.screenX=-1,this.screenY=-1,this.isDown=!1,this.isUp=!0,this.withinGame=!1,this.active=!1,this.timeDown=0,this.timeUp=0,this.duration=0,this.frameDuration=0,this.justPressedRate=200,this.justReleasedRate=200,this._game=b,this.point=new a.Geom.Point,this.circle=new a.Geom.Circle(0,0,1),this.startPoint=new a.Geom.Point,this.endPoint=new a.Geom.Point}return b.prototype.objType=function(){return"Pointer"},Object.defineProperty(b.prototype,"game",{get:function(){return this._game},enumerable:!0,configurable:!0}),b.prototype.start=function(a){this.move(a),this.startPoint.setTo(this.x,this.y),this.frameDuration=0,this.withinGame=!0,this.isDown=!0,this.isUp=!1,this.timeDown=this.game.time.now()},b.prototype.stop=function(){this.withinGame=!1,this.endPoint.setTo(this.x,this.y),this.isDown=!1,this.isUp=!0,this.timeUp=this.game.time.now(),this.duration=this.timeUp-this.timeDown},b.prototype.move=function(a){this.clientX=a.clientX,this.clientY=a.clientY,this.pageX=a.pageX,this.pageY=a.pageY,this.screenX=a.screenX,this.screenY=a.screenY,this.x=(this.pageX-this.game.stage.offset.x)*this.game.stage.scaleX,this.y=(this.pageY-this.game.stage.offset.y)*this.game.stage.scaleY,this.point.setTo(this.x,this.y),this.circle.x=this.x,this.circle.y=this.y,this.duration=this.game.time.now()-this.timeDown},b.prototype.justPressed=function(a){return void 0===a&&(a=this.justPressedRate),this.isDown===!0&&this.timeDown+a>this._game.time.now()?!0:!1},b.prototype.justReleased=function(a){return void 0===a&&(a=this.justReleasedRate),this.isUp===!0&&this.timeUp+a>this._game.time.now()?!0:!1},Object.defineProperty(b.prototype,"pressed",{get:function(){return this.timeDown>=this._game.time.now()-this._game.time.delta()},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"released",{get:function(){return this.timeUp>=this._game.time.now()-this._game.time.delta()},enumerable:!0,configurable:!0}),b.prototype.reset=function(){this.isDown=!1,this.isUp=!0,this.timeDown=0,this.timeUp=0,this.duration=0,this.frameDuration=0},b.prototype.update=function(){this.isDown===!0&&(this.frameDuration++,this.duration=this._game.time.now()-this.timeDown)},b}();b.Pointer=c}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(a){function b(){a.apply(this,arguments),this.wheelDeltaX=0,this.wheelDeltaY=0,this.preventDown=!0,this.preventUp=!0,this.preventWheel=!0}return __extends(b,a),b.prototype.objType=function(){return"MouseCursor"},b.prototype.start=function(b){this.preventDown&&b.preventDefault(),this.ctrlKey=b.ctrlKey,this.shiftKey=b.shiftKey,this.altKey=b.altKey,this.button=b.button,a.prototype.start.call(this,b)},b.prototype.stop=function(b){this.preventUp&&b.preventDefault(),this.move(b),a.prototype.stop.call(this,b)},b.prototype.wheel=function(a){this.preventWheel&&a.preventDefault(),this.wheelDeltaX=a.wheelDeltaX?a.wheelDeltaX:a.deltaX,this.wheelDeltaY=a.wheelDeltaY?a.wheelDeltaY:a.deltaY},b}(a.Pointer);a.MouseCursor=b}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(a){function b(b){a.call(this,b),this.circle.diameter=44}return __extends(b,a),b.prototype.objType=function(){return"Finger"},b.prototype.start=function(b){this.active=!0,a.prototype.start.call(this,b)},b.prototype.stop=function(b){this.active=!1,a.prototype.stop.call(this,b)},b.prototype.leave=function(a){this.withinGame=!1,this.move(a)},b.prototype.reset=function(){this.active=!1,a.prototype.reset.call(this)},b}(a.Pointer);a.Finger=b}(b=a.Input||(a.Input={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(a,b,c,d){this.cx=0,this.cy=0,this.halfWidth=0,this.halfHeight=0,this.cx=a||0,this.cy=b||0,this.halfWidth=c/2||0,this.halfHeight=d/2||0}return b.prototype.objType=function(){return"AABB"},Object.defineProperty(b.prototype,"height",{get:function(){return 2*this.halfHeight},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"width",{get:function(){return 2*this.halfWidth},enumerable:!0,configurable:!0}),b.prototype.draw=function(a){return a.beginPath(),a.moveTo(this.cx-this.halfWidth,this.cy),a.lineTo(this.cx+this.halfWidth,this.cy),a.moveTo(this.cx,this.cy-this.halfHeight),a.lineTo(this.cx,this.cy+this.halfHeight),a.stroke(),this},b.prototype.setPosition=function(a,b){return this.cx=a,this.cy=b,this},b.prototype.setPositionPoint=function(a){return this.cx=a.x,this.cy=a.y,this},b.prototype.toRect=function(){return new a.Rectangle(this.cx-this.halfWidth,this.cy-this.halfHeight,2*this.halfWidth,2*this.halfHeight)},b.prototype.fromRect=function(a){return this.halfWidth=a.width/2,this.halfHeight=a.height/2,this.cx=a.x+this.halfWidth,this.cy=a.y+this.halfHeight,this},b}();a.AABB=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(a,b,c){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),this._diameter=0,this._radius=0,this.x=0,this.y=0,this.setTo(a,b,c)}return b.prototype.objType=function(){return"Circle"},Object.defineProperty(b.prototype,"diameter",{get:function(){return this._diameter},set:function(a){a>0&&(this._diameter=a,this._radius=.5*a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"radius",{get:function(){return this._radius},set:function(a){a>0&&(this._radius=a,this._diameter=2*a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"circumference",{get:function(){return 2*Math.PI*this._radius},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"bottom",{get:function(){return this.y+this._radius},set:function(a){isNaN(a)||(a<this.y?(this._radius=0,this._diameter=0):this.radius=a-this.y)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"left",{get:function(){return this.x-this._radius},set:function(a){isNaN(a)||(a<this.x?this.radius=this.x-a:(this._radius=0,this._diameter=0))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"right",{get:function(){return this.x+this._radius},set:function(a){a&&!isNaN(a)&&(a>this.x?this.radius=a-this.x:(this._radius=0,this._diameter=0))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"top",{get:function(){return this.y-this._radius},set:function(a){a&&!isNaN(a)&&(a>this.y?(this._radius=0,this._diameter=0):this.radius=this.y-a)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"area",{get:function(){return this._radius>0?Math.PI*this._radius*this._radius:0},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"isEmpty",{get:function(){return this._diameter<=0?!0:!1},enumerable:!0,configurable:!0}),b.prototype.clone=function(a){return void 0===a&&(a=new b),a.setTo(this.x,this.y,this._diameter)},b.prototype.copyFrom=function(a){return this.setTo(a.x,a.y,a.diameter)},b.prototype.copyTo=function(a){return a.copyFrom(this)},b.prototype.distanceTo=function(a,b){void 0===b&&(b=!1);var c=this.x-a.x,d=this.y-a.y;return b===!0?Math.round(Math.sqrt(c*c+d*d)):Math.sqrt(c*c+d*d)},b.prototype.equals=function(a){return this.x===a.x&&this.y===a.y&&this.diameter===a.diameter?!0:!1},b.prototype.intersects=function(a){return this.distanceTo(a,!1)<this._radius+a._radius?!0:!1},b.prototype.circumferencePoint=function(b,c,d){return void 0===c&&(c=!1),void 0===d&&(d=new a.Point),c===!0&&(b*=Math.PI/180),d.x=this.x+this._radius*Math.cos(b),d.y=this.y+this._radius*Math.sin(b),d},b.prototype.offset=function(a,b){return isNaN(a)||isNaN(b)||(this.x+=a,this.y+=b),this},b.prototype.offsetPoint=function(a){return this.offset(a.x,a.y)},b.prototype.setTo=function(a,b,c){return this.x=a,this.y=b,this._diameter=c,this._radius=.5*c,this},b.prototype.toString=function(){return"[{Circle (x="+this.x+" y="+this.y+" diameter="+this.diameter+" radius="+this.radius+")}]"},b}();a.Circle=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b,c,d){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=0,this.y1=0,this.x2=0,this.y2=0,this.setTo(a,b,c,d)}return a.prototype.objType=function(){return"Ray"},a.prototype.clone=function(b){return void 0===b&&(b=new a),b.setTo(this.x1,this.y1,this.x2,this.y2)},a.prototype.copyFrom=function(a){return this.setTo(a.x1,a.y1,a.x2,a.y2)},a.prototype.copyTo=function(a){return a.copyFrom(this)},a.prototype.setTo=function(a,b,c,d){return void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=a,this.y1=b,this.x2=c,this.y2=d,this},Object.defineProperty(a.prototype,"angle",{get:function(){return Math.atan2(this.y2-this.y1,this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"slope",{get:function(){return(this.y2-this.y1)/(this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"yIntercept",{get:function(){return this.y1-this.slope*this.x1},enumerable:!0,configurable:!0}),a.prototype.isPointOnRay=function(a,b){return(a-this.x1)*(this.y2-this.y1)===(this.x2-this.x1)*(b-this.y1)&&Math.atan2(b-this.y1,a-this.x1)==Math.atan2(this.y2-this.y1,this.x2-this.x1)?!0:!1},a.prototype.toString=function(){return"[{Ray (x1="+this.x1+" y1="+this.y1+" x2="+this.x2+" y2="+this.y2+")}]"},a}();a.Ray=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(){}return b.prototype.objType=function(){return"Intersect"},b.distance=function(a,b,c,d){return Math.sqrt((c-a)*(c-a)+(d-b)*(d-b))},b.distanceSquared=function(a,b,c,d){return(c-a)*(c-a)+(d-b)*(d-b)},b.lineToLine=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=(b.x1-b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1-c.x2);return 0!==e&&(d.result=!0,d.x=((b.x1*b.y2-b.y1*b.x2)*(c.x1-c.x2)-(b.x1-b.x2)*(c.x1*c.y2-c.y1*c.x2))/e,d.y=((b.x1*b.y2-b.y1*b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1*c.y2-c.y1*c.x2))/e),d},b.lineToLineSegment=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=(b.x1-b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1-c.x2);if(0!==e){d.x=((b.x1*b.y2-b.y1*b.x2)*(c.x1-c.x2)-(b.x1-b.x2)*(c.x1*c.y2-c.y1*c.x2))/e,d.y=((b.x1*b.y2-b.y1*b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1*c.y2-c.y1*c.x2))/e;var f=Math.max(c.x1,c.x2),g=Math.min(c.x1,c.x2),h=Math.max(c.y1,c.y2),i=Math.min(c.y1,c.y2);(d.x<=f&&d.x>=g)==!0&&(d.y<=h&&d.y>=i)==!0&&(d.result=!0)}return d},b.lineToRawSegment=function(b,c,d,e,f,g){void 0===g&&(g=new a.IntersectResult),g.result=!1;var h=(b.x1-b.x2)*(d-f)-(b.y1-b.y2)*(c-e);if(0!==h){g.x=((b.x1*b.y2-b.y1*b.x2)*(c-e)-(b.x1-b.x2)*(c*f-d*e))/h,g.y=((b.x1*b.y2-b.y1*b.x2)*(d-f)-(b.y1-b.y2)*(c*f-d*e))/h;var i=Math.max(c,e),j=Math.min(c,e),k=Math.max(d,f),l=Math.min(d,f);g.x<=i&&g.x>=j&&g.y<=k&&g.y>=l&&(g.result=!0)}return g},b.lineSegmentToRawSegment=function(c,d,e,f,g,h){void 0===h&&(h=new a.IntersectResult),h=b.lineToRawSegment(c,d,e,f,g,h);var i=Math.max(c.x1,c.x2),j=Math.min(c.x1,c.x2),k=Math.max(c.y1,c.y2),l=Math.min(c.y1,c.y2);return h.x<=i&&h.x>=j&&h.y<=k&&h.y>=l?h:(h.result=!1,h)},b.lineToRay=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=(b.x1-b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1-c.x2);return 0!==e&&(d.x=((b.x1*b.y2-b.y1*b.x2)*(c.x1-c.x2)-(b.x1-b.x2)*(c.x1*c.y2-c.y1*c.x2))/e,d.y=((b.x1*b.y2-b.y1*b.x2)*(c.y1-c.y2)-(b.y1-b.y2)*(c.x1*c.y2-c.y1*c.x2))/e,d.result=!0,!(c.x1>=c.x2)&&d.x<c.x1&&(d.result=!1),!(c.y1>=c.y2)&&d.y<c.y1&&(d.result=!1)),d},b.lineToCircle=function(b,c,d){return void 0===d&&(d=new a.IntersectResult),d.result=!1,b.perp(c.x,c.y).length<=c.radius&&(d.result=!0),d},b.lineToRectangle=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToRawSegment(c,d.x,d.y,d.right,d.y,e),e.result===!0?e:(b.lineToRawSegment(c,d.x,d.y,d.x,d.bottom,e),e.result===!0?e:(b.lineToRawSegment(c,d.x,d.bottom,d.right,d.bottom,e),e.result===!0?e:(b.lineToRawSegment(c,d.right,d.y,d.right,d.bottom,e),e)))},b.lineSegmentToLineSegment=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToLineSegment(c,d,e),e.result===!0&&(e.x>=Math.min(c.x1,c.x2)&&e.x<=Math.max(c.x1,c.x2)&&e.y>=Math.min(c.y1,c.y2)&&e.y<=Math.max(c.y1,c.y2)||(e.result=!1)),e},b.lineSegmentToRay=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToRay(c,d,e),e.result===!0&&(e.x>=Math.min(c.x1,c.x2)&&e.x<=Math.max(c.x1,c.x2)&&e.y>=Math.min(c.y1,c.y2)&&e.y<=Math.max(c.y1,c.y2)||(e.result=!1)),e},b.lineSegmentToCircle=function(c,d,e){void 0===e&&(e=new a.IntersectResult),e.result=!1;var f=c.perp(d.x,d.y);if(f.length<=d.radius){var g=Math.max(c.x1,c.x2),h=Math.min(c.x1,c.x2),i=Math.max(c.y1,c.y2),j=Math.min(c.y1,c.y2);f.x2<=g&&f.x2>=h&&f.y2<=i&&f.y2>=j?e.result=!0:(b.circleContainsPoint(d,{x:c.x1,y:c.y1}).result||b.circleContainsPoint(d,{x:c.x2,y:c.y2}).result)&&(e.result=!0)}return e},b.lineSegmentToRectangle=function(c,d,e){if(void 0===e&&(e=new a.IntersectResult),e.result=!1,d.contains(c.x1,c.y1)&&d.contains(c.x2,c.y2))e.x=(c.x1+c.x2)/2,e.y=(c.y1+c.y2)/2,e.result=!0;else{if(b.lineSegmentToRawSegment(c,d.x,d.y,d.right,d.y,e),e.result===!0)return e;if(b.lineSegmentToRawSegment(c,d.x,d.y,d.x,d.bottom,e),e.result===!0)return e;if(b.lineSegmentToRawSegment(c,d.x,d.bottom,d.right,d.bottom,e),e.result===!0)return e;b.lineSegmentToRawSegment(c,d.right,d.y,d.right,d.bottom,e)}return e},b.rayToRectangle=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,b.lineToRectangle(c,d,e),e},b.rayToLineSegment=function(b,c,d,e,f,g,h,i,j){void 0===j&&(j=new a.IntersectResult),j.result=!1;var k,l,m;return(e-c)/(d-b)!=(i-g)/(h-f)&&(m=(d-b)*(i-g)-(e-c)*(h-f),0!=m&&(k=((c-g)*(h-f)-(b-f)*(i-g))/m,l=((c-g)*(d-b)-(b-f)*(e-c))/m,k>=0&&l>=0&&1>=l&&(j.result=!0,j.x=b+k*(d-b),c+k*(e-c)))),j},b.circleToCircle=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,e.result=(c.radius+d.radius)*(c.radius+d.radius)>=b.distanceSquared(c.x,c.y,d.x,d.y),e},b.circleToRectangle=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e,f,g,h,i,j,k,l;return i=c.width/2,g=Math.abs(b.x-c.x-i),k=b.radius+i,g>k?(d.result=!1,d):(j=c.height/2,h=Math.abs(b.y-c.y-j),l=b.radius+j,h>l?(d.result=!1,d):i>=g||h<=c.height/2?(d.result=!0,d):(e=g-i,f=h-j,d.result=e*e+f*f<=b.radius*b.radius,d))},b.circleContainsPoint=function(c,d,e){return void 0===e&&(e=new a.IntersectResult),e.result=!1,e.result=c.radius*c.radius>=b.distanceSquared(c.x,c.y,d.x,d.y),e},b.pointToRectangle=function(b,c,d){return void 0===d&&(d=new a.IntersectResult),d.result=!1,d.setTo(b.x,b.y),d.result=c.containsPoint(b),d},b.rectangleToRectangle=function(b,c,d){void 0===d&&(d=new a.IntersectResult),d.result=!1;var e=Math.max(b.x,c.x),f=Math.min(b.right,c.right),g=Math.max(b.y,c.y),h=Math.min(b.bottom,c.bottom);d.setTo(e,g,f-e,h-g,f-e,h-g);var i=d.x+.5*d.width,j=d.y+.5*d.height;return i>b.x&&i<b.right&&j>b.y&&j<b.bottom&&(d.result=!0),d},b}();a.Intersect=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){this.result=!1}return a.prototype.objType=function(){return"IntersectResult"},a.prototype.setTo=function(a,b,c,d,e,f){void 0===c&&(c=0),void 0===d&&(d=0),void 0===e&&(e=0),void 0===f&&(f=0),this.x=a,this.y=b,this.x1=a,this.y1=b,this.x2=c,this.y2=d,this.width=e,this.height=f},a}();a.IntersectResult=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c,d){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=0,this.y1=0,this.x2=0,this.y2=0,this.setTo(a,b,c,d)}return b.prototype.objType=function(){return"Line"},b.prototype.clone=function(a){return void 0===a&&(a=new b),a.setTo(this.x1,this.y1,this.x2,this.y2)},b.prototype.copyFrom=function(a){return this.setTo(a.x1,a.y1,a.x2,a.y2)},b.prototype.copyTo=function(a){return a.copyFrom(this)},b.prototype.setTo=function(a,b,c,d){return void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x1=a,this.y1=b,this.x2=c,this.y2=d,this},Object.defineProperty(b.prototype,"length",{get:function(){return Math.sqrt((this.x2-this.x1)*(this.x2-this.x1)+(this.y2-this.y1)*(this.y2-this.y1))},enumerable:!0,configurable:!0}),b.prototype.getY=function(a){return this.x1==this.x2?null:this.slope*a+this.yIntercept},Object.defineProperty(b.prototype,"angle",{get:function(){return Math.atan2(this.y2-this.y1,this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"slope",{get:function(){return(this.y2-this.y1)/(this.x2-this.x1)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"perpSlope",{get:function(){return-((this.x2-this.x1)/(this.y2-this.y1))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"yIntercept",{get:function(){return this.y1-this.slope*this.x1},enumerable:!0,configurable:!0}),b.prototype.isPointOnLine=function(a,b){return(a-this.x1)*(this.y2-this.y1)===(this.x2-this.x1)*(b-this.y1)?!0:!1},b.prototype.isPointOnLineSegment=function(a,b){var c=Math.min(this.x1,this.x2),d=Math.max(this.x1,this.x2),e=Math.min(this.y1,this.y2),f=Math.max(this.y1,this.y2);return this.isPointOnLine(a,b)&&a>=c&&d>=a&&b>=e&&f>=b?!0:!1},b.prototype.intersectLineLine=function(b){return a.Geom.Intersect.lineToLine(this,b)},b.prototype.perp=function(a,c,d){void 0===d&&(d=new b);var e;if(this.y1===this.y2)return d.setTo(a,c,a,this.y1),d;if(this.x1===this.x2)return d.setTo(a,c,this.x1,c),d;var f=c-this.perpSlope*a;return e=this.intersectLineLine(0!==a?{x1:a,y1:c,x2:0,y2:f}:{x1:a,y1:c,x2:1,y2:f+this.perpSlope}),d.setTo(a,c,e.x,e.y),d},b.prototype.toString=function(){return"[{Line (x1="+this.x1+" y1="+this.y1+" x2="+this.x2+" y2="+this.y2+")}]"},b}();b.Line=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a,b,c,d,e,f){void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0),this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this.setTo(a,b,c,d,e,f)}return b.prototype.objType=function(){return"Matrix"},b.prototype.setTo=function(a,b,c,d,e,f){return void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0),this.a=a,this.b=b,this.c=c,this.d=d,this.tx=e,this.ty=f,this},b.prototype.setFromTransform=function(a,b,c,d,e){this.identity();var f=Math.cos(e),g=Math.sin(e);return this.append(f*c,g*c,-g*d,f*d,a,b),this},b.prototype.setFromOffsetTransform=function(a,b,c,d,e,f,g){this.identity();var h=Math.cos(e),i=Math.sin(e);return this.append(h*c,i*c,-i*d,h*d,a+f,b+g),this},b.prototype.prepend=function(a,b,c,d,e,f){void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0);var g=this.tx,h=this.a,i=this.c;return this.a=h*a+this.b*c,this.b=h*b+this.b*d,this.c=i*a+this.d*c,this.d=i*b+this.d*d,this.tx=g*a+this.ty*c+e,this.ty=g*b+this.ty*d+f,this},b.prototype.prependMatrix=function(a){var b=this.tx,c=this.a,d=this.c;return this.a=c*a.a+this.b*a.c,this.b=c*a.b+this.b*a.d,this.c=d*a.a+this.d*a.c,this.d=d*a.b+this.d*a.d,this.tx=b*a.a+this.ty*a.c+a.tx,this.ty=b*a.b+this.ty*a.d+a.ty,this},b.prototype.append=function(a,b,c,d,e,f){void 0===a&&(a=1),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0);var g=this.a,h=this.b,i=this.c,j=this.d;return this.a=a*g+b*i,this.b=a*h+b*j,this.c=c*g+d*i,this.d=c*h+d*j,this.tx=e*g+f*i+this.tx,this.ty=e*h+f*j+this.ty,this},b.prototype.appendMatrix=function(a){var b=this.a,c=this.b,d=this.c,e=this.d;return this.a=a.a*b+a.b*d,this.b=a.a*c+a.b*e,this.c=a.c*b+a.d*d,this.d=a.c*c+a.d*e,this.tx=a.tx*b+a.ty*d+this.tx,this.ty=a.tx*c+a.ty*e+this.ty,this},b.prototype.setPosition=function(a,b){return this.tx=a,this.ty=b,this},b.prototype.setPositionPoint=function(a){return this.tx=a.x,this.ty=a.y,this},b.prototype.getPosition=function(b){return void 0===b&&(b=new a.Geom.Point),b.setTo(this.tx,this.ty)},b.prototype.identity=function(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this},b.prototype.rotate=function(a){var b=Math.cos(a),c=Math.sin(a),d=this.a,e=this.c,f=this.tx;return this.a=d*b-this.b*c,this.b=d*c+this.b*b,this.c=e*b-this.d*c,this.d=e*c+this.d*b,this.tx=f*b-this.ty*c,this.ty=f*c+this.ty*b,this},b.prototype.translate=function(a,b){return this.tx+=a,this.ty+=b,this},b.prototype.scale=function(a,b){return this.a*=a,this.d*=b,this},b.prototype.transformPoint=function(a){var b=a.x,c=a.y;return a.x=this.a*b+this.c*c+this.tx,a.y=this.b*b+this.d*c+this.ty,a},b.prototype.invert=function(){var a=this.a,b=this.b,c=this.c,d=this.d,e=this.tx,f=a*d-b*c;return this.a=d/f,this.b=-b/f,this.c=-c/f,this.d=a/f,this.tx=(c*this.ty-d*e)/f,this.ty=-(a*this.ty-b*e)/f,this},b.prototype.copyFrom=function(a){return this.a=a.a,this.b=a.b,this.c=a.c,this.d=a.d,this.tx=a.tx,this.ty=a.ty,this},b.prototype.copyTo=function(a){return a.a=this.a,a.b=this.b,a.c=this.c,a.d=this.d,a.tx=this.tx,a.ty=this.ty,this},b.prototype.clone=function(){return new a.Geom.Matrix(this.a,this.b,this.c,this.d,this.tx,this.ty)},Object.defineProperty(b.prototype,"toString",{get:function(){return"[{Matrix (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")}]"},enumerable:!0,configurable:!0}),b}();b.Matrix=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b){void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(a,b)}return a.prototype.objType=function(){return"Point"},a.prototype.polar=function(a,b){return this.x=a*Math.cos(b),this.y=a*Math.sin(b),this},a.prototype.add=function(b,c){return void 0===c&&(c=new a),c.setTo(this.x+b.x,this.y+b.y)},a.prototype.addTo=function(a,b){return void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(this.x+a,this.y+b)},a.prototype.subtractFrom=function(a,b){return void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(this.x-a,this.y-b)},a.prototype.invert=function(){return this.setTo(this.y,this.x)},a.prototype.clamp=function(a,b){return this.clampX(a,b),this.clampY(a,b),this},a.prototype.clampX=function(a,b){return this.x=Math.max(Math.min(this.x,b),a),this
 },a.prototype.clampY=function(a,b){return this.x=Math.max(Math.min(this.x,b),a),this.y=Math.max(Math.min(this.y,b),a),this},a.prototype.clone=function(b){return void 0===b&&(b=new a),b.setTo(this.x,this.y)},a.prototype.copyFrom=function(a){return this.setTo(a.x,a.y)},a.prototype.copyTo=function(a){return a.setTo(this.x,this.y)},a.prototype.angleTo=function(a){return Math.atan2(a.y-this.y,a.x-this.x)},a.prototype.angleToXY=function(a,b){return Math.atan2(b-this.y,a-this.x)},a.prototype.distanceTo=function(a,b){void 0===b&&(b=!1);var c=this.x-a.x,d=this.y-a.y;return b===!0?Math.round(Math.sqrt(c*c+d*d)):Math.sqrt(c*c+d*d)},a.prototype.distanceToXY=function(a,b,c){void 0===c&&(c=!1);var d=this.x-a,e=this.y-b;return c===!0?Math.round(Math.sqrt(d*d+e*e)):Math.sqrt(d*d+e*e)},a.distanceBetween=function(a,b,c){void 0===c&&(c=!1);var d=a.x-b.x,e=a.y-b.y;return c===!0?Math.round(Math.sqrt(d*d+e*e)):Math.sqrt(d*d+e*e)},a.polar=function(b,c){return new a(b*Math.cos(c),b*Math.sin(c))},a.prototype.distanceCompare=function(a,b){return this.distanceTo(a)>=b?!0:!1},a.prototype.equals=function(a){return this.x===a.x&&this.y===a.y?!0:!1},a.interpolate=function(b,c,d){var e=c.x-b.x,f=c.y-b.y;return new a(c.x-e*d,c.y-f*d)},a.prototype.offset=function(a,b){return this.x+=a,this.y+=b,this},a.prototype.setTo=function(a,b){return this.x=a,this.y=b,this},a.prototype.subtract=function(b,c){return void 0===c&&(c=new a),c.setTo(this.x-b.x,this.y-b.y)},a.prototype.getCSS=function(){return this.x+"px "+this.y+"px"},a.prototype.toString=function(){return"[{Point (x="+this.x+" y="+this.y+")}]"},a}();a.Point=b}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(a,b,c,d){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.x=0,this.y=0,this.width=0,this.height=0,this.setTo(a,b,c,d)}return c.prototype.objType=function(){return"Rectangle"},Object.defineProperty(c.prototype,"bottom",{get:function(){return this.y+this.height},set:function(a){a&&(this.height=a<this.y?0:a)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"center",{get:function(){var a=new b.Point;return a.setTo(Math.round(this.width/2),Math.round(this.height/2))},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"bottomRight",{get:function(){var a=new b.Point;return a.setTo(this.right,this.bottom)},set:function(a){a&&(this.right=a.x,this.bottom=a.y)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"left",{get:function(){return this.x},set:function(a){if(a){var b=this.x-a;this.width+b<0?(this.width=0,this.x=a):(this.width+=b,this.x=a)}},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"right",{get:function(){return this.x+this.width},set:function(a){a&&(this.width=a<this.x?0:a-this.x)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"size",{get:function(){var a=new b.Point;return a.setTo(this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"volume",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"perimeter",{get:function(){return 2*this.width+2*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"top",{get:function(){return this.y},set:function(a){if(a){var b=this.y-a;this.height+b<0?(this.height=0,this.y=a):(this.height+=b,this.y=a)}},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"topLeft",{get:function(){var a=new b.Point;return a.setTo(this.x,this.y)},set:function(a){a&&(this.x=a.x,this.y=a.y)},enumerable:!0,configurable:!0}),c.prototype.clone=function(a){return void 0===a&&(a=new c),a.setTo(this.x,this.y,this.width,this.height)},c.prototype.contains=function(a,b){return a>=this.x&&a<=this.right&&b>=this.y&&b<=this.bottom?!0:!1},c.prototype.containsPoint=function(a){return this.contains(a.x,a.y)},c.prototype.containsRect=function(a){return a.volume>this.volume?!1:a.x>=this.x&&a.y>=this.y&&a.right<=this.right&&a.bottom<=this.bottom?!0:!1},c.prototype.copyFrom=function(a){return this.setTo(a.x,a.y,a.width,a.height)},c.prototype.copyTo=function(a){return void 0===a&&(a=new c),a.copyFrom(this)},c.prototype.equals=function(a){return this.x===a.x&&this.y===a.y&&this.width===a.width&&this.height===a.height?!0:!1},c.prototype.inflate=function(a,b){return isNaN(a)||isNaN(b)||(this.x-=a,this.width+=2*a,this.y-=b,this.height+=2*b),this},c.prototype.inflatePoint=function(a){return this.inflate(a.x,a.y)},c.prototype.intersection=function(a,b){return void 0===b&&(b=new c),this.intersects(a)===!0&&(b.x=Math.max(a.x,this.x),b.y=Math.max(a.y,this.y),b.width=Math.min(a.right,this.right)-b.x,b.height=Math.min(a.bottom,this.bottom)-b.y),b},c.prototype.intersects=function(a){return a.x>this.right-1?!1:a.right-1<this.x?!1:a.bottom-1<this.y?!1:a.y>this.bottom-1?!1:!0},c.prototype.overlap=function(a){var b={top:!1,bottom:!1,left:!1,right:!1,contains:!1,contained:!1},c=this.intersection(a);return c.isEmpty?b:(this.containsRect(a)&&(b.contains=!0),a.containsRect(this)&&(b.contained=!0),this.top<a.top&&(b.top=!0),this.bottom>a.bottom&&(b.bottom=!0),this.left<a.left&&(b.left=!0),this.right>a.right&&(b.right=!0),b)},c.prototype.isEmpty=function(){return this.width<1||this.height<1?!0:!1},c.prototype.offset=function(a,b){return isNaN(a)||isNaN(b)||(this.x+=a,this.y+=b),this},c.prototype.offsetPoint=function(a){return this.offset(a.x,a.y)},c.prototype.setEmpty=function(){return this.setTo(0,0,0,0)},c.prototype.setTo=function(a,b,c,d){return isNaN(a)||isNaN(b)||isNaN(c)||isNaN(d)||(this.x=a,this.y=b,c>=0&&(this.width=c),d>=0&&(this.height=d)),this},c.prototype.union=function(a,b){return void 0===b&&(b=new c),b.setTo(Math.min(a.x,this.x),Math.min(a.y,this.y),Math.max(a.right,this.right),Math.max(a.bottom,this.bottom))},c.prototype.scale=function(b,c,d){var e=new a.Geom.Transform;e.scaleX=b,e.scaleY=c,e.x=d.x,e.y=d.y;var f=this.topLeft;return e.transformPoint(f),this.topLeft=f,this.width*=b,this.height*=c,this},c.prototype.toString=function(){return"[{Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+" isEmpty="+this.isEmpty()+")}]"},c}();b.Rectangle=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(a,c,d,e,f,g,h){void 0===a&&(a=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=1),void 0===f&&(f=0),void 0===g&&(g=0),void 0===h&&(h=0),this._x=0,this._y=0,this._scaleX=1,this._scaleY=1,this._rotation=0,this._rotPointX=0,this._rotPointY=0,this._parent=null,this._locked=!1,this._ignoreParent=!1,this.setTransform(a,c,d,e,f,g,h),this._matrix=new b.Matrix,this._matrix.setFromOffsetTransform(this._x,this._y,this._scaleX,this._scaleY,this._rotation,this._rotPointX,this._rotPointY),this._cachedConcatenatedMatrix=this.getConcatenatedMatrix(),this._concatMatrix=new b.Matrix}return c.prototype.objType=function(){return"Transform"},Object.defineProperty(c.prototype,"x",{get:function(){return this._x},set:function(a){this._x=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"y",{get:function(){return this._y},set:function(a){this._y=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"scaleX",{get:function(){return this._scaleX},set:function(a){this._scaleX=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"scaleY",{get:function(){return this._scaleY},set:function(a){this._scaleY=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"rotation",{get:function(){return this._rotation},set:function(a){this._rotation=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"rotPointX",{get:function(){return this._rotPointX},set:function(a){this._rotPointX=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"rotPointY",{get:function(){return this._rotPointY},set:function(a){this._rotPointY=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"anchorPointX",{get:function(){return this.rotPointX},set:function(a){this.rotPointX=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"anchorPointY",{get:function(){return this._rotPointY},set:function(a){this._rotPointY=a},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"matrix",{get:function(){return this._matrix},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"worldX",{get:function(){return this.getConcatenatedMatrix().tx-this._rotPointX},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"worldY",{get:function(){return this.getConcatenatedMatrix().ty-this._rotPointY},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"parent",{get:function(){return this._parent},set:function(a){this.checkAncestor(a)||(this._parent=a)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"locked",{get:function(){return this._locked},set:function(a){this._locked=a,this._locked&&this._matrix.setFromOffsetTransform(this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.anchorPointX,this.anchorPointY)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"ignoreParent",{get:function(){return this._ignoreParent},set:function(a){this._ignoreParent=a},enumerable:!0,configurable:!0}),c.prototype.setPosition=function(a,b){return this._x=a,this._y=b,this},c.prototype.setPositionFromPoint=function(a){return this._x=a.x,this._y=a.y,this},c.prototype.translatePositionFromPoint=function(a){return this._x+=a.x,this._y+=a.y,this},c.prototype.getPositionPoint=function(b){return void 0===b&&(b=new a.Geom.Point),b.setTo(this._x,this._y)},Object.defineProperty(c.prototype,"scale",{set:function(a){this._scaleX=a,this._scaleY=a},enumerable:!0,configurable:!0}),c.prototype.setTransform=function(a,b,c,d,e,f,g){return void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=1),void 0===d&&(d=1),void 0===e&&(e=0),void 0===f&&(f=0),void 0===g&&(g=0),this._x=a,this._y=b,this._scaleX=c,this._scaleY=d,this._rotation=e,this._rotPointX=f,this._rotPointY=g,this},c.prototype.getParentMatrix=function(){return this._parent?this._parent.getConcatenatedMatrix():null},c.prototype.getConcatenatedMatrix=function(){var a;return this._locked||(this._parent?this._matrix.setFromOffsetTransform(this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.anchorPointX-this._parent.anchorPointX,this.anchorPointY-this._parent.anchorPointY):this._matrix.setFromOffsetTransform(this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.anchorPointX,this.anchorPointY)),!this._ignoreParent&&(a=this.getParentMatrix())?(this._concatMatrix.copyFrom(this._matrix),this._concatMatrix.prependMatrix(a),this._concatMatrix):this._matrix},c.prototype.transformPoint=function(a){var b=this.getConcatenatedMatrix();return b.transformPoint(a)},c.prototype.copyFrom=function(a){return this.setTransform(a.x,a.y,a.scaleX,a.scaleY,a.rotation,a.rotPointX,a.rotPointY),this.parent=a.parent,this._matrix=a.matrix.clone(),this},c.prototype.copyTo=function(a){return a.copyFrom(this),this},c.prototype.clone=function(a){return void 0===a&&(a=new c),a.copyFrom(this),a},c.prototype.checkAncestor=function(){return!1},Object.defineProperty(c.prototype,"toString",{get:function(){return"[{Transform (x="+this._x+" y="+this._y+" scaleX="+this._scaleX+" scaleY="+this._scaleY+" rotation="+this._rotation+" regX="+this._rotPointX+" regY="+this.rotPointY+" matrix="+this._matrix+")}]"},enumerable:!0,configurable:!0}),c}();b.Transform=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(a,b){void 0===a&&(a=0),void 0===b&&(b=0),this.setTo(a,b)}return c.prototype.objType=function(){return"Vector2"},c.fromAngle=function(a){return new c(Math.cos(a),Math.sin(a))},c.randomRadius=function(a){return new c(2*Math.random()-1,2*Math.random()-1).multiplyScalar(a)},c.fromPoint=function(a){return new c(a.x,a.y)},c.prototype.add=function(a){return new c(this.x+a.x,this.y+a.y)},c.prototype.addX=function(a){return new c(this.x+a.x,this.y)},c.prototype.addY=function(a){return new c(this.x,this.y+a.y)},c.prototype.subtract=function(b){return new a.Geom.Vector2(this.x-b.x,this.y-b.y)},c.prototype.multiply=function(b){return new a.Geom.Vector2(this.x*b.x,this.y*b.y)},c.prototype.multiplyScalar=function(b){return new a.Geom.Vector2(this.x*b,this.y*b)},c.prototype.dot=function(a){return this.x*a.x+this.y*a.y},c.prototype.lenSqr=function(){return this.x*this.x+this.y*this.y},c.prototype.len=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},c.prototype.unit=function(){var a=1/this.len();return this.multiplyScalar(a)},c.prototype.floor=function(){return new c(Math.floor(this.x),Math.floor(this.y))},c.prototype.ceil=function(){return new c(Math.ceil(this.x),Math.ceil(this.y))},c.prototype.round=function(){return new c(Math.round(this.x),Math.round(this.y))},c.prototype.clamp=function(a,b){return new c(Math.max(Math.min(this.x,b.x),a.x),Math.max(Math.min(this.y,b.y),a.y))},c.prototype.perp=function(){return new c(-this.y,this.x)},c.prototype.neg=function(){return new c(-this.x,-this.y)},c.prototype.equal=function(a){return this.x===a.x&&this.y===a.y},c.prototype.point=function(){return new b.Point(this.x,this.y)},c.prototype.clear=function(){return this.x=0,this.y=0,this},c.prototype.clone=function(a){return void 0===a&&(a=new c),a.setTo(this.x,this.y)},c.prototype.copyFrom=function(a){return this.x=a.x,this.y=a.y,this},c.prototype.copyTo=function(a){return a.x=this.x,a.y=this.y,a},c.prototype.setTo=function(a,b){return this.x=a,this.y=b,this},c.prototype.toString=function(){return"[{Vector2 (x="+this.x+" y="+this.y+")}]"},c}();b.Vector2=c}(b=a.Geom||(a.Geom={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c){if(this._game=b,this.name=c,this._manager=this._game.huds,this._device=this._game.deviceTargetOption,this._manager.supported){switch(this._device){case a.TARGET_BROWSER:this.container=document.createElement("div"),this.container.id="HUD-layer-"+b.rnd.uuid(),this.container.style.width="100%",this.container.style.height="100%",this.container.style.position="absolute",this._widgets=new Array}this["class"]="kiwi-display"}}return b.prototype.objType=function(){return"HUDDisplay"},b.prototype.addWidget=function(b){return this._manager.supported&&(this._widgets.push(b),this._device==a.TARGET_BROWSER)?(this.container.appendChild(b.container),!0):!1},b.prototype.removeWidget=function(a){if(this._manager.supported&&this.removeFromContainer(a)){var b=this._widgets.indexOf(a);if(-1!==b)return this._widgets.splice(b,1),!0}return!1},b.prototype.removeAllWidgets=function(){for(var a=0;a<this._widgets.length;a++)this.removeFromContainer(this._widgets[a]);this._widgets=[]},b.prototype.removeFromContainer=function(b){return this._manager.supported&&this._device==a.TARGET_BROWSER&&this.container.contains(b.container)?(this.container.removeChild(b.container),!0):!1},b.prototype.update=function(){for(var a=0;a<this._widgets.length;a++)this._widgets[a].update()},b.prototype.show=function(){this.container.style.display="block"},b.prototype.hide=function(){this.container.style.display="none"},Object.defineProperty(b.prototype,"class",{get:function(){return this._device==a.TARGET_BROWSER?this.container.className:void 0},set:function(b){this._device==a.TARGET_BROWSER&&(this.container.className=b)},enumerable:!0,configurable:!0}),b}();b.HUDDisplay=c}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._game=a,this._device=this._game.deviceTargetOption}return Object.defineProperty(b.prototype,"supported",{get:function(){return this._supported},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._device===a.TARGET_BROWSER?(this._supported=!0,this._hudContainer=document.createElement("div"),this._hudContainer.id="HUDContainer",this._hudContainer.style.position="absolute",this._hudContainer.style.width="100%",this._hudContainer.style.height="100%",this._hudContainer.style.top="0",this._hudContainer.style.left="0",this._game.stage.container.appendChild(this._hudContainer),this._huds=new Array,this._defaultHUD=this.createHUD("defaultHUD"),this._currentHUD=this._defaultHUD,this.setHUD(this._defaultHUD)):this._supported=!1},b.prototype.objType=function(){return"HUDManager"},Object.defineProperty(b.prototype,"defaultHUD",{get:function(){return this._defaultHUD},set:function(a){this._currentHUD===this._defaultHUD&&(this._currentHUD=a,this.setHUD(this._currentHUD)),this._defaultHUD=a},enumerable:!0,configurable:!0}),b.prototype.setHUD=function(a){this.supported&&(this.hideHUD(),this._currentHUD=a,this.showHUD())},b.prototype.showHUD=function(a){void 0===a&&(a=this._currentHUD),a.show()},b.prototype.hideHUD=function(a){void 0===a&&(a=this._currentHUD),a.hide()},b.prototype.createHUD=function(b,c){if(void 0===c&&(c=!1),this.supported){var d=new a.HUD.HUDDisplay(this._game,b);return d.hide(),this.addToContainer(d),this._huds.push(d),c===!0&&this.setHUD(d),d}},b.prototype.removeHUD=function(a){if(this.supported){if(a===this._defaultHUD)return!1;this._currentHUD===a&&this.setHUD(this._defaultHUD),this.removeFromContainer(a);var b=this._huds.indexOf(a);return-1!==b&&this._huds.splice(b,1),!0}},b.prototype.addToContainer=function(b){this._device==a.TARGET_BROWSER&&this._hudContainer.appendChild(b.container)},b.prototype.removeFromContainer=function(b){this._device==a.TARGET_BROWSER&&this._hudContainer.contains(b.container)&&this._hudContainer.removeChild(b.container)},b.prototype.update=function(){if(this._supported)for(var a=0;a<this._huds.length;a++)this._huds[a].update()},b}();b.HUDManager=c}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c,d,e){this.name=c,this.game=b,this._manager=this.game.huds,this._device=this.game.deviceTargetOption,this.components=new a.ComponentManager(a.HUD_WIDGET,this),this._manager.supported&&(this._device===a.TARGET_BROWSER&&(this.container=document.createElement("div"),this.container.id="HUD-widget-"+this.game.rnd.uuid(),this.container.className="HUD-widget",this.container.style.position="absolute"),this.onCoordsUpdate=new a.Signal,this.x=d,this.y=e)}return b.prototype.objType=function(){return"HUDWidget"},Object.defineProperty(b.prototype,"style",{get:function(){return this._device===a.TARGET_BROWSER?this.container.style:void 0},set:function(b){this._device===a.TARGET_BROWSER&&(this.container.style=b)},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"x",{get:function(){return this._x},set:function(b){this._manager.supported&&(this._x=b,this._device==a.TARGET_BROWSER&&(this.container.style.left=this.x+"px"),this.onCoordsUpdate.dispatch(this.x,this.y))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"y",{get:function(){return this._y},set:function(b){this._manager.supported&&(this._y=b,this._device==a.TARGET_BROWSER&&(this.container.style.top=this.y+"px"),this.onCoordsUpdate.dispatch(this.x,this.y))},enumerable:!0,configurable:!0}),b.prototype.setTemplate=function(b,c){for(var d=[],e=2;e<arguments.length;e++)d[e-2]=arguments[e];if(this._device==a.TARGET_BROWSER){var f=document.getElementById(b);if(void 0===f)return;if(void 0===c)var g=f;else{var g=document.getElementById(c);if(void 0===g||f.contains(g)===!1)return}this.tempElement=g,this._tempContainer=f,this._tempParent=f.parentElement,this._tempParent.removeChild(f),this.container.appendChild(f)}},b.prototype.removeTemplate=function(){this._device==a.TARGET_BROWSER&&void 0!==this.tempElement&&(this.container.removeChild(this._tempContainer),this._tempParent.appendChild(this._tempContainer),this.tempElement=null,this._tempParent=null,this._tempContainer=null)},Object.defineProperty(b.prototype,"class",{get:function(){return this._device==a.TARGET_BROWSER?this.container.className:void 0},set:function(b){this._device==a.TARGET_BROWSER&&(this.container.className=b)},enumerable:!0,configurable:!0}),b.prototype.update=function(){this.components.update()},b.prototype.destroy=function(){delete this.game,delete this._manager,delete this._device,this.onCoordsUpdate&&this.onCoordsUpdate.dispose(),delete this.onCoordsUpdate},b}();b.HUDWidget=c}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f){b.call(this,c,"textField",e,f),this._prefix="",this._suffix="",this["class"]="kiwi-textfield-widget kiwi-widget",this._manager.supported&&this._device===a.TARGET_BROWSER&&(this._textField=this.container,this._textField.innerHTML=d)}return __extends(c,b),c.prototype.objType=function(){return"TextFieldWidget"},c.prototype.setTemplate=function(c,d){this._device===a.TARGET_BROWSER&&(this._textField.innerText="",b.prototype.setTemplate.call(this,c,d),void 0!==this.tempElement&&(this._textField=this.tempElement),this._textField.innerHTML=this._text)},c.prototype.removeTemplate=function(){this._device===a.TARGET_BROWSER&&(b.prototype.removeTemplate.call(this),this._device===a.TARGET_BROWSER&&(this._textField=this.container,this._textField.innerHTML=this._text))},Object.defineProperty(c.prototype,"text",{get:function(){return this._text},set:function(b){this._manager.supported&&this._device===a.TARGET_BROWSER&&(""!==this._prefix&&(b=this._prefix+b),""!==this._suffix&&(b+=this._suffix),this._text=b,this._textField.innerHTML=this._text)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"suffix",{get:function(){return this._suffix},set:function(a){this._suffix=a,this._updateText()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"prefix",{get:function(){return this._prefix},set:function(a){this._prefix=a,this._updateText()},enumerable:!0,configurable:!0}),c.prototype._updateText=function(){this.text=this._text},c}(a.HUD.HUDWidget);b.TextField=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f,g,h,i,j){void 0===h&&(h=120),void 0===i&&(i=20),void 0===j&&(j="#000"),b.call(this,c,"bar",f,g),this._horizontal=!0,this["class"]="kiwi-bar-widget kiwi-widget",this._manager.supported&&(this._device==a.TARGET_BROWSER&&(this._bar=document.createElement("div"),this._bar.className="kiwi-innerbar-widget",this._bar.style.backgroundColor=j,this.bar=this._bar,this.container.appendChild(this.bar)),this.counter=this.components.add(new a.HUD.HUDComponents.Counter(this,d,e,0)),this.counter.updated.add(this.updateCSS,this),this.width=h,this.height=i,this._bar.style.height="100%",this._bar.style.width="100%",this.updateCSS())}return __extends(c,b),c.prototype.objType=function(){return"BarWidget"},Object.defineProperty(c.prototype,"width",{get:function(){return this._width},set:function(b){this._device==a.TARGET_BROWSER&&(this.container.style.width=b+"px"),this._width=b},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"height",{get:function(){return this._height},set:function(b){this._device==a.TARGET_BROWSER&&(this.container.style.height=b+"px"),this._height=b},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"horizontal",{get:function(){return this._horizontal},set:function(a){this._horizontal=a,this.updateCSS()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"vertical",{get:function(){return!this._horizontal},set:function(a){this._horizontal=!a,this.updateCSS()},enumerable:!0,configurable:!0}),c.prototype.setTemplate=function(c,d){this._device==a.TARGET_BROWSER&&(b.prototype.setTemplate.call(this,c,d),void 0!==this.tempElement&&(this.bar=this.tempElement))},c.prototype.removeTemplate=function(){this._device==a.TARGET_BROWSER&&(b.prototype.removeTemplate.call(this),this.bar=this._bar,this.container.appendChild(this.bar),this.updateCSS())},c.prototype.updateCSS=function(){this.horizontal===!0?(this.bar.style.width=String(this.counter.currentPercent())+"%",this.bar.style.height="100%"):(this.bar.style.height=String(this.counter.currentPercent())+"%",this.bar.style.width="100%")},c}(a.HUD.HUDWidget);b.Bar=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(a,c,d,e){b.call(this,a,"Icon",d,e),this._cellIndex=0,this["class"]="kiwi-icon-widget kiwi-widget",this.atlas=c,this.icon=this.container,this._applyCSS()}return __extends(c,b),Object.defineProperty(c.prototype,"cellIndex",{get:function(){return this._cellIndex},set:function(a){this._cellIndex=a,this.width=this.atlas.cells[this.cellIndex].w,this.height=this.atlas.cells[this.cellIndex].h,this._applyCSS()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"width",{get:function(){return this.atlas.cells[this.cellIndex].w},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"height",{get:function(){return this.atlas.cells[this.cellIndex].h},enumerable:!0,configurable:!0}),c.prototype._removeCSS=function(){this.icon.style.width="",this.icon.style.height="",this.icon.style.backgroundImage="",this.icon.style.backgroundRepeat=""},c.prototype._applyCSS=function(){this.icon.style.width=this.width+"px",this.icon.style.height=this.height+"px",this.icon.style.backgroundPositionX=-this.atlas.cells[this.cellIndex].x+"px",this.icon.style.backgroundPositionY=-this.atlas.cells[this.cellIndex].y+"px",this.icon.style.backgroundRepeat="no-repeat",this.icon.style.backgroundImage=0==a.Utils.Common.isUndefined(this.atlas.image.src)?'url("'+this.atlas.image.src+'")':'url("'+this.atlas.image.toDataURL("image/png")+'")'},c.prototype.setTemplate=function(c,d){this._device==a.TARGET_BROWSER&&(this._removeCSS(),b.prototype.setTemplate.call(this,c,d),void 0!==this.tempElement&&(this.icon=this.tempElement),this._applyCSS())},c.prototype.removeTemplate=function(){this._device==a.TARGET_BROWSER&&(b.prototype.removeTemplate.call(this),this._removeCSS(),this.icon=this.container,this._applyCSS())},c}(a.HUD.HUDWidget);b.Icon=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f,g,h){b.call(this,c,"IconBar",g,h),this.iconGap=0,this["class"]="kiwi-iconbar-widget kiwi-widget",this.atlas=d,this.width=this.atlas.cells[0].w,this.height=this.atlas.cells[0].h,this._horizontal=!0,this.counter=this.components.add(new a.HUD.HUDComponents.Counter(this,e,f,0)),this.counter.updated.add(this._amountChanged,this),this._icons=[],this._amountChanged()}return __extends(c,b),c.prototype.objType=function(){return"IconBarWidget"},c.prototype._amountChanged=function(){if(this.counter.max!==this._icons.length)if(this.counter.max>this._icons.length)for(var a=this.counter.max-this._icons.length,b=0;a>b;b++)this._addIcon();else for(var b=this.counter.max;b<this._icons.length;b++)this._removeIcon(this._icons[b]),this._icons[b].destroy(),this._icons.splice(b,1),b--;for(var b=0;b<this._icons.length;b++)this._icons[b].style.display=b>this.counter.current-1?"none":"block"},c.prototype._addIcon=function(){if(this.horizontal)var b=new a.HUD.Widget.Icon(this.game,this.atlas,this.x+(this.width+this.iconGap)*(this._icons.length-1),this.y);else var b=new a.HUD.Widget.Icon(this.game,this.atlas,this.x,(this.height+this.iconGap)*(this._icons.length-1)+this.y);this._icons.push(b),this._device==a.TARGET_BROWSER&&this.container.appendChild(b.container)},c.prototype._removeIcon=function(b){this._device==a.TARGET_BROWSER&&this.container.removeChild(b.container)},Object.defineProperty(c.prototype,"horizontal",{get:function(){return this._horizontal},set:function(a){this._horizontal=a,this._amountChanged()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"vertical",{get:function(){return!this._horizontal},set:function(a){this._horizontal=!a,this._amountChanged()},enumerable:!0,configurable:!0}),c}(a.HUD.HUDWidget);b.IconBar=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f){void 0===f&&(f=0),b.call(this,c,"basicScore",d,e),this.name="basicScore",this["class"]="kiwi-basicscore-widget kiwi-widget",this.counter=this.components.add(new a.HUD.HUDComponents.Counter(this,f)),this.counter.updated.add(this._updateText,this),this._updateText()}return __extends(c,b),c.prototype.objType=function(){return"BasicScoreWidget"},c.prototype._updateText=function(){this.text=String(this.counter.current)},c}(a.HUD.Widget.TextField);b.BasicScore=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f){b.call(this,c,d,e,f),this.name="button",this["class"]="kiwi-button-widget kiwi-widget",this.input=this.components.add(new a.HUD.HUDComponents.WidgetInput(this,this.container))}return __extends(c,b),c.prototype.objType=function(){return"ButtonWidget"},c}(a.HUD.Widget.TextField);b.Button=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f){b.call(this,c,"time",e,f),this.name="time",this["class"]="kiwi-time-widget kiwi-widget",this.time=this.components.add(new a.HUD.HUDComponents.Time(this,d))}return __extends(c,b),c.prototype.objType=function(){return"TimeWidget"},c.prototype.pause=function(){this.time.pause()},c.prototype.stop=function(){this.time.stop()},c.prototype.start=function(){this.time.start()},c.prototype.resume=function(){this.time.resume()},c.prototype.update=function(){b.prototype.update.call(this),this.time.isRunning&&(this.text=this.time.getTime())},c}(a.HUD.Widget.TextField);b.Time=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(a,c,d){b.call(this,a,"menu",c,d),this._menuItems=[],this._styles=[],this["class"]="kiwi-menu-widget kiwi-widget"}return __extends(c,b),c.prototype.objType=function(){return"MenuWidget"},c.prototype.setIconStyle=function(a,b){this._styles.push({index:a,value:b});for(var c=0;c<this._menuItems.length;c++)this._menuItems[c].style[a]=b},Object.defineProperty(c.prototype,"menuItems",{get:function(){return this._menuItems},enumerable:!0,configurable:!0}),c.prototype.createMenuItem=function(b,c,d){return this.addMenuItem(new a.HUD.Widget.MenuItem(this.game,b,c,d))},c.prototype.addMenuItem=function(b){this._menuItems.push(b),b.menu=this;for(var c=0;c<this._styles.length;c++)b.style[this._styles[c].index]=this._styles[c].value;return this._device==a.TARGET_BROWSER&&this.container.appendChild(b.container),b},c.prototype.addMenuItems=function(a){for(var b=0;b<a.length;b++)this.addMenuItem(a[b])},c.prototype.getMenuItem=function(a){return this._menuItems[a]},c.prototype.setTemplate=function(a,b){},c.prototype.removeTemplate=function(){},c.prototype.update=function(){for(var a=0;a<this._menuItems.length;a++)this._menuItems[a].update();b.prototype.update.call(this)},c}(a.HUD.HUDWidget);b.Menu=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(a){function b(b,c,d,e){a.call(this,b,c,d,e),this.name="menuItem",this["class"]="kiwi-menuitem-widget kiwi-widget"}return __extends(b,a),b.prototype.objType=function(){return"MenuItem"},b}(a.HUD.Widget.Button);b.MenuItem=c}(c=b.Widget||(b.Widget={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d,e,f){void 0===e&&(e=null),void 0===f&&(f=null),b.call(this,c,"counter"),this._current=d,this._max=e,this._min=f,this.updated=new a.Signal}return __extends(c,b),c.prototype.objType=function(){return"CounterComponent"},Object.defineProperty(c.prototype,"max",{get:function(){return this._max},set:function(a){this._max=a,this.updated.dispatch(this._current,this._max,this._min)
-},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"min",{get:function(){return this._min},set:function(a){this._min=a,this.updated.dispatch(this._current,this._max,this._min)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"current",{get:function(){return this._current},set:function(a){this._current=null!==this._max&&a>this._max?this._max:null!==this._min&&a<this._min?this._min:a,this.updated.dispatch(this._current,this._max,this._min)},enumerable:!0,configurable:!0}),c.prototype.decrease=function(a){return void 0===a&&(a=1),(null===this._min||this._current>this._min)&&(null!==this._min&&this._current-a<this._min?this._current=this._min:this._current-=a,this.updated.dispatch(this._current,this._max,this._min)),this._current},c.prototype.increase=function(a){return void 0===a&&(a=1),(null===this._max||this._current<this._max)&&(null!==this._max&&this._current+a>this._max?this._current=this._max:this._current+=a,this.updated.dispatch(this._current,this._max,this._min)),this._current},c.prototype.currentPercent=function(){return null!==this.max?this.current/this.max*100:void 0},c}(a.Component);b.Counter=c}(c=b.HUDComponents||(b.HUDComponents={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d){b.call(this,c,"WidgetInput"),this._active=!1,this._container=d,this.onUp=new a.Signal,this.onDown=new a.Signal,this.onOver=new a.Signal,this.onOut=new a.Signal,this._addEvents()}return __extends(c,b),c.prototype.objType=function(){return"WidgetInputComponent"},c.prototype.setElement=function(a){this._removeEvents(),this._container=a,this._addEvents()},c.prototype._addEvents=function(){if(!this._active){this._binds=[],this._binds.push({event:"mouseup","function":this._up.bind(this)}),this._binds.push({event:"mousedown","function":this._down.bind(this)}),this._binds.push({event:"mouseover","function":this._over.bind(this)}),this._binds.push({event:"mouseout","function":this._out.bind(this)});for(var a=0;a<this._binds.length;a++)this._container.addEventListener(this._binds[a].event,this._binds[a]["function"],!1);this._active=!0}},c.prototype._removeEvents=function(){if(this._active){for(var a=0;a<this._binds.length;a++)this._container.removeEventListener(this._binds[a].event,this._binds[a]["function"],!1);this._binds=[],this._active=!1}},c.prototype._up=function(a){this.onUp.dispatch(a)},c.prototype._down=function(a){this.onDown.dispatch(a)},c.prototype._over=function(a){this.onOver.dispatch(a)},c.prototype._out=function(a){this.onOut.dispatch(a)},c}(a.Component);b.WidgetInput=c}(c=b.HUDComponents||(b.HUDComponents={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(a){function b(b,c){void 0===c&&(c=""),a.call(this,b,"time"),this.countDown=!1,this._displayString="",this._currentTime=0,this._timeBefore=0,this.speed=1,this.clock=this.game.time.addClock(name+"-clock",1e3),this.format=c}return __extends(b,a),b.prototype.objType=function(){return"TimeComponent"},Object.defineProperty(b.prototype,"isRunning",{get:function(){return this.clock.isRunning()},enumerable:!0,configurable:!0}),b.prototype.pause=function(){this.clock.pause()},b.prototype.stop=function(){this.clock.stop()},b.prototype.start=function(){this.clock.start(),this._timeBefore=this.clock.elapsed()},b.prototype.resume=function(){this.clock.resume()},Object.defineProperty(b.prototype,"format",{get:function(){return this._format},set:function(a){this._format=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"currentTime",{get:function(){return this._currentTime},enumerable:!0,configurable:!0}),b.prototype.setTime=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=0),this._currentTime=a,0!=b&&(this._currentTime+=1e3*b),0!=c&&(this._currentTime+=60*c*1e3)},b.prototype.addTime=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=0),this._currentTime+=a,0!=b&&(this._currentTime+=1e3*b),0!=c&&(this._currentTime+=60*c*1e3)},b.prototype.removeTime=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=0),this._currentTime-=a,0!=b&&(this._currentTime-=1e3*b),0!=c&&(this._currentTime-=60*c*1e3)},b.prototype.getTime=function(){if(this.countDown?this._currentTime-=(this.clock.elapsed()-this._timeBefore)*this.speed:this._currentTime+=(this.clock.elapsed()-this._timeBefore)*this.speed,this._timeBefore=this.clock.elapsed(),""!==this._format){if(this._displayString=this._format,-1!==this._displayString.indexOf("ms")){var a=String(Math.floor(1e3*this._currentTime)%1e3);this._displayString=this._displayString.replace("ms",a)}if(-1!=this._displayString.indexOf("ss")){var a=String(Math.floor(this._currentTime)%60);a.length<2&&(a="0"+a),this._displayString=this._displayString.replace("ss",a)}if(-1!==this._displayString.indexOf("mm")){var a=String(Math.floor(this._currentTime/60)%60);a.length<2&&(a="0"+a),this._displayString=this._displayString.replace("mm",a)}if(-1!=this._displayString.indexOf("s")){var a=String(Math.floor(this._currentTime)%60);this._displayString=this._displayString.replace("s",a)}if(-1!==this._displayString.indexOf("m")){var a=String(Math.floor(this._currentTime/60)%60);this._displayString=this._displayString.replace("m",a)}return this._displayString}return String(this._currentTime.toFixed(2))},b}(a.Component);b.Time=c}(c=b.HUDComponents||(b.HUDComponents={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this.noAudio=!1,this.usingWebAudio=!1,this.usingAudioTag=!1,this.context=null,this.masterGain=null,this._unlockedSource=null,this._game=a}return b.prototype.objType=function(){return"AudioManager"},Object.defineProperty(b.prototype,"locked",{get:function(){return this._locked},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._volume=1,this._muted=!1,this._sounds=[],a.DEVICE.iOS&&0==a.DEVICE.webaudio&&(this.channels=1),a.DEVICE.iOS&&this._game.deviceTargetOption!==a.TARGET_COCOON?(this._locked=!0,this._game.input.onUp.addOnce(this._unlocked,this),a.Log.log("Kiwi.AudioManager: Audio is currently Locked until at touch event.","#audio","#locked")):this._locked=!1,this.usingWebAudio=!0,this.usingAudioTag=!1,window.AudioContext?this.context=new window.AudioContext:window.webkitAudioContext?this.context=new window.webkitAudioContext:window.Audio?(this.usingWebAudio=!1,this.usingAudioTag=!0):(this.usingWebAudio=!1,this.noAudio=!0),null!==this.context&&(this.masterGain=void 0===this.context.createGain?this.context.createGainNode():this.context.createGain(),this.masterGain.gain.value=1,this.masterGain.connect(this.context.destination))},b.prototype._unlocked=function(){if(a.Log.log("Kiwi.AudioManager: Audio now Unlocked.","#audio","#unlocked"),this.usingAudioTag){this._locked=!1;for(var b=0;b<this._sounds.length;b++)this._sounds[b].playable=!0}else{var c=this.context.createBuffer(1,1,22050);this._unlockedSource=this.context.createBufferSource(),this._unlockedSource.buffer=c,this._unlockedSource.connect(this.context.destination),this._unlockedSource.noteOn(0)}},Object.defineProperty(b.prototype,"mute",{get:function(){return this._muted},set:function(a){if(a===!0){if(this._muted)return;if(this._muted=!0,this.usingWebAudio)this._muteVolume=this.masterGain.gain.value,this.masterGain.gain.value=0;else if(this.usingAudioTag)for(var b=0;b<this._sounds.length;b++)this._sounds[b].mute=!0}else{if(0==this._muted)return;if(this._muted=!1,this.usingWebAudio)this.masterGain.gain.value=this._muteVolume;else if(this.usingAudioTag)for(var b=0;b<this._sounds.length;b++)this._sounds[b].mute=!1}},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(b){if(void 0!==b)if(b=a.Utils.GameMath.clamp(b,1,0),this._volume=b,this._muted&&(this._muteVolume=this._volume),this.usingWebAudio)this.masterGain.gain.value=b;else if(this.usingAudioTag)for(var c=0;c<this._sounds.length;c++)this._sounds[c].volume=this._sounds[c].volume},enumerable:!0,configurable:!0}),b.prototype.isRegistered=function(a){return this.noAudio?void 0:-1!==this._sounds.indexOf(a)?!0:!1},b.prototype.registerSound=function(a){return this.isRegistered(a)===!1?(a.id=this._game.rnd.uuid(),this._sounds.push(a),!0):!1},b.prototype.add=function(b,c,d){if(void 0===c&&(c=1),void 0===d&&(d=!1),!this.noAudio){var e=new a.Sound.Audio(this._game,b,c,d);return e}},b.prototype.remove=function(a,b){void 0===b&&(b=!0);for(var c=0;c<this._sounds.length;c++)if(a.id==this._sounds[c].id)return this.usingWebAudio&&a.gainNode&&a.gainNode.disconnect(),1==b&&a.destroy(),void this._sounds.splice(c,1)},b.prototype.playAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].play()},b.prototype.stopAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].stop()},b.prototype.pauseAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].pause()},b.prototype.resumeAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].resume()},b.prototype.update=function(){if(this._locked&&this.usingWebAudio&&null!==this._unlockedSource&&(this._unlockedSource.playbackState===this._unlockedSource.PLAYING_STATE||this._unlockedSource.playbackState===this._unlockedSource.FINISHED_STATE)){this._locked=!1,this._unlockedSource=null;for(var a=0;a<this._sounds.length;a++)this._sounds[a].playable=!0}if(!this.noAudio)for(var a=0;a<this._sounds.length;a++)this._sounds[a].update()},b}();b.AudioManager=c}(b=a.Sound||(a.Sound={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c,d,e){return this._muted=!1,this.totalDuration=0,this._buffer=null,this._decoded=!1,this._markers=[],this._currentMarker="default",this.ready=!1,this._game=b,this._game.audio.registerSound(this),this._usingAudioTag=this._game.audio.usingAudioTag,this._usingWebAudio=this._game.audio.usingWebAudio,this._playable=1==this._game.audio.locked?!1:!0,this.duration=0,this._volume=d,this._muteVolume=d,this._muted=this._game.audio.mute,this._loop=e,this.key=c,!a.Utils.Common.isString(this.key)&&this.key.isAudio&&(this.key=this.key.key),this._game.audio.noAudio||this._game.fileStore.exists(this.key)===!1?void a.Log.log("Could not play Audio. Either the browser doesn't support audio or the Audio file was not found on the filestore.","#audio","#notfound"):(this._usingWebAudio?(this._setAudio(),this.ready&&(this.context=this._game.audio.context,this.masterGainNode=this._game.audio.masterGain,this.gainNode="undefined"==typeof this.context.createGain?this.context.createGainNode():this.context.createGain(),this._decode(),this.gainNode.gain.value=this.volume*this._game.audio.volume,this.gainNode.connect(this.masterGainNode))):this._usingAudioTag&&this._playable===!0&&(this._setAudio(),this.ready&&(this.totalDuration=this._sound.duration,this._sound.volume=this.volume*this._game.audio.volume,(isNaN(this.totalDuration)||0==this.totalDuration)&&(this._pending=!0))),this.addMarker("default",0,this.totalDuration,this._loop),this._currentMarker="default",this.onPlay=new a.Signal,this.onStop=new a.Signal,this.onPause=new a.Signal,this.onResume=new a.Signal,this.onLoop=new a.Signal,void(this.onMute=new a.Signal))}return Object.defineProperty(b.prototype,"playable",{get:function(){return this._playable},set:function(a){this._playable!==!0&&1==a&&(this._playable=a,this._setAudio(),this.ready&&this._usingAudioTag&&(this.totalDuration=this._sound.duration,this._sound.volume=this.volume*this._game.audio.volume))},enumerable:!0,configurable:!0}),b.prototype.objType=function(){return"Audio"},Object.defineProperty(b.prototype,"loop",{get:function(){return this._loop},enumerable:!0,configurable:!0}),b.prototype._setAudio=function(){this._file=this._game.fileStore.getFile(this.key),"undefined"!=typeof this._file.data&&(this._usingAudioTag?(this._sound=this._file.data.cloneNode(!0),this._game.deviceTargetOption==a.TARGET_BROWSER&&(this._sound.play(),this._sound.pause())):this._sound=this._file.data,this.ready=!0)},b.prototype._decode=function(){if(0!=this.ready&&!this._usingAudioTag){if(this._file.data.decoded===!0&&null!==this._file.data.buffer)return this._buffer=this._file.data.buffer,void(this._decoded=!0);var a=this;this.context.decodeAudioData(this._file.data.raw,function(b){a._buffer=b,a._decoded=!0})}},Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(b){this._game.audio.noAudio||this.ready===!1||(b=a.Utils.GameMath.clamp(b,1,0),this._volume=b,this._muted&&(this._muteVolume=this._volume),this._playable&&(this._usingWebAudio?this.gainNode.gain.value=this._volume*this._game.audio.volume:this._usingAudioTag&&(this._sound.volume=this._volume*this._game.audio.volume)))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"mute",{get:function(){return this._muted},set:function(a){this._game.audio.noAudio||void 0!==a&&this._muted!==a&&(a===!0?(this._muteVolume=this._volume,this.volume=0,this._muted=!0):(this._muted=!1,this.volume=this._muteVolume),this.onMute.dispatch(this._muted))},enumerable:!0,configurable:!0}),b.prototype.addMarker=function(a,b,c,d){void 0===d&&(d=!1),this._markers[a]={start:b,stop:c,duration:c-b,loop:d}},b.prototype.removeMarker=function(a){"default"!==a&&(this.isPlaying&&this._currentMarker==a&&(this.stop(),this._currentMarker="default"),delete this._markers[a])},b.prototype.play=function(b,c){return void 0===b&&(b=this._currentMarker),void 0===c&&(c=!1),this.isPlaying&&!c||this._game.audio.noAudio||(c&&!this._pending&&this.stop(),"undefined"==typeof this._markers[b]||this._currentMarker===b&&this.isPlaying&&0==c)?void 0:(this.paused=!1,this._currentMarker=b,this.duration=1e3*this._markers[this._currentMarker].duration,this._loop=this._markers[this._currentMarker].loop,this._playable===!1?void(this._pending=!0):void(this._usingWebAudio?this._decoded===!0?(null==this._buffer&&(this._buffer=this._file.data.buffer),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this._sound.connect(this.gainNode),this.totalDuration=this._sound.buffer.duration,0==this.duration&&(this.duration=1e3*this.totalDuration),this._loop&&(this._sound.loop=!0),void 0===this._sound.start?this._sound.noteGrainOn(0,this._markers[this._currentMarker].start,this.duration/1e3):this._sound.start(0,this._markers[this._currentMarker].start,this.duration/1e3),this.isPlaying=!0,this._startTime=this._game.time.now(),this._currentTime=0,this._stopTime=this._startTime+this.duration,this.onPlay.dispatch()):(this._pending=!0,this._decode()):this._usingAudioTag&&(this._sound&&4==this._sound.readyState||this._game.deviceTargetOption==a.TARGET_COCOON?((0==this.duration||isNaN(this.duration))&&(this.duration=1e3*this.totalDuration),this._sound.volume=this._muted?0:this._volume,this._sound.currentTime=this._markers[this._currentMarker].start,this._sound.play(),this.isPlaying=!0,this._startTime=this._game.time.now(),this._currentTime=0,this._stopTime=this._startTime+this.duration,this.paused||this.onPlay.dispatch()):this._pending=!0)))},b.prototype.stop=function(){this.isPlaying&&this._sound&&(this._usingWebAudio?void 0===this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this._usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0),this.isPlaying=!1,0==this.paused&&this.onStop.dispatch())},b.prototype.pause=function(){this.isPlaying&&(this.paused=!0,this.stop(),this.onPause.dispatch())},b.prototype.resume=function(){this.paused&&0==this.isPlaying&&(this._usingWebAudio?(null==this._buffer&&(this._buffer=this._file.data.buffer),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this._sound.connect(this.gainNode),this._loop&&(this._sound.loop=!0),void 0===this._sound.start?this._sound.noteGrainOn(0,this._markers[this._currentMarker].start+this._currentTime/1e3,this.duration/1e3):this._sound.start(0,this._markers[this._currentMarker].start+this._currentTime/1e3,this.duration/1e3)):(this._sound.currentTime=this._markers[this._currentMarker].start+this._currentTime/1e3,this._sound.play()),this.paused=!1,this.isPlaying=!0,this.onResume.dispatch())},b.prototype.update=function(){this.ready&&(this._playable&&this._pending&&(this._decoded===!0||this._file.data&&this._file.data.decoded?(this._pending=!1,this.play()):(this._usingAudioTag&&!isNaN(this._sound.duration)||this._game.deviceTargetOption==a.TARGET_COCOON&&0!==this._sound.duration)&&(this.totalDuration=this._sound.duration,this._markers["default"].duration=this.totalDuration,this._pending=!1,this.isPlaying&&"default"==this._currentMarker&&(this.duration=this.totalDuration))),this.isPlaying&&(this._currentTime=this._game.time.now()-this._startTime,this._currentTime>=this.duration&&(this._usingWebAudio?this._loop?("default"==this._currentMarker?(this._currentTime=0,this._startTime=this._game.time.now()):this.play(this._currentMarker,!0),this.onLoop.dispatch()):this.stop():this._usingAudioTag&&(this._loop?(this.play(this._currentMarker,!0),this.onLoop.dispatch()):this.stop()))))},b.prototype.destroy=function(){this._game&&this._game.audio.remove(this,!1),this.onLoop&&this.onLoop.dispose(),this.onStop&&this.onStop.dispose(),this.onPlay&&this.onPlay.dispose(),this.onMute&&this.onMute.dispose(),this.onPause&&this.onPause.dispose(),this.onResume&&this.onResume.dispose(),delete this.onLoop,delete this.onStop,delete this.onPause,delete this.onMute,delete this.onPlay,delete this.onResume,delete this._game,delete this._sound,delete this._currentTime,delete this._startTime,delete this._stopTime,delete this._pending,delete this.masterGainNode,delete this.gainNode,delete this.totalDuration,delete this.duration,delete this._file,delete this._buffer,delete this._decoded},b}();b.Audio=c}(b=a.Sound||(a.Sound={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._game=a,this.audio={}}return b.prototype.objType=function(){return"AudioLibrary"},b.prototype.clear=function(){for(var a in this.audio)delete this.audio[a]},b.prototype.rebuild=function(b,c){this.clear(),a.Log.log("Kiwi.AudioLibrary: Rebuilding Audio Library.","#audio","#rebuild");for(var d=b.keys,e=0;e<d.length;e++){var f=this._game.fileStore.getFile(d[e]);f.isAudio&&(a.Log.log("  Kiwi.AudioLibrary: Adding Audio: "+f.name,"#audio","#added"),c.audioLibrary.add(f))}},b.prototype.add=function(b){switch(b.dataType){case a.Files.File.AUDIO:this.audio[b.key]=b}},b}();b.AudioLibrary=c}(b=a.Sound||(a.Sound={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(b,c,d,e){void 0===e&&(e=1e3),this._timeFirstStarted=null,this._timeLastStarted=null,this.timeScale=1,this._elapsed=0,this.rate=1,this._maxFrameDuration=-1,this._timeLastStopped=null,this._timeLastPaused=null,this._timeLastUnpaused=null,this._totalPaused=0,this._isRunning=!1,this._isStopped=!0,this._isPaused=!1,this._elapsedState=a.Time.Clock._RUNNING,this.manager=null,this.master=null,this.name=null,this.units=0,this.manager=b,this.master=c,this.name=d,this.units=e,this.timers=[],this.units<1&&(this.units=1),this._lastMasterElapsed=this.master.elapsed(),this._currentMasterElapsed=this.master.elapsed()}return c.prototype.objType=function(){return"Clock"},c.prototype.elapsedSinceFirstStarted=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeFirstStarted)/this.units:null},c.prototype.started=function(){return this._timeLastStarted},Object.defineProperty(c.prototype,"maxFrameDuration",{get:function(){return this._maxFrameDuration},set:function(a){this._maxFrameDuration=a},enumerable:!0,configurable:!0}),c.prototype.elapsed=function(){return this._elapsed},c.prototype.elapsedSinceLastStopped=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeLastStopped)/this.units:null},c.prototype.elapsedSinceLastPaused=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeLastPaused)/this.units:null},c.prototype.elapsedSinceLastUnpaused=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeLastUnpaused)/this.units:null},c.prototype.isRunning=function(){return this._isRunning},c.prototype.isStopped=function(){return this._isStopped},c.prototype.isPaused=function(){return this._isPaused},c.prototype.addTimer=function(a){return this.timers.push(a),this},c.prototype.createTimer=function(a,c,d,e){return void 0===c&&(c=1),void 0===d&&(d=0),void 0===e&&(e=!0),this.timers.push(new b.Timer(a,this,c,d)),e===!0&&this.timers[this.timers.length-1].start(),this.timers[this.timers.length-1]},c.prototype.removeTimer=function(a,b){void 0===a&&(a=null),void 0===b&&(b="");var c;if(null!==a){if(c=this.timers.indexOf(a),-1!==c)return this.timers.splice(c,1),!0}else if(""!==b)for(c=0;c<this.timers.length;c++)if(this.timers[c].name===b)return this.timers.splice(c,1),!0;return!1},c.prototype.checkExists=function(a){return this.timers[a]?!0:!1},c.prototype.stopAllTimers=function(){for(var a=0;a<this.timers.length;a++)this.timers[a].stop();return this},c.prototype.convertToMilliseconds=function(a){return a*this.units},c.prototype.update=function(){var b=this._currentMasterElapsed-this._lastMasterElapsed;this._maxFrameDuration>0&&(b=Math.min(b,this._maxFrameDuration));for(var c=0;c<this.timers.length;c++)this.timers[c].update();this._lastMasterElapsed=this._currentMasterElapsed,this._currentMasterElapsed=this.master.elapsed(),this._elapsedState===a.Time.Clock._RUNNING||this._elapsedState===a.Time.Clock._RESUMED?(this._elapsed+=this.timeScale*b/this.units,this.rate=this.timeScale*b/this.master.idealDelta):this._elapsedState===a.Time.Clock._PAUSED?(this._totalPaused+=b,this.rate=0):this._elapsedState===a.Time.Clock._STOPPED&&(this.rate=0)},c.prototype.start=function(){return this._timeLastStarted=this.master.elapsed(),this._totalPaused=0,this._timeFirstStarted||(this._timeFirstStarted=this._timeLastStarted),this._isRunning=!0,this._isPaused=!1,this._isStopped=!1,this._elapsedState=a.Time.Clock._RUNNING,this},c.prototype.pause=function(){return this._isRunning===!0&&(this._timeLastPaused=this.master.elapsed(),this._isRunning=!1,this._isPaused=!0,this._isStopped=!1,this._elapsedState=a.Time.Clock._PAUSED),this},c.prototype.resume=function(){return this._isPaused===!0&&(this._timeLastUnpaused=this.master.elapsed(),this._totalPaused+=this._timeLastUnpaused-this._timeLastPaused,this._isRunning=!0,this._isPaused=!1,this._isStopped=!1,this._elapsedState=a.Time.Clock._RESUMED),this},c.prototype.stop=function(){return this._isStopped===!1&&(this._timeLastStopped=this.master.elapsed(),this._isPaused===!0&&(this._totalPaused+=this._timeLastStopped-this._timeLastPaused),this._isRunning=!1,this._isPaused=!1,this._isStopped=!0,this._elapsedState=a.Time.Clock._STOPPED),this},c.prototype.toString=function(){return"[{Clock (name="+this.name+" units="+this.units+" running="+this._isRunning+")}]"},c.prototype.setTimeout=function(a,c,d){for(var e=[],f=3;f<arguments.length;f++)e[f-3]=arguments[f];var g=this,h=this.createTimer("timeoutTimer",c/1e3);return d||(d=this),h.createTimerEvent(b.TimerEvent.TIMER_STOP,function(){a.apply(d,e),g.removeTimer(h)},d),h.start(),h},c.prototype.setInterval=function(a,c,d){for(var e=[],f=3;f<arguments.length;f++)e[f-3]=arguments[f];var g=this.createTimer("timeoutTimer",c/1e3,-1);return d||(d=this),g.createTimerEvent(b.TimerEvent.TIMER_COUNT,function(){a.apply(d,e)},d),g.start(),g},c._RUNNING=0,c._PAUSED=1,c._RESUMED=2,c._STOPPED=3,c}();b.Clock=c}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(a){this._clocks=[],this.rate=1,this._game=a}return c.prototype.objType=function(){return"ClockManager"},c.prototype.boot=function(){this.master=new a.Time.MasterClock,this.clock=new b.Clock(this,this.master,"default",1e3),this.clock.start()},c.prototype.addClock=function(a,c){return void 0===c&&(c=1e3),this._clocks.push(new b.Clock(this,this.master,a,c)),this._clocks[this._clocks.length-1]},c.prototype.getClock=function(a){for(var b=0;b<this._clocks.length;b++)if(this._clocks[b].name===a)return this._clocks[b]},c.prototype.update=function(){this.master.update(),this.clock.update();for(var a=0;a<this._clocks.length;a++)this._clocks[a].update();this.rate=this.master.rate},c.prototype.now=function(){return this.master.now},c.prototype.elapsed=function(){return this.master.elapsed()},c.prototype.delta=function(){return this.master.delta},c.prototype.setMasterInterval=function(a){this.master.idealDelta=a},c}();b.ClockManager=c}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){this.time=0,this.now=0,this.delta=0,this.rate=1,this.idealDelta=1e3/60,this._started=Date.now(),this.now=Date.now(),this.time=this._started}return a.prototype.objType=function(){return"MasterClock"},a.prototype.elapsed=function(){return this.now-this._started},a.prototype.totalElapsedSeconds=function(){return.001*(this.now-this._started)},a.prototype.update=function(){this.now=Date.now(),this.delta=this.now-this.time,this.time=this.now,this.rate=this.delta/this.idealDelta},a.prototype.elapsedSince=function(a){return this.now-a},a.prototype.elapsedSecondsSince=function(a){return.001*(this.now-a)},a.prototype.reset=function(){this._started=this.now},a}();a.MasterClock=b}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(a,b,c,d){void 0===d&&(d=0),this._currentCount=0,this._startEvents=null,this._countEvents=null,this._stopEvents=null,this._clock=null,this._timeLastCount=null,this._isRunning=!1,this._isStopped=!0,this._isPaused=!1,this.name=null,this.delay=0,this.repeatCount=0,this._elapsed=0,this._clock=b,this._startEvents=[],this._countEvents=[],this._stopEvents=[],this.name=a,this.delay=c,this.repeatCount=d}return b.prototype.objType=function(){return"Timer"},b.prototype.currentCount=function(){return this._currentCount},b.prototype.isRunning=function(){return this._isRunning},b.prototype.isStopped=function(){return this._isStopped},b.prototype.isPaused=function(){return this._isPaused},b.prototype.processEvents=function(b){if(b===a.TimerEvent.TIMER_START)for(var c=0;c<this._startEvents.length;c++)this._startEvents[c].run();else if(b===a.TimerEvent.TIMER_COUNT)for(var c=0;c<this._countEvents.length;c++)this._countEvents[c].run();else if(b===a.TimerEvent.TIMER_STOP)for(var c=0;c<this._stopEvents.length;c++)this._stopEvents[c].run()},b.prototype.update=function(){var b=this._clock.elapsed()-this._lastElapsed;for(this._lastElapsed=this._clock.elapsed(),this._isRunning&&(this._elapsed+=b);this._elapsed>=this.delay;)this._currentCount++,this.processEvents(a.TimerEvent.TIMER_COUNT),this._elapsed-=this.delay,-1!==this.repeatCount&&this._currentCount>=this.repeatCount&&this.stop();for(;this._elapsed<0;)this._currentCount--,this._elapsed+=this.delay,this._currentCount<0&&(this.clear(),this.stop())},b.prototype.start=function(){return this._isStopped===!0&&(this._isRunning=!0,this._isPaused=!1,this._isStopped=!1,this._currentCount=0,this._elapsed=0,this._lastElapsed=this._clock.elapsed()||0,this.processEvents(a.TimerEvent.TIMER_START)),this},b.prototype.stop=function(){return(this._isRunning===!0||this._isPaused===!0)&&(this._isRunning=!1,this._isPaused=!1,this._isStopped=!0,this.processEvents(a.TimerEvent.TIMER_STOP)),this},b.prototype.pause=function(){return this._isRunning===!0&&(this._isRunning=!1,this._isPaused=!0),this},b.prototype.resume=function(){return this._isPaused===!0&&(this._isRunning=!0,this._isPaused=!1),this},b.prototype.addTimerEvent=function(b){return b.type===a.TimerEvent.TIMER_START?this._startEvents.push(b):b.type===a.TimerEvent.TIMER_COUNT?this._countEvents.push(b):b.type===a.TimerEvent.TIMER_STOP&&this._stopEvents.push(b),b},b.prototype.createTimerEvent=function(b,c,d){return b===a.TimerEvent.TIMER_START?(this._startEvents.push(new a.TimerEvent(b,c,d)),this._startEvents[this._startEvents.length-1]):b===a.TimerEvent.TIMER_COUNT?(this._countEvents.push(new a.TimerEvent(b,c,d)),this._countEvents[this._countEvents.length-1]):b===a.TimerEvent.TIMER_STOP?(this._stopEvents.push(new a.TimerEvent(b,c,d)),this._stopEvents[this._stopEvents.length-1]):null},b.prototype.removeTimerEvent=function(b){var c=[];return b.type===a.TimerEvent.TIMER_START?c=this._startEvents.splice(this._startEvents.indexOf(b),1):b.type===a.TimerEvent.TIMER_COUNT?c=this._countEvents.splice(this._countEvents.indexOf(b),1):b.type===a.TimerEvent.TIMER_STOP&&(c=this._stopEvents.splice(this._stopEvents.indexOf(b),1)),1===c.length?!0:!1},b.prototype.clear=function(b){void 0===b&&(b=0),0===b?(this._startEvents.length=0,this._countEvents.length=0,this._stopEvents.length=0):b===a.TimerEvent.TIMER_START?this._startEvents.length=0:b===a.TimerEvent.TIMER_COUNT?this._countEvents.length=0:b===a.TimerEvent.TIMER_STOP&&(this._stopEvents.length=0)},b.prototype.toString=function(){return"[{Timer (name="+this.name+" delay="+this.delay+" repeatCount="+this.repeatCount+" running="+this._isRunning+")}]"},b}();a.Timer=b}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b,c){this._callback=null,this.type=0,this.type=a,this._callback=b,this._callbackContext=c}return a.prototype.objType=function(){return"TimerEvent"},a.prototype.run=function(){this._callback&&this._callback.apply(this._callbackContext)},a.TIMER_START=1,a.TIMER_COUNT=2,a.TIMER_STOP=3,a}();a.TimerEvent=b}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c,d,e){void 0===d&&(d=!0),void 0===e&&(e=!1),this.domElement=null,this.context=null,this._visible=!0,this._offScreen=!1,this._clearMode=1,this.domElement=document.createElement("canvas"),this.domElement.width=b,this.domElement.height=c,this._width=b,this._height=c,this.context=this.domElement.getContext("2d"),this._offScreen=e,this._visible=d,d===!1&&(this.domElement.style.display="none"),this._bgColor=new a.Utils.Color(0,0,0)}return Object.defineProperty(b.prototype,"width",{get:function(){return this._width},set:function(a){this._width=a,this._updatedSize()},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"height",{get:function(){return this._height},set:function(a){this._height=a,this._updatedSize()},enumerable:!0,configurable:!0}),b.prototype.objType=function(){return"Canvas"},Object.defineProperty(b.prototype,"bgColor",{get:function(){return"#"+this._bgColor.getHex()},set:function(b){a.Utils.Common.isArray(b)||(b=[b]),this._bgColor.set.apply(this._bgColor,b)},enumerable:!0,configurable:!0}),b.prototype._updatedSize=function(){this.domElement.width=this._width,this.domElement.height=this._height},b.prototype.destroy=function(){this._offScreen===!1&&(this.domElement.style.display="none")},Object.defineProperty(b.prototype,"visible",{get:function(){return this._visible},set:function(a){null!==a&&a!==this._visible&&(this._visible=a,this.domElement.style.display=a===!0?"block":"none")},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"clearMode",{get:function(){return this._clearMode},set:function(b){null!==b&&b!==this._clearMode&&b>=a.Utils.Canvas.CLEARMODE_NONE&&b<=a.Utils.Canvas.CLEARMODE_FILLRECT_ALPHA&&(this._clearMode=b)},enumerable:!0,configurable:!0}),b.prototype.clear=function(){this._clearMode===b.CLEARMODE_NONE||(this._clearMode===b.CLEARMODE_CLEARRECT?this.context.clearRect(0,0,this.domElement.width,this.domElement.height):this._clearMode===b.CLEARMODE_FILLRECT?(this.context.fillStyle=this.bgColor,this.context.fillRect(0,0,this.domElement.width,this.domElement.height)):this._clearMode===b.CLEARMODE_FILLRECT_ALPHA&&(this.context.clearRect(0,0,this.domElement.width,this.domElement.height),this.context.fillStyle=this.bgColor,this.context.fillRect(0,0,this.domElement.width,this.domElement.height)))},b.prototype.saveAsPNG=function(){return this.domElement.toDataURL()},b.prototype.toString=function(){return"[{Canvas (width="+this.width+" height="+this.height+" visible="+this.visible+" offScreen="+this._offScreen+" clearMode="+this.clearMode+")}]"
-},b.CLEARMODE_NONE=0,b.CLEARMODE_CLEARRECT=1,b.CLEARMODE_FILLRECT=2,b.CLEARMODE_FILLRECT_ALPHA=3,b}();b.Canvas=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this._r=.5,this._g=.5,this._b=.5,this._a=1,this.set.apply(this,a),this}return a.prototype.set=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return 3===a.length?(this.r=a[0],this.g=a[1],this.b=a[2]):4===a.length?isNaN(a[3])?"hsv"===a[3]?this.parseHsv(a[0],a[1],a[2]):"hsl"===a[3]&&this.parseHsl(a[0],a[1],a[2]):(this.r=a[0],this.g=a[1],this.b=a[2],this.a=a[3]):5===a.length?"hsv"===a[4]?this.parseHsv(a[0],a[1],a[2],a[3]):"hsl"===a[4]&&this.parseHsl(a[0],a[1],a[2],a[3]):1===a.length?"string"==typeof a[0]?this.parseString(a[0]):isNaN(a[0])||(this.r=a[0],this.g=a[0],this.b=a[0]):2===a.length&&(this.r=a[0],this.g=a[0],this.b=a[0],this.a=a[1]),this},Object.defineProperty(a.prototype,"rNorm",{get:function(){return this._r},set:function(a){isNaN(a)||(this._r=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"gNorm",{get:function(){return this._g},set:function(a){isNaN(a)||(this._g=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"bNorm",{get:function(){return this._b},set:function(a){isNaN(a)||(this._b=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"aNorm",{get:function(){return this._a},set:function(a){isNaN(a)||(this._a=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"r",{get:function(){return this._r},set:function(a){a>1?this.r255=a:this.rNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"g",{get:function(){return this._g},set:function(a){a>1?this.g255=a:this.gNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"b",{get:function(){return this._b},set:function(a){a>1?this.b255=a:this.bNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"a",{get:function(){return this._a},set:function(a){a>1?this.a255=a:this.aNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"r255",{get:function(){return Math.round(255*this._r)},set:function(a){isNaN(a)||(this._r=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"g255",{get:function(){return Math.round(255*this._g)},set:function(a){isNaN(a)||(this._g=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"b255",{get:function(){return Math.round(255*this._b)},set:function(a){isNaN(a)||(this._b=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"a255",{get:function(){return Math.round(255*this._a)},set:function(a){isNaN(a)||(this._a=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"red",{get:function(){return this.r},set:function(a){this.r=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"green",{get:function(){return this.g},set:function(a){this.g=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"blue",{get:function(){return this.b},set:function(a){this.b=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alpha",{get:function(){return this.a},set:function(a){this.a=a},enumerable:!0,configurable:!0}),a.prototype.parseString=function(a){var b;return a=a.toLowerCase(),"rgba"===a.slice(0,4)?(a=a.replace("rgba",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.r=+b[0],this.g=+b[1],this.b=+b[2],this.a=+b[3]):"rgb"===a.slice(0,3)?(a=a.replace("rgb",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.r=+b[0],this.g=+b[1],this.b=+b[2]):"hsla"===a.slice(0,4)?(a=a.replace("hsla",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.parseHsl(+b[0],+b[1],+b[2],+b[3])):"hsl"===a.slice(0,3)?(a=a.replace("hsl",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.parseHsl(+b[0],+b[1],+b[2])):this.parseHex(a),this},a.prototype.parseHex=function(a){var b,c=this.r255,d=this.g255,e=this.b255,f=this.a255;return"#"===a.charAt(0)&&(a=a.slice(1)),"0x"===a.slice(0,2)&&(a=a.slice(2)),b=parseInt(a,16),3===a.length?(c=17*(b>>8&15),d=17*(b>>4&15),e=17*(15&b)):4===a.length?(c=17*(b>>12&15),d=17*(b>>8&15),e=17*(b>>4&15),f=17*(15&b)):6===a.length?(c=b>>16&255,d=b>>8&255,e=255&b,f=255):8===a.length&&(c=b>>24&255,d=b>>16&255,e=b>>8&255,f=255&b),this.r255=c,this.g255=d,this.b255=e,this.a255=f,this},a.prototype.getHex=function(a){void 0===a&&(a=!0);var b,c="";for(b=this.r255.toString(16);b.length<2;)b="0"+b;for(c+=b,b=this.g255.toString(16);b.length<2;)b="0"+b;for(c+=b,b=this.b255.toString(16);b.length<2;)b="0"+b;if(c+=b,a){for(b=this.a255.toString(16);b.length<2;)b="0"+b;c+=b}return c},a.prototype.parseHsv=function(a,b,c,d){void 0===d&&(d=1);var e,f,g,h,i,j,k,l;if(isNaN(a)||isNaN(b)||isNaN(c)||isNaN(d))return this;switch(a>1&&(a/=360),b>1&&(b/=100),c>1&&(c/=100),d>1&&(d/=255),h=Math.floor(6*a),i=6*a-h,j=c*(1-b),k=c*(1-i*b),l=c*(1-(1-i)*b),h%6){case 0:e=c,f=l,g=j;break;case 1:e=k,f=c,g=j;break;case 2:e=j,f=c,g=l;break;case 3:e=j,f=k,g=c;break;case 4:e=l,f=j,g=c;break;case 5:e=c,f=j,g=k}return this._r=e,this._g=f,this._b=g,this._a=d,this},a.prototype.getHsva=function(){var a,b,c,d,e=this._r,f=this._g,g=this._b,h=Math.max(e,f,g),i=Math.min(e,f,g);if(a=h,b=h,c=h,d=h-i,b=0===h?0:d/h,h===i)a=0;else{switch(h){case e:a=(f-g)/d+(g>f?6:0);break;case f:a=(g-e)/d+2;break;case g:a=(e-f)/d+4}a/=6}return{h:a,s:b,v:c,a:this._a}},a.prototype.parseHsl=function(a,b,c,d){void 0===d&&(d=1);var e,f,g=this._r,h=this._g,i=this._b;return isNaN(a)||isNaN(b)||isNaN(c)||isNaN(d)?this:(a>1&&(a/=360),b>1&&(b/=100),c>1&&(c/=100),d>1&&(d/=255),0===b?(g=c,h=c,i=c):(e=.5>c?c*(1+b):c+b-c*b,f=2*c-e,g=this._hue2rgb(f,e,a+1/3),h=this._hue2rgb(f,e,a),i=this._hue2rgb(f,e,a-1/3)),this._r=g,this._g=h,this._b=i,this._a=d,this)},a.prototype.getHsla=function(){var a,b=this._r,c=this._g,d=this._b,e=Math.max(b,c,d),f=Math.min(b,c,d),g=(e+f)/2,h=(e+f)/2,i=(e+f)/2;if(e==f)g=0,h=0;else{switch(a=e-f,h=i>.5?a/(2-e-f):a/(e+f),e){case b:g=(c-d)/a+(d>c?6:0);break;case c:g=(d-b)/a+2;break;case d:g=(b-c)/a+4}g/=6}return{h:g,s:h,l:i,a:this._a}},a.prototype._hue2rgb=function(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+(b-a)*(2/3-c)*6:a},a}();a.Color=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){}return b.defaultCompare=function(a,b){return b>a?-1:a===b?0:1},b.prototype.objType=function(){return"Common"},b.defaultEquals=function(a,b){return a===b},b.defaultToString=function(b){return null===b?"KIWI_NULL":a.Utils.Common.isUndefined(b)?"KIWI_UNDEFINED":a.Utils.Common.isString(b)?b:b.toString()},b.isBetween=function(a,b,c){return a>b&&c>a},b.isFunction=function(a){return"function"==typeof a},b.isNumeric=function(a){return!isNaN(a)},b.isUndefined=function(a){return"undefined"==typeof a},b.isString=function(a){return"[object String]"===Object.prototype.toString.call(a)},b.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},b.isObject=function(a){return"[object Object]"===Object.prototype.toString.call(a)},b.reverseCompareFunction=function(b){return a.Utils.Common.isFunction(b)?function(a,c){return-1*b(a,c)}:function(a,b){return b>a?1:a===b?0:-1}},b.compareToEquals=function(a){return function(b,c){return 0===a(b,c)}},b.shuffleArray=function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},b.convertToBase2=function(a){var b=a.width,c=a.height;if(-1==this.base2Sizes.indexOf(b)){for(var d=0;b>this.base2Sizes[d];)d++;b=this.base2Sizes[d]}if(-1==this.base2Sizes.indexOf(c)){for(var d=0;c>this.base2Sizes[d];)d++;c=this.base2Sizes[d]}if(a.width!==b||a.height!==c){var e=document.createElement("canvas");return e.width=b,e.height=c,e.getContext("2d").drawImage(a,0,0),e}return a},b.base2Sizes=[2,4,16,32,64,128,256,512,1024,2048,4096],b}();b.Common=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){}return b.prototype.objType=function(){return"GameMath"},b.computeMachineEpsilon=function(){var a=4/3,b=a-1,c=b+b+b;return Math.abs(1-c)},b.fuzzyEqual=function(a,b,c){return void 0===c&&(c=1e-4),Math.abs(a-b)<c},b.fuzzyLessThan=function(a,b,c){return void 0===c&&(c=1e-4),b+c>a},b.fuzzyGreaterThan=function(a,b,c){return void 0===c&&(c=1e-4),a>b-c},b.fuzzyCeil=function(a,b){return void 0===b&&(b=1e-4),Math.ceil(a-b)},b.fuzzyFloor=function(a,b){return void 0===b&&(b=1e-4),Math.floor(a+b)},b.average=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0,d=0;d<a.length;d++)c+=a[d];return c/a.length},b.slam=function(a,b,c){return void 0===c&&(c=1e-4),Math.abs(a-b)<c?b:a},b.percentageMinMax=function(a,b,c){return void 0===c&&(c=0),a-=c,b-=c,b?a/b:0},b.sign=function(a){return a?a/Math.abs(a):0},b.truncate=function(a){return a>0?Math.floor(a):Math.ceil(a)},b.shear=function(a){return a%1},b.wrap=function(a,b,c){if(void 0===c&&(c=0),a-=c,b-=c,0==b)return c;for(a%=b,a+=c;c>a;)a+=b;return a},b.arithWrap=function(a,b,c){return void 0===c&&(c=0),b-=c,0==b?c:a-b*Math.floor((a-c)/b)},b.clamp=function(a,b,c){return void 0===c&&(c=0),Math.max(c,Math.min(b,a))},b.snapTo=function(a,b,c){return void 0===c&&(c=0),0==b?a:(a-=c,a=b*Math.round(a/b),c+a)},b.snapToFloor=function(a,b,c){return void 0===c&&(c=0),0==b?a:(a-=c,a=b*Math.floor(a/b),c+a)},b.snapToCeil=function(a,b,c){return void 0===c&&(c=0),0==b?a:(a-=c,a=b*Math.ceil(a/b),c+a)},b.snapToInArray=function(a,b,c){if(void 0===c&&(c=!0),c&&b.sort(),a<b[0])return b[0];for(var d=1;b[d]<a;)d++;var e=b[d-1],f=d<b.length?b[d]:Number.POSITIVE_INFINITY;return a-e>=f-a?f:e},b.roundTo=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=10);var d=Math.pow(c,-b);return Math.round(a*d)/d},b.floorTo=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=10);var d=Math.pow(c,-b);return Math.floor(a*d)/d},b.ceilTo=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=10);var d=Math.pow(c,-b);return Math.ceil(a*d)/d},b.interpolateFloat=function(a,b,c){return(b-a)*c+a},b.radiansToDegrees=function(a){return a*b.RAD_TO_DEG},b.degreesToRadians=function(a){return a*b.DEG_TO_RAD},b.angleBetween=function(a,b,c,d){return Math.atan2(d-b,c-a)},b.normalizeAngle=function(a,c){void 0===c&&(c=!0);var d=c?b.PI:180;return b.wrap(a,d,-d)},b.nearestAngleBetween=function(a,c,d){void 0===d&&(d=!0);var e=d?b.PI:180;return a=b.normalizeAngle(a,d),c=b.normalizeAngle(c,d),-e/2>a&&c>e/2&&(a+=2*e),-e/2>c&&a>e/2&&(c+=2*e),b.normalizeAngle(c-a,d)},b.normalizeAngleToAnother=function(b,c,d){return void 0===d&&(d=!0),c+a.Utils.GameMath.nearestAngleBetween(c,b,d)},b.normalizeAngleAfterAnother=function(b,c,d){return void 0===d&&(d=!0),b=a.Utils.GameMath.normalizeAngle(b-c,d),c+b},b.normalizeAngleBeforeAnother=function(b,c,d){return void 0===d&&(d=!0),b=a.Utils.GameMath.normalizeAngle(c-b,d),c-b},b.interpolateAngles=function(b,c,d,e,f){return void 0===e&&(e=!0),void 0===f&&(f=null),b=a.Utils.GameMath.normalizeAngle(b,e),c=a.Utils.GameMath.normalizeAngleToAnother(c,b,e),"function"==typeof f?f(d,b,c-b,1):a.Utils.GameMath.interpolateFloat(b,c,d)},b.logBaseOf=function(a,b){return Math.log(a)/Math.log(b)},b.GCD=function(a,b){var c;for(a=Math.abs(a),b=Math.abs(b),b>a&&(c=a,a=b,b=c);;){if(c=a%b,!c)return b;a=b,b=c}return 1},b.LCM=function(b,c){return b*c/a.Utils.GameMath.GCD(b,c)},b.factorial=function(a){if(0==a)return 1;for(var b=a;--a;)b*=a;return b},b.gammaFunction=function(b){return a.Utils.GameMath.factorial(b-1)},b.fallingFactorial=function(b,c){return a.Utils.GameMath.factorial(b)/a.Utils.GameMath.factorial(b-c)},b.risingFactorial=function(b,c){return a.Utils.GameMath.factorial(b+c-1)/a.Utils.GameMath.factorial(b-1)},b.binCoef=function(b,c){return a.Utils.GameMath.fallingFactorial(b,c)/a.Utils.GameMath.factorial(c)},b.risingBinCoef=function(b,c){return a.Utils.GameMath.risingFactorial(b,c)/a.Utils.GameMath.factorial(c)},b.chanceRoll=function(a){return void 0===a&&(a=50),0>=a?!1:a>=100?!0:100*Math.random()>=a?!1:!0},b.maxAdd=function(a,b,c){return a+=b,a>c&&(a=c),a},b.minSub=function(a,b,c){return a-=b,c>a&&(a=c),a},b.wrapValue=function(a,b,c){var d;return a=Math.abs(a),b=Math.abs(b),c=Math.abs(c),d=(a+b)%c},b.randomSign=function(){return Math.random()>.5?1:-1},b.isOdd=function(a){return 1&a?!0:!1},b.isEven=function(a){return 1&a?!1:!0},b.wrapAngle=function(a){var b=a;return a>=-180&&180>=a?a:(b=(a+180)%360,0>b&&(b+=360),b-180)},b.angleLimit=function(a,b,c){var d=a;return a>c?d=c:b>a&&(d=b),d},b.linearInterpolation=function(b,c){var d=b.length-1,e=d*c,f=Math.floor(e);return 0>c?a.Utils.GameMath.linear(b[0],b[1],e):c>1?a.Utils.GameMath.linear(b[d],b[d-1],d-e):a.Utils.GameMath.linear(b[f],b[f+1>d?d:f+1],e-f)},b.bezierInterpolation=function(b,c){for(var d=0,e=b.length-1,f=0;e>=f;f++)d+=Math.pow(1-c,e-f)*Math.pow(c,f)*b[f]*a.Utils.GameMath.bernstein(e,f);return d},b.catmullRomInterpolation=function(b,c){var d=b.length-1,e=d*c,f=Math.floor(e);return b[0]===b[d]?(0>c&&(f=Math.floor(e=d*(1+c))),a.Utils.GameMath.catmullRom(b[(f-1+d)%d],b[f],b[(f+1)%d],b[(f+2)%d],e-f)):0>c?b[0]-(a.Utils.GameMath.catmullRom(b[0],b[0],b[1],b[1],-e)-b[0]):c>1?b[d]-(a.Utils.GameMath.catmullRom(b[d],b[d],b[d-1],b[d-1],e-d)-b[d]):a.Utils.GameMath.catmullRom(b[f?f-1:0],b[f],b[f+1>d?d:f+1],b[f+2>d?d:f+2],e-f)},b.linear=function(a,b,c){return(b-a)*c+a},b.bernstein=function(b,c){return a.Utils.GameMath.factorial(b)/a.Utils.GameMath.factorial(c)/a.Utils.GameMath.factorial(b-c)},b.catmullRom=function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b},b.difference=function(a,b){return Math.abs(a-b)},b.PI=3.141592653589793,b.PI_2=1.5707963267948966,b.PI_4=.7853981633974483,b.PI_8=.39269908169872414,b.PI_16=.19634954084936207,b.TWO_PI=6.283185307179586,b.THREE_PI_2=4.71238898038469,b.E=2.71828182845905,b.LN10=2.302585092994046,b.LN2=.6931471805599453,b.LOG10E=.4342944819032518,b.LOG2E=1.4426950408889634,b.SQRT1_2=.7071067811865476,b.SQRT2=1.4142135623730951,b.DEG_TO_RAD=.017453292519943295,b.RAD_TO_DEG=57.29577951308232,b.B_16=65536,b.B_31=2147483648,b.B_32=4294967296,b.B_48=281474976710656,b.B_53=9007199254740992,b.B_64=0x10000000000000000,b.ONE_THIRD=.3333333333333333,b.TWO_THIRDS=.6666666666666666,b.ONE_SIXTH=.16666666666666666,b.COS_PI_3=.8660254037844386,b.SIN_2PI_3=.03654595,b.CIRCLE_ALPHA=.5522847498307935,b.ON=!0,b.OFF=!1,b.SHORT_EPSILON=.1,b.PERC_EPSILON=.001,b.EPSILON=1e-4,b.LONG_EPSILON=1e-8,b}();b.GameMath=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a){void 0===a&&(a=[]),this.c=1,this._data={lipsum:["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","nunc","sagittis","tortor","ac","mi","pretium","sed","convallis","massa","pulvinar","curabitur","non","turpis","velit","vitae","rutrum","odio","aliquam","sapien","orci","tempor","sed","elementum","sit","amet","tincidunt","sed","risus","etiam","nec","lacus","id","ante","hendrerit","malesuada","donec","porttitor","magna","eget","libero","pharetra","sollicitudin","aliquam","mattis","mattis","massa","et","porta","morbi","vitae","magna","augue","vestibulum","at","lectus","sed","tellus","facilisis","tincidunt","suspendisse","eros","magna","consequat","at","sollicitudin","ac","vestibulum","vel","dolor","in","egestas","lacus","quis","lacus","placerat","et","molestie","ipsum","scelerisque","nullam","sit","amet","tortor","dui","aenean","pulvinar","odio","nec","placerat","fringilla","neque","dolor"]},this.sow(a)}return a.prototype.objType=function(){return"RandomDataGenerator"},a.prototype.uint32=function(){return 4294967296*this.rnd.apply(this)},a.prototype.fract32=function(){return this.rnd.apply(this)+1.1102230246251565e-16*(2097152*this.rnd.apply(this)|0)},a.prototype.rnd=function(){var a=2091639*this.s0+2.3283064365386963e-10*this.c;return this.c=0|a,this.s0=this.s1,this.s1=this.s2,this.s2=a-this.c,this.s2},a.prototype.hash=function(a){var b,c,d;for(d=4022871197,a=a.toString(),c=0;c<a.length;c++)d+=a.charCodeAt(c),b=.02519603282416938*d,d=b>>>0,b-=d,b*=d,d=b>>>0,b-=d,d+=4294967296*b;return 2.3283064365386963e-10*(d>>>0)},a.prototype.sow=function(a){void 0===a&&(a=[]),this.s0=this.hash(" "),this.s1=this.hash(this.s0),this.s2=this.hash(this.s1);for(var b,c=0;b=a[c++];)this.s0-=this.hash(b),this.s0+=~~(this.s0<0),this.s1-=this.hash(b),this.s1+=~~(this.s1<0),this.s2-=this.hash(b),this.s2+=~~(this.s2<0)},a.prototype.integer=function(){return this.uint32()},a.prototype.frac=function(){return this.fract32()},a.prototype.real=function(){return this.uint32()+this.fract32()},a.prototype.integerInRange=function(a,b){return Math.floor(this.realInRange(a,b))},a.prototype.realInRange=function(a,b){return a=a||0,b=b||0,this.frac()*(b-a)+a},a.prototype.normal=function(){return 1-2*this.frac()},a.prototype.uuid=function(){var a,b;for(b=a="";a++<36;b+=~a%5|3*a&4?(15^a?8^this.frac()*(20^a?16:4):4).toString(16):"-");return b},a.prototype.pick=function(a){return a[this.integerInRange(0,a.length)]},a.prototype.weightedPick=function(a){return a[~~(Math.pow(this.frac(),2)*a.length)]},a.prototype.word=function(){return this.pick(this._data.lipsum)},a.prototype.words=function(a){void 0===a&&(a=3);for(var b=[],c=0;a>c;c++)b.push(this.pick(this._data.lipsum));return b.join(" ")},a.prototype.sentence=function(){var a;return a=this.words(this.integerInRange(2,16)).replace(/[a-z]/,function(a){return a.toUpperCase()}),a+"."},a.prototype.sentences=function(a){void 0===a&&(a=3);for(var b=[],c=0;a>c;c++)b.push(this.sentence());return b.join(" ")},a.prototype.timestamp=function(a,b){return void 0===a&&(a=9466848e5),void 0===b&&(b=1577862e6),this.realInRange(a,b)},a.prototype.angle=function(){return this.integerInRange(-180,180)},a}();a.RandomDataGenerator=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a){this._isSetTimeOut=!1,this.lastTime=0,this.currentTime=0,this.isRunning=!1,this._callback=a;for(var b=["ms","moz","webkit","o"],c=0;c<b.length&&!window.requestAnimationFrame;c++)window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]}return a.prototype.objType=function(){return"RequestAnimationFrame"},a.prototype.setCallback=function(a){this._callback=a},a.prototype.isUsingSetTimeOut=function(){return this._isSetTimeOut},a.prototype.isUsingRAF=function(){return this._isSetTimeOut===!0?!1:!0},a.prototype.start=function(a){var b=this;void 0===a&&(a=null),a&&(this._callback=a),window.requestAnimationFrame?(this._isSetTimeOut=!1,window.requestAnimationFrame(function(){return b.RAFUpdate()})):(this._isSetTimeOut=!0,this._timeOutID=window.setTimeout(function(){return b.SetTimeoutUpdate()},0)),this.isRunning=!0},a.prototype.stop=function(){this._isSetTimeOut?clearTimeout(this._timeOutID):window.cancelAnimationFrame,this.isRunning=!1},a.prototype.RAFUpdate=function(){var a=this;this.currentTime=Date.now(),this._callback&&this._callback();var b=Math.max(0,16-(this.currentTime-this.lastTime));window.requestAnimationFrame(function(){return a.RAFUpdate()}),this.lastTime=this.currentTime+b},a.prototype.SetTimeoutUpdate=function(){var a=this;this.currentTime=Date.now(),this._callback&&this._callback();var b=Math.max(0,16-(this.currentTime-this.lastTime));this._timeOutID=window.setTimeout(function(){return a.SetTimeoutUpdate()},b),this.lastTime=this.currentTime+b},a}();a.RequestAnimationFrame=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){void 0===a&&(a={}),this.enabled=!0,this.recording=!0,this.display=!0,this.tagFilters=[],this.maxRecordings=1/0,this.recordings=[],this.setDefaultsFromParams(a)}return b.prototype.setDefaultsFromParams=function(b){void 0===b&&(b={}),a.Utils.Common.isUndefined(b.enabled)||(this.enabled=b.enabled),a.Utils.Common.isUndefined(b.recording)||(this.recording=b.recording),a.Utils.Common.isUndefined(b.display)||(this.display=b.display),a.Utils.Common.isUndefined(b.maxRecordings)||(this.maxRecordings=b.maxRecordings),a.Utils.Common.isArray(b.tagFilters)&&(this.tagFilters=b.tagFilters)},Object.defineProperty(b.prototype,"lastMessageTime",{get:function(){return this.recordings.length>0?this.recordings[this.recordings.length-1].time:0},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"numRecordings",{get:function(){return this.recordings.length},enumerable:!0,configurable:!0}),b.prototype.record=function(a,b,c){if(void 0===b&&(b=[]),void 0===c&&(c=console.log),this.recording){var d={messages:a,time:Date.now(),tags:b,logMethod:c};this.recordings.push(d)>this.maxRecordings&&this.recordings.shift()}},b.prototype.clearRecordings=function(a,b){void 0===a&&(a=0),void 0===b&&(b=this.recordings.length),this.recordings.splice(a,b)},b.prototype._execute=function(a,b,c,d){void 0===d&&(d=!1),(this.display||d)&&a.apply(b,c)},b.prototype.getTagsFromArray=function(a){for(var b=0,c=[];b<a.length;)"string"==typeof a[b]&&"#"===a[b].charAt(0)&&c.push(a[b]),b++;return c},b.prototype._filterTags=function(a,b){if(void 0===b&&(b=this.tagFilters),0===b.length)return!0;for(var c=0;c<a.length;){if(-1===b.indexOf(a[c]))return!1;c++}return!0},b.prototype.log=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(this.enabled){var c=this.getTagsFromArray(a);this.record(a,c,console.log),this._filterTags(c)&&this._execute(console.log,console,a)}},b.prototype.warn=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(this.enabled){var c=this.getTagsFromArray(a);this.record(a,c,console.warn),this._filterTags(c)&&this._execute(console.warn,console,a)}},b.prototype.error=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(this.enabled){var c=this.getTagsFromArray(a);this.record(a,c,console.error),this._filterTags(c)&&this._execute(console.error,console,a)}},b.prototype._show=function(a,b){if(!a.logMethod)return!1;for(var c=b.length;c--;)if(-1==a.tags.indexOf(b[c]))return!1;return this._execute(a.logMethod,console,a.messages,!0),!0},b.prototype.showLast=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=this.recordings.length;c--;)if(this._show(this.recordings[c],a))return},b.prototype.showAll=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this._show(this.recordings[c],a)},b.prototype.showLogs=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this.recordings[c].logMethod===console.log&&this._show(this.recordings[c],a)},b.prototype.showErrors=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this.recordings[c].logMethod===console.error&&this._show(this.recordings[c],a)},b.prototype.showWarnings=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this.recordings[c].logMethod===console.warn&&this._show(this.recordings[c],a)},b.prototype.showTimePeriod=function(a,b,c){void 0===a&&(a=0),void 0===b&&(b=1/0),void 0===c&&(c=[]);for(var d,e=0;e<this.recordings.length;e++)d=this.recordings[e],a<d.time&&b>d.time&&this._show(d,c)},b.prototype.addFilter=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];this.tagFilters=this.tagFilters.concat(a)},b.prototype.removeFilter=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c,d=0;d<a.length;)c=this.tagFilters.indexOf(a[d]),-1!==c&&this.tagFilters.splice(c,1),d++},b}();b.Log=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){}return a.parseVersion=function(a){var b=a.split(".");return{majorVersion:parseInt(b[0]),minorVersion:parseInt(b[1]),patchVersion:parseInt(b[2])}},a.compareVersions=function(b,c){var d=a.parseVersion(b),e=a.parseVersion(c);return d.majorVersion>e.majorVersion?"greater":d.majorVersion<e.majorVersion?"less":d.minorVersion>e.minorVersion?"greater":d.minorVersion<e.minorVersion?"less":d.patchVersion>e.patchVersion?"greater":d.patchVersion<e.patchVersion?"less":"equal"},a.greaterOrEqual=function(b,c){var d=a.compareVersions(b,c);return"greater"==d||"equal"==d},a}();a.Version=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){a.Log=new a.Utils.Log,a.VERSION="1.3.0",a.RENDERER_CANVAS=0,a.RENDERER_WEBGL=1,a.RENDERER_AUTO=2,a.TARGET_BROWSER=0,a.TARGET_COCOON=1,a.DEBUG_ON=0,a.DEBUG_OFF=1,a.DEVICE=null,a.STATE=0,a.GROUP=2,a.ENTITY=3,a.CAMERA=4,a.HUD_WIDGET=5,a.TILE_LAYER=6;var b=function(){function b(){}return b.prototype.objType=function(){return"GameManager"},b.register=function(b){return a.GameManager._games.push(b)},b.total=function(){return a.GameManager._games.length},b._games=[],b}();a.GameManager=b,a.Plugins={},a.extend=function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c}}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(c,d){void 0===d&&(d={}),b.call(this,c,d),this.crossOrigin="",this.game.audio.usingAudioTag?(this.useTagLoader=!0,this._loadInParallel=!0):this.useTagLoader=!1,a.Utils.Common.isUndefined(d.crossOrigin)||(this.crossOrigin=d.crossOrigin)}return __extends(c,b),c.prototype.objType=function(){return"AudioFile"},c.prototype._load=function(){this.attemptCounter++,this.useTagLoader?this.tagLoader():this.xhrLoader("GET","arraybuffer")},c.prototype.tagLoader=function(){if(this.data=document.createElement("audio"),this.data.src=this.URL,this.data.preload="auto",this.crossOrigin&&(this.data.crossOrigin=this.crossOrigin),this.game.audio.locked)this.loadSuccess();else{var b=this,c=function(){b.data.removeEventListener("canplaythrough",c,!1),b.data.pause(),b.data.currentTime=0,b.data.volume=1,b.loadSuccess()};this.data.addEventListener("canplaythrough",c,!1),this.game.deviceTargetOption==a.TARGET_COCOON?this.data.load():(this.data.volume=0,this.data.play())}},c.prototype.processXhr=function(a){this.data={raw:a,decoded:!1,buffer:null},this._decodeAudio()},c.prototype._decodeAudio=function(){var b=this;this.game.audio.context.decodeAudioData(this.data.raw,function(a){a&&(b.data.buffer=a,b.data.decoded=!0,b.loadSuccess())},function(c){a.Log.error("Kiwi.Files.AudioFile: Error decoding audio data.","#loading","#decoding"),b.loadError(c)})},c}(a.Files.File);b.AudioFile=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(a,c){void 0===c&&(c={}),b.call(this,a,c),this.parse=!1,this.useTagLoader=!1,this._loadInParallel=!1}return __extends(c,b),c.prototype.parseParams=function(c){b.prototype.parseParams.call(this,c),a.Utils.Common.isUndefined(c.parse)||(this.parse=c.parse)},c.prototype.objType=function(){return"DataFile"},c.prototype._load=function(){this.attemptCounter++,this.dataType===a.Files.File.BINARY_DATA?this.xhrLoader("GET","arraybuffer"):this.xhrLoader("GET","text")},c.prototype.processXhr=function(b){if(!this.parse)return this.data=b,void this.loadSuccess();switch(this.dataType){case a.Files.File.JSON:this.processJSON(b);break;case a.Files.File.XML:this.parseXML(b);break;case a.Files.File.TEXT_DATA:case a.Files.File.BINARY_DATA:default:this.data=b}},c.prototype.parseXML=function(b){if(a.Log.log("Kiwi.Files.DataFile: Data loaded is being parsed as XML.","#loading","#parsing"),window.DOMParser){var c=new DOMParser;this.data=c.parseFromString(b,"text/xml")}else this.data=new ActiveXObject("Microsoft.XMLDOM"),this.data.async="false",this.data.loadXML(b);this.data&&this.data.documentElement&&!this.data.getElementsByTagName("parsererror").length?this.loadSuccess():this.loadError("XML parse error.")},c.prototype.processJSON=function(b){a.Log.log("Kiwi.Files.DataFile: Data loaded is being parsed as JSON.","#loading","#parsing");try{this.data=JSON.parse(b),this.loadSuccess()}catch(c){this.loadError(c)}},c}(a.Files.File);b.DataFile=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(c,d){void 0===d&&(d={}),b.call(this,c,d),this.crossOrigin="",d.xhrLoading?(this.useTagLoader=!1,this._loadInParallel=!1):(this.useTagLoader=!0,this._loadInParallel=!0),a.Utils.Common.isUndefined(d.crossOrigin)||(this.crossOrigin=d.crossOrigin)}return __extends(c,b),c.prototype.objType=function(){return"TextureFile"},c.prototype._load=function(){this.attemptCounter++,this.useTagLoader?this.tagLoader():this.xhrLoader("GET","arraybuffer")},c.prototype.tagLoader=function(){var a=this;this.data=new Image,this.data.src=this.URL,this.crossOrigin&&(this.data.crossOrigin=this.crossOrigin),this.data.onload=function(){return a.loadSuccess()},this.data.onerror=function(b){return a.loadError(b)}},c.prototype.processXhr=function(a){this.data=document.createElement("img");var b=new Blob([a],{type:this.type});window.URL?this.data.src=window.URL.createObjectURL(b):window.webkitURL&&(this.data.src=window.webkitURL.createObjectURL(b)),this.loadSuccess()},c.prototype.revoke=function(){window.URL?window.URL.revokeObjectURL(this.data.src):window.webkitURL&&window.webkitURL.revokeObjectURL(this.data.src)},c.prototype.destroy=function(){this.useTagLoader||this.revoke(),b.prototype.destroy.call(this)},c}(a.Files.File);b.TextureFile=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={})),function(a){"use strict";var b={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(b.exports={},define(function(){return b.exports})):b.exports="undefined"!=typeof window?window:a:b.exports=exports,function(a){if(!b)var b=1e-6;if(!c)var c="undefined"!=typeof Float32Array?Float32Array:Array;if(!d)var d=Math.random;var e={};e.setMatrixArrayType=function(a){c=a},"undefined"!=typeof a&&(a.glMatrix=e);var f={};f.create=function(){var a=new c(2);return a[0]=0,a[1]=0,a},f.clone=function(a){var b=new c(2);return b[0]=a[0],b[1]=a[1],b},f.fromValues=function(a,b){var d=new c(2);return d[0]=a,d[1]=b,d},f.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a},f.set=function(a,b,c){return a[0]=b,a[1]=c,a},f.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a},f.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a},f.sub=f.subtract,f.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a},f.mul=f.multiply,f.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a},f.div=f.divide,f.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a},f.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a},f.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a},f.scaleAndAdd=function(a,b,c,d){return a[0]=b[0]+c[0]*d,a[1]=b[1]+c[1]*d,a},f.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},f.dist=f.distance,f.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return c*c+d*d},f.sqrDist=f.squaredDistance,f.length=function(a){var b=a[0],c=a[1];return Math.sqrt(b*b+c*c)},f.len=f.length,f.squaredLength=function(a){var b=a[0],c=a[1];return b*b+c*c},f.sqrLen=f.squaredLength,f.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a},f.normalize=function(a,b){var c=b[0],d=b[1],e=c*c+d*d;return e>0&&(e=1/Math.sqrt(e),a[0]=b[0]*e,a[1]=b[1]*e),a},f.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},f.cross=function(a,b,c){var d=b[0]*c[1]-b[1]*c[0];return a[0]=a[1]=0,a[2]=d,a},f.lerp=function(a,b,c,d){var e=b[0],f=b[1];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a},f.random=function(a,b){b=b||1;var c=2*d()*Math.PI;return a[0]=Math.cos(c)*b,a[1]=Math.sin(c)*b,a},f.transformMat2=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[2]*e,a[1]=c[1]*d+c[3]*e,a},f.transformMat2d=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[2]*e+c[4],a[1]=c[1]*d+c[3]*e+c[5],a},f.transformMat3=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[3]*e+c[6],a[1]=c[1]*d+c[4]*e+c[7],a},f.transformMat4=function(a,b,c){var d=b[0],e=b[1];
-return a[0]=c[0]*d+c[4]*e+c[12],a[1]=c[1]*d+c[5]*e+c[13],a},f.forEach=function(){var a=f.create();return function(b,c,d,e,f,g){var h,i;for(c||(c=2),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],f(a,a,g),b[h]=a[0],b[h+1]=a[1];return b}}(),f.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof a&&(a.vec2=f);var g={};g.create=function(){var a=new c(3);return a[0]=0,a[1]=0,a[2]=0,a},g.clone=function(a){var b=new c(3);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b},g.fromValues=function(a,b,d){var e=new c(3);return e[0]=a,e[1]=b,e[2]=d,e},g.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a},g.set=function(a,b,c,d){return a[0]=b,a[1]=c,a[2]=d,a},g.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a[2]=b[2]+c[2],a},g.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a[2]=b[2]-c[2],a},g.sub=g.subtract,g.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a[2]=b[2]*c[2],a},g.mul=g.multiply,g.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a[2]=b[2]/c[2],a},g.div=g.divide,g.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a[2]=Math.min(b[2],c[2]),a},g.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a[2]=Math.max(b[2],c[2]),a},g.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a[2]=b[2]*c,a},g.scaleAndAdd=function(a,b,c,d){return a[0]=b[0]+c[0]*d,a[1]=b[1]+c[1]*d,a[2]=b[2]+c[2]*d,a},g.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2];return Math.sqrt(c*c+d*d+e*e)},g.dist=g.distance,g.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2];return c*c+d*d+e*e},g.sqrDist=g.squaredDistance,g.length=function(a){var b=a[0],c=a[1],d=a[2];return Math.sqrt(b*b+c*c+d*d)},g.len=g.length,g.squaredLength=function(a){var b=a[0],c=a[1],d=a[2];return b*b+c*c+d*d},g.sqrLen=g.squaredLength,g.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a[2]=-b[2],a},g.normalize=function(a,b){var c=b[0],d=b[1],e=b[2],f=c*c+d*d+e*e;return f>0&&(f=1/Math.sqrt(f),a[0]=b[0]*f,a[1]=b[1]*f,a[2]=b[2]*f),a},g.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},g.cross=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=c[0],h=c[1],i=c[2];return a[0]=e*i-f*h,a[1]=f*g-d*i,a[2]=d*h-e*g,a},g.lerp=function(a,b,c,d){var e=b[0],f=b[1],g=b[2];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a[2]=g+d*(c[2]-g),a},g.random=function(a,b){b=b||1;var c=2*d()*Math.PI,e=2*d()-1,f=Math.sqrt(1-e*e)*b;return a[0]=Math.cos(c)*f,a[1]=Math.sin(c)*f,a[2]=e*b,a},g.transformMat4=function(a,b,c){var d=b[0],e=b[1],f=b[2];return a[0]=c[0]*d+c[4]*e+c[8]*f+c[12],a[1]=c[1]*d+c[5]*e+c[9]*f+c[13],a[2]=c[2]*d+c[6]*e+c[10]*f+c[14],a},g.transformMat3=function(a,b,c){var d=b[0],e=b[1],f=b[2];return a[0]=d*c[0]+e*c[3]+f*c[6],a[1]=d*c[1]+e*c[4]+f*c[7],a[2]=d*c[2]+e*c[5]+f*c[8],a},g.transformQuat=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=c[0],h=c[1],i=c[2],j=c[3],k=j*d+h*f-i*e,l=j*e+i*d-g*f,m=j*f+g*e-h*d,n=-g*d-h*e-i*f;return a[0]=k*j+n*-g+l*-i-m*-h,a[1]=l*j+n*-h+m*-g-k*-i,a[2]=m*j+n*-i+k*-h-l*-g,a},g.forEach=function(){var a=g.create();return function(b,c,d,e,f,g){var h,i;for(c||(c=3),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],a[2]=b[h+2],f(a,a,g),b[h]=a[0],b[h+1]=a[1],b[h+2]=a[2];return b}}(),g.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof a&&(a.vec3=g);var h={};h.create=function(){var a=new c(4);return a[0]=0,a[1]=0,a[2]=0,a[3]=0,a},h.clone=function(a){var b=new c(4);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b},h.fromValues=function(a,b,d,e){var f=new c(4);return f[0]=a,f[1]=b,f[2]=d,f[3]=e,f},h.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a},h.set=function(a,b,c,d,e){return a[0]=b,a[1]=c,a[2]=d,a[3]=e,a},h.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a[2]=b[2]+c[2],a[3]=b[3]+c[3],a},h.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a[2]=b[2]-c[2],a[3]=b[3]-c[3],a},h.sub=h.subtract,h.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a[2]=b[2]*c[2],a[3]=b[3]*c[3],a},h.mul=h.multiply,h.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a[2]=b[2]/c[2],a[3]=b[3]/c[3],a},h.div=h.divide,h.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a[2]=Math.min(b[2],c[2]),a[3]=Math.min(b[3],c[3]),a},h.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a[2]=Math.max(b[2],c[2]),a[3]=Math.max(b[3],c[3]),a},h.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a[2]=b[2]*c,a[3]=b[3]*c,a},h.scaleAndAdd=function(a,b,c,d){return a[0]=b[0]+c[0]*d,a[1]=b[1]+c[1]*d,a[2]=b[2]+c[2]*d,a[3]=b[3]+c[3]*d,a},h.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2],f=b[3]-a[3];return Math.sqrt(c*c+d*d+e*e+f*f)},h.dist=h.distance,h.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2],f=b[3]-a[3];return c*c+d*d+e*e+f*f},h.sqrDist=h.squaredDistance,h.length=function(a){var b=a[0],c=a[1],d=a[2],e=a[3];return Math.sqrt(b*b+c*c+d*d+e*e)},h.len=h.length,h.squaredLength=function(a){var b=a[0],c=a[1],d=a[2],e=a[3];return b*b+c*c+d*d+e*e},h.sqrLen=h.squaredLength,h.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a[2]=-b[2],a[3]=-b[3],a},h.normalize=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*c+d*d+e*e+f*f;return g>0&&(g=1/Math.sqrt(g),a[0]=b[0]*g,a[1]=b[1]*g,a[2]=b[2]*g,a[3]=b[3]*g),a},h.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},h.lerp=function(a,b,c,d){var e=b[0],f=b[1],g=b[2],h=b[3];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a[2]=g+d*(c[2]-g),a[3]=h+d*(c[3]-h),a},h.random=function(a,b){return b=b||1,a[0]=d(),a[1]=d(),a[2]=d(),a[3]=d(),h.normalize(a,a),h.scale(a,a,b),a},h.transformMat4=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3];return a[0]=c[0]*d+c[4]*e+c[8]*f+c[12]*g,a[1]=c[1]*d+c[5]*e+c[9]*f+c[13]*g,a[2]=c[2]*d+c[6]*e+c[10]*f+c[14]*g,a[3]=c[3]*d+c[7]*e+c[11]*f+c[15]*g,a},h.transformQuat=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=c[0],h=c[1],i=c[2],j=c[3],k=j*d+h*f-i*e,l=j*e+i*d-g*f,m=j*f+g*e-h*d,n=-g*d-h*e-i*f;return a[0]=k*j+n*-g+l*-i-m*-h,a[1]=l*j+n*-h+m*-g-k*-i,a[2]=m*j+n*-i+k*-h-l*-g,a},h.forEach=function(){var a=h.create();return function(b,c,d,e,f,g){var h,i;for(c||(c=4),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],a[2]=b[h+2],a[3]=b[h+3],f(a,a,g),b[h]=a[0],b[h+1]=a[1],b[h+2]=a[2],b[h+3]=a[3];return b}}(),h.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof a&&(a.vec4=h);var i={};i.create=function(){var a=new c(4);return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a},i.clone=function(a){var b=new c(4);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b},i.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a},i.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a},i.transpose=function(a,b){if(a===b){var c=b[1];a[1]=b[2],a[2]=c}else a[0]=b[0],a[1]=b[2],a[2]=b[1],a[3]=b[3];return a},i.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*f-e*d;return g?(g=1/g,a[0]=f*g,a[1]=-d*g,a[2]=-e*g,a[3]=c*g,a):null},i.adjoint=function(a,b){var c=b[0];return a[0]=b[3],a[1]=-b[1],a[2]=-b[2],a[3]=c,a},i.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},i.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1],j=c[2],k=c[3];return a[0]=d*h+e*j,a[1]=d*i+e*k,a[2]=f*h+g*j,a[3]=f*i+g*k,a},i.mul=i.multiply,i.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+e*h,a[1]=d*-h+e*i,a[2]=f*i+g*h,a[3]=f*-h+g*i,a},i.scale=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1];return a[0]=d*h,a[1]=e*i,a[2]=f*h,a[3]=g*i,a},i.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof a&&(a.mat2=i);var j={};j.create=function(){var a=new c(6);return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a[4]=0,a[5]=0,a},j.clone=function(a){var b=new c(6);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b},j.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a},j.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a[4]=0,a[5]=0,a},j.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=c*f-d*e;return i?(i=1/i,a[0]=f*i,a[1]=-d*i,a[2]=-e*i,a[3]=c*i,a[4]=(e*h-f*g)*i,a[5]=(d*g-c*h)*i,a):null},j.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},j.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=c[0],k=c[1],l=c[2],m=c[3],n=c[4],o=c[5];return a[0]=d*j+e*l,a[1]=d*k+e*m,a[2]=f*j+g*l,a[3]=f*k+g*m,a[4]=j*h+l*i+n,a[5]=k*h+m*i+o,a},j.mul=j.multiply,j.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=Math.sin(c),k=Math.cos(c);return a[0]=d*k+e*j,a[1]=-d*j+e*k,a[2]=f*k+g*j,a[3]=-f*j+k*g,a[4]=k*h+j*i,a[5]=k*i-j*h,a},j.scale=function(a,b,c){var d=c[0],e=c[1];return a[0]=b[0]*d,a[1]=b[1]*e,a[2]=b[2]*d,a[3]=b[3]*e,a[4]=b[4]*d,a[5]=b[5]*e,a},j.translate=function(a,b,c){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4]+c[0],a[5]=b[5]+c[1],a},j.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof a&&(a.mat2d=j);var k={};k.create=function(){var a=new c(9);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},k.fromMat4=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[4],a[4]=b[5],a[5]=b[6],a[6]=b[8],a[7]=b[9],a[8]=b[10],a},k.clone=function(a){var b=new c(9);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b},k.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a},k.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},k.transpose=function(a,b){if(a===b){var c=b[1],d=b[2],e=b[5];a[1]=b[3],a[2]=b[6],a[3]=c,a[5]=b[7],a[6]=d,a[7]=e}else a[0]=b[0],a[1]=b[3],a[2]=b[6],a[3]=b[1],a[4]=b[4],a[5]=b[7],a[6]=b[2],a[7]=b[5],a[8]=b[8];return a},k.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=k*g-h*j,m=-k*f+h*i,n=j*f-g*i,o=c*l+d*m+e*n;return o?(o=1/o,a[0]=l*o,a[1]=(-k*d+e*j)*o,a[2]=(h*d-e*g)*o,a[3]=m*o,a[4]=(k*c-e*i)*o,a[5]=(-h*c+e*f)*o,a[6]=n*o,a[7]=(-j*c+d*i)*o,a[8]=(g*c-d*f)*o,a):null},k.adjoint=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8];return a[0]=g*k-h*j,a[1]=e*j-d*k,a[2]=d*h-e*g,a[3]=h*i-f*k,a[4]=c*k-e*i,a[5]=e*f-c*h,a[6]=f*j-g*i,a[7]=d*i-c*j,a[8]=c*g-d*f,a},k.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],i=a[7],j=a[8];return b*(j*f-g*i)+c*(-j*e+g*h)+d*(i*e-f*h)},k.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=c[0],n=c[1],o=c[2],p=c[3],q=c[4],r=c[5],s=c[6],t=c[7],u=c[8];return a[0]=m*d+n*g+o*j,a[1]=m*e+n*h+o*k,a[2]=m*f+n*i+o*l,a[3]=p*d+q*g+r*j,a[4]=p*e+q*h+r*k,a[5]=p*f+q*i+r*l,a[6]=s*d+t*g+u*j,a[7]=s*e+t*h+u*k,a[8]=s*f+t*i+u*l,a},k.mul=k.multiply,k.translate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=c[0],n=c[1];return a[0]=d,a[1]=e,a[2]=f,a[3]=g,a[4]=h,a[5]=i,a[6]=m*d+n*g+j,a[7]=m*e+n*h+k,a[8]=m*f+n*i+l,a},k.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=Math.sin(c),n=Math.cos(c);return a[0]=n*d+m*g,a[1]=n*e+m*h,a[2]=n*f+m*i,a[3]=n*g-m*d,a[4]=n*h-m*e,a[5]=n*i-m*f,a[6]=j,a[7]=k,a[8]=l,a},k.scale=function(a,b,c){var d=c[0],e=c[1];return a[0]=d*b[0],a[1]=d*b[1],a[2]=d*b[2],a[3]=e*b[3],a[4]=e*b[4],a[5]=e*b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a},k.fromMat2d=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=0,a[3]=b[2],a[4]=b[3],a[5]=0,a[6]=b[4],a[7]=b[5],a[8]=1,a},k.fromQuat=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return a[0]=1-(m+o),a[3]=k+r,a[6]=l-q,a[1]=k-r,a[4]=1-(j+o),a[7]=n+p,a[2]=l+q,a[5]=n-p,a[8]=1-(j+m),a},k.normalFromMat4=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15],s=c*h-d*g,t=c*i-e*g,u=c*j-f*g,v=d*i-e*h,w=d*j-f*h,x=e*j-f*i,y=k*p-l*o,z=k*q-m*o,A=k*r-n*o,B=l*q-m*p,C=l*r-n*p,D=m*r-n*q,E=s*D-t*C+u*B+v*A-w*z+x*y;return E?(E=1/E,a[0]=(h*D-i*C+j*B)*E,a[1]=(i*A-g*D-j*z)*E,a[2]=(g*C-h*A+j*y)*E,a[3]=(e*C-d*D-f*B)*E,a[4]=(c*D-e*A+f*z)*E,a[5]=(d*A-c*C-f*y)*E,a[6]=(p*x-q*w+r*v)*E,a[7]=(q*u-o*x-r*t)*E,a[8]=(o*w-p*u+r*s)*E,a):null},k.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof a&&(a.mat3=k);var l={};l.create=function(){var a=new c(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},l.clone=function(a){var b=new c(16);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15],b},l.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a[9]=b[9],a[10]=b[10],a[11]=b[11],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15],a},l.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},l.transpose=function(a,b){if(a===b){var c=b[1],d=b[2],e=b[3],f=b[6],g=b[7],h=b[11];a[1]=b[4],a[2]=b[8],a[3]=b[12],a[4]=c,a[6]=b[9],a[7]=b[13],a[8]=d,a[9]=f,a[11]=b[14],a[12]=e,a[13]=g,a[14]=h}else a[0]=b[0],a[1]=b[4],a[2]=b[8],a[3]=b[12],a[4]=b[1],a[5]=b[5],a[6]=b[9],a[7]=b[13],a[8]=b[2],a[9]=b[6],a[10]=b[10],a[11]=b[14],a[12]=b[3],a[13]=b[7],a[14]=b[11],a[15]=b[15];return a},l.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15],s=c*h-d*g,t=c*i-e*g,u=c*j-f*g,v=d*i-e*h,w=d*j-f*h,x=e*j-f*i,y=k*p-l*o,z=k*q-m*o,A=k*r-n*o,B=l*q-m*p,C=l*r-n*p,D=m*r-n*q,E=s*D-t*C+u*B+v*A-w*z+x*y;return E?(E=1/E,a[0]=(h*D-i*C+j*B)*E,a[1]=(e*C-d*D-f*B)*E,a[2]=(p*x-q*w+r*v)*E,a[3]=(m*w-l*x-n*v)*E,a[4]=(i*A-g*D-j*z)*E,a[5]=(c*D-e*A+f*z)*E,a[6]=(q*u-o*x-r*t)*E,a[7]=(k*x-m*u+n*t)*E,a[8]=(g*C-h*A+j*y)*E,a[9]=(d*A-c*C-f*y)*E,a[10]=(o*w-p*u+r*s)*E,a[11]=(l*u-k*w-n*s)*E,a[12]=(h*z-g*B-i*y)*E,a[13]=(c*B-d*z+e*y)*E,a[14]=(p*t-o*v-q*s)*E,a[15]=(k*v-l*t+m*s)*E,a):null},l.adjoint=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15];return a[0]=h*(m*r-n*q)-l*(i*r-j*q)+p*(i*n-j*m),a[1]=-(d*(m*r-n*q)-l*(e*r-f*q)+p*(e*n-f*m)),a[2]=d*(i*r-j*q)-h*(e*r-f*q)+p*(e*j-f*i),a[3]=-(d*(i*n-j*m)-h*(e*n-f*m)+l*(e*j-f*i)),a[4]=-(g*(m*r-n*q)-k*(i*r-j*q)+o*(i*n-j*m)),a[5]=c*(m*r-n*q)-k*(e*r-f*q)+o*(e*n-f*m),a[6]=-(c*(i*r-j*q)-g*(e*r-f*q)+o*(e*j-f*i)),a[7]=c*(i*n-j*m)-g*(e*n-f*m)+k*(e*j-f*i),a[8]=g*(l*r-n*p)-k*(h*r-j*p)+o*(h*n-j*l),a[9]=-(c*(l*r-n*p)-k*(d*r-f*p)+o*(d*n-f*l)),a[10]=c*(h*r-j*p)-g*(d*r-f*p)+o*(d*j-f*h),a[11]=-(c*(h*n-j*l)-g*(d*n-f*l)+k*(d*j-f*h)),a[12]=-(g*(l*q-m*p)-k*(h*q-i*p)+o*(h*m-i*l)),a[13]=c*(l*q-m*p)-k*(d*q-e*p)+o*(d*m-e*l),a[14]=-(c*(h*q-i*p)-g*(d*q-e*p)+o*(d*i-e*h)),a[15]=c*(h*m-i*l)-g*(d*m-e*l)+k*(d*i-e*h),a},l.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],i=a[7],j=a[8],k=a[9],l=a[10],m=a[11],n=a[12],o=a[13],p=a[14],q=a[15],r=b*g-c*f,s=b*h-d*f,t=b*i-e*f,u=c*h-d*g,v=c*i-e*g,w=d*i-e*h,x=j*o-k*n,y=j*p-l*n,z=j*q-m*n,A=k*p-l*o,B=k*q-m*o,C=l*q-m*p;return r*C-s*B+t*A+u*z-v*y+w*x},l.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=b[9],n=b[10],o=b[11],p=b[12],q=b[13],r=b[14],s=b[15],t=c[0],u=c[1],v=c[2],w=c[3];return a[0]=t*d+u*h+v*l+w*p,a[1]=t*e+u*i+v*m+w*q,a[2]=t*f+u*j+v*n+w*r,a[3]=t*g+u*k+v*o+w*s,t=c[4],u=c[5],v=c[6],w=c[7],a[4]=t*d+u*h+v*l+w*p,a[5]=t*e+u*i+v*m+w*q,a[6]=t*f+u*j+v*n+w*r,a[7]=t*g+u*k+v*o+w*s,t=c[8],u=c[9],v=c[10],w=c[11],a[8]=t*d+u*h+v*l+w*p,a[9]=t*e+u*i+v*m+w*q,a[10]=t*f+u*j+v*n+w*r,a[11]=t*g+u*k+v*o+w*s,t=c[12],u=c[13],v=c[14],w=c[15],a[12]=t*d+u*h+v*l+w*p,a[13]=t*e+u*i+v*m+w*q,a[14]=t*f+u*j+v*n+w*r,a[15]=t*g+u*k+v*o+w*s,a},l.mul=l.multiply,l.translate=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p=c[0],q=c[1],r=c[2];return b===a?(a[12]=b[0]*p+b[4]*q+b[8]*r+b[12],a[13]=b[1]*p+b[5]*q+b[9]*r+b[13],a[14]=b[2]*p+b[6]*q+b[10]*r+b[14],a[15]=b[3]*p+b[7]*q+b[11]*r+b[15]):(d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=b[9],n=b[10],o=b[11],a[0]=d,a[1]=e,a[2]=f,a[3]=g,a[4]=h,a[5]=i,a[6]=j,a[7]=k,a[8]=l,a[9]=m,a[10]=n,a[11]=o,a[12]=d*p+h*q+l*r+b[12],a[13]=e*p+i*q+m*r+b[13],a[14]=f*p+j*q+n*r+b[14],a[15]=g*p+k*q+o*r+b[15]),a},l.scale=function(a,b,c){var d=c[0],e=c[1],f=c[2];return a[0]=b[0]*d,a[1]=b[1]*d,a[2]=b[2]*d,a[3]=b[3]*d,a[4]=b[4]*e,a[5]=b[5]*e,a[6]=b[6]*e,a[7]=b[7]*e,a[8]=b[8]*f,a[9]=b[9]*f,a[10]=b[10]*f,a[11]=b[11]*f,a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15],a},l.rotate=function(a,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D=e[0],E=e[1],F=e[2],G=Math.sqrt(D*D+E*E+F*F);return Math.abs(G)<b?null:(G=1/G,D*=G,E*=G,F*=G,f=Math.sin(d),g=Math.cos(d),h=1-g,i=c[0],j=c[1],k=c[2],l=c[3],m=c[4],n=c[5],o=c[6],p=c[7],q=c[8],r=c[9],s=c[10],t=c[11],u=D*D*h+g,v=E*D*h+F*f,w=F*D*h-E*f,x=D*E*h-F*f,y=E*E*h+g,z=F*E*h+D*f,A=D*F*h+E*f,B=E*F*h-D*f,C=F*F*h+g,a[0]=i*u+m*v+q*w,a[1]=j*u+n*v+r*w,a[2]=k*u+o*v+s*w,a[3]=l*u+p*v+t*w,a[4]=i*x+m*y+q*z,a[5]=j*x+n*y+r*z,a[6]=k*x+o*y+s*z,a[7]=l*x+p*y+t*z,a[8]=i*A+m*B+q*C,a[9]=j*A+n*B+r*C,a[10]=k*A+o*B+s*C,a[11]=l*A+p*B+t*C,c!==a&&(a[12]=c[12],a[13]=c[13],a[14]=c[14],a[15]=c[15]),a)},l.rotateX=function(a,b,c){var d=Math.sin(c),e=Math.cos(c),f=b[4],g=b[5],h=b[6],i=b[7],j=b[8],k=b[9],l=b[10],m=b[11];return b!==a&&(a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]),a[4]=f*e+j*d,a[5]=g*e+k*d,a[6]=h*e+l*d,a[7]=i*e+m*d,a[8]=j*e-f*d,a[9]=k*e-g*d,a[10]=l*e-h*d,a[11]=m*e-i*d,a},l.rotateY=function(a,b,c){var d=Math.sin(c),e=Math.cos(c),f=b[0],g=b[1],h=b[2],i=b[3],j=b[8],k=b[9],l=b[10],m=b[11];return b!==a&&(a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]),a[0]=f*e-j*d,a[1]=g*e-k*d,a[2]=h*e-l*d,a[3]=i*e-m*d,a[8]=f*d+j*e,a[9]=g*d+k*e,a[10]=h*d+l*e,a[11]=i*d+m*e,a},l.rotateZ=function(a,b,c){var d=Math.sin(c),e=Math.cos(c),f=b[0],g=b[1],h=b[2],i=b[3],j=b[4],k=b[5],l=b[6],m=b[7];return b!==a&&(a[8]=b[8],a[9]=b[9],a[10]=b[10],a[11]=b[11],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]),a[0]=f*e+j*d,a[1]=g*e+k*d,a[2]=h*e+l*d,a[3]=i*e+m*d,a[4]=j*e-f*d,a[5]=k*e-g*d,a[6]=l*e-h*d,a[7]=m*e-i*d,a},l.fromRotationTranslation=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=d+d,i=e+e,j=f+f,k=d*h,l=d*i,m=d*j,n=e*i,o=e*j,p=f*j,q=g*h,r=g*i,s=g*j;return a[0]=1-(n+p),a[1]=l+s,a[2]=m-r,a[3]=0,a[4]=l-s,a[5]=1-(k+p),a[6]=o+q,a[7]=0,a[8]=m+r,a[9]=o-q,a[10]=1-(k+n),a[11]=0,a[12]=c[0],a[13]=c[1],a[14]=c[2],a[15]=1,a},l.fromQuat=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return a[0]=1-(m+o),a[1]=k+r,a[2]=l-q,a[3]=0,a[4]=k-r,a[5]=1-(j+o),a[6]=n+p,a[7]=0,a[8]=l+q,a[9]=n-p,a[10]=1-(j+m),a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},l.frustum=function(a,b,c,d,e,f,g){var h=1/(c-b),i=1/(e-d),j=1/(f-g);return a[0]=2*f*h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*f*i,a[6]=0,a[7]=0,a[8]=(c+b)*h,a[9]=(e+d)*i,a[10]=(g+f)*j,a[11]=-1,a[12]=0,a[13]=0,a[14]=g*f*2*j,a[15]=0,a},l.perspective=function(a,b,c,d,e){var f=1/Math.tan(b/2),g=1/(d-e);return a[0]=f/c,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=f,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=(e+d)*g,a[11]=-1,a[12]=0,a[13]=0,a[14]=2*e*d*g,a[15]=0,a},l.ortho=function(a,b,c,d,e,f,g){var h=1/(b-c),i=1/(d-e),j=1/(f-g);return a[0]=-2*h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=-2*i,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=2*j,a[11]=0,a[12]=(b+c)*h,a[13]=(e+d)*i,a[14]=(g+f)*j,a[15]=1,a},l.lookAt=function(a,c,d,e){var f,g,h,i,j,k,m,n,o,p,q=c[0],r=c[1],s=c[2],t=e[0],u=e[1],v=e[2],w=d[0],x=d[1],y=d[2];return Math.abs(q-w)<b&&Math.abs(r-x)<b&&Math.abs(s-y)<b?l.identity(a):(m=q-w,n=r-x,o=s-y,p=1/Math.sqrt(m*m+n*n+o*o),m*=p,n*=p,o*=p,f=u*o-v*n,g=v*m-t*o,h=t*n-u*m,p=Math.sqrt(f*f+g*g+h*h),p?(p=1/p,f*=p,g*=p,h*=p):(f=0,g=0,h=0),i=n*h-o*g,j=o*f-m*h,k=m*g-n*f,p=Math.sqrt(i*i+j*j+k*k),p?(p=1/p,i*=p,j*=p,k*=p):(i=0,j=0,k=0),a[0]=f,a[1]=i,a[2]=m,a[3]=0,a[4]=g,a[5]=j,a[6]=n,a[7]=0,a[8]=h,a[9]=k,a[10]=o,a[11]=0,a[12]=-(f*q+g*r+h*s),a[13]=-(i*q+j*r+k*s),a[14]=-(m*q+n*r+o*s),a[15]=1,a)},l.str=function(a){return"mat4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+")"},"undefined"!=typeof a&&(a.mat4=l);var m={};m.create=function(){var a=new c(4);return a[0]=0,a[1]=0,a[2]=0,a[3]=1,a},m.rotationTo=function(){var a=g.create(),b=g.fromValues(1,0,0),c=g.fromValues(0,1,0);return function(d,e,f){var h=g.dot(e,f);return-.999999>h?(g.cross(a,b,e),g.length(a)<1e-6&&g.cross(a,c,e),g.normalize(a,a),m.setAxisAngle(d,a,Math.PI),d):h>.999999?(d[0]=0,d[1]=0,d[2]=0,d[3]=1,d):(g.cross(a,e,f),d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=1+h,m.normalize(d,d))}}(),m.setAxes=function(){var a=k.create();return function(b,c,d,e){return a[0]=d[0],a[3]=d[1],a[6]=d[2],a[1]=e[0],a[4]=e[1],a[7]=e[2],a[2]=c[0],a[5]=c[1],a[8]=c[2],m.normalize(b,m.fromMat3(b,a))}}(),m.clone=h.clone,m.fromValues=h.fromValues,m.copy=h.copy,m.set=h.set,m.identity=function(a){return a[0]=0,a[1]=0,a[2]=0,a[3]=1,a},m.setAxisAngle=function(a,b,c){c*=.5;var d=Math.sin(c);return a[0]=d*b[0],a[1]=d*b[1],a[2]=d*b[2],a[3]=Math.cos(c),a},m.add=h.add,m.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1],j=c[2],k=c[3];return a[0]=d*k+g*h+e*j-f*i,a[1]=e*k+g*i+f*h-d*j,a[2]=f*k+g*j+d*i-e*h,a[3]=g*k-d*h-e*i-f*j,a},m.mul=m.multiply,m.scale=h.scale,m.rotateX=function(a,b,c){c*=.5;var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+g*h,a[1]=e*i+f*h,a[2]=f*i-e*h,a[3]=g*i-d*h,a},m.rotateY=function(a,b,c){c*=.5;var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i-f*h,a[1]=e*i+g*h,a[2]=f*i+d*h,a[3]=g*i-e*h,a},m.rotateZ=function(a,b,c){c*=.5;var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+e*h,a[1]=e*i-d*h,a[2]=f*i+g*h,a[3]=g*i-f*h,a},m.calculateW=function(a,b){var c=b[0],d=b[1],e=b[2];return a[0]=c,a[1]=d,a[2]=e,a[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e)),a},m.dot=h.dot,m.lerp=h.lerp,m.slerp=function(a,b,c,d){var e,f,g,h,i,j=b[0],k=b[1],l=b[2],m=b[3],n=c[0],o=c[1],p=c[2],q=c[3];return f=j*n+k*o+l*p+m*q,0>f&&(f=-f,n=-n,o=-o,p=-p,q=-q),1-f>1e-6?(e=Math.acos(f),g=Math.sin(e),h=Math.sin((1-d)*e)/g,i=Math.sin(d*e)/g):(h=1-d,i=d),a[0]=h*j+i*n,a[1]=h*k+i*o,a[2]=h*l+i*p,a[3]=h*m+i*q,a},m.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*c+d*d+e*e+f*f,h=g?1/g:0;return a[0]=-c*h,a[1]=-d*h,a[2]=-e*h,a[3]=f*h,a},m.conjugate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a[2]=-b[2],a[3]=b[3],a},m.length=h.length,m.len=m.length,m.squaredLength=h.squaredLength,m.sqrLen=m.squaredLength,m.normalize=h.normalize,m.fromMat3=function(){var a="undefined"!=typeof Int8Array?new Int8Array([1,2,0]):[1,2,0];return function(b,c){var d,e=c[0]+c[4]+c[8];if(e>0)d=Math.sqrt(e+1),b[3]=.5*d,d=.5/d,b[0]=(c[7]-c[5])*d,b[1]=(c[2]-c[6])*d,b[2]=(c[3]-c[1])*d;else{var f=0;c[4]>c[0]&&(f=1),c[8]>c[3*f+f]&&(f=2);var g=a[f],h=a[g];d=Math.sqrt(c[3*f+f]-c[3*g+g]-c[3*h+h]+1),b[f]=.5*d,d=.5/d,b[3]=(c[3*h+g]-c[3*g+h])*d,b[g]=(c[3*g+f]+c[3*f+g])*d,b[h]=(c[3*h+f]+c[3*f+h])*d}return b}}(),m.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof a&&(a.quat=m)}(b.exports)}(this);
\ No newline at end of file
+},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"min",{get:function(){return this._min},set:function(a){this._min=a,this.updated.dispatch(this._current,this._max,this._min)},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"current",{get:function(){return this._current},set:function(a){this._current=null!==this._max&&a>this._max?this._max:null!==this._min&&a<this._min?this._min:a,this.updated.dispatch(this._current,this._max,this._min)},enumerable:!0,configurable:!0}),c.prototype.decrease=function(a){return void 0===a&&(a=1),(null===this._min||this._current>this._min)&&(null!==this._min&&this._current-a<this._min?this._current=this._min:this._current-=a,this.updated.dispatch(this._current,this._max,this._min)),this._current},c.prototype.increase=function(a){return void 0===a&&(a=1),(null===this._max||this._current<this._max)&&(null!==this._max&&this._current+a>this._max?this._current=this._max:this._current+=a,this.updated.dispatch(this._current,this._max,this._min)),this._current},c.prototype.currentPercent=function(){return null!==this.max?this.current/this.max*100:void 0},c}(a.Component);b.Counter=c}(c=b.HUDComponents||(b.HUDComponents={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(b){function c(c,d){b.call(this,c,"WidgetInput"),this._active=!1,this._container=d,this.onUp=new a.Signal,this.onDown=new a.Signal,this.onOver=new a.Signal,this.onOut=new a.Signal,this._addEvents()}return __extends(c,b),c.prototype.objType=function(){return"WidgetInputComponent"},c.prototype.setElement=function(a){this._removeEvents(),this._container=a,this._addEvents()},c.prototype._addEvents=function(){if(!this._active){this._binds=[],this._binds.push({event:"mouseup","function":this._up.bind(this)}),this._binds.push({event:"mousedown","function":this._down.bind(this)}),this._binds.push({event:"mouseover","function":this._over.bind(this)}),this._binds.push({event:"mouseout","function":this._out.bind(this)});for(var a=0;a<this._binds.length;a++)this._container.addEventListener(this._binds[a].event,this._binds[a]["function"],!1);this._active=!0}},c.prototype._removeEvents=function(){if(this._active){for(var a=0;a<this._binds.length;a++)this._container.removeEventListener(this._binds[a].event,this._binds[a]["function"],!1);this._binds=[],this._active=!1}},c.prototype._up=function(a){this.onUp.dispatch(a)},c.prototype._down=function(a){this.onDown.dispatch(a)},c.prototype._over=function(a){this.onOver.dispatch(a)},c.prototype._out=function(a){this.onOut.dispatch(a)},c}(a.Component);b.WidgetInput=c}(c=b.HUDComponents||(b.HUDComponents={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c;!function(b){var c=function(a){function b(b,c){void 0===c&&(c=""),a.call(this,b,"time"),this.countDown=!1,this._displayString="",this._currentTime=0,this._timeBefore=0,this.speed=1,this.clock=this.game.time.addClock(name+"-clock",1e3),this.format=c}return __extends(b,a),b.prototype.objType=function(){return"TimeComponent"},Object.defineProperty(b.prototype,"isRunning",{get:function(){return this.clock.isRunning()},enumerable:!0,configurable:!0}),b.prototype.pause=function(){this.clock.pause()},b.prototype.stop=function(){this.clock.stop()},b.prototype.start=function(){this.clock.start(),this._timeBefore=this.clock.elapsed()},b.prototype.resume=function(){this.clock.resume()},Object.defineProperty(b.prototype,"format",{get:function(){return this._format},set:function(a){this._format=a},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"currentTime",{get:function(){return this._currentTime},enumerable:!0,configurable:!0}),b.prototype.setTime=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=0),this._currentTime=a,0!=b&&(this._currentTime+=1e3*b),0!=c&&(this._currentTime+=60*c*1e3)},b.prototype.addTime=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=0),this._currentTime+=a,0!=b&&(this._currentTime+=1e3*b),0!=c&&(this._currentTime+=60*c*1e3)},b.prototype.removeTime=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=0),this._currentTime-=a,0!=b&&(this._currentTime-=1e3*b),0!=c&&(this._currentTime-=60*c*1e3)},b.prototype.getTime=function(){if(this.countDown?this._currentTime-=(this.clock.elapsed()-this._timeBefore)*this.speed:this._currentTime+=(this.clock.elapsed()-this._timeBefore)*this.speed,this._timeBefore=this.clock.elapsed(),""!==this._format){if(this._displayString=this._format,-1!==this._displayString.indexOf("ms")){var a=String(Math.floor(1e3*this._currentTime)%1e3);this._displayString=this._displayString.replace("ms",a)}if(-1!=this._displayString.indexOf("ss")){var a=String(Math.floor(this._currentTime)%60);a.length<2&&(a="0"+a),this._displayString=this._displayString.replace("ss",a)}if(-1!==this._displayString.indexOf("mm")){var a=String(Math.floor(this._currentTime/60)%60);a.length<2&&(a="0"+a),this._displayString=this._displayString.replace("mm",a)}if(-1!=this._displayString.indexOf("s")){var a=String(Math.floor(this._currentTime)%60);this._displayString=this._displayString.replace("s",a)}if(-1!==this._displayString.indexOf("m")){var a=String(Math.floor(this._currentTime/60)%60);this._displayString=this._displayString.replace("m",a)}return this._displayString}return String(this._currentTime.toFixed(2))},b}(a.Component);b.Time=c}(c=b.HUDComponents||(b.HUDComponents={}))}(b=a.HUD||(a.HUD={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this.noAudio=!1,this.usingWebAudio=!1,this.usingAudioTag=!1,this.context=null,this.masterGain=null,this._unlockedSource=null,this._game=a}return b.prototype.objType=function(){return"AudioManager"},Object.defineProperty(b.prototype,"locked",{get:function(){return this._locked},enumerable:!0,configurable:!0}),b.prototype.boot=function(){this._volume=1,this._muted=!1,this._sounds=[],a.DEVICE.iOS&&0==a.DEVICE.webaudio&&(this.channels=1),a.DEVICE.iOS&&this._game.deviceTargetOption!==a.TARGET_COCOON?(this._locked=!0,this._game.input.onUp.addOnce(this._unlocked,this),a.Log.log("Kiwi.AudioManager: Audio is currently Locked until at touch event.","#audio","#locked")):this._locked=!1,this.usingWebAudio=!0,this.usingAudioTag=!1,window.AudioContext?this.context=new window.AudioContext:window.webkitAudioContext?this.context=new window.webkitAudioContext:window.Audio?(this.usingWebAudio=!1,this.usingAudioTag=!0):(this.usingWebAudio=!1,this.noAudio=!0),null!==this.context&&(this.masterGain=void 0===this.context.createGain?this.context.createGainNode():this.context.createGain(),this.masterGain.gain.value=1,this.masterGain.connect(this.context.destination))},b.prototype._unlocked=function(){if(a.Log.log("Kiwi.AudioManager: Audio now Unlocked.","#audio","#unlocked"),this.usingAudioTag){this._locked=!1;for(var b=0;b<this._sounds.length;b++)this._sounds[b].playable=!0}else{var c=this.context.createBuffer(1,1,22050);this._unlockedSource=this.context.createBufferSource(),this._unlockedSource.buffer=c,this._unlockedSource.connect(this.context.destination),this._unlockedSource.noteOn(0)}},Object.defineProperty(b.prototype,"mute",{get:function(){return this._muted},set:function(a){if(a===!0){if(this._muted)return;if(this._muted=!0,this.usingWebAudio)this._muteVolume=this.masterGain.gain.value,this.masterGain.gain.value=0;else if(this.usingAudioTag)for(var b=0;b<this._sounds.length;b++)this._sounds[b].mute=!0}else{if(0==this._muted)return;if(this._muted=!1,this.usingWebAudio)this.masterGain.gain.value=this._muteVolume;else if(this.usingAudioTag)for(var b=0;b<this._sounds.length;b++)this._sounds[b].mute=!1}},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(b){if(void 0!==b)if(b=a.Utils.GameMath.clamp(b,1,0),this._volume=b,this._muted&&(this._muteVolume=this._volume),this.usingWebAudio)this.masterGain.gain.value=b;else if(this.usingAudioTag)for(var c=0;c<this._sounds.length;c++)this._sounds[c].volume=this._sounds[c].volume},enumerable:!0,configurable:!0}),b.prototype.isRegistered=function(a){return this.noAudio?void 0:-1!==this._sounds.indexOf(a)?!0:!1},b.prototype.registerSound=function(a){return this.isRegistered(a)===!1?(a.id=this._game.rnd.uuid(),this._sounds.push(a),!0):!1},b.prototype.add=function(b,c,d){if(void 0===c&&(c=1),void 0===d&&(d=!1),!this.noAudio){var e=new a.Sound.Audio(this._game,b,c,d);return e}},b.prototype.remove=function(a,b){void 0===b&&(b=!0);for(var c=0;c<this._sounds.length;c++)if(a.id==this._sounds[c].id)return this.usingWebAudio&&a.gainNode&&a.gainNode.disconnect(),1==b&&a.destroy(),void this._sounds.splice(c,1)},b.prototype.playAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].play()},b.prototype.stopAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].stop()},b.prototype.pauseAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].pause()},b.prototype.resumeAll=function(){for(var a=0;a<this._sounds.length;a++)this._sounds[a]&&this._sounds[a].resume()},b.prototype.update=function(){if(this._locked&&this.usingWebAudio&&null!==this._unlockedSource&&(this._unlockedSource.playbackState===this._unlockedSource.PLAYING_STATE||this._unlockedSource.playbackState===this._unlockedSource.FINISHED_STATE)){this._locked=!1,this._unlockedSource=null;for(var a=0;a<this._sounds.length;a++)this._sounds[a].playable=!0}if(!this.noAudio)for(var a=0;a<this._sounds.length;a++)this._sounds[a].update()},b}();b.AudioManager=c}(b=a.Sound||(a.Sound={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c,d,e){return this._muted=!1,this.totalDuration=0,this._buffer=null,this._decoded=!1,this._markers=[],this._currentMarker="default",this.ready=!1,this._game=b,this._game.audio.registerSound(this),this._usingAudioTag=this._game.audio.usingAudioTag,this._usingWebAudio=this._game.audio.usingWebAudio,this._playable=1==this._game.audio.locked?!1:!0,this.duration=0,this._volume=d,this._muteVolume=d,this._muted=this._game.audio.mute,this._loop=e,this.key=c,!a.Utils.Common.isString(this.key)&&this.key.isAudio&&(this.key=this.key.key),this._game.audio.noAudio||this._game.fileStore.exists(this.key)===!1?void a.Log.log("Could not play Audio. Either the browser doesn't support audio or the Audio file was not found on the filestore.","#audio","#notfound"):(this._usingWebAudio?(this._setAudio(),this.ready&&(this.context=this._game.audio.context,this.masterGainNode=this._game.audio.masterGain,this.gainNode="undefined"==typeof this.context.createGain?this.context.createGainNode():this.context.createGain(),this._decode(),this.gainNode.gain.value=this.volume*this._game.audio.volume,this.gainNode.connect(this.masterGainNode))):this._usingAudioTag&&this._playable===!0&&(this._setAudio(),this.ready&&(this.totalDuration=this._sound.duration,this._sound.volume=this.volume*this._game.audio.volume,(isNaN(this.totalDuration)||0==this.totalDuration)&&(this._pending=!0))),this.addMarker("default",0,this.totalDuration,this._loop),this._currentMarker="default",this.onPlay=new a.Signal,this.onStop=new a.Signal,this.onPause=new a.Signal,this.onResume=new a.Signal,this.onLoop=new a.Signal,void(this.onMute=new a.Signal))}return Object.defineProperty(b.prototype,"playable",{get:function(){return this._playable},set:function(a){this._playable!==!0&&1==a&&(this._playable=a,this._setAudio(),this.ready&&this._usingAudioTag&&(this.totalDuration=this._sound.duration,this._sound.volume=this.volume*this._game.audio.volume))},enumerable:!0,configurable:!0}),b.prototype.objType=function(){return"Audio"},Object.defineProperty(b.prototype,"loop",{get:function(){return this._loop},enumerable:!0,configurable:!0}),b.prototype._setAudio=function(){this._file=this._game.fileStore.getFile(this.key),"undefined"!=typeof this._file.data&&(this._usingAudioTag?(this._sound=this._file.data.cloneNode(!0),this._game.deviceTargetOption==a.TARGET_BROWSER&&(this._sound.play(),this._sound.pause())):this._sound=this._file.data,this.ready=!0)},b.prototype._decode=function(){if(0!=this.ready&&!this._usingAudioTag){if(this._file.data.decoded===!0&&null!==this._file.data.buffer)return this._buffer=this._file.data.buffer,void(this._decoded=!0);var a=this;this.context.decodeAudioData(this._file.data.raw,function(b){a._buffer=b,a._decoded=!0})}},Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(b){this._game.audio.noAudio||this.ready===!1||(b=a.Utils.GameMath.clamp(b,1,0),this._volume=b,this._muted&&(this._muteVolume=this._volume),this._playable&&(this._usingWebAudio?this.gainNode.gain.value=this._volume*this._game.audio.volume:this._usingAudioTag&&(this._sound.volume=this._volume*this._game.audio.volume)))},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"mute",{get:function(){return this._muted},set:function(a){this._game.audio.noAudio||void 0!==a&&this._muted!==a&&(a===!0?(this._muteVolume=this._volume,this.volume=0,this._muted=!0):(this._muted=!1,this.volume=this._muteVolume),this.onMute.dispatch(this._muted))},enumerable:!0,configurable:!0}),b.prototype.addMarker=function(a,b,c,d){void 0===d&&(d=!1),this._markers[a]={start:b,stop:c,duration:c-b,loop:d}},b.prototype.removeMarker=function(a){"default"!==a&&(this.isPlaying&&this._currentMarker==a&&(this.stop(),this._currentMarker="default"),delete this._markers[a])},b.prototype.play=function(b,c){return void 0===b&&(b=this._currentMarker),void 0===c&&(c=!1),this.isPlaying&&!c||this._game.audio.noAudio||(c&&!this._pending&&this.stop(),"undefined"==typeof this._markers[b]||this._currentMarker===b&&this.isPlaying&&0==c)?void 0:(this.paused=!1,this._currentMarker=b,this.duration=1e3*this._markers[this._currentMarker].duration,this._loop=this._markers[this._currentMarker].loop,this._playable===!1?void(this._pending=!0):void(this._usingWebAudio?this._decoded===!0?(null==this._buffer&&(this._buffer=this._file.data.buffer),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this._sound.connect(this.gainNode),this.totalDuration=this._sound.buffer.duration,0==this.duration&&(this.duration=1e3*this.totalDuration),this._loop&&(this._sound.loop=!0),void 0===this._sound.start?this._sound.noteGrainOn(0,this._markers[this._currentMarker].start,this.duration/1e3):this._sound.start(0,this._markers[this._currentMarker].start,this.duration/1e3),this.isPlaying=!0,this._startTime=this._game.time.now(),this._currentTime=0,this._stopTime=this._startTime+this.duration,this.onPlay.dispatch()):(this._pending=!0,this._decode()):this._usingAudioTag&&(this._sound&&4==this._sound.readyState||this._game.deviceTargetOption==a.TARGET_COCOON?((0==this.duration||isNaN(this.duration))&&(this.duration=1e3*this.totalDuration),this._sound.volume=this._muted?0:this._volume,this._sound.currentTime=this._markers[this._currentMarker].start,this._sound.play(),this.isPlaying=!0,this._startTime=this._game.time.now(),this._currentTime=0,this._stopTime=this._startTime+this.duration,this.paused||this.onPlay.dispatch()):this._pending=!0)))},b.prototype.stop=function(){this.isPlaying&&this._sound&&(this._usingWebAudio?void 0===this._sound.stop?this._sound.noteOff(0):this._sound.stop(0):this._usingAudioTag&&(this._sound.pause(),this._sound.currentTime=0),this.isPlaying=!1,0==this.paused&&this.onStop.dispatch())},b.prototype.pause=function(){this.isPlaying&&(this.paused=!0,this.stop(),this.onPause.dispatch())},b.prototype.resume=function(){this.paused&&0==this.isPlaying&&(this._usingWebAudio?(null==this._buffer&&(this._buffer=this._file.data.buffer),this._sound=this.context.createBufferSource(),this._sound.buffer=this._buffer,this._sound.connect(this.gainNode),this._loop&&(this._sound.loop=!0),void 0===this._sound.start?this._sound.noteGrainOn(0,this._markers[this._currentMarker].start+this._currentTime/1e3,this.duration/1e3):this._sound.start(0,this._markers[this._currentMarker].start+this._currentTime/1e3,this.duration/1e3)):(this._sound.currentTime=this._markers[this._currentMarker].start+this._currentTime/1e3,this._sound.play()),this.paused=!1,this.isPlaying=!0,this.onResume.dispatch())},b.prototype.update=function(){this.ready&&(this._playable&&this._pending&&(this._decoded===!0||this._file.data&&this._file.data.decoded?(this._pending=!1,this.play()):(this._usingAudioTag&&!isNaN(this._sound.duration)||this._game.deviceTargetOption==a.TARGET_COCOON&&0!==this._sound.duration)&&(this.totalDuration=this._sound.duration,this._markers["default"].duration=this.totalDuration,this._pending=!1,this.isPlaying&&"default"==this._currentMarker&&(this.duration=this.totalDuration))),this.isPlaying&&(this._currentTime=this._game.time.now()-this._startTime,this._currentTime>=this.duration&&(this._usingWebAudio?this._loop?("default"==this._currentMarker?(this._currentTime=0,this._startTime=this._game.time.now()):this.play(this._currentMarker,!0),this.onLoop.dispatch()):this.stop():this._usingAudioTag&&(this._loop?(this.play(this._currentMarker,!0),this.onLoop.dispatch()):this.stop()))))},b.prototype.destroy=function(){this._game&&this._game.audio.remove(this,!1),this.onLoop&&this.onLoop.dispose(),this.onStop&&this.onStop.dispose(),this.onPlay&&this.onPlay.dispose(),this.onMute&&this.onMute.dispose(),this.onPause&&this.onPause.dispose(),this.onResume&&this.onResume.dispose(),delete this.onLoop,delete this.onStop,delete this.onPause,delete this.onMute,delete this.onPlay,delete this.onResume,delete this._game,delete this._sound,delete this._currentTime,delete this._startTime,delete this._stopTime,delete this._pending,delete this.masterGainNode,delete this.gainNode,delete this.totalDuration,delete this.duration,delete this._file,delete this._buffer,delete this._decoded},b}();b.Audio=c}(b=a.Sound||(a.Sound={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){this._game=a,this.audio={}}return b.prototype.objType=function(){return"AudioLibrary"},b.prototype.clear=function(){for(var a in this.audio)delete this.audio[a]},b.prototype.rebuild=function(b,c){this.clear(),a.Log.log("Kiwi.AudioLibrary: Rebuilding Audio Library.","#audio","#rebuild");for(var d=b.keys,e=0;e<d.length;e++){var f=this._game.fileStore.getFile(d[e]);f.isAudio&&(a.Log.log("  Kiwi.AudioLibrary: Adding Audio: "+f.name,"#audio","#added"),c.audioLibrary.add(f))}},b.prototype.add=function(b){switch(b.dataType){case a.Files.File.AUDIO:this.audio[b.key]=b}},b}();b.AudioLibrary=c}(b=a.Sound||(a.Sound={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(b,c,d,e){void 0===e&&(e=1e3),this._timeFirstStarted=null,this._timeLastStarted=null,this.timeScale=1,this._elapsed=0,this.rate=1,this._maxFrameDuration=-1,this._timeLastStopped=null,this._timeLastPaused=null,this._timeLastUnpaused=null,this._totalPaused=0,this._isRunning=!1,this._isStopped=!0,this._isPaused=!1,this._elapsedState=a.Time.Clock._RUNNING,this.manager=null,this.master=null,this.name=null,this.units=0,this.manager=b,this.master=c,this.name=d,this.units=e,this.timers=[],this.units<1&&(this.units=1),this._lastMasterElapsed=this.master.elapsed(),this._currentMasterElapsed=this.master.elapsed()}return c.prototype.objType=function(){return"Clock"},c.prototype.elapsedSinceFirstStarted=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeFirstStarted)/this.units:null},c.prototype.started=function(){return this._timeLastStarted},Object.defineProperty(c.prototype,"maxFrameDuration",{get:function(){return this._maxFrameDuration},set:function(a){this._maxFrameDuration=a},enumerable:!0,configurable:!0}),c.prototype.elapsed=function(){return this._elapsed},c.prototype.elapsedSinceLastStopped=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeLastStopped)/this.units:null},c.prototype.elapsedSinceLastPaused=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeLastPaused)/this.units:null},c.prototype.elapsedSinceLastUnpaused=function(){return this._timeLastStarted?(this.master.elapsed()-this._timeLastUnpaused)/this.units:null},c.prototype.isRunning=function(){return this._isRunning},c.prototype.isStopped=function(){return this._isStopped},c.prototype.isPaused=function(){return this._isPaused},c.prototype.addTimer=function(a){return this.timers.push(a),this},c.prototype.createTimer=function(a,c,d,e){return void 0===c&&(c=1),void 0===d&&(d=0),void 0===e&&(e=!0),this.timers.push(new b.Timer(a,this,c,d)),e===!0&&this.timers[this.timers.length-1].start(),this.timers[this.timers.length-1]},c.prototype.removeTimer=function(a,b){void 0===a&&(a=null),void 0===b&&(b="");var c;if(null!==a){if(c=this.timers.indexOf(a),-1!==c)return this.timers.splice(c,1),!0}else if(""!==b)for(c=0;c<this.timers.length;c++)if(this.timers[c].name===b)return this.timers.splice(c,1),!0;return!1},c.prototype.checkExists=function(a){return this.timers[a]?!0:!1},c.prototype.stopAllTimers=function(){for(var a=0;a<this.timers.length;a++)this.timers[a].stop();return this},c.prototype.convertToMilliseconds=function(a){return a*this.units},c.prototype.update=function(){var b=this._currentMasterElapsed-this._lastMasterElapsed;this._maxFrameDuration>0&&(b=Math.min(b,this._maxFrameDuration));for(var c=0;c<this.timers.length;c++)this.timers[c].update();this._lastMasterElapsed=this._currentMasterElapsed,this._currentMasterElapsed=this.master.elapsed(),this._elapsedState===a.Time.Clock._RUNNING||this._elapsedState===a.Time.Clock._RESUMED?(this._elapsed+=this.timeScale*b/this.units,this.rate=this.timeScale*b/this.master.idealDelta):this._elapsedState===a.Time.Clock._PAUSED?(this._totalPaused+=b,this.rate=0):this._elapsedState===a.Time.Clock._STOPPED&&(this.rate=0)},c.prototype.start=function(){return this._timeLastStarted=this.master.elapsed(),this._totalPaused=0,this._timeFirstStarted||(this._timeFirstStarted=this._timeLastStarted),this._isRunning=!0,this._isPaused=!1,this._isStopped=!1,this._elapsedState=a.Time.Clock._RUNNING,this._elapsed=0,this._lastMasterElapsed=this.master.elapsed(),this._currentMasterElapsed=this.master.elapsed(),this},c.prototype.pause=function(){return this._isRunning===!0&&(this._timeLastPaused=this.master.elapsed(),this._isRunning=!1,this._isPaused=!0,this._isStopped=!1,this._elapsedState=a.Time.Clock._PAUSED),this},c.prototype.resume=function(){return this._isPaused===!0&&(this._timeLastUnpaused=this.master.elapsed(),this._totalPaused+=this._timeLastUnpaused-this._timeLastPaused,this._isRunning=!0,this._isPaused=!1,this._isStopped=!1,this._elapsedState=a.Time.Clock._RESUMED),this},c.prototype.stop=function(){return this._isStopped===!1&&(this._timeLastStopped=this.master.elapsed(),this._isPaused===!0&&(this._totalPaused+=this._timeLastStopped-this._timeLastPaused),this._isRunning=!1,this._isPaused=!1,this._isStopped=!0,this._elapsedState=a.Time.Clock._STOPPED),this},c.prototype.toString=function(){return"[{Clock (name="+this.name+" units="+this.units+" running="+this._isRunning+")}]"},c.prototype.setTimeout=function(a,c,d){for(var e=[],f=3;f<arguments.length;f++)e[f-3]=arguments[f];var g=this,h=this.createTimer("timeoutTimer",c/1e3);return d||(d=this),h.createTimerEvent(b.TimerEvent.TIMER_STOP,function(){a.apply(d,e),g.removeTimer(h)},d),h.start(),h},c.prototype.setInterval=function(a,c,d){for(var e=[],f=3;f<arguments.length;f++)e[f-3]=arguments[f];var g=this.createTimer("timeoutTimer",c/1e3,-1);return d||(d=this),g.createTimerEvent(b.TimerEvent.TIMER_COUNT,function(){a.apply(d,e)},d),g.start(),g},c._RUNNING=0,c._PAUSED=1,c._RESUMED=2,c._STOPPED=3,c}();b.Clock=c}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function c(a){this._clocks=[],this.rate=1,this._game=a}return c.prototype.objType=function(){return"ClockManager"},c.prototype.boot=function(){this.master=new a.Time.MasterClock,this.clock=new b.Clock(this,this.master,"default",1e3),this.clock.start()},c.prototype.addClock=function(a,c){return void 0===c&&(c=1e3),this._clocks.push(new b.Clock(this,this.master,a,c)),this._clocks[this._clocks.length-1]},c.prototype.getClock=function(a){for(var b=0;b<this._clocks.length;b++)if(this._clocks[b].name===a)return this._clocks[b]},c.prototype.update=function(){this.master.update(),this.clock.update();for(var a=0;a<this._clocks.length;a++)this._clocks[a].update();this.rate=this.master.rate},c.prototype.now=function(){return this.master.now},c.prototype.elapsed=function(){return this.master.elapsed()},c.prototype.delta=function(){return this.master.delta},c.prototype.setMasterInterval=function(a){this.master.idealDelta=a},c}();b.ClockManager=c}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){this.time=0,this.now=0,this.delta=0,this.rate=1,this.idealDelta=1e3/60,this._started=Date.now(),this.now=Date.now(),this.time=this._started}return a.prototype.objType=function(){return"MasterClock"},a.prototype.elapsed=function(){return this.now-this._started},a.prototype.totalElapsedSeconds=function(){return.001*(this.now-this._started)},a.prototype.update=function(){this.now=Date.now(),this.delta=this.now-this.time,this.time=this.now,this.rate=this.delta/this.idealDelta},a.prototype.elapsedSince=function(a){return this.now-a},a.prototype.elapsedSecondsSince=function(a){return.001*(this.now-a)},a.prototype.reset=function(){this._started=this.now},a}();a.MasterClock=b}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function b(a,b,c,d){void 0===d&&(d=0),this._currentCount=0,this._startEvents=null,this._countEvents=null,this._stopEvents=null,this._clock=null,this._timeLastCount=null,this._isRunning=!1,this._isStopped=!0,this._isPaused=!1,this.name=null,this.delay=0,this.repeatCount=0,this._elapsed=0,this._clock=b,this._startEvents=[],this._countEvents=[],this._stopEvents=[],this.name=a,this.delay=c,this.repeatCount=d}return b.prototype.objType=function(){return"Timer"},b.prototype.currentCount=function(){return this._currentCount},b.prototype.isRunning=function(){return this._isRunning},b.prototype.isStopped=function(){return this._isStopped},b.prototype.isPaused=function(){return this._isPaused},b.prototype.processEvents=function(b){if(b===a.TimerEvent.TIMER_START)for(var c=0;c<this._startEvents.length;c++)this._startEvents[c].run();else if(b===a.TimerEvent.TIMER_COUNT)for(var c=0;c<this._countEvents.length;c++)this._countEvents[c].run();else if(b===a.TimerEvent.TIMER_STOP)for(var c=0;c<this._stopEvents.length;c++)this._stopEvents[c].run()},b.prototype.update=function(){var b=this._clock.elapsed()-this._lastElapsed;for(this._lastElapsed=this._clock.elapsed(),this._isRunning&&(this._elapsed+=b);this._elapsed>=this.delay;)this._currentCount++,this.processEvents(a.TimerEvent.TIMER_COUNT),this._elapsed-=this.delay,-1!==this.repeatCount&&this._currentCount>=this.repeatCount&&this.stop();for(;this._elapsed<0;)this._currentCount--,this._elapsed+=this.delay,this._currentCount<0&&(this.clear(),this.stop())},b.prototype.start=function(){return this._isStopped===!0&&(this._isRunning=!0,this._isPaused=!1,this._isStopped=!1,this._currentCount=0,this._elapsed=0,this._lastElapsed=this._clock.elapsed()||0,this.processEvents(a.TimerEvent.TIMER_START)),this},b.prototype.stop=function(){return(this._isRunning===!0||this._isPaused===!0)&&(this._isRunning=!1,this._isPaused=!1,this._isStopped=!0,this.processEvents(a.TimerEvent.TIMER_STOP)),this},b.prototype.pause=function(){return this._isRunning===!0&&(this._isRunning=!1,this._isPaused=!0),this},b.prototype.resume=function(){return this._isPaused===!0&&(this._isRunning=!0,this._isPaused=!1),this},b.prototype.addTimerEvent=function(b){return b.type===a.TimerEvent.TIMER_START?this._startEvents.push(b):b.type===a.TimerEvent.TIMER_COUNT?this._countEvents.push(b):b.type===a.TimerEvent.TIMER_STOP&&this._stopEvents.push(b),b},b.prototype.createTimerEvent=function(b,c,d){return b===a.TimerEvent.TIMER_START?(this._startEvents.push(new a.TimerEvent(b,c,d)),this._startEvents[this._startEvents.length-1]):b===a.TimerEvent.TIMER_COUNT?(this._countEvents.push(new a.TimerEvent(b,c,d)),this._countEvents[this._countEvents.length-1]):b===a.TimerEvent.TIMER_STOP?(this._stopEvents.push(new a.TimerEvent(b,c,d)),this._stopEvents[this._stopEvents.length-1]):null},b.prototype.removeTimerEvent=function(b){var c=[];return b.type===a.TimerEvent.TIMER_START?c=this._startEvents.splice(this._startEvents.indexOf(b),1):b.type===a.TimerEvent.TIMER_COUNT?c=this._countEvents.splice(this._countEvents.indexOf(b),1):b.type===a.TimerEvent.TIMER_STOP&&(c=this._stopEvents.splice(this._stopEvents.indexOf(b),1)),1===c.length?!0:!1},b.prototype.clear=function(b){void 0===b&&(b=0),0===b?(this._startEvents.length=0,this._countEvents.length=0,this._stopEvents.length=0):b===a.TimerEvent.TIMER_START?this._startEvents.length=0:b===a.TimerEvent.TIMER_COUNT?this._countEvents.length=0:b===a.TimerEvent.TIMER_STOP&&(this._stopEvents.length=0)},b.prototype.toString=function(){return"[{Timer (name="+this.name+" delay="+this.delay+" repeatCount="+this.repeatCount+" running="+this._isRunning+")}]"},b}();a.Timer=b}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a,b,c){this._callback=null,this.type=0,this.type=a,this._callback=b,this._callbackContext=c}return a.prototype.objType=function(){return"TimerEvent"},a.prototype.run=function(){this._callback&&this._callback.apply(this._callbackContext)},a.TIMER_START=1,a.TIMER_COUNT=2,a.TIMER_STOP=3,a}();a.TimerEvent=b}(b=a.Time||(a.Time={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(b,c,d,e){void 0===d&&(d=!0),void 0===e&&(e=!1),this.domElement=null,this.context=null,this._visible=!0,this._offScreen=!1,this._clearMode=1,this.domElement=document.createElement("canvas"),this.domElement.width=b,this.domElement.height=c,this._width=b,this._height=c,this.context=this.domElement.getContext("2d"),this._offScreen=e,this._visible=d,d===!1&&(this.domElement.style.display="none"),this._bgColor=new a.Utils.Color(0,0,0)}return Object.defineProperty(b.prototype,"width",{get:function(){return this._width},set:function(a){this._width=a,this._updatedSize()},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"height",{get:function(){return this._height},set:function(a){this._height=a,this._updatedSize()},enumerable:!0,configurable:!0}),b.prototype.objType=function(){return"Canvas"},Object.defineProperty(b.prototype,"bgColor",{get:function(){return"#"+this._bgColor.getHex()},set:function(b){a.Utils.Common.isArray(b)||(b=[b]),this._bgColor.set.apply(this._bgColor,b)},enumerable:!0,configurable:!0}),b.prototype._updatedSize=function(){this.domElement.width=this._width,this.domElement.height=this._height},b.prototype.destroy=function(){this._offScreen===!1&&(this.domElement.style.display="none")},Object.defineProperty(b.prototype,"visible",{get:function(){return this._visible},set:function(a){null!==a&&a!==this._visible&&(this._visible=a,this.domElement.style.display=a===!0?"block":"none")},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"clearMode",{get:function(){return this._clearMode},set:function(b){null!==b&&b!==this._clearMode&&b>=a.Utils.Canvas.CLEARMODE_NONE&&b<=a.Utils.Canvas.CLEARMODE_FILLRECT_ALPHA&&(this._clearMode=b)},enumerable:!0,configurable:!0}),b.prototype.clear=function(){this._clearMode===b.CLEARMODE_NONE||(this._clearMode===b.CLEARMODE_CLEARRECT?this.context.clearRect(0,0,this.domElement.width,this.domElement.height):this._clearMode===b.CLEARMODE_FILLRECT?(this.context.fillStyle=this.bgColor,this.context.fillRect(0,0,this.domElement.width,this.domElement.height)):this._clearMode===b.CLEARMODE_FILLRECT_ALPHA&&(this.context.clearRect(0,0,this.domElement.width,this.domElement.height),this.context.fillStyle=this.bgColor,this.context.fillRect(0,0,this.domElement.width,this.domElement.height)))
+},b.prototype.saveAsPNG=function(){return this.domElement.toDataURL()},b.prototype.toString=function(){return"[{Canvas (width="+this.width+" height="+this.height+" visible="+this.visible+" offScreen="+this._offScreen+" clearMode="+this.clearMode+")}]"},b.CLEARMODE_NONE=0,b.CLEARMODE_CLEARRECT=1,b.CLEARMODE_FILLRECT=2,b.CLEARMODE_FILLRECT_ALPHA=3,b}();b.Canvas=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return this._r=.5,this._g=.5,this._b=.5,this._a=1,this.set.apply(this,a),this}return a.prototype.set=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];return 3===a.length?(this.r=a[0],this.g=a[1],this.b=a[2]):4===a.length?isNaN(a[3])?"hsv"===a[3]?this.parseHsv(a[0],a[1],a[2]):"hsl"===a[3]&&this.parseHsl(a[0],a[1],a[2]):(this.r=a[0],this.g=a[1],this.b=a[2],this.a=a[3]):5===a.length?"hsv"===a[4]?this.parseHsv(a[0],a[1],a[2],a[3]):"hsl"===a[4]&&this.parseHsl(a[0],a[1],a[2],a[3]):1===a.length?"string"==typeof a[0]?this.parseString(a[0]):isNaN(a[0])||(this.r=a[0],this.g=a[0],this.b=a[0]):2===a.length&&(this.r=a[0],this.g=a[0],this.b=a[0],this.a=a[1]),this},Object.defineProperty(a.prototype,"rNorm",{get:function(){return this._r},set:function(a){isNaN(a)||(this._r=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"gNorm",{get:function(){return this._g},set:function(a){isNaN(a)||(this._g=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"bNorm",{get:function(){return this._b},set:function(a){isNaN(a)||(this._b=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"aNorm",{get:function(){return this._a},set:function(a){isNaN(a)||(this._a=a)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"r",{get:function(){return this._r},set:function(a){a>1?this.r255=a:this.rNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"g",{get:function(){return this._g},set:function(a){a>1?this.g255=a:this.gNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"b",{get:function(){return this._b},set:function(a){a>1?this.b255=a:this.bNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"a",{get:function(){return this._a},set:function(a){a>1?this.a255=a:this.aNorm=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"r255",{get:function(){return Math.round(255*this._r)},set:function(a){isNaN(a)||(this._r=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"g255",{get:function(){return Math.round(255*this._g)},set:function(a){isNaN(a)||(this._g=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"b255",{get:function(){return Math.round(255*this._b)},set:function(a){isNaN(a)||(this._b=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"a255",{get:function(){return Math.round(255*this._a)},set:function(a){isNaN(a)||(this._a=a/255)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"red",{get:function(){return this.r},set:function(a){this.r=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"green",{get:function(){return this.g},set:function(a){this.g=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"blue",{get:function(){return this.b},set:function(a){this.b=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alpha",{get:function(){return this.a},set:function(a){this.a=a},enumerable:!0,configurable:!0}),a.prototype.parseString=function(a){var b;return a=a.toLowerCase(),"rgba"===a.slice(0,4)?(a=a.replace("rgba",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.r=+b[0],this.g=+b[1],this.b=+b[2],this.a=+b[3]):"rgb"===a.slice(0,3)?(a=a.replace("rgb",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.r=+b[0],this.g=+b[1],this.b=+b[2]):"hsla"===a.slice(0,4)?(a=a.replace("hsla",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.parseHsl(+b[0],+b[1],+b[2],+b[3])):"hsl"===a.slice(0,3)?(a=a.replace("hsl",""),a=a.replace("(",""),a=a.replace(")",""),b=a.split(","),this.parseHsl(+b[0],+b[1],+b[2])):this.parseHex(a),this},a.prototype.parseHex=function(a){var b,c=this.r255,d=this.g255,e=this.b255,f=this.a255;return"#"===a.charAt(0)&&(a=a.slice(1)),"0x"===a.slice(0,2)&&(a=a.slice(2)),b=parseInt(a,16),3===a.length?(c=17*(b>>8&15),d=17*(b>>4&15),e=17*(15&b)):4===a.length?(c=17*(b>>12&15),d=17*(b>>8&15),e=17*(b>>4&15),f=17*(15&b)):6===a.length?(c=b>>16&255,d=b>>8&255,e=255&b,f=255):8===a.length&&(c=b>>24&255,d=b>>16&255,e=b>>8&255,f=255&b),this.r255=c,this.g255=d,this.b255=e,this.a255=f,this},a.prototype.getHex=function(a){void 0===a&&(a=!0);var b,c="";for(b=this.r255.toString(16);b.length<2;)b="0"+b;for(c+=b,b=this.g255.toString(16);b.length<2;)b="0"+b;for(c+=b,b=this.b255.toString(16);b.length<2;)b="0"+b;if(c+=b,a){for(b=this.a255.toString(16);b.length<2;)b="0"+b;c+=b}return c},a.prototype.parseHsv=function(a,b,c,d){void 0===d&&(d=1);var e,f,g,h,i,j,k,l;if(isNaN(a)||isNaN(b)||isNaN(c)||isNaN(d))return this;switch(a>1&&(a/=360),b>1&&(b/=100),c>1&&(c/=100),d>1&&(d/=255),h=Math.floor(6*a),i=6*a-h,j=c*(1-b),k=c*(1-i*b),l=c*(1-(1-i)*b),h%6){case 0:e=c,f=l,g=j;break;case 1:e=k,f=c,g=j;break;case 2:e=j,f=c,g=l;break;case 3:e=j,f=k,g=c;break;case 4:e=l,f=j,g=c;break;case 5:e=c,f=j,g=k}return this._r=e,this._g=f,this._b=g,this._a=d,this},a.prototype.getHsva=function(){var a,b,c,d,e=this._r,f=this._g,g=this._b,h=Math.max(e,f,g),i=Math.min(e,f,g);if(a=h,b=h,c=h,d=h-i,b=0===h?0:d/h,h===i)a=0;else{switch(h){case e:a=(f-g)/d+(g>f?6:0);break;case f:a=(g-e)/d+2;break;case g:a=(e-f)/d+4}a/=6}return{h:a,s:b,v:c,a:this._a}},a.prototype.parseHsl=function(a,b,c,d){void 0===d&&(d=1);var e,f,g=this._r,h=this._g,i=this._b;return isNaN(a)||isNaN(b)||isNaN(c)||isNaN(d)?this:(a>1&&(a/=360),b>1&&(b/=100),c>1&&(c/=100),d>1&&(d/=255),0===b?(g=c,h=c,i=c):(e=.5>c?c*(1+b):c+b-c*b,f=2*c-e,g=this._hue2rgb(f,e,a+1/3),h=this._hue2rgb(f,e,a),i=this._hue2rgb(f,e,a-1/3)),this._r=g,this._g=h,this._b=i,this._a=d,this)},a.prototype.getHsla=function(){var a,b=this._r,c=this._g,d=this._b,e=Math.max(b,c,d),f=Math.min(b,c,d),g=(e+f)/2,h=(e+f)/2,i=(e+f)/2;if(e==f)g=0,h=0;else{switch(a=e-f,h=i>.5?a/(2-e-f):a/(e+f),e){case b:g=(c-d)/a+(d>c?6:0);break;case c:g=(d-b)/a+2;break;case d:g=(b-c)/a+4}g/=6}return{h:g,s:h,l:i,a:this._a}},a.prototype._hue2rgb=function(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+(b-a)*(2/3-c)*6:a},a}();a.Color=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){}return b.defaultCompare=function(a,b){return b>a?-1:a===b?0:1},b.prototype.objType=function(){return"Common"},b.defaultEquals=function(a,b){return a===b},b.defaultToString=function(b){return null===b?"KIWI_NULL":a.Utils.Common.isUndefined(b)?"KIWI_UNDEFINED":a.Utils.Common.isString(b)?b:b.toString()},b.isBetween=function(a,b,c){return a>b&&c>a},b.isFunction=function(a){return"function"==typeof a},b.isNumeric=function(a){return!isNaN(a)},b.isUndefined=function(a){return"undefined"==typeof a},b.isString=function(a){return"[object String]"===Object.prototype.toString.call(a)},b.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},b.isObject=function(a){return"[object Object]"===Object.prototype.toString.call(a)},b.reverseCompareFunction=function(b){return a.Utils.Common.isFunction(b)?function(a,c){return-1*b(a,c)}:function(a,b){return b>a?1:a===b?0:-1}},b.compareToEquals=function(a){return function(b,c){return 0===a(b,c)}},b.shuffleArray=function(a){for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a},b.convertToBase2=function(a){var b=a.width,c=a.height;if(-1==this.base2Sizes.indexOf(b)){for(var d=0;b>this.base2Sizes[d];)d++;b=this.base2Sizes[d]}if(-1==this.base2Sizes.indexOf(c)){for(var d=0;c>this.base2Sizes[d];)d++;c=this.base2Sizes[d]}if(a.width!==b||a.height!==c){var e=document.createElement("canvas");return e.width=b,e.height=c,e.getContext("2d").drawImage(a,0,0),e}return a},b.base2Sizes=[2,4,16,32,64,128,256,512,1024,2048,4096],b}();b.Common=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(){}return b.prototype.objType=function(){return"GameMath"},b.computeMachineEpsilon=function(){var a=4/3,b=a-1,c=b+b+b;return Math.abs(1-c)},b.fuzzyEqual=function(a,b,c){return void 0===c&&(c=1e-4),Math.abs(a-b)<c},b.fuzzyLessThan=function(a,b,c){return void 0===c&&(c=1e-4),b+c>a},b.fuzzyGreaterThan=function(a,b,c){return void 0===c&&(c=1e-4),a>b-c},b.fuzzyCeil=function(a,b){return void 0===b&&(b=1e-4),Math.ceil(a-b)},b.fuzzyFloor=function(a,b){return void 0===b&&(b=1e-4),Math.floor(a+b)},b.average=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0,d=0;d<a.length;d++)c+=a[d];return c/a.length},b.slam=function(a,b,c){return void 0===c&&(c=1e-4),Math.abs(a-b)<c?b:a},b.percentageMinMax=function(a,b,c){return void 0===c&&(c=0),a-=c,b-=c,b?a/b:0},b.sign=function(a){return a?a/Math.abs(a):0},b.truncate=function(a){return a>0?Math.floor(a):Math.ceil(a)},b.shear=function(a){return a%1},b.wrap=function(a,b,c){if(void 0===c&&(c=0),a-=c,b-=c,0==b)return c;for(a%=b,a+=c;c>a;)a+=b;return a},b.arithWrap=function(a,b,c){return void 0===c&&(c=0),b-=c,0==b?c:a-b*Math.floor((a-c)/b)},b.clamp=function(a,b,c){return void 0===c&&(c=0),Math.max(c,Math.min(b,a))},b.snapTo=function(a,b,c){return void 0===c&&(c=0),0==b?a:(a-=c,a=b*Math.round(a/b),c+a)},b.snapToFloor=function(a,b,c){return void 0===c&&(c=0),0==b?a:(a-=c,a=b*Math.floor(a/b),c+a)},b.snapToCeil=function(a,b,c){return void 0===c&&(c=0),0==b?a:(a-=c,a=b*Math.ceil(a/b),c+a)},b.snapToInArray=function(a,b,c){if(void 0===c&&(c=!0),c&&b.sort(),a<b[0])return b[0];for(var d=1;b[d]<a;)d++;var e=b[d-1],f=d<b.length?b[d]:Number.POSITIVE_INFINITY;return a-e>=f-a?f:e},b.roundTo=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=10);var d=Math.pow(c,-b);return Math.round(a*d)/d},b.floorTo=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=10);var d=Math.pow(c,-b);return Math.floor(a*d)/d},b.ceilTo=function(a,b,c){void 0===b&&(b=0),void 0===c&&(c=10);var d=Math.pow(c,-b);return Math.ceil(a*d)/d},b.interpolateFloat=function(a,b,c){return(b-a)*c+a},b.radiansToDegrees=function(a){return a*b.RAD_TO_DEG},b.degreesToRadians=function(a){return a*b.DEG_TO_RAD},b.angleBetween=function(a,b,c,d){return Math.atan2(d-b,c-a)},b.normalizeAngle=function(a,c){void 0===c&&(c=!0);var d=c?b.PI:180;return b.wrap(a,d,-d)},b.nearestAngleBetween=function(a,c,d){void 0===d&&(d=!0);var e=d?b.PI:180;return a=b.normalizeAngle(a,d),c=b.normalizeAngle(c,d),-e/2>a&&c>e/2&&(a+=2*e),-e/2>c&&a>e/2&&(c+=2*e),b.normalizeAngle(c-a,d)},b.normalizeAngleToAnother=function(b,c,d){return void 0===d&&(d=!0),c+a.Utils.GameMath.nearestAngleBetween(c,b,d)},b.normalizeAngleAfterAnother=function(b,c,d){return void 0===d&&(d=!0),b=a.Utils.GameMath.normalizeAngle(b-c,d),c+b},b.normalizeAngleBeforeAnother=function(b,c,d){return void 0===d&&(d=!0),b=a.Utils.GameMath.normalizeAngle(c-b,d),c-b},b.interpolateAngles=function(b,c,d,e,f){return void 0===e&&(e=!0),void 0===f&&(f=null),b=a.Utils.GameMath.normalizeAngle(b,e),c=a.Utils.GameMath.normalizeAngleToAnother(c,b,e),"function"==typeof f?f(d,b,c-b,1):a.Utils.GameMath.interpolateFloat(b,c,d)},b.logBaseOf=function(a,b){return Math.log(a)/Math.log(b)},b.GCD=function(a,b){var c;for(a=Math.abs(a),b=Math.abs(b),b>a&&(c=a,a=b,b=c);;){if(c=a%b,!c)return b;a=b,b=c}return 1},b.LCM=function(b,c){return b*c/a.Utils.GameMath.GCD(b,c)},b.factorial=function(a){if(0==a)return 1;for(var b=a;--a;)b*=a;return b},b.gammaFunction=function(b){return a.Utils.GameMath.factorial(b-1)},b.fallingFactorial=function(b,c){return a.Utils.GameMath.factorial(b)/a.Utils.GameMath.factorial(b-c)},b.risingFactorial=function(b,c){return a.Utils.GameMath.factorial(b+c-1)/a.Utils.GameMath.factorial(b-1)},b.binCoef=function(b,c){return a.Utils.GameMath.fallingFactorial(b,c)/a.Utils.GameMath.factorial(c)},b.risingBinCoef=function(b,c){return a.Utils.GameMath.risingFactorial(b,c)/a.Utils.GameMath.factorial(c)},b.chanceRoll=function(a){return void 0===a&&(a=50),0>=a?!1:a>=100?!0:100*Math.random()>=a?!1:!0},b.maxAdd=function(a,b,c){return a+=b,a>c&&(a=c),a},b.minSub=function(a,b,c){return a-=b,c>a&&(a=c),a},b.wrapValue=function(a,b,c){var d;return a=Math.abs(a),b=Math.abs(b),c=Math.abs(c),d=(a+b)%c},b.randomSign=function(){return Math.random()>.5?1:-1},b.isOdd=function(a){return 1&a?!0:!1},b.isEven=function(a){return 1&a?!1:!0},b.wrapAngle=function(a){var b=a;return a>=-180&&180>=a?a:(b=(a+180)%360,0>b&&(b+=360),b-180)},b.angleLimit=function(a,b,c){var d=a;return a>c?d=c:b>a&&(d=b),d},b.linearInterpolation=function(b,c){var d=b.length-1,e=d*c,f=Math.floor(e);return 0>c?a.Utils.GameMath.linear(b[0],b[1],e):c>1?a.Utils.GameMath.linear(b[d],b[d-1],d-e):a.Utils.GameMath.linear(b[f],b[f+1>d?d:f+1],e-f)},b.bezierInterpolation=function(b,c){for(var d=0,e=b.length-1,f=0;e>=f;f++)d+=Math.pow(1-c,e-f)*Math.pow(c,f)*b[f]*a.Utils.GameMath.bernstein(e,f);return d},b.catmullRomInterpolation=function(b,c){var d=b.length-1,e=d*c,f=Math.floor(e);return b[0]===b[d]?(0>c&&(f=Math.floor(e=d*(1+c))),a.Utils.GameMath.catmullRom(b[(f-1+d)%d],b[f],b[(f+1)%d],b[(f+2)%d],e-f)):0>c?b[0]-(a.Utils.GameMath.catmullRom(b[0],b[0],b[1],b[1],-e)-b[0]):c>1?b[d]-(a.Utils.GameMath.catmullRom(b[d],b[d],b[d-1],b[d-1],e-d)-b[d]):a.Utils.GameMath.catmullRom(b[f?f-1:0],b[f],b[f+1>d?d:f+1],b[f+2>d?d:f+2],e-f)},b.linear=function(a,b,c){return(b-a)*c+a},b.bernstein=function(b,c){return a.Utils.GameMath.factorial(b)/a.Utils.GameMath.factorial(c)/a.Utils.GameMath.factorial(b-c)},b.catmullRom=function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b},b.difference=function(a,b){return Math.abs(a-b)},b.PI=3.141592653589793,b.PI_2=1.5707963267948966,b.PI_4=.7853981633974483,b.PI_8=.39269908169872414,b.PI_16=.19634954084936207,b.TWO_PI=6.283185307179586,b.THREE_PI_2=4.71238898038469,b.E=2.71828182845905,b.LN10=2.302585092994046,b.LN2=.6931471805599453,b.LOG10E=.4342944819032518,b.LOG2E=1.4426950408889634,b.SQRT1_2=.7071067811865476,b.SQRT2=1.4142135623730951,b.DEG_TO_RAD=.017453292519943295,b.RAD_TO_DEG=57.29577951308232,b.B_16=65536,b.B_31=2147483648,b.B_32=4294967296,b.B_48=281474976710656,b.B_53=9007199254740992,b.B_64=0x10000000000000000,b.ONE_THIRD=.3333333333333333,b.TWO_THIRDS=.6666666666666666,b.ONE_SIXTH=.16666666666666666,b.COS_PI_3=.8660254037844386,b.SIN_2PI_3=.03654595,b.CIRCLE_ALPHA=.5522847498307935,b.ON=!0,b.OFF=!1,b.SHORT_EPSILON=.1,b.PERC_EPSILON=.001,b.EPSILON=1e-4,b.LONG_EPSILON=1e-8,b}();b.GameMath=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a){void 0===a&&(a=[]),this.c=1,this._data={lipsum:["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","nunc","sagittis","tortor","ac","mi","pretium","sed","convallis","massa","pulvinar","curabitur","non","turpis","velit","vitae","rutrum","odio","aliquam","sapien","orci","tempor","sed","elementum","sit","amet","tincidunt","sed","risus","etiam","nec","lacus","id","ante","hendrerit","malesuada","donec","porttitor","magna","eget","libero","pharetra","sollicitudin","aliquam","mattis","mattis","massa","et","porta","morbi","vitae","magna","augue","vestibulum","at","lectus","sed","tellus","facilisis","tincidunt","suspendisse","eros","magna","consequat","at","sollicitudin","ac","vestibulum","vel","dolor","in","egestas","lacus","quis","lacus","placerat","et","molestie","ipsum","scelerisque","nullam","sit","amet","tortor","dui","aenean","pulvinar","odio","nec","placerat","fringilla","neque","dolor"]},this.sow(a)}return a.prototype.objType=function(){return"RandomDataGenerator"},a.prototype.uint32=function(){return 4294967296*this.rnd.apply(this)},a.prototype.fract32=function(){return this.rnd.apply(this)+1.1102230246251565e-16*(2097152*this.rnd.apply(this)|0)},a.prototype.rnd=function(){var a=2091639*this.s0+2.3283064365386963e-10*this.c;return this.c=0|a,this.s0=this.s1,this.s1=this.s2,this.s2=a-this.c,this.s2},a.prototype.hash=function(a){var b,c,d;for(d=4022871197,a=a.toString(),c=0;c<a.length;c++)d+=a.charCodeAt(c),b=.02519603282416938*d,d=b>>>0,b-=d,b*=d,d=b>>>0,b-=d,d+=4294967296*b;return 2.3283064365386963e-10*(d>>>0)},a.prototype.sow=function(a){void 0===a&&(a=[]),this.s0=this.hash(" "),this.s1=this.hash(this.s0),this.s2=this.hash(this.s1);for(var b,c=0;b=a[c++];)this.s0-=this.hash(b),this.s0+=~~(this.s0<0),this.s1-=this.hash(b),this.s1+=~~(this.s1<0),this.s2-=this.hash(b),this.s2+=~~(this.s2<0)},a.prototype.integer=function(){return this.uint32()},a.prototype.frac=function(){return this.fract32()},a.prototype.real=function(){return this.uint32()+this.fract32()},a.prototype.integerInRange=function(a,b){return Math.floor(this.realInRange(a,b))},a.prototype.realInRange=function(a,b){return a=a||0,b=b||0,this.frac()*(b-a)+a},a.prototype.normal=function(){return 1-2*this.frac()},a.prototype.uuid=function(){var a,b;for(b=a="";a++<36;b+=~a%5|3*a&4?(15^a?8^this.frac()*(20^a?16:4):4).toString(16):"-");return b},a.prototype.pick=function(a){return a[this.integerInRange(0,a.length)]},a.prototype.weightedPick=function(a){return a[~~(Math.pow(this.frac(),2)*a.length)]},a.prototype.word=function(){return this.pick(this._data.lipsum)},a.prototype.words=function(a){void 0===a&&(a=3);for(var b=[],c=0;a>c;c++)b.push(this.pick(this._data.lipsum));return b.join(" ")},a.prototype.sentence=function(){var a;return a=this.words(this.integerInRange(2,16)).replace(/[a-z]/,function(a){return a.toUpperCase()}),a+"."},a.prototype.sentences=function(a){void 0===a&&(a=3);for(var b=[],c=0;a>c;c++)b.push(this.sentence());return b.join(" ")},a.prototype.timestamp=function(a,b){return void 0===a&&(a=9466848e5),void 0===b&&(b=1577862e6),this.realInRange(a,b)},a.prototype.angle=function(){return this.integerInRange(-180,180)},a}();a.RandomDataGenerator=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(a){this._isSetTimeOut=!1,this.lastTime=0,this.currentTime=0,this.isRunning=!1,this._callback=a;for(var b=["ms","moz","webkit","o"],c=0;c<b.length&&!window.requestAnimationFrame;c++)window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]}return a.prototype.objType=function(){return"RequestAnimationFrame"},a.prototype.setCallback=function(a){this._callback=a},a.prototype.isUsingSetTimeOut=function(){return this._isSetTimeOut},a.prototype.isUsingRAF=function(){return this._isSetTimeOut===!0?!1:!0},a.prototype.start=function(a){var b=this;void 0===a&&(a=null),a&&(this._callback=a),window.requestAnimationFrame?(this._isSetTimeOut=!1,window.requestAnimationFrame(function(){return b.RAFUpdate()})):(this._isSetTimeOut=!0,this._timeOutID=window.setTimeout(function(){return b.SetTimeoutUpdate()},0)),this.isRunning=!0},a.prototype.stop=function(){this._isSetTimeOut?clearTimeout(this._timeOutID):window.cancelAnimationFrame,this.isRunning=!1},a.prototype.RAFUpdate=function(){var a=this;this.currentTime=Date.now(),this._callback&&this._callback();var b=Math.max(0,16-(this.currentTime-this.lastTime));window.requestAnimationFrame(function(){return a.RAFUpdate()}),this.lastTime=this.currentTime+b},a.prototype.SetTimeoutUpdate=function(){var a=this;this.currentTime=Date.now(),this._callback&&this._callback();var b=Math.max(0,16-(this.currentTime-this.lastTime));this._timeOutID=window.setTimeout(function(){return a.SetTimeoutUpdate()},b),this.lastTime=this.currentTime+b},a}();a.RequestAnimationFrame=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(){function b(a){void 0===a&&(a={}),this.enabled=!0,this.recording=!0,this.display=!0,this.tagFilters=[],this.maxRecordings=1/0,this.recordings=[],this.setDefaultsFromParams(a)}return b.prototype.setDefaultsFromParams=function(b){void 0===b&&(b={}),a.Utils.Common.isUndefined(b.enabled)||(this.enabled=b.enabled),a.Utils.Common.isUndefined(b.recording)||(this.recording=b.recording),a.Utils.Common.isUndefined(b.display)||(this.display=b.display),a.Utils.Common.isUndefined(b.maxRecordings)||(this.maxRecordings=b.maxRecordings),a.Utils.Common.isArray(b.tagFilters)&&(this.tagFilters=b.tagFilters)},Object.defineProperty(b.prototype,"lastMessageTime",{get:function(){return this.recordings.length>0?this.recordings[this.recordings.length-1].time:0},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"numRecordings",{get:function(){return this.recordings.length},enumerable:!0,configurable:!0}),b.prototype.record=function(a,b,c){if(void 0===b&&(b=[]),void 0===c&&(c=console.log),this.recording){var d={messages:a,time:Date.now(),tags:b,logMethod:c};this.recordings.push(d)>this.maxRecordings&&this.recordings.shift()}},b.prototype.clearRecordings=function(a,b){void 0===a&&(a=0),void 0===b&&(b=this.recordings.length),this.recordings.splice(a,b)},b.prototype._execute=function(a,b,c,d){void 0===d&&(d=!1),(this.display||d)&&a.apply(b,c)},b.prototype.getTagsFromArray=function(a){for(var b=0,c=[];b<a.length;)"string"==typeof a[b]&&"#"===a[b].charAt(0)&&c.push(a[b]),b++;return c},b.prototype._filterTags=function(a,b){if(void 0===b&&(b=this.tagFilters),0===b.length)return!0;for(var c=0;c<a.length;){if(-1===b.indexOf(a[c]))return!1;c++}return!0},b.prototype.log=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(this.enabled){var c=this.getTagsFromArray(a);this.record(a,c,console.log),this._filterTags(c)&&this._execute(console.log,console,a)}},b.prototype.warn=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(this.enabled){var c=this.getTagsFromArray(a);this.record(a,c,console.warn),this._filterTags(c)&&this._execute(console.warn,console,a)}},b.prototype.error=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];if(this.enabled){var c=this.getTagsFromArray(a);this.record(a,c,console.error),this._filterTags(c)&&this._execute(console.error,console,a)}},b.prototype._show=function(a,b){if(!a.logMethod)return!1;for(var c=b.length;c--;)if(-1==a.tags.indexOf(b[c]))return!1;return this._execute(a.logMethod,console,a.messages,!0),!0},b.prototype.showLast=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=this.recordings.length;c--;)if(this._show(this.recordings[c],a))return},b.prototype.showAll=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this._show(this.recordings[c],a)},b.prototype.showLogs=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this.recordings[c].logMethod===console.log&&this._show(this.recordings[c],a)},b.prototype.showErrors=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this.recordings[c].logMethod===console.error&&this._show(this.recordings[c],a)},b.prototype.showWarnings=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c=0;c<this.recordings.length;c++)this.recordings[c].logMethod===console.warn&&this._show(this.recordings[c],a)},b.prototype.showTimePeriod=function(a,b,c){void 0===a&&(a=0),void 0===b&&(b=1/0),void 0===c&&(c=[]);for(var d,e=0;e<this.recordings.length;e++)d=this.recordings[e],a<d.time&&b>d.time&&this._show(d,c)},b.prototype.addFilter=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];this.tagFilters=this.tagFilters.concat(a)},b.prototype.removeFilter=function(){for(var a=[],b=0;b<arguments.length;b++)a[b-0]=arguments[b];for(var c,d=0;d<a.length;)c=this.tagFilters.indexOf(a[d]),-1!==c&&this.tagFilters.splice(c,1),d++},b}();b.Log=c}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(a){var b=function(){function a(){}return a.parseVersion=function(a){var b=a.split(".");return{majorVersion:parseInt(b[0]),minorVersion:parseInt(b[1]),patchVersion:parseInt(b[2])}},a.compareVersions=function(b,c){var d=a.parseVersion(b),e=a.parseVersion(c);return d.majorVersion>e.majorVersion?"greater":d.majorVersion<e.majorVersion?"less":d.minorVersion>e.minorVersion?"greater":d.minorVersion<e.minorVersion?"less":d.patchVersion>e.patchVersion?"greater":d.patchVersion<e.patchVersion?"less":"equal"},a.greaterOrEqual=function(b,c){var d=a.compareVersions(b,c);return"greater"==d||"equal"==d},a}();a.Version=b}(b=a.Utils||(a.Utils={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){a.Log=new a.Utils.Log,a.VERSION="1.3.0",a.RENDERER_CANVAS=0,a.RENDERER_WEBGL=1,a.RENDERER_AUTO=2,a.TARGET_BROWSER=0,a.TARGET_COCOON=1,a.DEBUG_ON=0,a.DEBUG_OFF=1,a.DEVICE=null,a.STATE=0,a.GROUP=2,a.ENTITY=3,a.CAMERA=4,a.HUD_WIDGET=5,a.TILE_LAYER=6;var b=function(){function b(){}return b.prototype.objType=function(){return"GameManager"},b.register=function(b){return a.GameManager._games.push(b)},b.total=function(){return a.GameManager._games.length},b._games=[],b}();a.GameManager=b,a.Plugins={},a.extend=function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c}}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(c,d){void 0===d&&(d={}),b.call(this,c,d),this.crossOrigin="",this.game.audio.usingAudioTag?(this.useTagLoader=!0,this._loadInParallel=!0):this.useTagLoader=!1,a.Utils.Common.isUndefined(d.crossOrigin)||(this.crossOrigin=d.crossOrigin)}return __extends(c,b),c.prototype.objType=function(){return"AudioFile"},c.prototype._load=function(){this.attemptCounter++,this.useTagLoader?this.tagLoader():this.xhrLoader("GET","arraybuffer")},c.prototype.tagLoader=function(){if(this.data=document.createElement("audio"),this.data.src=this.URL,this.data.preload="auto",this.crossOrigin&&(this.data.crossOrigin=this.crossOrigin),this.game.audio.locked)this.loadSuccess();else{var b=this,c=function(){b.data.removeEventListener("canplaythrough",c,!1),b.data.pause(),b.data.currentTime=0,b.data.volume=1,b.loadSuccess()};this.data.addEventListener("canplaythrough",c,!1),this.game.deviceTargetOption==a.TARGET_COCOON?this.data.load():(this.data.volume=0,this.data.play())}},c.prototype.processXhr=function(a){this.data={raw:a,decoded:!1,buffer:null},this._decodeAudio()},c.prototype._decodeAudio=function(){var b=this;this.game.audio.context.decodeAudioData(this.data.raw,function(a){a&&(b.data.buffer=a,b.data.decoded=!0,b.loadSuccess())},function(c){a.Log.error("Kiwi.Files.AudioFile: Error decoding audio data.","#loading","#decoding"),b.loadError(c)})},c}(a.Files.File);b.AudioFile=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(a,c){void 0===c&&(c={}),b.call(this,a,c),this.parse=!1,this.useTagLoader=!1,this._loadInParallel=!1}return __extends(c,b),c.prototype.parseParams=function(c){b.prototype.parseParams.call(this,c),a.Utils.Common.isUndefined(c.parse)||(this.parse=c.parse)},c.prototype.objType=function(){return"DataFile"},c.prototype._load=function(){this.attemptCounter++,this.dataType===a.Files.File.BINARY_DATA?this.xhrLoader("GET","arraybuffer"):this.xhrLoader("GET","text")},c.prototype.processXhr=function(b){if(!this.parse)return this.data=b,void this.loadSuccess();switch(this.dataType){case a.Files.File.JSON:this.processJSON(b);break;case a.Files.File.XML:this.parseXML(b);break;case a.Files.File.TEXT_DATA:case a.Files.File.BINARY_DATA:default:this.data=b}},c.prototype.parseXML=function(b){if(a.Log.log("Kiwi.Files.DataFile: Data loaded is being parsed as XML.","#loading","#parsing"),window.DOMParser){var c=new DOMParser;this.data=c.parseFromString(b,"text/xml")}else this.data=new ActiveXObject("Microsoft.XMLDOM"),this.data.async="false",this.data.loadXML(b);this.data&&this.data.documentElement&&!this.data.getElementsByTagName("parsererror").length?this.loadSuccess():this.loadError("XML parse error.")},c.prototype.processJSON=function(b){a.Log.log("Kiwi.Files.DataFile: Data loaded is being parsed as JSON.","#loading","#parsing");try{this.data=JSON.parse(b),this.loadSuccess()}catch(c){this.loadError(c)}},c}(a.Files.File);b.DataFile=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={}));var Kiwi;!function(a){var b;!function(b){var c=function(b){function c(c,d){void 0===d&&(d={}),b.call(this,c,d),this.crossOrigin="",d.xhrLoading?(this.useTagLoader=!1,this._loadInParallel=!1):(this.useTagLoader=!0,this._loadInParallel=!0),a.Utils.Common.isUndefined(d.crossOrigin)||(this.crossOrigin=d.crossOrigin)}return __extends(c,b),c.prototype.objType=function(){return"TextureFile"},c.prototype._load=function(){this.attemptCounter++,this.useTagLoader?this.tagLoader():this.xhrLoader("GET","arraybuffer")},c.prototype.tagLoader=function(){var a=this;this.data=new Image,this.data.src=this.URL,this.crossOrigin&&(this.data.crossOrigin=this.crossOrigin),this.data.onload=function(){return a.loadSuccess()},this.data.onerror=function(b){return a.loadError(b)}},c.prototype.processXhr=function(a){this.data=document.createElement("img");var b=new Blob([a],{type:this.type});window.URL?this.data.src=window.URL.createObjectURL(b):window.webkitURL&&(this.data.src=window.webkitURL.createObjectURL(b)),this.loadSuccess()},c.prototype.revoke=function(){window.URL?window.URL.revokeObjectURL(this.data.src):window.webkitURL&&window.webkitURL.revokeObjectURL(this.data.src)},c.prototype.destroy=function(){this.useTagLoader||this.revoke(),b.prototype.destroy.call(this)},c}(a.Files.File);b.TextureFile=c}(b=a.Files||(a.Files={}))}(Kiwi||(Kiwi={})),function(a){"use strict";var b={};"undefined"==typeof exports?"function"==typeof define&&"object"==typeof define.amd&&define.amd?(b.exports={},define(function(){return b.exports})):b.exports="undefined"!=typeof window?window:a:b.exports=exports,function(a){if(!b)var b=1e-6;if(!c)var c="undefined"!=typeof Float32Array?Float32Array:Array;if(!d)var d=Math.random;var e={};e.setMatrixArrayType=function(a){c=a},"undefined"!=typeof a&&(a.glMatrix=e);var f={};f.create=function(){var a=new c(2);return a[0]=0,a[1]=0,a},f.clone=function(a){var b=new c(2);return b[0]=a[0],b[1]=a[1],b},f.fromValues=function(a,b){var d=new c(2);return d[0]=a,d[1]=b,d},f.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a},f.set=function(a,b,c){return a[0]=b,a[1]=c,a},f.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a},f.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a},f.sub=f.subtract,f.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a},f.mul=f.multiply,f.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a},f.div=f.divide,f.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a},f.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a},f.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a},f.scaleAndAdd=function(a,b,c,d){return a[0]=b[0]+c[0]*d,a[1]=b[1]+c[1]*d,a},f.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},f.dist=f.distance,f.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return c*c+d*d},f.sqrDist=f.squaredDistance,f.length=function(a){var b=a[0],c=a[1];return Math.sqrt(b*b+c*c)},f.len=f.length,f.squaredLength=function(a){var b=a[0],c=a[1];return b*b+c*c},f.sqrLen=f.squaredLength,f.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a},f.normalize=function(a,b){var c=b[0],d=b[1],e=c*c+d*d;return e>0&&(e=1/Math.sqrt(e),a[0]=b[0]*e,a[1]=b[1]*e),a},f.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},f.cross=function(a,b,c){var d=b[0]*c[1]-b[1]*c[0];return a[0]=a[1]=0,a[2]=d,a},f.lerp=function(a,b,c,d){var e=b[0],f=b[1];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a},f.random=function(a,b){b=b||1;var c=2*d()*Math.PI;return a[0]=Math.cos(c)*b,a[1]=Math.sin(c)*b,a},f.transformMat2=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[2]*e,a[1]=c[1]*d+c[3]*e,a
+},f.transformMat2d=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[2]*e+c[4],a[1]=c[1]*d+c[3]*e+c[5],a},f.transformMat3=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[3]*e+c[6],a[1]=c[1]*d+c[4]*e+c[7],a},f.transformMat4=function(a,b,c){var d=b[0],e=b[1];return a[0]=c[0]*d+c[4]*e+c[12],a[1]=c[1]*d+c[5]*e+c[13],a},f.forEach=function(){var a=f.create();return function(b,c,d,e,f,g){var h,i;for(c||(c=2),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],f(a,a,g),b[h]=a[0],b[h+1]=a[1];return b}}(),f.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof a&&(a.vec2=f);var g={};g.create=function(){var a=new c(3);return a[0]=0,a[1]=0,a[2]=0,a},g.clone=function(a){var b=new c(3);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b},g.fromValues=function(a,b,d){var e=new c(3);return e[0]=a,e[1]=b,e[2]=d,e},g.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a},g.set=function(a,b,c,d){return a[0]=b,a[1]=c,a[2]=d,a},g.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a[2]=b[2]+c[2],a},g.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a[2]=b[2]-c[2],a},g.sub=g.subtract,g.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a[2]=b[2]*c[2],a},g.mul=g.multiply,g.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a[2]=b[2]/c[2],a},g.div=g.divide,g.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a[2]=Math.min(b[2],c[2]),a},g.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a[2]=Math.max(b[2],c[2]),a},g.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a[2]=b[2]*c,a},g.scaleAndAdd=function(a,b,c,d){return a[0]=b[0]+c[0]*d,a[1]=b[1]+c[1]*d,a[2]=b[2]+c[2]*d,a},g.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2];return Math.sqrt(c*c+d*d+e*e)},g.dist=g.distance,g.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2];return c*c+d*d+e*e},g.sqrDist=g.squaredDistance,g.length=function(a){var b=a[0],c=a[1],d=a[2];return Math.sqrt(b*b+c*c+d*d)},g.len=g.length,g.squaredLength=function(a){var b=a[0],c=a[1],d=a[2];return b*b+c*c+d*d},g.sqrLen=g.squaredLength,g.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a[2]=-b[2],a},g.normalize=function(a,b){var c=b[0],d=b[1],e=b[2],f=c*c+d*d+e*e;return f>0&&(f=1/Math.sqrt(f),a[0]=b[0]*f,a[1]=b[1]*f,a[2]=b[2]*f),a},g.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},g.cross=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=c[0],h=c[1],i=c[2];return a[0]=e*i-f*h,a[1]=f*g-d*i,a[2]=d*h-e*g,a},g.lerp=function(a,b,c,d){var e=b[0],f=b[1],g=b[2];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a[2]=g+d*(c[2]-g),a},g.random=function(a,b){b=b||1;var c=2*d()*Math.PI,e=2*d()-1,f=Math.sqrt(1-e*e)*b;return a[0]=Math.cos(c)*f,a[1]=Math.sin(c)*f,a[2]=e*b,a},g.transformMat4=function(a,b,c){var d=b[0],e=b[1],f=b[2];return a[0]=c[0]*d+c[4]*e+c[8]*f+c[12],a[1]=c[1]*d+c[5]*e+c[9]*f+c[13],a[2]=c[2]*d+c[6]*e+c[10]*f+c[14],a},g.transformMat3=function(a,b,c){var d=b[0],e=b[1],f=b[2];return a[0]=d*c[0]+e*c[3]+f*c[6],a[1]=d*c[1]+e*c[4]+f*c[7],a[2]=d*c[2]+e*c[5]+f*c[8],a},g.transformQuat=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=c[0],h=c[1],i=c[2],j=c[3],k=j*d+h*f-i*e,l=j*e+i*d-g*f,m=j*f+g*e-h*d,n=-g*d-h*e-i*f;return a[0]=k*j+n*-g+l*-i-m*-h,a[1]=l*j+n*-h+m*-g-k*-i,a[2]=m*j+n*-i+k*-h-l*-g,a},g.forEach=function(){var a=g.create();return function(b,c,d,e,f,g){var h,i;for(c||(c=3),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],a[2]=b[h+2],f(a,a,g),b[h]=a[0],b[h+1]=a[1],b[h+2]=a[2];return b}}(),g.str=function(a){return"vec3("+a[0]+", "+a[1]+", "+a[2]+")"},"undefined"!=typeof a&&(a.vec3=g);var h={};h.create=function(){var a=new c(4);return a[0]=0,a[1]=0,a[2]=0,a[3]=0,a},h.clone=function(a){var b=new c(4);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b},h.fromValues=function(a,b,d,e){var f=new c(4);return f[0]=a,f[1]=b,f[2]=d,f[3]=e,f},h.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a},h.set=function(a,b,c,d,e){return a[0]=b,a[1]=c,a[2]=d,a[3]=e,a},h.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a[2]=b[2]+c[2],a[3]=b[3]+c[3],a},h.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a[2]=b[2]-c[2],a[3]=b[3]-c[3],a},h.sub=h.subtract,h.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a[2]=b[2]*c[2],a[3]=b[3]*c[3],a},h.mul=h.multiply,h.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a[2]=b[2]/c[2],a[3]=b[3]/c[3],a},h.div=h.divide,h.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a[2]=Math.min(b[2],c[2]),a[3]=Math.min(b[3],c[3]),a},h.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a[2]=Math.max(b[2],c[2]),a[3]=Math.max(b[3],c[3]),a},h.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a[2]=b[2]*c,a[3]=b[3]*c,a},h.scaleAndAdd=function(a,b,c,d){return a[0]=b[0]+c[0]*d,a[1]=b[1]+c[1]*d,a[2]=b[2]+c[2]*d,a[3]=b[3]+c[3]*d,a},h.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2],f=b[3]-a[3];return Math.sqrt(c*c+d*d+e*e+f*f)},h.dist=h.distance,h.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2],f=b[3]-a[3];return c*c+d*d+e*e+f*f},h.sqrDist=h.squaredDistance,h.length=function(a){var b=a[0],c=a[1],d=a[2],e=a[3];return Math.sqrt(b*b+c*c+d*d+e*e)},h.len=h.length,h.squaredLength=function(a){var b=a[0],c=a[1],d=a[2],e=a[3];return b*b+c*c+d*d+e*e},h.sqrLen=h.squaredLength,h.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a[2]=-b[2],a[3]=-b[3],a},h.normalize=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*c+d*d+e*e+f*f;return g>0&&(g=1/Math.sqrt(g),a[0]=b[0]*g,a[1]=b[1]*g,a[2]=b[2]*g,a[3]=b[3]*g),a},h.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},h.lerp=function(a,b,c,d){var e=b[0],f=b[1],g=b[2],h=b[3];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a[2]=g+d*(c[2]-g),a[3]=h+d*(c[3]-h),a},h.random=function(a,b){return b=b||1,a[0]=d(),a[1]=d(),a[2]=d(),a[3]=d(),h.normalize(a,a),h.scale(a,a,b),a},h.transformMat4=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3];return a[0]=c[0]*d+c[4]*e+c[8]*f+c[12]*g,a[1]=c[1]*d+c[5]*e+c[9]*f+c[13]*g,a[2]=c[2]*d+c[6]*e+c[10]*f+c[14]*g,a[3]=c[3]*d+c[7]*e+c[11]*f+c[15]*g,a},h.transformQuat=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=c[0],h=c[1],i=c[2],j=c[3],k=j*d+h*f-i*e,l=j*e+i*d-g*f,m=j*f+g*e-h*d,n=-g*d-h*e-i*f;return a[0]=k*j+n*-g+l*-i-m*-h,a[1]=l*j+n*-h+m*-g-k*-i,a[2]=m*j+n*-i+k*-h-l*-g,a},h.forEach=function(){var a=h.create();return function(b,c,d,e,f,g){var h,i;for(c||(c=4),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],a[2]=b[h+2],a[3]=b[h+3],f(a,a,g),b[h]=a[0],b[h+1]=a[1],b[h+2]=a[2],b[h+3]=a[3];return b}}(),h.str=function(a){return"vec4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof a&&(a.vec4=h);var i={};i.create=function(){var a=new c(4);return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a},i.clone=function(a){var b=new c(4);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b},i.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a},i.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a},i.transpose=function(a,b){if(a===b){var c=b[1];a[1]=b[2],a[2]=c}else a[0]=b[0],a[1]=b[2],a[2]=b[1],a[3]=b[3];return a},i.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*f-e*d;return g?(g=1/g,a[0]=f*g,a[1]=-d*g,a[2]=-e*g,a[3]=c*g,a):null},i.adjoint=function(a,b){var c=b[0];return a[0]=b[3],a[1]=-b[1],a[2]=-b[2],a[3]=c,a},i.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},i.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1],j=c[2],k=c[3];return a[0]=d*h+e*j,a[1]=d*i+e*k,a[2]=f*h+g*j,a[3]=f*i+g*k,a},i.mul=i.multiply,i.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+e*h,a[1]=d*-h+e*i,a[2]=f*i+g*h,a[3]=f*-h+g*i,a},i.scale=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1];return a[0]=d*h,a[1]=e*i,a[2]=f*h,a[3]=g*i,a},i.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof a&&(a.mat2=i);var j={};j.create=function(){var a=new c(6);return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a[4]=0,a[5]=0,a},j.clone=function(a){var b=new c(6);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b},j.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a},j.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a[4]=0,a[5]=0,a},j.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=c*f-d*e;return i?(i=1/i,a[0]=f*i,a[1]=-d*i,a[2]=-e*i,a[3]=c*i,a[4]=(e*h-f*g)*i,a[5]=(d*g-c*h)*i,a):null},j.determinant=function(a){return a[0]*a[3]-a[1]*a[2]},j.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=c[0],k=c[1],l=c[2],m=c[3],n=c[4],o=c[5];return a[0]=d*j+e*l,a[1]=d*k+e*m,a[2]=f*j+g*l,a[3]=f*k+g*m,a[4]=j*h+l*i+n,a[5]=k*h+m*i+o,a},j.mul=j.multiply,j.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=Math.sin(c),k=Math.cos(c);return a[0]=d*k+e*j,a[1]=-d*j+e*k,a[2]=f*k+g*j,a[3]=-f*j+k*g,a[4]=k*h+j*i,a[5]=k*i-j*h,a},j.scale=function(a,b,c){var d=c[0],e=c[1];return a[0]=b[0]*d,a[1]=b[1]*e,a[2]=b[2]*d,a[3]=b[3]*e,a[4]=b[4]*d,a[5]=b[5]*e,a},j.translate=function(a,b,c){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4]+c[0],a[5]=b[5]+c[1],a},j.str=function(a){return"mat2d("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+")"},"undefined"!=typeof a&&(a.mat2d=j);var k={};k.create=function(){var a=new c(9);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},k.fromMat4=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[4],a[4]=b[5],a[5]=b[6],a[6]=b[8],a[7]=b[9],a[8]=b[10],a},k.clone=function(a){var b=new c(9);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b},k.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a},k.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},k.transpose=function(a,b){if(a===b){var c=b[1],d=b[2],e=b[5];a[1]=b[3],a[2]=b[6],a[3]=c,a[5]=b[7],a[6]=d,a[7]=e}else a[0]=b[0],a[1]=b[3],a[2]=b[6],a[3]=b[1],a[4]=b[4],a[5]=b[7],a[6]=b[2],a[7]=b[5],a[8]=b[8];return a},k.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=k*g-h*j,m=-k*f+h*i,n=j*f-g*i,o=c*l+d*m+e*n;return o?(o=1/o,a[0]=l*o,a[1]=(-k*d+e*j)*o,a[2]=(h*d-e*g)*o,a[3]=m*o,a[4]=(k*c-e*i)*o,a[5]=(-h*c+e*f)*o,a[6]=n*o,a[7]=(-j*c+d*i)*o,a[8]=(g*c-d*f)*o,a):null},k.adjoint=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8];return a[0]=g*k-h*j,a[1]=e*j-d*k,a[2]=d*h-e*g,a[3]=h*i-f*k,a[4]=c*k-e*i,a[5]=e*f-c*h,a[6]=f*j-g*i,a[7]=d*i-c*j,a[8]=c*g-d*f,a},k.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],i=a[7],j=a[8];return b*(j*f-g*i)+c*(-j*e+g*h)+d*(i*e-f*h)},k.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=c[0],n=c[1],o=c[2],p=c[3],q=c[4],r=c[5],s=c[6],t=c[7],u=c[8];return a[0]=m*d+n*g+o*j,a[1]=m*e+n*h+o*k,a[2]=m*f+n*i+o*l,a[3]=p*d+q*g+r*j,a[4]=p*e+q*h+r*k,a[5]=p*f+q*i+r*l,a[6]=s*d+t*g+u*j,a[7]=s*e+t*h+u*k,a[8]=s*f+t*i+u*l,a},k.mul=k.multiply,k.translate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=c[0],n=c[1];return a[0]=d,a[1]=e,a[2]=f,a[3]=g,a[4]=h,a[5]=i,a[6]=m*d+n*g+j,a[7]=m*e+n*h+k,a[8]=m*f+n*i+l,a},k.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=Math.sin(c),n=Math.cos(c);return a[0]=n*d+m*g,a[1]=n*e+m*h,a[2]=n*f+m*i,a[3]=n*g-m*d,a[4]=n*h-m*e,a[5]=n*i-m*f,a[6]=j,a[7]=k,a[8]=l,a},k.scale=function(a,b,c){var d=c[0],e=c[1];return a[0]=d*b[0],a[1]=d*b[1],a[2]=d*b[2],a[3]=e*b[3],a[4]=e*b[4],a[5]=e*b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a},k.fromMat2d=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=0,a[3]=b[2],a[4]=b[3],a[5]=0,a[6]=b[4],a[7]=b[5],a[8]=1,a},k.fromQuat=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return a[0]=1-(m+o),a[3]=k+r,a[6]=l-q,a[1]=k-r,a[4]=1-(j+o),a[7]=n+p,a[2]=l+q,a[5]=n-p,a[8]=1-(j+m),a},k.normalFromMat4=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15],s=c*h-d*g,t=c*i-e*g,u=c*j-f*g,v=d*i-e*h,w=d*j-f*h,x=e*j-f*i,y=k*p-l*o,z=k*q-m*o,A=k*r-n*o,B=l*q-m*p,C=l*r-n*p,D=m*r-n*q,E=s*D-t*C+u*B+v*A-w*z+x*y;return E?(E=1/E,a[0]=(h*D-i*C+j*B)*E,a[1]=(i*A-g*D-j*z)*E,a[2]=(g*C-h*A+j*y)*E,a[3]=(e*C-d*D-f*B)*E,a[4]=(c*D-e*A+f*z)*E,a[5]=(d*A-c*C-f*y)*E,a[6]=(p*x-q*w+r*v)*E,a[7]=(q*u-o*x-r*t)*E,a[8]=(o*w-p*u+r*s)*E,a):null},k.str=function(a){return"mat3("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+")"},"undefined"!=typeof a&&(a.mat3=k);var l={};l.create=function(){var a=new c(16);return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},l.clone=function(a){var b=new c(16);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15],b},l.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a[9]=b[9],a[10]=b[10],a[11]=b[11],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15],a},l.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},l.transpose=function(a,b){if(a===b){var c=b[1],d=b[2],e=b[3],f=b[6],g=b[7],h=b[11];a[1]=b[4],a[2]=b[8],a[3]=b[12],a[4]=c,a[6]=b[9],a[7]=b[13],a[8]=d,a[9]=f,a[11]=b[14],a[12]=e,a[13]=g,a[14]=h}else a[0]=b[0],a[1]=b[4],a[2]=b[8],a[3]=b[12],a[4]=b[1],a[5]=b[5],a[6]=b[9],a[7]=b[13],a[8]=b[2],a[9]=b[6],a[10]=b[10],a[11]=b[14],a[12]=b[3],a[13]=b[7],a[14]=b[11],a[15]=b[15];return a},l.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15],s=c*h-d*g,t=c*i-e*g,u=c*j-f*g,v=d*i-e*h,w=d*j-f*h,x=e*j-f*i,y=k*p-l*o,z=k*q-m*o,A=k*r-n*o,B=l*q-m*p,C=l*r-n*p,D=m*r-n*q,E=s*D-t*C+u*B+v*A-w*z+x*y;return E?(E=1/E,a[0]=(h*D-i*C+j*B)*E,a[1]=(e*C-d*D-f*B)*E,a[2]=(p*x-q*w+r*v)*E,a[3]=(m*w-l*x-n*v)*E,a[4]=(i*A-g*D-j*z)*E,a[5]=(c*D-e*A+f*z)*E,a[6]=(q*u-o*x-r*t)*E,a[7]=(k*x-m*u+n*t)*E,a[8]=(g*C-h*A+j*y)*E,a[9]=(d*A-c*C-f*y)*E,a[10]=(o*w-p*u+r*s)*E,a[11]=(l*u-k*w-n*s)*E,a[12]=(h*z-g*B-i*y)*E,a[13]=(c*B-d*z+e*y)*E,a[14]=(p*t-o*v-q*s)*E,a[15]=(k*v-l*t+m*s)*E,a):null},l.adjoint=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15];return a[0]=h*(m*r-n*q)-l*(i*r-j*q)+p*(i*n-j*m),a[1]=-(d*(m*r-n*q)-l*(e*r-f*q)+p*(e*n-f*m)),a[2]=d*(i*r-j*q)-h*(e*r-f*q)+p*(e*j-f*i),a[3]=-(d*(i*n-j*m)-h*(e*n-f*m)+l*(e*j-f*i)),a[4]=-(g*(m*r-n*q)-k*(i*r-j*q)+o*(i*n-j*m)),a[5]=c*(m*r-n*q)-k*(e*r-f*q)+o*(e*n-f*m),a[6]=-(c*(i*r-j*q)-g*(e*r-f*q)+o*(e*j-f*i)),a[7]=c*(i*n-j*m)-g*(e*n-f*m)+k*(e*j-f*i),a[8]=g*(l*r-n*p)-k*(h*r-j*p)+o*(h*n-j*l),a[9]=-(c*(l*r-n*p)-k*(d*r-f*p)+o*(d*n-f*l)),a[10]=c*(h*r-j*p)-g*(d*r-f*p)+o*(d*j-f*h),a[11]=-(c*(h*n-j*l)-g*(d*n-f*l)+k*(d*j-f*h)),a[12]=-(g*(l*q-m*p)-k*(h*q-i*p)+o*(h*m-i*l)),a[13]=c*(l*q-m*p)-k*(d*q-e*p)+o*(d*m-e*l),a[14]=-(c*(h*q-i*p)-g*(d*q-e*p)+o*(d*i-e*h)),a[15]=c*(h*m-i*l)-g*(d*m-e*l)+k*(d*i-e*h),a},l.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],i=a[7],j=a[8],k=a[9],l=a[10],m=a[11],n=a[12],o=a[13],p=a[14],q=a[15],r=b*g-c*f,s=b*h-d*f,t=b*i-e*f,u=c*h-d*g,v=c*i-e*g,w=d*i-e*h,x=j*o-k*n,y=j*p-l*n,z=j*q-m*n,A=k*p-l*o,B=k*q-m*o,C=l*q-m*p;return r*C-s*B+t*A+u*z-v*y+w*x},l.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=b[9],n=b[10],o=b[11],p=b[12],q=b[13],r=b[14],s=b[15],t=c[0],u=c[1],v=c[2],w=c[3];return a[0]=t*d+u*h+v*l+w*p,a[1]=t*e+u*i+v*m+w*q,a[2]=t*f+u*j+v*n+w*r,a[3]=t*g+u*k+v*o+w*s,t=c[4],u=c[5],v=c[6],w=c[7],a[4]=t*d+u*h+v*l+w*p,a[5]=t*e+u*i+v*m+w*q,a[6]=t*f+u*j+v*n+w*r,a[7]=t*g+u*k+v*o+w*s,t=c[8],u=c[9],v=c[10],w=c[11],a[8]=t*d+u*h+v*l+w*p,a[9]=t*e+u*i+v*m+w*q,a[10]=t*f+u*j+v*n+w*r,a[11]=t*g+u*k+v*o+w*s,t=c[12],u=c[13],v=c[14],w=c[15],a[12]=t*d+u*h+v*l+w*p,a[13]=t*e+u*i+v*m+w*q,a[14]=t*f+u*j+v*n+w*r,a[15]=t*g+u*k+v*o+w*s,a},l.mul=l.multiply,l.translate=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p=c[0],q=c[1],r=c[2];return b===a?(a[12]=b[0]*p+b[4]*q+b[8]*r+b[12],a[13]=b[1]*p+b[5]*q+b[9]*r+b[13],a[14]=b[2]*p+b[6]*q+b[10]*r+b[14],a[15]=b[3]*p+b[7]*q+b[11]*r+b[15]):(d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],i=b[5],j=b[6],k=b[7],l=b[8],m=b[9],n=b[10],o=b[11],a[0]=d,a[1]=e,a[2]=f,a[3]=g,a[4]=h,a[5]=i,a[6]=j,a[7]=k,a[8]=l,a[9]=m,a[10]=n,a[11]=o,a[12]=d*p+h*q+l*r+b[12],a[13]=e*p+i*q+m*r+b[13],a[14]=f*p+j*q+n*r+b[14],a[15]=g*p+k*q+o*r+b[15]),a},l.scale=function(a,b,c){var d=c[0],e=c[1],f=c[2];return a[0]=b[0]*d,a[1]=b[1]*d,a[2]=b[2]*d,a[3]=b[3]*d,a[4]=b[4]*e,a[5]=b[5]*e,a[6]=b[6]*e,a[7]=b[7]*e,a[8]=b[8]*f,a[9]=b[9]*f,a[10]=b[10]*f,a[11]=b[11]*f,a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15],a},l.rotate=function(a,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D=e[0],E=e[1],F=e[2],G=Math.sqrt(D*D+E*E+F*F);return Math.abs(G)<b?null:(G=1/G,D*=G,E*=G,F*=G,f=Math.sin(d),g=Math.cos(d),h=1-g,i=c[0],j=c[1],k=c[2],l=c[3],m=c[4],n=c[5],o=c[6],p=c[7],q=c[8],r=c[9],s=c[10],t=c[11],u=D*D*h+g,v=E*D*h+F*f,w=F*D*h-E*f,x=D*E*h-F*f,y=E*E*h+g,z=F*E*h+D*f,A=D*F*h+E*f,B=E*F*h-D*f,C=F*F*h+g,a[0]=i*u+m*v+q*w,a[1]=j*u+n*v+r*w,a[2]=k*u+o*v+s*w,a[3]=l*u+p*v+t*w,a[4]=i*x+m*y+q*z,a[5]=j*x+n*y+r*z,a[6]=k*x+o*y+s*z,a[7]=l*x+p*y+t*z,a[8]=i*A+m*B+q*C,a[9]=j*A+n*B+r*C,a[10]=k*A+o*B+s*C,a[11]=l*A+p*B+t*C,c!==a&&(a[12]=c[12],a[13]=c[13],a[14]=c[14],a[15]=c[15]),a)},l.rotateX=function(a,b,c){var d=Math.sin(c),e=Math.cos(c),f=b[4],g=b[5],h=b[6],i=b[7],j=b[8],k=b[9],l=b[10],m=b[11];return b!==a&&(a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]),a[4]=f*e+j*d,a[5]=g*e+k*d,a[6]=h*e+l*d,a[7]=i*e+m*d,a[8]=j*e-f*d,a[9]=k*e-g*d,a[10]=l*e-h*d,a[11]=m*e-i*d,a},l.rotateY=function(a,b,c){var d=Math.sin(c),e=Math.cos(c),f=b[0],g=b[1],h=b[2],i=b[3],j=b[8],k=b[9],l=b[10],m=b[11];return b!==a&&(a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]),a[0]=f*e-j*d,a[1]=g*e-k*d,a[2]=h*e-l*d,a[3]=i*e-m*d,a[8]=f*d+j*e,a[9]=g*d+k*e,a[10]=h*d+l*e,a[11]=i*d+m*e,a},l.rotateZ=function(a,b,c){var d=Math.sin(c),e=Math.cos(c),f=b[0],g=b[1],h=b[2],i=b[3],j=b[4],k=b[5],l=b[6],m=b[7];return b!==a&&(a[8]=b[8],a[9]=b[9],a[10]=b[10],a[11]=b[11],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]),a[0]=f*e+j*d,a[1]=g*e+k*d,a[2]=h*e+l*d,a[3]=i*e+m*d,a[4]=j*e-f*d,a[5]=k*e-g*d,a[6]=l*e-h*d,a[7]=m*e-i*d,a},l.fromRotationTranslation=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=d+d,i=e+e,j=f+f,k=d*h,l=d*i,m=d*j,n=e*i,o=e*j,p=f*j,q=g*h,r=g*i,s=g*j;return a[0]=1-(n+p),a[1]=l+s,a[2]=m-r,a[3]=0,a[4]=l-s,a[5]=1-(k+p),a[6]=o+q,a[7]=0,a[8]=m+r,a[9]=o-q,a[10]=1-(k+n),a[11]=0,a[12]=c[0],a[13]=c[1],a[14]=c[2],a[15]=1,a},l.fromQuat=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return a[0]=1-(m+o),a[1]=k+r,a[2]=l-q,a[3]=0,a[4]=k-r,a[5]=1-(j+o),a[6]=n+p,a[7]=0,a[8]=l+q,a[9]=n-p,a[10]=1-(j+m),a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},l.frustum=function(a,b,c,d,e,f,g){var h=1/(c-b),i=1/(e-d),j=1/(f-g);return a[0]=2*f*h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*f*i,a[6]=0,a[7]=0,a[8]=(c+b)*h,a[9]=(e+d)*i,a[10]=(g+f)*j,a[11]=-1,a[12]=0,a[13]=0,a[14]=g*f*2*j,a[15]=0,a},l.perspective=function(a,b,c,d,e){var f=1/Math.tan(b/2),g=1/(d-e);return a[0]=f/c,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=f,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=(e+d)*g,a[11]=-1,a[12]=0,a[13]=0,a[14]=2*e*d*g,a[15]=0,a},l.ortho=function(a,b,c,d,e,f,g){var h=1/(b-c),i=1/(d-e),j=1/(f-g);return a[0]=-2*h,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=-2*i,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=2*j,a[11]=0,a[12]=(b+c)*h,a[13]=(e+d)*i,a[14]=(g+f)*j,a[15]=1,a},l.lookAt=function(a,c,d,e){var f,g,h,i,j,k,m,n,o,p,q=c[0],r=c[1],s=c[2],t=e[0],u=e[1],v=e[2],w=d[0],x=d[1],y=d[2];return Math.abs(q-w)<b&&Math.abs(r-x)<b&&Math.abs(s-y)<b?l.identity(a):(m=q-w,n=r-x,o=s-y,p=1/Math.sqrt(m*m+n*n+o*o),m*=p,n*=p,o*=p,f=u*o-v*n,g=v*m-t*o,h=t*n-u*m,p=Math.sqrt(f*f+g*g+h*h),p?(p=1/p,f*=p,g*=p,h*=p):(f=0,g=0,h=0),i=n*h-o*g,j=o*f-m*h,k=m*g-n*f,p=Math.sqrt(i*i+j*j+k*k),p?(p=1/p,i*=p,j*=p,k*=p):(i=0,j=0,k=0),a[0]=f,a[1]=i,a[2]=m,a[3]=0,a[4]=g,a[5]=j,a[6]=n,a[7]=0,a[8]=h,a[9]=k,a[10]=o,a[11]=0,a[12]=-(f*q+g*r+h*s),a[13]=-(i*q+j*r+k*s),a[14]=-(m*q+n*r+o*s),a[15]=1,a)},l.str=function(a){return"mat4("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+")"},"undefined"!=typeof a&&(a.mat4=l);var m={};m.create=function(){var a=new c(4);return a[0]=0,a[1]=0,a[2]=0,a[3]=1,a},m.rotationTo=function(){var a=g.create(),b=g.fromValues(1,0,0),c=g.fromValues(0,1,0);return function(d,e,f){var h=g.dot(e,f);return-.999999>h?(g.cross(a,b,e),g.length(a)<1e-6&&g.cross(a,c,e),g.normalize(a,a),m.setAxisAngle(d,a,Math.PI),d):h>.999999?(d[0]=0,d[1]=0,d[2]=0,d[3]=1,d):(g.cross(a,e,f),d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=1+h,m.normalize(d,d))}}(),m.setAxes=function(){var a=k.create();return function(b,c,d,e){return a[0]=d[0],a[3]=d[1],a[6]=d[2],a[1]=e[0],a[4]=e[1],a[7]=e[2],a[2]=c[0],a[5]=c[1],a[8]=c[2],m.normalize(b,m.fromMat3(b,a))}}(),m.clone=h.clone,m.fromValues=h.fromValues,m.copy=h.copy,m.set=h.set,m.identity=function(a){return a[0]=0,a[1]=0,a[2]=0,a[3]=1,a},m.setAxisAngle=function(a,b,c){c*=.5;var d=Math.sin(c);return a[0]=d*b[0],a[1]=d*b[1],a[2]=d*b[2],a[3]=Math.cos(c),a},m.add=h.add,m.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1],j=c[2],k=c[3];return a[0]=d*k+g*h+e*j-f*i,a[1]=e*k+g*i+f*h-d*j,a[2]=f*k+g*j+d*i-e*h,a[3]=g*k-d*h-e*i-f*j,a},m.mul=m.multiply,m.scale=h.scale,m.rotateX=function(a,b,c){c*=.5;var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+g*h,a[1]=e*i+f*h,a[2]=f*i-e*h,a[3]=g*i-d*h,a},m.rotateY=function(a,b,c){c*=.5;var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i-f*h,a[1]=e*i+g*h,a[2]=f*i+d*h,a[3]=g*i-e*h,a},m.rotateZ=function(a,b,c){c*=.5;var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+e*h,a[1]=e*i-d*h,a[2]=f*i+g*h,a[3]=g*i-f*h,a},m.calculateW=function(a,b){var c=b[0],d=b[1],e=b[2];return a[0]=c,a[1]=d,a[2]=e,a[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e)),a},m.dot=h.dot,m.lerp=h.lerp,m.slerp=function(a,b,c,d){var e,f,g,h,i,j=b[0],k=b[1],l=b[2],m=b[3],n=c[0],o=c[1],p=c[2],q=c[3];return f=j*n+k*o+l*p+m*q,0>f&&(f=-f,n=-n,o=-o,p=-p,q=-q),1-f>1e-6?(e=Math.acos(f),g=Math.sin(e),h=Math.sin((1-d)*e)/g,i=Math.sin(d*e)/g):(h=1-d,i=d),a[0]=h*j+i*n,a[1]=h*k+i*o,a[2]=h*l+i*p,a[3]=h*m+i*q,a},m.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*c+d*d+e*e+f*f,h=g?1/g:0;return a[0]=-c*h,a[1]=-d*h,a[2]=-e*h,a[3]=f*h,a},m.conjugate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a[2]=-b[2],a[3]=b[3],a},m.length=h.length,m.len=m.length,m.squaredLength=h.squaredLength,m.sqrLen=m.squaredLength,m.normalize=h.normalize,m.fromMat3=function(){var a="undefined"!=typeof Int8Array?new Int8Array([1,2,0]):[1,2,0];return function(b,c){var d,e=c[0]+c[4]+c[8];if(e>0)d=Math.sqrt(e+1),b[3]=.5*d,d=.5/d,b[0]=(c[7]-c[5])*d,b[1]=(c[2]-c[6])*d,b[2]=(c[3]-c[1])*d;else{var f=0;c[4]>c[0]&&(f=1),c[8]>c[3*f+f]&&(f=2);var g=a[f],h=a[g];d=Math.sqrt(c[3*f+f]-c[3*g+g]-c[3*h+h]+1),b[f]=.5*d,d=.5/d,b[3]=(c[3*h+g]-c[3*g+h])*d,b[g]=(c[3*g+f]+c[3*f+g])*d,b[h]=(c[3*h+f]+c[3*f+h])*d}return b}}(),m.str=function(a){return"quat("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof a&&(a.quat=m)}(b.exports)}(this);
\ No newline at end of file
diff --git a/docs/assets/favicon.png b/docs/assets/favicon.png
index 5a95dda..29f57d9 100644
Binary files a/docs/assets/favicon.png and b/docs/assets/favicon.png differ
diff --git a/gruntfile.js b/gruntfile.js
index ed94436..6e0a3a5 100644
--- a/gruntfile.js
+++ b/gruntfile.js
@@ -1,22 +1,22 @@
 module.exports = function(grunt) {
 
-	require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
+	require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
 
 	// Project configuration.
 	grunt.initConfig({
-		pkg: grunt.file.readJSON('package.json'),
+		pkg: grunt.file.readJSON("package.json"),
 
-		BASE_PATH: '',
-		DEVELOPMENT_PATH: '',
+		BASE_PATH: "",
+		DEVELOPMENT_PATH: "",
 
 		ts: {
 			build: {
 				src: ["./src/**/*.ts"],
-				out: './build/kiwi.js',
+				out: "./build/kiwi.js",
 
 				options: {
-					target: 'es5',
-					module: 'commonjs',
+					target: "es5",
+					module: "commonjs",
 					sourcemap: false,
 					declaration: true,
 					comments: true
@@ -26,15 +26,15 @@ module.exports = function(grunt) {
 
 		yuidoc: {
 			compile: {
-				name: '<%= pkg.name %>',
-				description: '<%= pkg.description %>',
-				version: '<%= pkg.version %>',
-				url: '<%= pkg.homepage %>',
+				name: "<%= pkg.name %>",
+				description: "<%= pkg.description %>",
+				version: "<%= pkg.version %>",
+				url: "<%= pkg.homepage %>",
 
 				options: {
-					extension: '.ts',
-					paths: '<%= DEVELOPMENT_PATH %>' + 'src/',
-					outdir: '<%= BASE_PATH %>' + 'docs/'
+					extension: ".ts",
+					paths: "<%= DEVELOPMENT_PATH %>" + "src/",
+					outdir: "<%= BASE_PATH %>" + "docs/"
 				}
 			}
 		},
@@ -42,19 +42,19 @@ module.exports = function(grunt) {
 		uglify: {
 			build: {
 				files: {
-					'build/kiwi.min.js': ['build/kiwi.js']
+					"build/kiwi.min.js": ["build/kiwi.js"]
 				}
 			}
 		},
 
 		concat: {
 			build: {
-				src: ['build/kiwi.js', 'src/gl-matrix-min.js'],
-				dest: 'build/kiwi.js'
+				src: ["build/kiwi.js", "src/gl-matrix-min.js"],
+				dest: "build/kiwi.js"
 			},
 			buildmin: {
-				src: ['build/kiwi.min.js', 'src/gl-matrix-min.js'],
-				dest: 'build/kiwi.min.js'
+				src: ["build/kiwi.min.js", "src/gl-matrix-min.js"],
+				dest: "build/kiwi.min.js"
 			}
 		},
 
@@ -69,30 +69,36 @@ module.exports = function(grunt) {
 
 		copy: {
 			doclogo: {
-				src: 'docstyles/logo.png',
-				dest: 'docs/assets/css/logo.png'
+				src: "docstyles/logo.png",
+				dest: "docs/assets/css/logo.png"
 			},
 
 			docfavicon: {
-				src: 'docstyles/favicon.png',
-				dest: 'docs/assets/favicon.png'
+				src: "docstyles/favicon.png",
+				dest: "docs/assets/favicon.png"
 			},
 
 			docstyles: {
-				src: 'docstyles/main.css',
-				dest: 'docs/assets/css/main.css'
+				src: "docstyles/main.css",
+				dest: "docs/assets/css/main.css"
 			},
 
 			templateGame: {
-				src: './build/kiwi.js',
-				dest: './templateGame/lib/kiwi.js'
+				src: "./build/kiwi.js",
+				dest: "./templateGame/lib/kiwi.js"
 			}
 		}
 	});
 
-	grunt.registerTask("default", ["ts:build", "tslint", "concat:build", "uglify:build", "copy:templateGame"]);
-	grunt.registerTask("full", ["ts:build", "concat:build", "uglify:build", "yuidoc:compile", "copy:templateGame", "copy:doclogo", "copy:docstyles"]);
-	grunt.registerTask("docs", ["yuidoc:compile", "copy:doclogo", "copy:docstyles", "copy:docfavicon"]);
-	grunt.registerTask("join", ["concat:build"]);
-
-};
\ No newline at end of file
+	grunt.registerTask( "default", [
+		"ts:build", "tslint", "concat:build", "uglify:build",
+		"copy:templateGame" ] );
+	grunt.registerTask( "full", [
+		"ts:build", "tslint", "concat:build", "uglify:build",
+		"yuidoc:compile", "copy:templateGame",
+		"copy:doclogo", "copy:docstyles", "copy:docfavicon" ] );
+	grunt.registerTask( "docs", [
+		"yuidoc:compile", "copy:doclogo",
+		"copy:docstyles", "copy:docfavicon" ] );
+	grunt.registerTask( "join", [ "concat:build" ] );
+};
diff --git a/src/components/ArcadePhysics.ts b/src/components/ArcadePhysics.ts
index 151ec6c..aecfdd8 100644
--- a/src/components/ArcadePhysics.ts
+++ b/src/components/ArcadePhysics.ts
@@ -327,10 +327,13 @@ module Kiwi.Components {
 		public parent: Kiwi.Entity;
 
 		/**
-		* Sets the parents rotation to be equal to the trajectory of the velocity of the physics component. 
+		* Sets the parent's rotation to be equal to the trajectory of the
+		* velocity of the physics component. Note that rotation 0 corresponds
+		* to pointing directly to the right.
 		* @method rotateToVelocity
-		* @return { Number }
+		* @return {number} New rotation value
 		* @public
+		* @since 1.3.0
 		*/
 		public rotateToVelocity (): number {
 
diff --git a/src/core/Entity.ts b/src/core/Entity.ts
index 0ea4024..f28bfe8 100644
--- a/src/core/Entity.ts
+++ b/src/core/Entity.ts
@@ -570,6 +570,7 @@ module Kiwi {
 		* @property _inputEnabled
 		* @type boolean
 		* @private
+		* @deprecated As of 1.2.3, nothing was found to use this.
 		*/
 		private _inputEnabled: boolean;
 
@@ -579,6 +580,7 @@ module Kiwi {
 		* @property inputEnabled
 		* @type boolean
 		* @public
+		* @deprecated As of 1.2.3, nothing was found to use this.
 		*/
 		public set inputEnabled(value: boolean) {
 			this._inputEnabled = value;
diff --git a/src/geom/Intersect.ts b/src/geom/Intersect.ts
index 2c4f438..acd5bdc 100644
--- a/src/geom/Intersect.ts
+++ b/src/geom/Intersect.ts
@@ -113,43 +113,51 @@ module Kiwi.Geom {
 
 		/**
 		* Check to see if a Line and a Line Segment intersect at any point. 
-		* Note: The first line passed is treated as if it extends infinately though space, 
-		* The second is treated as if it only exists between its two points.
+		* Note: The first line passed is treated as if it extends infinitely
+		* though space. The second is treated as if it only exists between
+		* its two points.
 		*
 		* @method lineToLineSegment
-		* @param line1 {Kiwi.Geom.Line} The first line to check. This is the one that will extend through space infinately.
-		* @param seg {Kiwi.Geom.Line} The second line to check. This is the one that will only exist between its two coordinates.
-		* @param [output] {Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-		* @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection.
+		* @param line1 {Kiwi.Geom.Line} The first line to check.
+			This is the one that will extend through space infinately.
+		* @param seg {Kiwi.Geom.Line} The second line to check.
+			This is the one that will only exist between its two coordinates.
+		* @param [output] {Kiwi.Geom.IntersectResult} An optional
+			IntersectResult object to store the intersection values in. One is
+			created if none given.
+		* @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+			containing the results of this intersection.
 		* @public
 		* @static
 		*/
-		static lineToLineSegment(line1: Line, seg: Line, output: IntersectResult = new IntersectResult): IntersectResult {
+		static lineToLineSegment( line1: Line, seg: Line, output: IntersectResult = new IntersectResult ): IntersectResult {
 
 			output.result = false;
 
-			var denom = (line1.x1 - line1.x2) * (seg.y1 - seg.y2) - (line1.y1 - line1.y2) * (seg.x1 - seg.x2);
-
-			if (denom !== 0)
-			{
-				output.x = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (seg.x1 - seg.x2) - (line1.x1 - line1.x2) * (seg.x1 * seg.y2 - seg.y1 * seg.x2)) / denom;
-				output.y = ((line1.x1 * line1.y2 - line1.y1 * line1.x2) * (seg.y1 - seg.y2) - (line1.y1 - line1.y2) * (seg.x1 * seg.y2 - seg.y1 * seg.x2)) / denom;
-
-				var maxX = Math.max(seg.x1, seg.x2);
-				var minX = Math.min(seg.x1, seg.x2);
-				var maxY = Math.max(seg.y1, seg.y2);
-				var minY = Math.min(seg.y1, seg.y2);
+			var denom = ( line1.x1 - line1.x2 ) * ( seg.y1 - seg.y2 ) -
+				( line1.y1 - line1.y2 ) * ( seg.x1 - seg.x2 );
 
-				//if (!(output.x <= maxX && output.x >= minX) || !(output.y <= maxY && output.y >= minY))
-				if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true)
-				{
+			if ( denom !== 0 ) {
+				output.x = ( ( line1.x1 * line1.y2 - line1.y1 * line1.x2 ) *
+					( seg.x1 - seg.x2 ) - ( line1.x1 - line1.x2 ) *
+					( seg.x1 * seg.y2 - seg.y1 * seg.x2 ) ) / denom;
+				output.y = ( ( line1.x1 * line1.y2 - line1.y1 * line1.x2 ) *
+					( seg.y1 - seg.y2 ) - (line1.y1 - line1.y2 ) *
+					( seg.x1 * seg.y2 - seg.y1 * seg.x2 ) ) / denom;
+
+				var maxX = Math.max( seg.x1, seg.x2 );
+				var minX = Math.min( seg.x1, seg.x2 );
+				var maxY = Math.max( seg.y1, seg.y2 );
+				var minY = Math.min( seg.y1, seg.y2 );
+
+				if ( ( output.x <= maxX && output.x >= minX ) === true &&
+					( output.y <= maxY && output.y >= minY ) === true ) {
 					output.result = true;
 				}
 
 			}
 
 			return output;
-
 		}
 
 		/**
@@ -344,20 +352,24 @@ module Kiwi.Geom {
 		}
 
 		/**
-		* -------------------------------------------------------------------------------------------
+		* ---------------------------------------------------------------------
 		* Line Segment
-		* -------------------------------------------------------------------------------------------
+		* ---------------------------------------------------------------------
 		**/
 
 		/**
 		* Checks to see if two Line Segments intersect at any point in space. 
-		* Note: Both lines are treated as if they only exist between their two line coordinates.
+		* Note: Both lines are treated as if they only exist between their two
+		* line coordinates.
 		* 
 		* @method lineSegmentToLineSegment
 		* @param line1 {Kiwi.Geom.Line} The first line object to check.
 		* @param line2 {Kiwi.Geom.Line} The second line object to check.
-		* @param [output]{Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-		* @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection in x/y.
+		* @param [output]{Kiwi.Geom.IntersectResult} An optional
+			IntersectResult object to store the intersection values in.
+			One is created if none given.
+		* @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+			containing the results of this intersection in x/y.
 		* @public
 		* @static
 		*/
@@ -365,13 +377,13 @@ module Kiwi.Geom {
 
 			output.result = false;
 
-			Intersect.lineToLineSegment(line1, line2, output);
+			Intersect.lineToLineSegment( line1, line2, output );
 
-			if (output.result === true)
-			{
-				if (!(output.x >= Math.min(line1.x1, line1.x2) && output.x <= Math.max(line1.x1, line1.x2)
-					&& output.y >= Math.min(line1.y1, line1.y2) && output.y <= Math.max(line1.y1, line1.y2)))
-				{
+			if ( output.result === true ) {
+				if ( !( output.x >= Math.min( line1.x1, line1.x2 ) &&
+						output.x <= Math.max( line1.x1, line1.x2 ) &&
+						output.y >= Math.min( line1.y1, line1.y2 ) &&
+						output.y <= Math.max( line1.y1, line1.y2 ) ) ) {
 					output.result = false;
 				}
 			}
diff --git a/src/time/Clock.ts b/src/time/Clock.ts
index db090bb..c57549e 100644
--- a/src/time/Clock.ts
+++ b/src/time/Clock.ts
@@ -1,29 +1,41 @@
 /**
-* 
 * @module Kiwi
 * @submodule Time
-*
 */
 
 module Kiwi.Time {
 
 	/**
-	* The Clock class offers a way of tracking time within a game. When creating a new Clock you should NOT directly instantiate this class but instead use the addClock method on a ClockManager.
-	* - The MasterClock is a property of the Kiwi.Time.Manager class and tracks real world time in milliseconds elapsed since the application started. This happens automatically and there is no need to do anything to set this up.
-	* - An instance of a clock is used to track time in arbitrary units (milliseconds by default)
-	* - A clock can be started, paused, unpaused and stopped. Once stopped, re-starting the clock again will reset it. It can also have its time scale freely transformed.
-	* - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer class for timer details.
-	* - If the clock is paused, any timers attached to the clock will take this into account and not continue to fire events until the clock is unpaused. (Note that this is not the same as pausing timers, which can be done manually and needs to be undone manually.)
+	* The Clock class offers a way of tracking time within a game.
+	* When creating a new Clock you should NOT directly instantiate this class
+	* but instead use the addClock method on a ClockManager.
+	* - The MasterClock is a property of the Kiwi.Time.Manager class and tracks
+	*   real world time in milliseconds elapsed since the application started.
+	*   This happens automatically and there is no need to do anything to set
+	*   this up.
+	* - An instance of a clock is used to track time in arbitrary units
+	*   (milliseconds by default)
+	* - A clock can be started, paused, unpaused and stopped. Once stopped,
+	*   re-starting the clock again will reset it. It can also have its time
+	*   scale freely transformed.
+	* - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer
+	*   class for timer details.
+	* - If the clock is paused, any timers attached to the clock will take this
+	*   into account and not continue to fire events until the clock is
+	*   unpaused. (Note that this is not the same as pausing timers, which can
+	*   be done manually and needs to be undone manually.)
 	* - Animations and TweenManagers can use any Clock.
 	* 
 	* @class Clock
 	* @namespace Kiwi.Time
 	* @constructor
-	* @param manager {ClockManager} The ClockManager that this clock belongs to.
-	* @param master {Kiwi.Time.MasterClock} The MasterClock that it is getting the time in relation to.
-	* @param name {String} The name of the clock.
-	* @param [units=1000] {Number} The units that this clock is to operate in per second.
-	* @return {Kiwi.Time.Clock} This Clock object.
+	* @param manager {ClockManager} ClockManager that this clock belongs to
+	* @param master {Kiwi.Time.MasterClock} MasterClock that this is getting
+	*	the time in relation to
+	* @param name {String} Name of the clock
+	* @param [units=1000] {Number} Units that this clock is to operate in
+	*	per second
+	* @return {Kiwi.Time.Clock} This Clock object
 	*/
 	export class Clock {
 
@@ -44,7 +56,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* The type of object that this is.
+		* The type of object that this is
 		* @method objType
 		* @return {String} "Clock"
 		* @public
@@ -54,7 +66,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* A collection of Timer objects using this clock.
+		* Collection of Timer objects using this clock
 		* @property timers
 		* @type Timer[]
 		* @private
@@ -62,7 +74,7 @@ module Kiwi.Time {
 		private timers: Kiwi.Time.Timer[];
 
 		/**
-		* The time the clock was first started relative to the master clock.
+		* Time the clock was first started relative to the master clock
 		* @property _timeFirstStarted
 		* @type Number
 		* @default null
@@ -71,9 +83,9 @@ module Kiwi.Time {
 		private _timeFirstStarted: number = null;
 
 		/**
-		* The number of clock units elapsed since the clock was first started.
-		* @method elapsedSinceFirstStarted.
-		* @return {Number} number of clock units.
+		* Number of clock units elapsed since the clock was first started
+		* @method elapsedSinceFirstStarted
+		* @return {Number} Number of clock units elapsed
 		* @public
 		*/
 		public elapsedSinceFirstStarted(): number {
@@ -83,7 +95,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* The time the clock was most recently started relative to the master clock.
+		* Most recent time the clock was started relative to the master clock
 		* @property _timeLastStarted
 		* @type Number
 		* @default null
@@ -92,9 +104,9 @@ module Kiwi.Time {
 		private _timeLastStarted: number = null;
 
 		/**
-		* Get the most recent time the clock was started relative to the master clock.
+		* Most recent time the clock was started relative to the master clock
 		* @method started
-		* @return {Number} milliseconds.
+		* @return {Number} Milliseconds
 		* @public
 		*/
 		public started(): number {
@@ -106,7 +118,7 @@ module Kiwi.Time {
 
 		/**
 		* Rate at which time passes on this clock.
-		* 1 is normal speed. 0 is no speed. -1 is backwards.
+		* 1 is normal speed. 1.5 is faster. 0 is no speed. -1 is backwards.
 		* This mostly affects timers, animations and tweens.
 		* @property timeScale
 		* @type number
@@ -189,9 +201,10 @@ module Kiwi.Time {
 
 
 		/**
-		* The number of clock units elapsed since the clock was most recently started (not including time spent paused)
+		* Number of clock units elapsed since the clock was most recently
+		* started (not including time spent paused)
 		* @method elapsed
-		* @return {Number} number of clock units.
+		* @return {Number} Number of clock units
 		* @public
 		*/
 		public elapsed(): number {
@@ -199,7 +212,8 @@ module Kiwi.Time {
 		}
 
 		/**
-		* The time the clock was most recently stopped relative to the master clock.
+		* Time the clock was most recently stopped relative to the
+		* master clock.
 		* @property _timeLastStopped
 		* @type Number
 		* @default null
@@ -208,9 +222,10 @@ module Kiwi.Time {
 		private _timeLastStopped: number = null;
 
 		/**
-		* The number of clock units elapsed since the clock was most recently stopped.
-		* @method elapsedSinceLastStopped.
-		* @return {Number} number of clock units.
+		* Number of clock units elapsed since the clock was most recently
+		* stopped.
+		* @method elapsedSinceLastStopped
+		* @return {Number} Number of clock units
 		* @public
 		*/
 		public elapsedSinceLastStopped(): number {
@@ -220,7 +235,8 @@ module Kiwi.Time {
 		}
 
 		/**
-		* The time the clock was most receently paused relative to the master clock.
+		* Time the clock was most receently paused relative to the
+		* master clock.
 		* @property _timeLastPaused
 		* @private
 		* @type Number
@@ -230,9 +246,9 @@ module Kiwi.Time {
 		private _timeLastPaused: number = null;
 
 		/**
-		* The number of clock units elapsed since the clock was most recently paused.
-		* @method elapsedSinceLastPaused.
-		* @return {Number} number of clock units.
+		* Number of clock units elapsed since the clock was most recently paused.
+		* @method elapsedSinceLastPaused
+		* @return {Number} Number of clock units
 		* @public
 		*/
 		public elapsedSinceLastPaused(): number {
@@ -242,7 +258,8 @@ module Kiwi.Time {
 		}
 
 		/**
-		* The time the clock was most recently unpaused relative to the master clock.
+		* Time the clock was most recently unpaused relative to the
+		* master clock.
 		* @property _timeLastUnpaused
 		* @private
 		* @type Number
@@ -252,9 +269,10 @@ module Kiwi.Time {
 		private _timeLastUnpaused: number = null;
 
 		/**
-		* The number of clock units elapsed since the clock was most recently unpaused.
-		* @method elapsedSinceLastUnpaused.
-		* @return {Number} number of clock units.
+		* Number of clock units elapsed since the clock was most recently
+		* unpaused.
+		* @method elapsedSinceLastUnpaused
+		* @return {Number} Number of clock units
 		* @public
 		*/
 		public elapsedSinceLastUnpaused(): number {
@@ -264,7 +282,8 @@ module Kiwi.Time {
 		}
 
 		/**
-		* The total number of milliseconds the clock has been paused since it was last started.
+		* Total number of milliseconds the clock has been paused
+		* since it was last started
 		* @property _totalPaused
 		* @private
 		* @type Number
@@ -274,7 +293,7 @@ module Kiwi.Time {
 		private _totalPaused: number = 0;
 
 		/**
-		* Whether the clock is in a running state.
+		* Whether the clock is in a running state
 		* @property _isRunning
 		* @type boolean
 		* @default false
@@ -283,9 +302,9 @@ module Kiwi.Time {
 		private _isRunning: boolean = false;
 
 		/**
-		* Check if the clock is currently running.
+		* Check if the clock is currently running
 		* @method isRunning
-		* @return {boolean} true if running.
+		* @return {boolean} `true` if running
 		* @public
 		*/
 		public isRunning(): boolean {
@@ -295,7 +314,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Whether the clock is in a stopped state.
+		* Whether the clock is in a stopped state
 		* @property _isStopped
 		* @type boolean
 		* @default true
@@ -304,9 +323,9 @@ module Kiwi.Time {
 		private _isStopped: boolean = true;
 
 		/**
-		* Check if the clock is in the stopped state.
+		* Check if the clock is in the stopped state
 		* @method isStopped
-		* @return {boolean} true if stopped.
+		* @return {boolean} `true` if stopped
 		* @public
 		*/
 		public isStopped(): boolean {
@@ -316,7 +335,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Whether the clock is in a paused state.
+		* Whether the clock is in a paused state
 		* @property _isPaused
 		* @type boolean
 		* @default false
@@ -325,9 +344,9 @@ module Kiwi.Time {
 		private _isPaused: boolean = false;
 
 		/**
-		* Check if the clock is in the paused state.
+		* Check if the clock is in the paused state
 		* @method isPaused
-		* @return {boolean} true if paused.
+		* @return {boolean} `true` if paused
 		* @public
 		*/
 		public isPaused(): boolean {
@@ -337,7 +356,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* An internal reference to the state of the elapsed timer
+		* Internal reference to the state of the elapsed timer
 		* @property _elapsedState
 		* @type Number
 		* @private
@@ -345,7 +364,7 @@ module Kiwi.Time {
 		private _elapsedState: number = Kiwi.Time.Clock._RUNNING;
 
 		/**
-		* The time manager that this clock belongs to.
+		* Time manager that this clock belongs to
 		* @property manager
 		* @type ClockManager 
 		* @public
@@ -353,7 +372,7 @@ module Kiwi.Time {
 		public manager: Kiwi.Time.ClockManager = null;
 
 		/**
-		* The master clock.
+		* Master clock from which time is derived
 		* @property master
 		* @type Kiwi.Time.MasterClock
 		* @public
@@ -369,7 +388,7 @@ module Kiwi.Time {
 		public name: string = null;
 
 		/**
-		* The number of milliseconds counted as one unit of time by the clock.
+		* Number of milliseconds counted as one unit of time by the clock
 		* @property units
 		* @type Number
 		* @default 0
@@ -422,8 +441,8 @@ module Kiwi.Time {
 		/**
 		* Add an existing Timer to the Clock.
 		* @method addTimer
-		* @param timer {Timer} Timer object instance to be added to this Clock.
-		* @return {Kiwi.Time.Clock} This Clock object.
+		* @param timer {Timer} Timer object instance to be added to this Clock
+		* @return {Kiwi.Time.Clock} This Clock object
 		* @public
 		*/
 		public addTimer(timer: Timer): Clock {
@@ -434,13 +453,15 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Creates a new Timer and adds it to this Clock.
+		* Create a new Timer and add it to this Clock.
 		* @method createTimer
-		* @param name {string} The name of the Timer (must be unique on this Clock).
-		* @param [delay=1] {Number} The number of clock units to wait between firing events (default 1)
-		* @param [repeatCount=0] {Number} The number of times to repeat this Timer (default 0)
-		* @param [start=true] {Boolean} If the timer should start.
-		* @return {Kiwi.Time.Timer} The newly created Timer.
+		* @param name {string} Name of the Timer (must be unique on this Clock)
+		* @param [delay=1] {Number} Number of clock units to wait between
+		*	firing events
+		* @param [repeatCount=0] {Number} Number of times to repeat the Timer 
+		*	(default 0)
+		* @param [start=true] {Boolean} If the timer should start
+		* @return {Kiwi.Time.Timer} The newly created Timer
 		* @public
 		*/
 		public createTimer(name: string, delay: number = 1, repeatCount: number = 0, start: boolean=true): Timer {
@@ -456,11 +477,13 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Remove a Timer from this Clock based on either the Timer object or its name.
+		* Remove a Timer from this Clock based on either the Timer object
+		* or its name.
 		* @method removeTimer
-		* @param [timer=null] {Timer} The Timer object you wish to remove. If you wish to delete by Timer Name set this to null.
-		* @param [timerName=''] {string} The name of the Timer object to remove.
-		* @return {boolean} True if the Timer was successfully removed, false if not.
+		* @param [timer=null] {Timer} Timer object you wish to remove.
+		*	If you wish to delete by Timer Name set this to null.
+		* @param [timerName=''] {string} Name of the Timer object to remove
+		* @return {boolean} `true` if the Timer was successfully removed
 		* @public
 		*/
 		public removeTimer(timer: Timer = null, timerName:string = ""): boolean {
@@ -486,10 +509,10 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Check if the Timer already exists on this Clock
+		* Check if the Timer already exists on this Clock.
 		* @method checkExists
-		* @param name {string} The name of the Timer.
-		* @return {boolean} true if the Timer exists, false if not.
+		* @param name {string} Name of the Timer
+		* @return {boolean} `true` if the Timer exists
 		* @public
 		*/
 		public checkExists(name: string): boolean {
@@ -508,7 +531,7 @@ module Kiwi.Time {
 		/**
 		* Stop all timers attached to the clock.
 		* @method stopAllTimers
-		* @return {Clock} This Clock object.
+		* @return {Clock} This Clock object
 		* @public
 		*/
 		public stopAllTimers(): Clock {
@@ -524,9 +547,9 @@ module Kiwi.Time {
 
 		/**
 		* Convert a number to milliseconds based on clock units.
-		* @method toMilliseconds.
-		* @param time {number} seconds
-		* @return {Number} milliseconds.
+		* @method toMilliseconds
+		* @param time {number} Seconds
+		* @return {Number} Milliseconds
 		* @public
 		*/
 		public convertToMilliseconds(time: number): number {
@@ -536,7 +559,7 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Updates all Timers linked to this Clock.
+		* Update all Timers linked to this Clock.
 		* @method update
 		* @public
 		*/
@@ -571,7 +594,7 @@ module Kiwi.Time {
 		/**
 		* Start the clock. This resets the clock and starts it running.
 		* @method start
-		* @return {Clock} This Clock object.
+		* @return {Clock} This Clock object
 		* @public
 		*/
 		public start(): Clock {
@@ -590,14 +613,18 @@ module Kiwi.Time {
 
 			this._elapsedState = Kiwi.Time.Clock._RUNNING;
 
+			this._elapsed = 0;
+			this._lastMasterElapsed = this.master.elapsed();
+			this._currentMasterElapsed = this.master.elapsed();
+
 			return this;
 
 		}
 
 		/**
-		* Pause the clock. The clock can only be paused if it is already running.
+		* Pause the clock. This can only be paused if it is already running.
 		* @method pause
-		* @return {Kiwi.Time.Clock} This Clock object.
+		* @return {Kiwi.Time.Clock} This Clock object
 		* @public
 		*/
 		public pause(): Clock {
@@ -616,9 +643,9 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Resume the clock. The clock can only be resumed if it is already paused.
+		* Resume the clock. This can only be resumed if it is already paused.
 		* @method resume
-		* @return {Kiwi.Time.Clock} This Clock object.
+		* @return {Kiwi.Time.Clock} This Clock object
 		* @public
 		*/
 		public resume(): Clock {
@@ -639,9 +666,10 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Stop the clock. Clock can only be stopped if it is already running or is paused.
+		* Stop the clock. This can only be stopped if it is already running
+		*	or is paused.
 		* @method stop
-		* @return {Kiwi.Time.Clock} This Clock object.
+		* @return {Kiwi.Time.Clock} This Clock object
 		* @public
 		*/
 		public stop(): Clock {
@@ -667,9 +695,9 @@ module Kiwi.Time {
 		}
 
 		/**
-		* Returns a string representation of this object.
+		* Return a string representation of this object.
 		* @method toString
-		* @return {string} a string representation of the instance.
+		* @return {string} String representation of the instance
 		* @public
 		*/
 		public toString(): string {
@@ -681,24 +709,24 @@ module Kiwi.Time {
 
 		/**
 		* Set a function to execute after a certain time interval.
-		* Emulates window.setTimeout, except attached to a Kiwi.Time.Clock.
-		* This allows you to pause and manipulate time, and the timeout will respect
-		* the clock on which it is created.
+		* Emulates `window.setTimeout`, except attached to a `Kiwi.Time.Clock`.
+		* This allows you to pause and manipulate time, and the timeout will
+		* respect the clock on which it is created.
 		*
-		* No clearTimeout is provided; you should use Kiwi.Time.Timer functions
-		* to achieve further control.
+		* No `clearTimeout` is provided; you should use `Kiwi.Time.Timer`
+		* functions to achieve further control.
 		*
-		* Any parameters after "context" will be passed as parameters to the
-		* callback function. Note that you must specify "context" in order for
-		* this to work. You may specify "null", in which case it will default
-		* to the global scope "window".
+		* Any parameters after `context` will be passed as parameters to the
+		* callback function. Note that you must specify `context` in order for
+		* this to work. You may specify `null`, in which case it will default
+		* to the global scope `window`.
 		*
 		* @method setTimeout
 		* @param callback {function} Function to execute
 		* @param timeout {number} Milliseconds before execution
-		* @param [context] {object} Object to be "this" for the callback
-		* @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used to further
-		*   manipulate the timer
+		* @param [context] {object} Object to be `this` for the callback
+		* @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used
+		*	to further manipulate the timer
 		* @public
 		*/
 		public setTimeout( callback, timeout: number, context, ...args ): Timer {
@@ -724,22 +752,22 @@ module Kiwi.Time {
 
 		/**
 		* Set a function to repeatedly execute at fixed time intervals.
-		* Emulates window.setInterval, except attached to a Kiwi.Time.Clock.
-		* This allows you to pause and manipulate time, and the timeout will respect
-		* the clock on which it is created.
+		* Emulates `window.setInterval`, except attached to a `Kiwi.Time.Clock`.
+		* This allows you to pause and manipulate time, and the timeout will
+		* respect the clock on which it is created.
 		*
-		* No clearInterval is provided; you should use Kiwi.Time.Timer functions
-		* to achieve further control.
+		* No `clearInterval` is provided; you should use `Kiwi.Time.Timer`
+		* functions to achieve further control.
 		*
-		* Any parameters after "context" will be passed as parameters to the
-		* callback function. Note that you must specify "context" in order for
-		* this to work. You may specify "null", in which case it will default
-		* to the global scope "window".
+		* Any parameters after `context` will be passed as parameters to the
+		* callback function. Note that you must specify `context` in order for
+		* this to work. You may specify `null`, in which case it will default
+		* to the global scope `window`.
 		*
 		* @method setInterval
 		* @param callback {function} Function to execute
 		* @param timeout {number} Milliseconds between executions
-		* @param [context=window] {object} Object to be "this" for the callback
+		* @param [context=window] {object} Object to be `this` for the callback
 		* @return {Kiwi.Time.Timer} Kiwi.Time.Timer object
 		*   which can be used to further manipulate the timer
 		* @public
diff --git a/templateGame/lib/kiwi.js b/templateGame/lib/kiwi.js
index d6e0e1e..e147a0b 100644
--- a/templateGame/lib/kiwi.js
+++ b/templateGame/lib/kiwi.js
@@ -2811,6 +2811,7 @@ var Kiwi;
             * @property inputEnabled
             * @type boolean
             * @public
+            * @deprecated As of 1.2.3, nothing was found to use this.
             */
             set: function (value) {
                 this._inputEnabled = value;
@@ -8659,10 +8660,13 @@ var Kiwi;
                 this._callbackContext = callbackContext;
             };
             /**
-            * Sets the parents rotation to be equal to the trajectory of the velocity of the physics component.
+            * Sets the parent's rotation to be equal to the trajectory of the
+            * velocity of the physics component. Note that rotation 0 corresponds
+            * to pointing directly to the right.
             * @method rotateToVelocity
-            * @return { Number }
+            * @return {number} New rotation value
             * @public
+            * @since 1.3.0
             */
             ArcadePhysics.prototype.rotateToVelocity = function () {
                 var result = Math.atan2(this.velocity.y, this.velocity.x);
@@ -21317,14 +21321,20 @@ var Kiwi;
             };
             /**
             * Check to see if a Line and a Line Segment intersect at any point.
-            * Note: The first line passed is treated as if it extends infinately though space,
-            * The second is treated as if it only exists between its two points.
+            * Note: The first line passed is treated as if it extends infinitely
+            * though space. The second is treated as if it only exists between
+            * its two points.
             *
             * @method lineToLineSegment
-            * @param line1 {Kiwi.Geom.Line} The first line to check. This is the one that will extend through space infinately.
-            * @param seg {Kiwi.Geom.Line} The second line to check. This is the one that will only exist between its two coordinates.
-            * @param [output] {Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection.
+            * @param line1 {Kiwi.Geom.Line} The first line to check.
+                This is the one that will extend through space infinately.
+            * @param seg {Kiwi.Geom.Line} The second line to check.
+                This is the one that will only exist between its two coordinates.
+            * @param [output] {Kiwi.Geom.IntersectResult} An optional
+                IntersectResult object to store the intersection values in. One is
+                created if none given.
+            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+                containing the results of this intersection.
             * @public
             * @static
             */
@@ -21339,8 +21349,7 @@ var Kiwi;
                     var minX = Math.min(seg.x1, seg.x2);
                     var maxY = Math.max(seg.y1, seg.y2);
                     var minY = Math.min(seg.y1, seg.y2);
-                    //if (!(output.x <= maxX && output.x >= minX) || !(output.y <= maxY && output.y >= minY))
-                    if ((output.x <= maxX && output.x >= minX) === true || (output.y <= maxY && output.y >= minY) === true) {
+                    if ((output.x <= maxX && output.x >= minX) === true && (output.y <= maxY && output.y >= minY) === true) {
                         output.result = true;
                     }
                 }
@@ -21495,19 +21504,23 @@ var Kiwi;
                 return output;
             };
             /**
-            * -------------------------------------------------------------------------------------------
+            * ---------------------------------------------------------------------
             * Line Segment
-            * -------------------------------------------------------------------------------------------
+            * ---------------------------------------------------------------------
             **/
             /**
             * Checks to see if two Line Segments intersect at any point in space.
-            * Note: Both lines are treated as if they only exist between their two line coordinates.
+            * Note: Both lines are treated as if they only exist between their two
+            * line coordinates.
             *
             * @method lineSegmentToLineSegment
             * @param line1 {Kiwi.Geom.Line} The first line object to check.
             * @param line2 {Kiwi.Geom.Line} The second line object to check.
-            * @param [output]{Kiwi.Geom.IntersectResult} An optional IntersectResult object to store the intersection values in. One is created if none given.
-            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object containing the results of this intersection in x/y.
+            * @param [output]{Kiwi.Geom.IntersectResult} An optional
+                IntersectResult object to store the intersection values in.
+                One is created if none given.
+            * @return {Kiwi.Geom.IntersectResult} An IntersectResult object
+                containing the results of this intersection in x/y.
             * @public
             * @static
             */
@@ -27894,38 +27907,50 @@ var Kiwi;
     })(Sound = Kiwi.Sound || (Kiwi.Sound = {}));
 })(Kiwi || (Kiwi = {}));
 /**
-*
 * @module Kiwi
 * @submodule Time
-*
 */
 var Kiwi;
 (function (Kiwi) {
     var Time;
     (function (Time) {
         /**
-        * The Clock class offers a way of tracking time within a game. When creating a new Clock you should NOT directly instantiate this class but instead use the addClock method on a ClockManager.
-        * - The MasterClock is a property of the Kiwi.Time.Manager class and tracks real world time in milliseconds elapsed since the application started. This happens automatically and there is no need to do anything to set this up.
-        * - An instance of a clock is used to track time in arbitrary units (milliseconds by default)
-        * - A clock can be started, paused, unpaused and stopped. Once stopped, re-starting the clock again will reset it. It can also have its time scale freely transformed.
-        * - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer class for timer details.
-        * - If the clock is paused, any timers attached to the clock will take this into account and not continue to fire events until the clock is unpaused. (Note that this is not the same as pausing timers, which can be done manually and needs to be undone manually.)
+        * The Clock class offers a way of tracking time within a game.
+        * When creating a new Clock you should NOT directly instantiate this class
+        * but instead use the addClock method on a ClockManager.
+        * - The MasterClock is a property of the Kiwi.Time.Manager class and tracks
+        *   real world time in milliseconds elapsed since the application started.
+        *   This happens automatically and there is no need to do anything to set
+        *   this up.
+        * - An instance of a clock is used to track time in arbitrary units
+        *   (milliseconds by default)
+        * - A clock can be started, paused, unpaused and stopped. Once stopped,
+        *   re-starting the clock again will reset it. It can also have its time
+        *   scale freely transformed.
+        * - Any number of timers can be attached to a clock. See the Kiwi.Time.Timer
+        *   class for timer details.
+        * - If the clock is paused, any timers attached to the clock will take this
+        *   into account and not continue to fire events until the clock is
+        *   unpaused. (Note that this is not the same as pausing timers, which can
+        *   be done manually and needs to be undone manually.)
         * - Animations and TweenManagers can use any Clock.
         *
         * @class Clock
         * @namespace Kiwi.Time
         * @constructor
-        * @param manager {ClockManager} The ClockManager that this clock belongs to.
-        * @param master {Kiwi.Time.MasterClock} The MasterClock that it is getting the time in relation to.
-        * @param name {String} The name of the clock.
-        * @param [units=1000] {Number} The units that this clock is to operate in per second.
-        * @return {Kiwi.Time.Clock} This Clock object.
+        * @param manager {ClockManager} ClockManager that this clock belongs to
+        * @param master {Kiwi.Time.MasterClock} MasterClock that this is getting
+        *	the time in relation to
+        * @param name {String} Name of the clock
+        * @param [units=1000] {Number} Units that this clock is to operate in
+        *	per second
+        * @return {Kiwi.Time.Clock} This Clock object
         */
         var Clock = (function () {
             function Clock(manager, master, name, units) {
                 if (units === void 0) { units = 1000; }
                 /**
-                * The time the clock was first started relative to the master clock.
+                * Time the clock was first started relative to the master clock
                 * @property _timeFirstStarted
                 * @type Number
                 * @default null
@@ -27933,7 +27958,7 @@ var Kiwi;
                 */
                 this._timeFirstStarted = null;
                 /**
-                * The time the clock was most recently started relative to the master clock.
+                * Most recent time the clock was started relative to the master clock
                 * @property _timeLastStarted
                 * @type Number
                 * @default null
@@ -27942,7 +27967,7 @@ var Kiwi;
                 this._timeLastStarted = null;
                 /**
                 * Rate at which time passes on this clock.
-                * 1 is normal speed. 0 is no speed. -1 is backwards.
+                * 1 is normal speed. 1.5 is faster. 0 is no speed. -1 is backwards.
                 * This mostly affects timers, animations and tweens.
                 * @property timeScale
                 * @type number
@@ -27983,7 +28008,8 @@ var Kiwi;
                 */
                 this._maxFrameDuration = -1;
                 /**
-                * The time the clock was most recently stopped relative to the master clock.
+                * Time the clock was most recently stopped relative to the
+                * master clock.
                 * @property _timeLastStopped
                 * @type Number
                 * @default null
@@ -27991,7 +28017,8 @@ var Kiwi;
                 */
                 this._timeLastStopped = null;
                 /**
-                * The time the clock was most receently paused relative to the master clock.
+                * Time the clock was most receently paused relative to the
+                * master clock.
                 * @property _timeLastPaused
                 * @private
                 * @type Number
@@ -28000,7 +28027,8 @@ var Kiwi;
                 */
                 this._timeLastPaused = null;
                 /**
-                * The time the clock was most recently unpaused relative to the master clock.
+                * Time the clock was most recently unpaused relative to the
+                * master clock.
                 * @property _timeLastUnpaused
                 * @private
                 * @type Number
@@ -28009,7 +28037,8 @@ var Kiwi;
                 */
                 this._timeLastUnpaused = null;
                 /**
-                * The total number of milliseconds the clock has been paused since it was last started.
+                * Total number of milliseconds the clock has been paused
+                * since it was last started
                 * @property _totalPaused
                 * @private
                 * @type Number
@@ -28018,7 +28047,7 @@ var Kiwi;
                 */
                 this._totalPaused = 0;
                 /**
-                * Whether the clock is in a running state.
+                * Whether the clock is in a running state
                 * @property _isRunning
                 * @type boolean
                 * @default false
@@ -28026,7 +28055,7 @@ var Kiwi;
                 */
                 this._isRunning = false;
                 /**
-                * Whether the clock is in a stopped state.
+                * Whether the clock is in a stopped state
                 * @property _isStopped
                 * @type boolean
                 * @default true
@@ -28034,7 +28063,7 @@ var Kiwi;
                 */
                 this._isStopped = true;
                 /**
-                * Whether the clock is in a paused state.
+                * Whether the clock is in a paused state
                 * @property _isPaused
                 * @type boolean
                 * @default false
@@ -28042,21 +28071,21 @@ var Kiwi;
                 */
                 this._isPaused = false;
                 /**
-                * An internal reference to the state of the elapsed timer
+                * Internal reference to the state of the elapsed timer
                 * @property _elapsedState
                 * @type Number
                 * @private
                 */
                 this._elapsedState = Kiwi.Time.Clock._RUNNING;
                 /**
-                * The time manager that this clock belongs to.
+                * Time manager that this clock belongs to
                 * @property manager
                 * @type ClockManager
                 * @public
                 */
                 this.manager = null;
                 /**
-                * The master clock.
+                * Master clock from which time is derived
                 * @property master
                 * @type Kiwi.Time.MasterClock
                 * @public
@@ -28070,7 +28099,7 @@ var Kiwi;
                 */
                 this.name = null;
                 /**
-                * The number of milliseconds counted as one unit of time by the clock.
+                * Number of milliseconds counted as one unit of time by the clock
                 * @property units
                 * @type Number
                 * @default 0
@@ -28089,7 +28118,7 @@ var Kiwi;
                 this._currentMasterElapsed = this.master.elapsed();
             }
             /**
-            * The type of object that this is.
+            * The type of object that this is
             * @method objType
             * @return {String} "Clock"
             * @public
@@ -28098,18 +28127,18 @@ var Kiwi;
                 return "Clock";
             };
             /**
-            * The number of clock units elapsed since the clock was first started.
-            * @method elapsedSinceFirstStarted.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was first started
+            * @method elapsedSinceFirstStarted
+            * @return {Number} Number of clock units elapsed
             * @public
             */
             Clock.prototype.elapsedSinceFirstStarted = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeFirstStarted) / this.units : null;
             };
             /**
-            * Get the most recent time the clock was started relative to the master clock.
+            * Most recent time the clock was started relative to the master clock
             * @method started
-            * @return {Number} milliseconds.
+            * @return {Number} Milliseconds
             * @public
             */
             Clock.prototype.started = function () {
@@ -28136,63 +28165,66 @@ var Kiwi;
                 configurable: true
             });
             /**
-            * The number of clock units elapsed since the clock was most recently started (not including time spent paused)
+            * Number of clock units elapsed since the clock was most recently
+            * started (not including time spent paused)
             * @method elapsed
-            * @return {Number} number of clock units.
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsed = function () {
                 return this._elapsed;
             };
             /**
-            * The number of clock units elapsed since the clock was most recently stopped.
-            * @method elapsedSinceLastStopped.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was most recently
+            * stopped.
+            * @method elapsedSinceLastStopped
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsedSinceLastStopped = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeLastStopped) / this.units : null;
             };
             /**
-            * The number of clock units elapsed since the clock was most recently paused.
-            * @method elapsedSinceLastPaused.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was most recently paused.
+            * @method elapsedSinceLastPaused
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsedSinceLastPaused = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeLastPaused) / this.units : null;
             };
             /**
-            * The number of clock units elapsed since the clock was most recently unpaused.
-            * @method elapsedSinceLastUnpaused.
-            * @return {Number} number of clock units.
+            * Number of clock units elapsed since the clock was most recently
+            * unpaused.
+            * @method elapsedSinceLastUnpaused
+            * @return {Number} Number of clock units
             * @public
             */
             Clock.prototype.elapsedSinceLastUnpaused = function () {
                 return (this._timeLastStarted) ? (this.master.elapsed() - this._timeLastUnpaused) / this.units : null;
             };
             /**
-            * Check if the clock is currently running.
+            * Check if the clock is currently running
             * @method isRunning
-            * @return {boolean} true if running.
+            * @return {boolean} `true` if running
             * @public
             */
             Clock.prototype.isRunning = function () {
                 return this._isRunning;
             };
             /**
-            * Check if the clock is in the stopped state.
+            * Check if the clock is in the stopped state
             * @method isStopped
-            * @return {boolean} true if stopped.
+            * @return {boolean} `true` if stopped
             * @public
             */
             Clock.prototype.isStopped = function () {
                 return this._isStopped;
             };
             /**
-            * Check if the clock is in the paused state.
+            * Check if the clock is in the paused state
             * @method isPaused
-            * @return {boolean} true if paused.
+            * @return {boolean} `true` if paused
             * @public
             */
             Clock.prototype.isPaused = function () {
@@ -28201,8 +28233,8 @@ var Kiwi;
             /**
             * Add an existing Timer to the Clock.
             * @method addTimer
-            * @param timer {Timer} Timer object instance to be added to this Clock.
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @param timer {Timer} Timer object instance to be added to this Clock
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.addTimer = function (timer) {
@@ -28210,13 +28242,15 @@ var Kiwi;
                 return this;
             };
             /**
-            * Creates a new Timer and adds it to this Clock.
+            * Create a new Timer and add it to this Clock.
             * @method createTimer
-            * @param name {string} The name of the Timer (must be unique on this Clock).
-            * @param [delay=1] {Number} The number of clock units to wait between firing events (default 1)
-            * @param [repeatCount=0] {Number} The number of times to repeat this Timer (default 0)
-            * @param [start=true] {Boolean} If the timer should start.
-            * @return {Kiwi.Time.Timer} The newly created Timer.
+            * @param name {string} Name of the Timer (must be unique on this Clock)
+            * @param [delay=1] {Number} Number of clock units to wait between
+            *	firing events
+            * @param [repeatCount=0] {Number} Number of times to repeat the Timer
+            *	(default 0)
+            * @param [start=true] {Boolean} If the timer should start
+            * @return {Kiwi.Time.Timer} The newly created Timer
             * @public
             */
             Clock.prototype.createTimer = function (name, delay, repeatCount, start) {
@@ -28230,11 +28264,13 @@ var Kiwi;
                 return this.timers[this.timers.length - 1];
             };
             /**
-            * Remove a Timer from this Clock based on either the Timer object or its name.
+            * Remove a Timer from this Clock based on either the Timer object
+            * or its name.
             * @method removeTimer
-            * @param [timer=null] {Timer} The Timer object you wish to remove. If you wish to delete by Timer Name set this to null.
-            * @param [timerName=''] {string} The name of the Timer object to remove.
-            * @return {boolean} True if the Timer was successfully removed, false if not.
+            * @param [timer=null] {Timer} Timer object you wish to remove.
+            *	If you wish to delete by Timer Name set this to null.
+            * @param [timerName=''] {string} Name of the Timer object to remove
+            * @return {boolean} `true` if the Timer was successfully removed
             * @public
             */
             Clock.prototype.removeTimer = function (timer, timerName) {
@@ -28260,10 +28296,10 @@ var Kiwi;
                 return false;
             };
             /**
-            * Check if the Timer already exists on this Clock
+            * Check if the Timer already exists on this Clock.
             * @method checkExists
-            * @param name {string} The name of the Timer.
-            * @return {boolean} true if the Timer exists, false if not.
+            * @param name {string} Name of the Timer
+            * @return {boolean} `true` if the Timer exists
             * @public
             */
             Clock.prototype.checkExists = function (name) {
@@ -28277,7 +28313,7 @@ var Kiwi;
             /**
             * Stop all timers attached to the clock.
             * @method stopAllTimers
-            * @return {Clock} This Clock object.
+            * @return {Clock} This Clock object
             * @public
             */
             Clock.prototype.stopAllTimers = function () {
@@ -28288,16 +28324,16 @@ var Kiwi;
             };
             /**
             * Convert a number to milliseconds based on clock units.
-            * @method toMilliseconds.
-            * @param time {number} seconds
-            * @return {Number} milliseconds.
+            * @method toMilliseconds
+            * @param time {number} Seconds
+            * @return {Number} Milliseconds
             * @public
             */
             Clock.prototype.convertToMilliseconds = function (time) {
                 return time * this.units;
             };
             /**
-            * Updates all Timers linked to this Clock.
+            * Update all Timers linked to this Clock.
             * @method update
             * @public
             */
@@ -28330,7 +28366,7 @@ var Kiwi;
             /**
             * Start the clock. This resets the clock and starts it running.
             * @method start
-            * @return {Clock} This Clock object.
+            * @return {Clock} This Clock object
             * @public
             */
             Clock.prototype.start = function () {
@@ -28343,12 +28379,15 @@ var Kiwi;
                 this._isPaused = false;
                 this._isStopped = false;
                 this._elapsedState = Kiwi.Time.Clock._RUNNING;
+                this._elapsed = 0;
+                this._lastMasterElapsed = this.master.elapsed();
+                this._currentMasterElapsed = this.master.elapsed();
                 return this;
             };
             /**
-            * Pause the clock. The clock can only be paused if it is already running.
+            * Pause the clock. This can only be paused if it is already running.
             * @method pause
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.pause = function () {
@@ -28362,9 +28401,9 @@ var Kiwi;
                 return this;
             };
             /**
-            * Resume the clock. The clock can only be resumed if it is already paused.
+            * Resume the clock. This can only be resumed if it is already paused.
             * @method resume
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.resume = function () {
@@ -28379,9 +28418,10 @@ var Kiwi;
                 return this;
             };
             /**
-            * Stop the clock. Clock can only be stopped if it is already running or is paused.
+            * Stop the clock. This can only be stopped if it is already running
+            *	or is paused.
             * @method stop
-            * @return {Kiwi.Time.Clock} This Clock object.
+            * @return {Kiwi.Time.Clock} This Clock object
             * @public
             */
             Clock.prototype.stop = function () {
@@ -28398,9 +28438,9 @@ var Kiwi;
                 return this;
             };
             /**
-            * Returns a string representation of this object.
+            * Return a string representation of this object.
             * @method toString
-            * @return {string} a string representation of the instance.
+            * @return {string} String representation of the instance
             * @public
             */
             Clock.prototype.toString = function () {
@@ -28408,24 +28448,24 @@ var Kiwi;
             };
             /**
             * Set a function to execute after a certain time interval.
-            * Emulates window.setTimeout, except attached to a Kiwi.Time.Clock.
-            * This allows you to pause and manipulate time, and the timeout will respect
-            * the clock on which it is created.
+            * Emulates `window.setTimeout`, except attached to a `Kiwi.Time.Clock`.
+            * This allows you to pause and manipulate time, and the timeout will
+            * respect the clock on which it is created.
             *
-            * No clearTimeout is provided; you should use Kiwi.Time.Timer functions
-            * to achieve further control.
+            * No `clearTimeout` is provided; you should use `Kiwi.Time.Timer`
+            * functions to achieve further control.
             *
-            * Any parameters after "context" will be passed as parameters to the
-            * callback function. Note that you must specify "context" in order for
-            * this to work. You may specify "null", in which case it will default
-            * to the global scope "window".
+            * Any parameters after `context` will be passed as parameters to the
+            * callback function. Note that you must specify `context` in order for
+            * this to work. You may specify `null`, in which case it will default
+            * to the global scope `window`.
             *
             * @method setTimeout
             * @param callback {function} Function to execute
             * @param timeout {number} Milliseconds before execution
-            * @param [context] {object} Object to be "this" for the callback
-            * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used to further
-            *   manipulate the timer
+            * @param [context] {object} Object to be `this` for the callback
+            * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object which can be used
+            *	to further manipulate the timer
             * @public
             */
             Clock.prototype.setTimeout = function (callback, timeout, context) {
@@ -28446,22 +28486,22 @@ var Kiwi;
             };
             /**
             * Set a function to repeatedly execute at fixed time intervals.
-            * Emulates window.setInterval, except attached to a Kiwi.Time.Clock.
-            * This allows you to pause and manipulate time, and the timeout will respect
-            * the clock on which it is created.
+            * Emulates `window.setInterval`, except attached to a `Kiwi.Time.Clock`.
+            * This allows you to pause and manipulate time, and the timeout will
+            * respect the clock on which it is created.
             *
-            * No clearInterval is provided; you should use Kiwi.Time.Timer functions
-            * to achieve further control.
+            * No `clearInterval` is provided; you should use `Kiwi.Time.Timer`
+            * functions to achieve further control.
             *
-            * Any parameters after "context" will be passed as parameters to the
-            * callback function. Note that you must specify "context" in order for
-            * this to work. You may specify "null", in which case it will default
-            * to the global scope "window".
+            * Any parameters after `context` will be passed as parameters to the
+            * callback function. Note that you must specify `context` in order for
+            * this to work. You may specify `null`, in which case it will default
+            * to the global scope `window`.
             *
             * @method setInterval
             * @param callback {function} Function to execute
             * @param timeout {number} Milliseconds between executions
-            * @param [context=window] {object} Object to be "this" for the callback
+            * @param [context=window] {object} Object to be `this` for the callback
             * @return {Kiwi.Time.Timer} Kiwi.Time.Timer object
             *   which can be used to further manipulate the timer
             * @public
