var gStorageAvailable = false; var gSFXMuted = false; var gMusicMuted = false; var gMenuMusicTimer = -1; var gFocused = true; var globalScale = 0.66; var BRAND = { NONE: 0, FGL: 1, ADDICTING: 2, MRG: 3, MELODI: 4 }; var gCurrentBrand = BRAND.MRG; /*! * VERSION: 1.11.4 * DATE: 2014-01-18 * UPDATES AND DOCS AT: http://www.greensock.com * * @license Copyright (c) 2008-2014, GreenSock. All rights reserved. * This work is subject to the terms at http://www.greensock.com/terms_of_use.html or for * Club GreenSock members, the software agreement that was issued with your membership. * * @author: Jack Doyle, jack@greensock.com */ (function(ap) { var aF = ap.GreenSockGlobals || ap; if (!aF.TweenLite) { var aB, aq, ar, aw, aJ, av = function(b) { var a, c = b.split("."), d = aF; for (a = 0; c.length > a; a++) { d[c[a]] = d = d[c[a]] || {} } return d }, ay = av("com.greensock"), aC = 1e-10, aK = [].slice, ao = function() {}, ax = function() { var a = Object.prototype.toString, b = a.call([]); return function(c) { return null != c && (c instanceof Array || "object" == typeof c && !!c.push && a.call(c) === b) } }(), aE = {}, au = function(c, d, e, f) { this.sc = aE[c] ? aE[c].sc : [], aE[c] = this, this.gsClass = null, this.func = e; var b = []; this.check = function(g) { for (var k, j, i, a, o = d.length, n = o; --o > -1;) { (k = aE[d[o]] || new au(d[o], [])).gsClass ? (b[o] = k.gsClass, n--) : g && k.sc.push(this) } if (0 === n && e) { for (j = ("com.greensock." + c).split("."), i = j.pop(), a = av(j.join("."))[i] = this.gsClass = e.apply(e, b), f && (aF[i] = a, "function" == typeof define && define.amd ? define((ap.GreenSockAMDPath ? ap.GreenSockAMDPath + "/" : "") + c.split(".").join("/"), [], function() { return a }) : "undefined" != typeof module && module.exports && (module.exports = a)), o = 0; this.sc.length > o; o++) { this.sc[o].check() } } }, this.check(!0) }, aH = ap._gsDefine = function(b, d, a, c) { return new au(b, d, a, c) }, aG = ay._class = function(b, c, a) { return c = c || function() {}, aH(b, [], function() { return c }, a), c }; aH.globals = aF; var an = [0, 0, 1, 1], aD = [], H = aG("easing.Ease", function(b, d, a, c) { this._func = b, this._type = a || 0, this._power = c || 0, this._params = d ? an.concat(d) : an }, !0), am = H.map = {}, W = H.register = function(p, j, f, q) { for (var b, d, k, c, g = j.split(","), l = g.length, m = (f || "easeIn,easeOut,easeInOut").split(","); --l > -1;) { for (d = g[l], b = q ? aG("easing." + d, null, !0) : ay.easing[d] || {}, k = m.length; --k > -1;) { c = m[k], am[d + "." + c] = am[c + d] = b[c] = p.getRatio ? p : p[c] || new p } } }; for (ar = H.prototype, ar._calcEnd = !1, ar.getRatio = function(b) { if (this._func) { return this._params[0] = b, this._func.apply(null, this._params) } var d = this._type, a = this._power, c = 1 === d ? 1 - b : 2 === d ? b : 0.5 > b ? 2 * b : 2 * (1 - b); return 1 === a ? c *= c : 2 === a ? c *= c * c : 3 === a ? c *= c * c * c : 4 === a && (c *= c * c * c * c), 1 === d ? 1 - c : 2 === d ? c : 0.5 > b ? c / 2 : 1 - c / 2 }, aB = ["Linear", "Quad", "Cubic", "Quart", "Quint,Strong"], aq = aB.length; --aq > -1;) { ar = aB[aq] + ",Power" + aq, W(new H(null, null, 1, aq), ar, "easeOut", !0), W(new H(null, null, 2, aq), ar, "easeIn" + (0 === aq ? ",easeNone" : "")), W(new H(null, null, 3, aq), ar, "easeInOut") } am.linear = ay.easing.Linear.easeIn, am.swing = ay.easing.Quad.easeInOut; var ak = aG("events.EventDispatcher", function(a) { this._listeners = {}, this._eventTarget = a || this }); ar = ak.prototype, ar.addEventListener = function(k, g, d, m, a) { a = a || 0; var b, c, f = this._listeners[k], j = 0; for (null == f && (this._listeners[k] = f = []), c = f.length; --c > -1;) { b = f[c], b.c === g && b.s === d ? f.splice(c, 1) : 0 === j && a > b.pr && (j = c + 1) } f.splice(j, 0, { c: g, s: d, up: m, pr: a }), this !== aw || aJ || aw.wake() }, ar.removeEventListener = function(b, d) { var a, c = this._listeners[b]; if (c) { for (a = c.length; --a > -1;) { if (c[a].c === d) { return c.splice(a, 1), void 0 } } } }, ar.dispatchEvent = function(b) { var f, a, c, d = this._listeners[b]; if (d) { for (f = d.length, a = this._eventTarget; --f > -1;) { c = d[f], c.up ? c.c.call(c.s || a, { type: b, target: a }) : c.c.call(c.s || a) } } }; var aI = ap.requestAnimationFrame, az = ap.cancelAnimationFrame, ai = Date.now || function() { return (new Date).getTime() }, J = ai(); for (aB = ["ms", "moz", "webkit", "o"], aq = aB.length; --aq > -1 && !aI;) { aI = ap[aB[aq] + "RequestAnimationFrame"], az = ap[aB[aq] + "CancelAnimationFrame"] || ap[aB[aq] + "CancelRequestAnimationFrame"] } aG("Ticker", function(q, n) { var g, u, a, b, d, j = this, p = ai(), c = n !== !1 && aI, k = function(f) { J = ai(), j.time = (J - p) / 1000; var h, i = j.time - d; (!g || i > 0 || f === !0) && (j.frame++, d += i + (i >= b ? 0.004 : b - i), h = !0), f !== !0 && (a = u(k)), h && j.dispatchEvent("tick") }; ak.call(j), j.time = j.frame = 0, j.tick = function() { k(!0) }, j.sleep = function() { null != a && (c && az ? az(a) : clearTimeout(a), u = ao, a = null, j === aw && (aJ = !1)) }, j.wake = function() { null !== a && j.sleep(), u = 0 === g ? ao : c && aI ? aI : function(e) { return setTimeout(e, 0 | 1000 * (d - j.time) + 1) }, j === aw && (aJ = !0), k(2) }, j.fps = function(e) { return arguments.length ? (g = e, b = 1 / (g || 60), d = this.time + b, j.wake(), void 0) : g }, j.useRAF = function(e) { return arguments.length ? (j.sleep(), c = e, j.fps(g), void 0) : c }, j.fps(q), setTimeout(function() { c && (!a || 5 > j.frame) && j.useRAF(!1) }, 1500) }), ar = ay.Ticker.prototype = new ay.events.EventDispatcher, ar.constructor = ay.Ticker; var al = aG("core.Animation", function(b, c) { if (this.vars = c = c || {}, this._duration = this._totalDuration = b || 0, this._delay = Number(c.delay) || 0, this._timeScale = 1, this._active = c.immediateRender === !0, this.data = c.data, this._reversed = c.reversed === !0, V) { aJ || aw.wake(); var a = this.vars.useFrames ? ac : V; a.add(this, a._time), this.vars.paused && this.paused(!0) } }); aw = al.ticker = new ay.Ticker, ar = al.prototype, ar._dirty = ar._gc = ar._initted = ar._paused = !1, ar._totalTime = ar._time = 0, ar._rawPrevTime = -1, ar._next = ar._last = ar._onUpdate = ar._timeline = ar.timeline = null, ar._paused = !1; var ag = function() { aJ && ai() - J > 2000 && aw.wake(), setTimeout(ag, 2000) }; ag(), ar.play = function(a, b) { return arguments.length && this.seek(a, b), this.reversed(!1).paused(!1) }, ar.pause = function(a, b) { return arguments.length && this.seek(a, b), this.paused(!0) }, ar.resume = function(a, b) { return arguments.length && this.seek(a, b), this.paused(!1) }, ar.seek = function(a, b) { return this.totalTime(Number(a), b !== !1) }, ar.restart = function(a, b) { return this.reversed(!1).paused(!1).totalTime(a ? -this._delay : 0, b !== !1, !0) }, ar.reverse = function(a, b) { return arguments.length && this.seek(a || this.totalDuration(), b), this.reversed(!0).paused(!1) }, ar.render = function() {}, ar.invalidate = function() { return this }, ar.isActive = function() { var b, c = this._timeline, a = this._startTime; return !c || !this._gc && !this._paused && c.isActive() && (b = c.rawTime()) >= a && a + this.totalDuration() / this._timeScale > b }, ar._enabled = function(a, b) { return aJ || aw.wake(), this._gc = !a, this._active = this.isActive(), b !== !0 && (a && !this.timeline ? this._timeline.add(this, this._startTime - this._delay) : !a && this.timeline && this._timeline._remove(this, !0)), !1 }, ar._kill = function() { return this._enabled(!1, !1) }, ar.kill = function(a, b) { return this._kill(a, b), this }, ar._uncache = function(a) { for (var b = a ? this : this.timeline; b;) { b._dirty = !0, b = b.timeline } return this }, ar._swapSelfInParams = function(b) { for (var c = b.length, a = b.concat(); --c > -1;) { "{self}" === b[c] && (a[c] = this) } return a }, ar.eventCallback = function(b, f, a, c) { if ("on" === (b || "").substr(0, 2)) { var d = this.vars; if (1 === arguments.length) { return d[b] } null == f ? delete d[b] : (d[b] = f, d[b + "Params"] = ax(a) && -1 !== a.join("").indexOf("{self}") ? this._swapSelfInParams(a) : a, d[b + "Scope"] = c), "onUpdate" === b && (this._onUpdate = f) } return this }, ar.delay = function(a) { return arguments.length ? (this._timeline.smoothChildTiming && this.startTime(this._startTime + a - this._delay), this._delay = a, this) : this._delay }, ar.duration = function(a) { return arguments.length ? (this._duration = this._totalDuration = a, this._uncache(!0), this._timeline.smoothChildTiming && this._time > 0 && this._time < this._duration && 0 !== a && this.totalTime(this._totalTime * (a / this._duration), !0), this) : (this._dirty = !1, this._duration) }, ar.totalDuration = function(a) { return this._dirty = !1, arguments.length ? this.duration(a) : this._totalDuration }, ar.time = function(a, b) { return arguments.length ? (this._dirty && this.totalDuration(), this.totalTime(a > this._duration ? this._duration : a, b)) : this._time }, ar.totalTime = function(b, f, a) { if (aJ || aw.wake(), !arguments.length) { return this._totalTime } if (this._timeline) { if (0 > b && !a && (b += this.totalDuration()), this._timeline.smoothChildTiming) { this._dirty && this.totalDuration(); var c = this._totalDuration, d = this._timeline; if (b > c && !a && (b = c), this._startTime = (this._paused ? this._pauseTime : d._time) - (this._reversed ? c - b : b) / this._timeScale, d._dirty || this._uncache(!1), d._timeline) { for (; d._timeline;) { d._timeline._time !== (d._startTime + d._totalTime) / d._timeScale && d.totalTime(d._totalTime, !0), d = d._timeline } } } this._gc && this._enabled(!0, !1), (this._totalTime !== b || 0 === this._duration) && this.render(b, f, !1) } return this }, ar.progress = ar.totalProgress = function(a, b) { return arguments.length ? this.totalTime(this.duration() * a, b) : this._time / this.duration() }, ar.startTime = function(a) { return arguments.length ? (a !== this._startTime && (this._startTime = a, this.timeline && this.timeline._sortChildren && this.timeline.add(this, a - this._delay)), this) : this._startTime }, ar.timeScale = function(b) { if (!arguments.length) { return this._timeScale } if (b = b || aC, this._timeline && this._timeline.smoothChildTiming) { var c = this._pauseTime, a = c || 0 === c ? c : this._timeline.totalTime(); this._startTime = a - (a - this._startTime) * this._timeScale / b } return this._timeScale = b, this._uncache(!1) }, ar.reversed = function(a) { return arguments.length ? (a != this._reversed && (this._reversed = a, this.totalTime(this._timeline && !this._timeline.smoothChildTiming ? this.totalDuration() - this._totalTime : this._totalTime, !0)), this) : this._reversed }, ar.paused = function(b) { if (!arguments.length) { return this._paused } if (b != this._paused && this._timeline) { aJ || b || aw.wake(); var d = this._timeline, a = d.rawTime(), c = a - this._pauseTime; !b && d.smoothChildTiming && (this._startTime += c, this._uncache(!1)), this._pauseTime = b ? a : null, this._paused = b, this._active = this.isActive(), !b && 0 !== c && this._initted && this.duration() && this.render(d.smoothChildTiming ? this._totalTime : (a - this._startTime) / this._timeScale, !0, !0) } return this._gc && !b && this._enabled(!0, !1), this }; var K = aG("core.SimpleTimeline", function(a) { al.call(this, 0, a), this.autoRemoveChildren = this.smoothChildTiming = !0 }); ar = K.prototype = new al, ar.constructor = K, ar.kill()._gc = !1, ar._first = ar._last = null, ar._sortChildren = !1, ar.add = ar.insert = function(b, d) { var a, c; if (b._startTime = Number(d || 0) + b._delay, b._paused && this !== b._timeline && (b._pauseTime = b._startTime + (this.rawTime() - b._startTime) / b._timeScale), b.timeline && b.timeline._remove(b, !0), b.timeline = b._timeline = this, b._gc && b._enabled(!0, !0), a = this._last, this._sortChildren) { for (c = b._startTime; a && a._startTime > c;) { a = a._prev } } return a ? (b._next = a._next, a._next = b) : (b._next = this._first, this._first = b), b._next ? b._next._prev = b : this._last = b, b._prev = a, this._timeline && this._uncache(!0), this }, ar._remove = function(a, b) { return a.timeline === this && (b || a._enabled(!1, !0), a.timeline = null, a._prev ? a._prev._next = a._next : this._first === a && (this._first = a._next), a._next ? a._next._prev = a._prev : this._last === a && (this._last = a._prev), this._timeline && this._uncache(!0)), this }, ar.render = function(b, f, a) { var c, d = this._first; for (this._totalTime = this._time = this._rawPrevTime = b; d;) { c = d._next, (d._active || b >= d._startTime && !d._paused) && (d._reversed ? d.render((d._dirty ? d.totalDuration() : d._totalDuration) - (b - d._startTime) * d._timeScale, f, a) : d.render((b - d._startTime) * d._timeScale, f, a)), d = c } }, ar.rawTime = function() { return aJ || aw.wake(), this._totalTime }; var af = aG("TweenLite", function(h, d, f) { if (al.call(this, d, f), this.render = af.prototype.render, null == h) { throw "Cannot tween a null target." } this.target = h = "string" != typeof h ? h : af.selector(h) || h; var g, k, c, j = h.jquery || h.length && h !== ap && h[0] && (h[0] === ap || h[0].nodeType && h[0].style && !h.nodeType), b = this.vars.overwrite; if (this._overwrite = b = null == b ? aA[af.defaultOverwrite] : "number" == typeof b ? b >> 0 : aA[b], (j || h instanceof Array || h.push && ax(h)) && "number" != typeof h[0]) { for (this._targets = c = aK.call(h, 0), this._propLookup = [], this._siblings = [], g = 0; c.length > g; g++) { k = c[g], k ? "string" != typeof k ? k.length && k !== ap && k[0] && (k[0] === ap || k[0].nodeType && k[0].style && !k.nodeType) ? (c.splice(g--, 1), this._targets = c = c.concat(aK.call(k, 0))) : (this._siblings[g] = ah(k, this, !1), 1 === b && this._siblings[g].length > 1 && at(k, this, null, 1, this._siblings[g])) : (k = c[g--] = af.selector(k), "string" == typeof k && c.splice(g + 1, 1)) : c.splice(g--, 1) } } else { this._propLookup = {}, this._siblings = ah(h, this, !1), 1 === b && this._siblings.length > 1 && at(h, this, null, 1, this._siblings) }(this.vars.immediateRender || 0 === d && 0 === this._delay && this.vars.immediateRender !== !1) && this.render(-this._delay, !1, !0) }, !0), ae = function(a) { return a.length && a !== ap && a[0] && (a[0] === ap || a[0].nodeType && a[0].style && !a.nodeType) }, ab = function(b, d) { var a, c = {}; for (a in b) { ad[a] || a in d && "x" !== a && "y" !== a && "width" !== a && "height" !== a && "className" !== a && "border" !== a || !(!Y[a] || Y[a] && Y[a]._autoCSS) || (c[a] = b[a], delete b[a]) } b.css = c }; ar = af.prototype = new al, ar.constructor = af, ar.kill()._gc = !1, ar.ratio = 0, ar._firstPT = ar._targets = ar._overwrittenProps = ar._startAt = null, ar._notifyPluginsOfEnabled = !1, af.version = "1.11.4", af.defaultEase = ar._ease = new H(null, null, 1, 1), af.defaultOverwrite = "auto", af.ticker = aw, af.autoSleep = !0, af.selector = ap.$ || ap.jQuery || function(a) { return ap.$ ? (af.selector = ap.$, ap.$(a)) : ap.document ? ap.document.getElementById("#" === a.charAt(0) ? a.substr(1) : a) : a }; var X = af._internals = { isArray: ax, isSelector: ae }, Y = af._plugins = {}, aa = af._tweenLookup = {}, z = 0, ad = X.reservedProps = { ease: 1, delay: 1, overwrite: 1, onComplete: 1, onCompleteParams: 1, onCompleteScope: 1, useFrames: 1, runBackwards: 1, startAt: 1, onUpdate: 1, onUpdateParams: 1, onUpdateScope: 1, onStart: 1, onStartParams: 1, onStartScope: 1, onReverseComplete: 1, onReverseCompleteParams: 1, onReverseCompleteScope: 1, onRepeat: 1, onRepeatParams: 1, onRepeatScope: 1, easeParams: 1, yoyo: 1, immediateRender: 1, repeat: 1, repeatDelay: 1, data: 1, paused: 1, reversed: 1, autoCSS: 1 }, aA = { none: 0, all: 1, auto: 2, concurrent: 3, allOnStart: 4, preexisting: 5, "true": 1, "false": 0 }, ac = al._rootFramesTimeline = new K, V = al._rootTimeline = new K; V._startTime = aw.time, ac._startTime = aw.frame, V._active = ac._active = !0, al._updateRoot = function() { if (V.render((aw.time - V._startTime) * V._timeScale, !1, !1), ac.render((aw.frame - ac._startTime) * ac._timeScale, !1, !1), !(aw.frame % 120)) { var b, c, a; for (a in aa) { for (c = aa[a].tweens, b = c.length; --b > -1;) { c[b]._gc && c.splice(b, 1) } 0 === c.length && delete aa[a] } if (a = V._first, (!a || a._paused) && af.autoSleep && !ac._first && 1 === aw._listeners.tick.length) { for (; a && a._paused;) { a = a._next } a || aw.sleep() } } }, aw.addEventListener("tick", al._updateRoot); var ah = function(b, f, a) { var c, d, g = b._gsTweenID; if (aa[g || (b._gsTweenID = g = "t" + z++)] || (aa[g] = { target: b, tweens: [] }), f && (c = aa[g].tweens, c[d = c.length] = f, a)) { for (; --d > -1;) { c[d] === f && c.splice(d, 1) } } return aa[g].tweens }, at = function(A, v, k, B, b) { var g, w, d, j; if (1 === B || B >= 4) { for (j = b.length, g = 0; j > g; g++) { if ((d = b[g]) !== v) { d._gc || d._enabled(!1, !1) && (w = !0) } else { if (5 === B) { break } } } return w } var x, y = v._startTime + aC, h = [], q = 0, c = 0 === v._duration; for (g = b.length; --g > -1;) { (d = b[g]) === v || d._gc || d._paused || (d._timeline !== v._timeline ? (x = x || aj(v, 0, c), 0 === aj(d, x, c) && (h[q++] = d)) : y >= d._startTime && d._startTime + d.totalDuration() / d._timeScale > y && ((c || !d._initted) && 2e-10 >= y - d._startTime || (h[q++] = d))) } for (g = q; --g > -1;) { d = h[g], 2 === B && d._kill(k, A) && (w = !0), (2 !== B || !d._firstPT && d._initted) && d._enabled(!1, !1) && (w = !0) } return w }, aj = function(b, f, a) { for (var c = b._timeline, d = c._timeScale, g = b._startTime; c._timeline;) { if (g += c._startTime, d *= c._timeScale, c._paused) { return -100 } c = c._timeline } return g /= d, g > f ? g - f : a && g === f || !b._initted && 2 * aC > g - f ? aC : (g += b.totalDuration() / b._timeScale / d) > f + aC ? 0 : g - f - aC }; ar._init = function() { var k, h, g, m, b = this.vars, d = this._overwrittenProps, j = this._duration, c = b.immediateRender, f = b.ease; if (b.startAt) { if (this._startAt && this._startAt.render(-1, !0), b.startAt.overwrite = 0, b.startAt.immediateRender = !0, this._startAt = af.to(this.target, 0, b.startAt), c) { if (this._time > 0) { this._startAt = null } else { if (0 !== j) { return } } } } else { if (b.runBackwards && 0 !== j) { if (this._startAt) { this._startAt.render(-1, !0), this._startAt = null } else { g = {}; for (m in b) { ad[m] && "autoCSS" !== m || (g[m] = b[m]) } if (g.overwrite = 0, g.data = "isFromStart", this._startAt = af.to(this.target, 0, g), b.immediateRender) { if (0 === this._time) { return } } else { this._startAt.render(-1, !0) } } } } if (this._ease = f ? f instanceof H ? b.easeParams instanceof Array ? f.config.apply(f, b.easeParams) : f : "function" == typeof f ? new H(f, b.easeParams) : am[f] || af.defaultEase : af.defaultEase, this._easeType = this._ease._type, this._easePower = this._ease._power, this._firstPT = null, this._targets) { for (k = this._targets.length; --k > -1;) { this._initProps(this._targets[k], this._propLookup[k] = {}, this._siblings[k], d ? d[k] : null) && (h = !0) } } else { h = this._initProps(this.target, this._propLookup, this._siblings, d) } if (h && af._onPluginEvent("_onInitAllProps", this), d && (this._firstPT || "function" != typeof this.target && this._enabled(!1, !1)), b.runBackwards) { for (g = this._firstPT; g;) { g.s += g.c, g.c = -g.c, g = g._next } } this._onUpdate = b.onUpdate, this._initted = !0 }, ar._initProps = function(k, g, q, b) { var d, m, c, f, j, p; if (null == k) { return !1 } this.vars.css || k.style && k !== ap && k.nodeType && Y.css && this.vars.autoCSS !== !1 && ab(this.vars, k); for (d in this.vars) { if (p = this.vars[d], ad[d]) { p && (p instanceof Array || p.push && ax(p)) && -1 !== p.join("").indexOf("{self}") && (this.vars[d] = p = this._swapSelfInParams(p, this)) } else { if (Y[d] && (f = new Y[d])._onInitTween(k, this.vars[d], this)) { for (this._firstPT = j = { _next: this._firstPT, t: f, p: "setRatio", s: 0, c: 1, f: !0, n: d, pg: !0, pr: f._priority }, m = f._overwriteProps.length; --m > -1;) { g[f._overwriteProps[m]] = this._firstPT }(f._priority || f._onInitAllProps) && (c = !0), (f._onDisable || f._onEnable) && (this._notifyPluginsOfEnabled = !0) } else { this._firstPT = g[d] = j = { _next: this._firstPT, t: k, p: d, f: "function" == typeof k[d], n: d, pg: !1, pr: 0 }, j.s = j.f ? k[d.indexOf("set") || "function" != typeof k["get" + d.substr(3)] ? d : "get" + d.substr(3)]() : parseFloat(k[d]), j.c = "string" == typeof p && "=" === p.charAt(1) ? parseInt(p.charAt(0) + "1", 10) * Number(p.substr(2)) : Number(p) - j.s || 0 } } j && j._next && (j._next._prev = j) } return b && this._kill(b, k) ? this._initProps(k, g, q, b) : this._overwrite > 1 && this._firstPT && q.length > 1 && at(k, this, g, this._overwrite, q) ? (this._kill(g, k), this._initProps(k, g, q, b)) : c }, ar.render = function(v, j, h) { var w, b, d, k, c = this._time, g = this._duration; if (v >= g) { this._totalTime = this._time = g, this.ratio = this._ease._calcEnd ? this._ease.getRatio(1) : 1, this._reversed || (w = !0, b = "onComplete"), 0 === g && (k = this._rawPrevTime, (0 === v || 0 > k || k === aC) && k !== v && (h = !0, k > aC && (b = "onReverseComplete")), this._rawPrevTime = k = !j || v || 0 === k ? v : aC) } else { if (1e-7 > v) { this._totalTime = this._time = 0, this.ratio = this._ease._calcEnd ? this._ease.getRatio(0) : 0, (0 !== c || 0 === g && this._rawPrevTime > aC) && (b = "onReverseComplete", w = this._reversed), 0 > v ? (this._active = !1, 0 === g && (this._rawPrevTime >= 0 && (h = !0), this._rawPrevTime = k = !j || v || 0 === this._rawPrevTime ? v : aC)) : this._initted || (h = !0) } else { if (this._totalTime = this._time = v, this._easeType) { var p = v / g, q = this._easeType, f = this._easePower; (1 === q || 3 === q && p >= 0.5) && (p = 1 - p), 3 === q && (p *= 2), 1 === f ? p *= p : 2 === f ? p *= p * p : 3 === f ? p *= p * p * p : 4 === f && (p *= p * p * p * p), this.ratio = 1 === q ? 1 - p : 2 === q ? p : 0.5 > v / g ? p / 2 : 1 - p / 2 } else { this.ratio = this._ease.getRatio(v / g) } } } if (this._time !== c || h) { if (!this._initted) { if (this._init(), !this._initted || this._gc) { return } this._time && !w ? this.ratio = this._ease.getRatio(this._time / g) : w && this._ease._calcEnd && (this.ratio = this._ease.getRatio(0 === this._time ? 0 : 1)) } for (this._active || !this._paused && this._time !== c && v >= 0 && (this._active = !0), 0 === c && (this._startAt && (v >= 0 ? this._startAt.render(v, j, h) : b || (b = "_dummyGS")), this.vars.onStart && (0 !== this._time || 0 === g) && (j || this.vars.onStart.apply(this.vars.onStartScope || this, this.vars.onStartParams || aD))), d = this._firstPT; d;) { d.f ? d.t[d.p](d.c * this.ratio + d.s) : d.t[d.p] = d.c * this.ratio + d.s, d = d._next } this._onUpdate && (0 > v && this._startAt && this._startTime && this._startAt.render(v, j, h), j || (this._time !== c || w) && this._onUpdate.apply(this.vars.onUpdateScope || this, this.vars.onUpdateParams || aD)), b && (this._gc || (0 > v && this._startAt && !this._onUpdate && this._startTime && this._startAt.render(v, j, h), w && (this._timeline.autoRemoveChildren && this._enabled(!1, !1), this._active = !1), !j && this.vars[b] && this.vars[b].apply(this.vars[b + "Scope"] || this, this.vars[b + "Params"] || aD), 0 === g && this._rawPrevTime === aC && k !== aC && (this._rawPrevTime = 0))) } }, ar._kill = function(p, k) { if ("all" === p && (p = null), null == p && (null == k || k === this.target)) { return this._enabled(!1, !1) } k = "string" != typeof k ? k || this._targets || this.target : af.selector(k) || k; var g, q, b, d, m, c, f, j; if ((ax(k) || ae(k)) && "number" != typeof k[0]) { for (g = k.length; --g > -1;) { this._kill(p, k[g]) && (c = !0) } } else { if (this._targets) { for (g = this._targets.length; --g > -1;) { if (k === this._targets[g]) { m = this._propLookup[g] || {}, this._overwrittenProps = this._overwrittenProps || [], q = this._overwrittenProps[g] = p ? this._overwrittenProps[g] || {} : "all"; break } } } else { if (k !== this.target) { return !1 } m = this._propLookup, q = this._overwrittenProps = p ? this._overwrittenProps || {} : "all" } if (m) { f = p || m, j = p !== q && "all" !== q && p !== m && ("object" != typeof p || !p._tempKill); for (b in f) { (d = m[b]) && (d.pg && d.t._kill(f) && (c = !0), d.pg && 0 !== d.t._overwriteProps.length || (d._prev ? d._prev._next = d._next : d === this._firstPT && (this._firstPT = d._next), d._next && (d._next._prev = d._prev), d._next = d._prev = null), delete m[b]), j && (q[b] = 1) }!this._firstPT && this._initted && this._enabled(!1, !1) } } return c }, ar.invalidate = function() { return this._notifyPluginsOfEnabled && af._onPluginEvent("_onDisable", this), this._firstPT = null, this._overwrittenProps = null, this._onUpdate = null, this._startAt = null, this._initted = this._active = this._notifyPluginsOfEnabled = !1, this._propLookup = this._targets ? {} : [], this }, ar._enabled = function(b, d) { if (aJ || aw.wake(), b && this._gc) { var a, c = this._targets; if (c) { for (a = c.length; --a > -1;) { this._siblings[a] = ah(c[a], this, !0) } } else { this._siblings = ah(this.target, this, !0) } } return al.prototype._enabled.call(this, b, d), this._notifyPluginsOfEnabled && this._firstPT ? af._onPluginEvent(b ? "_onEnable" : "_onDisable", this) : !1 }, af.to = function(b, c, a) { return new af(b, c, a) }, af.from = function(b, c, a) { return a.runBackwards = !0, a.immediateRender = 0 != a.immediateRender, new af(b, c, a) }, af.fromTo = function(b, d, a, c) { return c.startAt = a, c.immediateRender = 0 != c.immediateRender && 0 != a.immediateRender, new af(b, d, c) }, af.delayedCall = function(b, f, a, c, d) { return new af(f, 0, { delay: b, onComplete: f, onCompleteParams: a, onCompleteScope: c, onReverseComplete: f, onReverseCompleteParams: a, onReverseCompleteScope: c, immediateRender: !1, useFrames: d, overwrite: 0 }) }, af.set = function(a, b) { return new af(a, 0, b) }, af.getTweensOf = function(b, f) { if (null == b) { return [] } b = "string" != typeof b ? b : af.selector(b) || b; var a, c, d, g; if ((ax(b) || ae(b)) && "number" != typeof b[0]) { for (a = b.length, c = []; --a > -1;) { c = c.concat(af.getTweensOf(b[a], f)) } for (a = c.length; --a > -1;) { for (g = c[a], d = a; --d > -1;) { g === c[d] && c.splice(a, 1) } } } else { for (c = ah(b).concat(), a = c.length; --a > -1;) { (c[a]._gc || f && !c[a].isActive()) && c.splice(a, 1) } } return c }, af.killTweensOf = af.killDelayedCallsTo = function(b, f, a) { "object" == typeof f && (a = f, f = !1); for (var c = af.getTweensOf(b, f), d = c.length; --d > -1;) { c[d]._kill(a, b) } }; var Z = aG("plugins.TweenPlugin", function(a, b) { this._overwriteProps = (a || "").split(","), this._propName = this._overwriteProps[0], this._priority = b || 0, this._super = Z.prototype }, !0); if (ar = Z.prototype, Z.version = "1.10.1", Z.API = 2, ar._firstPT = null, ar._addTween = function(d, h, c, f, g, k) { var b, j; return null != f && (b = "number" == typeof f || "=" !== f.charAt(1) ? Number(f) - c : parseInt(f.charAt(0) + "1", 10) * Number(f.substr(2))) ? (this._firstPT = j = { _next: this._firstPT, t: d, p: h, s: c, c: b, f: "function" == typeof d[h], n: g || h, r: k }, j._next && (j._next._prev = j), j) : void 0 }, ar.setRatio = function(b) { for (var d, a = this._firstPT, c = 0.000001; a;) { d = a.c * b + a.s, a.r ? d = 0 | d + (d > 0 ? 0.5 : -0.5) : c > d && d > -c && (d = 0), a.f ? a.t[a.p](d) : a.t[a.p] = d, a = a._next } }, ar._kill = function(b) { var d, a = this._overwriteProps, c = this._firstPT; if (null != b[this._propName]) { this._overwriteProps = [] } else { for (d = a.length; --d > -1;) { null != b[a[d]] && a.splice(d, 1) } } for (; c;) { null != b[c.n] && (c._next && (c._next._prev = c._prev), c._prev ? (c._prev._next = c._next, c._prev = null) : this._firstPT === c && (this._firstPT = c._next)), c = c._next } return !1 }, ar._roundProps = function(b, c) { for (var a = this._firstPT; a;) { (b[this._propName] || null != a.n && b[a.n.split(this._propName + "_").join("")]) && (a.r = c), a = a._next } }, af._onPluginEvent = function(d, h) { var c, f, g, k, b, j = h._firstPT; if ("_onInitAllProps" === d) { for (; j;) { for (b = j._next, f = g; f && f.pr > j.pr;) { f = f._next }(j._prev = f ? f._prev : k) ? j._prev._next = j: g = j, (j._next = f) ? f._prev = j : k = j, j = b } j = h._firstPT = g } for (; j;) { j.pg && "function" == typeof j.t[d] && j.t[d]() && (c = !0), j = j._next } return c }, Z.activate = function(a) { for (var b = a.length; --b > -1;) { a[b].API === Z.API && (Y[(new a[b])._propName] = a[b]) } return !0 }, aH.plugin = function(d) { if (!(d && d.propName && d.init && d.API)) { throw "illegal plugin definition." } var h, c = d.propName, f = d.priority || 0, g = d.overwriteProps, k = { init: "_onInitTween", set: "setRatio", kill: "_kill", round: "_roundProps", initAll: "_onInitAllProps" }, b = aG("plugins." + c.charAt(0).toUpperCase() + c.substr(1) + "Plugin", function() { Z.call(this, c, f), this._overwriteProps = g || [] }, d.global === !0), j = b.prototype = new Z(c); j.constructor = b, b.API = d.API; for (h in k) { "function" == typeof d[h] && (j[k[h]] = d[h]) } return b.version = d.version, Z.activate([b]), b }, aB = ap._gsQueue) { for (aq = 0; aB.length > aq; aq++) { aB[aq]() } for (ar in aE) { aE[ar].func || ap.console.log("GSAP encountered missing dependency: com.greensock." + ar) } } aJ = !1 } })(window); /*! * VERSION: beta 1.9.3 * DATE: 2013-04-02 * UPDATES AND DOCS AT: http://www.greensock.com * * @license Copyright (c) 2008-2014, GreenSock. All rights reserved. * This work is subject to the terms at http://www.greensock.com/terms_of_use.html or for * Club GreenSock members, the software agreement that was issued with your membership. * * @author: Jack Doyle, jack@greensock.com **/ (window._gsQueue || (window._gsQueue = [])).push(function() { window._gsDefine("easing.Back", ["easing.Ease"], function(F) { var z, w, G, b = window.GreenSockGlobals || window, k = b.com.greensock, C = 2 * Math.PI, j = Math.PI / 2, x = k._class, v = function(f, a) { var c = x("easing." + f, function() {}, !0), d = c.prototype = new F; return d.constructor = c, d.getRatio = a, c }, D = F.register || function() {}, E = function(c, h, a, d) { var f = x("easing." + c, { easeOut: new h, easeIn: new a, easeInOut: new d }, !0); return D(f, c), f }, B = function(c, d, a) { this.t = c, this.v = d, a && (this.next = a, a.prev = this, this.c = a.v - d, this.gap = a.t - c) }, g = function(f, a) { var c = x("easing." + f, function(e) { this._p1 = e || 0 === e ? e : 1.70158, this._p2 = 1.525 * this._p1 }, !0), d = c.prototype = new F; return d.constructor = c, d.getRatio = a, d.config = function(e) { return new c(e) }, c }, y = E("Back", g("BackOut", function(a) { return (a -= 1) * a * ((this._p1 + 1) * a + this._p1) + 1 }), g("BackIn", function(a) { return a * a * ((this._p1 + 1) * a - this._p1) }), g("BackInOut", function(a) { return 1 > (a *= 2) ? 0.5 * a * a * ((this._p2 + 1) * a - this._p2) : 0.5 * ((a -= 2) * a * ((this._p2 + 1) * a + this._p2) + 2) })), q = x("easing.SlowMo", function(c, d, a) { d = d || 0 === d ? d : 0.7, null == c ? c = 0.7 : c > 1 && (c = 1), this._p = 1 !== c ? d : 0, this._p1 = (1 - c) / 2, this._p2 = c, this._p3 = this._p1 + this._p2, this._calcEnd = a === !0 }, !0), A = q.prototype = new F; return A.constructor = q, A.getRatio = function(a) { var c = a + (0.5 - a) * this._p; return this._p1 > a ? this._calcEnd ? 1 - (a = 1 - a / this._p1) * a : c - (a = 1 - a / this._p1) * a * a * a * c : a > this._p3 ? this._calcEnd ? 1 - (a = (a - this._p3) / this._p1) * a : c + (a - c) * (a = (a - this._p3) / this._p1) * a * a * a : this._calcEnd ? 1 : c }, q.ease = new q(0.7, 0.7), A.config = q.config = function(c, d, a) { return new q(c, d, a) }, z = x("easing.SteppedEase", function(a) { a = a || 1, this._p1 = 1 / a, this._p2 = a + 1 }, !0), A = z.prototype = new F, A.constructor = z, A.getRatio = function(a) { return 0 > a ? a = 0 : a >= 1 && (a = 0.999999999), (this._p2 * a >> 0) * this._p1 }, A.config = z.config = function(a) { return new z(a) }, w = x("easing.RoughEase", function(P) { P = P || {}; for (var L, U, c, I, R, H, M = P.taper || "none", K = [], S = 0, T = 0 | (P.points || 20), t = T, O = P.randomize !== !1, J = P.clamp === !0, Q = P.template instanceof F ? P.template : null, N = "number" == typeof P.strength ? 0.4 * P.strength : 0.4; --t > -1;) { L = O ? Math.random() : 1 / T * t, U = Q ? Q.getRatio(L) : L, "none" === M ? c = N : "out" === M ? (I = 1 - L, c = I * I * N) : "in" === M ? c = L * L * N : 0.5 > L ? (I = 2 * L, c = 0.5 * I * I * N) : (I = 2 * (1 - L), c = 0.5 * I * I * N), O ? U += Math.random() * c - 0.5 * c : t % 2 ? U += 0.5 * c : U -= 0.5 * c, J && (U > 1 ? U = 1 : 0 > U && (U = 0)), K[S++] = { x: L, y: U } } for (K.sort(function(a, d) { return a.x - d.x }), H = new B(1, 1, null), t = T; --t > -1;) { R = K[t], H = new B(R.x, R.y, H) } this._prev = new B(0, 0, 0 !== H.t ? H : H.next) }, !0), A = w.prototype = new F, A.constructor = w, A.getRatio = function(a) { var c = this._prev; if (a > c.t) { for (; c.next && a >= c.t;) { c = c.next } c = c.prev } else { for (; c.prev && c.t >= a;) { c = c.prev } } return this._prev = c, c.v + (a - c.t) / c.gap * c.c }, A.config = function(a) { return new w(a) }, w.ease = new w, E("Bounce", v("BounceOut", function(a) { return 1 / 2.75 > a ? 7.5625 * a * a : 2 / 2.75 > a ? 7.5625 * (a -= 1.5 / 2.75) * a + 0.75 : 2.5 / 2.75 > a ? 7.5625 * (a -= 2.25 / 2.75) * a + 0.9375 : 7.5625 * (a -= 2.625 / 2.75) * a + 0.984375 }), v("BounceIn", function(a) { return 1 / 2.75 > (a = 1 - a) ? 1 - 7.5625 * a * a : 2 / 2.75 > a ? 1 - (7.5625 * (a -= 1.5 / 2.75) * a + 0.75) : 2.5 / 2.75 > a ? 1 - (7.5625 * (a -= 2.25 / 2.75) * a + 0.9375) : 1 - (7.5625 * (a -= 2.625 / 2.75) * a + 0.984375) }), v("BounceInOut", function(a) { var c = 0.5 > a; return a = c ? 1 - 2 * a : 2 * a - 1, a = 1 / 2.75 > a ? 7.5625 * a * a : 2 / 2.75 > a ? 7.5625 * (a -= 1.5 / 2.75) * a + 0.75 : 2.5 / 2.75 > a ? 7.5625 * (a -= 2.25 / 2.75) * a + 0.9375 : 7.5625 * (a -= 2.625 / 2.75) * a + 0.984375, c ? 0.5 * (1 - a) : 0.5 * a + 0.5 })), E("Circ", v("CircOut", function(a) { return Math.sqrt(1 - (a -= 1) * a) }), v("CircIn", function(a) { return -(Math.sqrt(1 - a * a) - 1) }), v("CircInOut", function(a) { return 1 > (a *= 2) ? -0.5 * (Math.sqrt(1 - a * a) - 1) : 0.5 * (Math.sqrt(1 - (a -= 2) * a) + 1) })), G = function(f, a, c) { var d = x("easing." + f, function(i, l) { this._p1 = i || 1, this._p2 = l || c, this._p3 = this._p2 / C * (Math.asin(1 / this._p1) || 0) }, !0), h = d.prototype = new F; return h.constructor = d, h.getRatio = a, h.config = function(i, l) { return new d(i, l) }, d }, E("Elastic", G("ElasticOut", function(a) { return this._p1 * Math.pow(2, -10 * a) * Math.sin((a - this._p3) * C / this._p2) + 1 }, 0.3), G("ElasticIn", function(a) { return -(this._p1 * Math.pow(2, 10 * (a -= 1)) * Math.sin((a - this._p3) * C / this._p2)) }, 0.3), G("ElasticInOut", function(a) { return 1 > (a *= 2) ? -0.5 * this._p1 * Math.pow(2, 10 * (a -= 1)) * Math.sin((a - this._p3) * C / this._p2) : 0.5 * this._p1 * Math.pow(2, -10 * (a -= 1)) * Math.sin((a - this._p3) * C / this._p2) + 1 }, 0.45)), E("Expo", v("ExpoOut", function(a) { return 1 - Math.pow(2, -10 * a) }), v("ExpoIn", function(a) { return Math.pow(2, 10 * (a - 1)) - 0.001 }), v("ExpoInOut", function(a) { return 1 > (a *= 2) ? 0.5 * Math.pow(2, 10 * (a - 1)) : 0.5 * (2 - Math.pow(2, -10 * (a - 1))) })), E("Sine", v("SineOut", function(a) { return Math.sin(a * j) }), v("SineIn", function(a) { return -Math.cos(a * j) + 1 }), v("SineInOut", function(a) { return -0.5 * (Math.cos(Math.PI * a) - 1) })), x("easing.EaseLookup", { find: function(a) { return F.map[a] } }, !0), D(b.SlowMo, "SlowMo", "ease,"), D(w, "RoughEase", "ease,"), D(z, "SteppedEase", "ease,"), y }, !0) }), window._gsDefine && window._gsQueue.pop()(); /*! * @license SoundJS * Visit http://createjs.com/ for documentation, updates and examples. * * Copyright (c) 2011-2013 gskinner.com, inc. * * Distributed under the terms of the MIT license. * http://www.opensource.org/licenses/mit-license.html * * This notice shall be included in all copies or substantial portions of the Software. */ ; this.createjs = this.createjs || {}, function() { var b = createjs.SoundJS = createjs.SoundJS || {}; b.version = "0.5.2", b.buildDate = "Thu, 12 Dec 2013 23:33:37 GMT" }(), this.createjs = this.createjs || {}, function() { var d = function() {}, c = d.prototype; d.initialize = function(b) { b.addEventListener = c.addEventListener, b.on = c.on, b.removeEventListener = b.off = c.removeEventListener, b.removeAllEventListeners = c.removeAllEventListeners, b.hasEventListener = c.hasEventListener, b.dispatchEvent = c.dispatchEvent, b._dispatchEvent = c._dispatchEvent, b.willTrigger = c.willTrigger }, c._listeners = null, c._captureListeners = null, c.initialize = function() {}, c.addEventListener = function(g, f, j) { var i; i = j ? this._captureListeners = this._captureListeners || {} : this._listeners = this._listeners || {}; var h = i[g]; return h && this.removeEventListener(g, f, j), h = i[g], h ? h.push(f) : i[g] = [f], f }, c.on = function(h, g, l, k, j, i) { return g.handleEvent && (l = l || g, g = g.handleEvent), l = l || this, this.addEventListener(h, function(b) { g.call(l, b, j), k && b.remove() }, i) }, c.removeEventListener = function(i, h, n) { var m = n ? this._captureListeners : this._listeners; if (m) { var l = m[i]; if (l) { for (var k = 0, j = l.length; j > k; k++) { if (l[k] == h) { 1 == j ? delete m[i] : l.splice(k, 1); break } } } } }, c.off = c.removeEventListener, c.removeAllEventListeners = function(b) { b ? (this._listeners && delete this._listeners[b], this._captureListeners && delete this._captureListeners[b]) : this._listeners = this._captureListeners = null }, c.dispatchEvent = function(i, h) { if ("string" == typeof i) { var n = this._listeners; if (!n || !n[i]) { return !1 } i = new createjs.Event(i) } if (i.target = h || this, i.bubbles && this.parent) { for (var m = this, l = [m]; m.parent;) { l.push(m = m.parent) } var k, j = l.length; for (k = j - 1; k >= 0 && !i.propagationStopped; k--) { l[k]._dispatchEvent(i, 1 + (0 == k)) } for (k = 1; j > k && !i.propagationStopped; k++) { l[k]._dispatchEvent(i, 3) } } else { this._dispatchEvent(i, 2) } return i.defaultPrevented }, c.hasEventListener = function(f) { var e = this._listeners, g = this._captureListeners; return !!(e && e[f] || g && g[f]) }, c.willTrigger = function(f) { for (var e = this; e;) { if (e.hasEventListener(f)) { return !0 } e = e.parent } return !1 }, c.toString = function() { return "[EventDispatcher]" }, c._dispatchEvent = function(i, h) { var n, m = 1 == h ? this._captureListeners : this._listeners; if (i && m) { var l = m[i.type]; if (!l || !(n = l.length)) { return } i.currentTarget = this, i.eventPhase = h, i.removed = !1, l = l.slice(); for (var k = 0; n > k && !i.immediatePropagationStopped; k++) { var j = l[k]; j.handleEvent ? j.handleEvent(i) : j(i), i.removed && (this.off(i.type, j, 1 == h), i.removed = !1) } } }, createjs.EventDispatcher = d }(), this.createjs = this.createjs || {}, function() { var d = function(f, e, g) { this.initialize(f, e, g) }, c = d.prototype; c.type = null, c.target = null, c.currentTarget = null, c.eventPhase = 0, c.bubbles = !1, c.cancelable = !1, c.timeStamp = 0, c.defaultPrevented = !1, c.propagationStopped = !1, c.immediatePropagationStopped = !1, c.removed = !1, c.initialize = function(f, e, g) { this.type = f, this.bubbles = e, this.cancelable = g, this.timeStamp = (new Date).getTime() }, c.preventDefault = function() { this.defaultPrevented = !0 }, c.stopPropagation = function() { this.propagationStopped = !0 }, c.stopImmediatePropagation = function() { this.immediatePropagationStopped = this.propagationStopped = !0 }, c.remove = function() { this.removed = !0 }, c.clone = function() { return new d(this.type, this.bubbles, this.cancelable) }, c.toString = function() { return "[Event (type=" + this.type + ")]" }, createjs.Event = d }(), this.createjs = this.createjs || {}, function() { createjs.indexOf = function(f, e) { for (var h = 0, g = f.length; g > h; h++) { if (e === f[h]) { return h } } return -1 } }(), this.createjs = this.createjs || {}, function() { createjs.proxy = function(e, d) { var f = Array.prototype.slice.call(arguments, 2); return function() { return e.apply(d, Array.prototype.slice.call(arguments, 0).concat(f)) } } }(), this.createjs = this.createjs || {}, function() { function h() { throw "Sound cannot be instantiated" } function g(d, c) { this.init(d, c) } function l() { this.isDefault = !0, this.addEventListener = this.removeEventListener = this.removeAllEventListeners = this.dispatchEvent = this.hasEventListener = this._listeners = this._interrupt = this._playFailed = this.pause = this.resume = this.play = this._beginPlaying = this._cleanUp = this.stop = this.setMasterVolume = this.setVolume = this.mute = this.setMute = this.getMute = this.setPan = this.getPosition = this.setPosition = this.playFailed = function() { return !1 }, this.getVolume = this.getPan = this.getDuration = function() { return 0 }, this.playState = h.PLAY_FAILED, this.toString = function() { return "[Sound Default Sound Instance]" } } function k() {} var j = h; j.DELIMITER = "|", j.INTERRUPT_ANY = "any", j.INTERRUPT_EARLY = "early", j.INTERRUPT_LATE = "late", j.INTERRUPT_NONE = "none", j.PLAY_INITED = "playInited", j.PLAY_SUCCEEDED = "playSucceeded", j.PLAY_INTERRUPTED = "playInterrupted", j.PLAY_FINISHED = "playFinished", j.PLAY_FAILED = "playFailed", j.SUPPORTED_EXTENSIONS = ["mp3", "ogg", "mpeg", "wav", "m4a", "mp4", "aiff", "wma", "mid"], j.EXTENSION_MAP = { m4a: "mp4" }, j.FILE_PATTERN = /^(?:(\w+:)\/{2}(\w+(?:\.\w+)*\/?))?([/.]*?(?:[^?]+)?\/)?((?:[^/?]+)\.(\w+))(?:\?(\S+)?)?$/, j.defaultInterruptBehavior = j.INTERRUPT_NONE, j.alternateExtensions = [], j._lastID = 0, j.activePlugin = null, j._pluginsRegistered = !1, j._masterVolume = 1, j._masterMute = !1, j._instances = [], j._idHash = {}, j._preloadHash = {}, j._defaultSoundInstance = null, j.addEventListener = null, j.removeEventListener = null, j.removeAllEventListeners = null, j.dispatchEvent = null, j.hasEventListener = null, j._listeners = null, createjs.EventDispatcher.initialize(j), j._sendFileLoadEvent = function(m) { if (j._preloadHash[m]) { for (var e = 0, p = j._preloadHash[m].length; p > e; e++) { var o = j._preloadHash[m][e]; if (j._preloadHash[m][e] = !0, j.hasEventListener("fileload")) { var n = new createjs.Event("fileload"); n.src = o.src, n.id = o.id, n.data = o.data, j.dispatchEvent(n) } } } }, j.getPreloadHandlers = function() { return { callback: createjs.proxy(j.initLoad, j), types: ["sound"], extensions: j.SUPPORTED_EXTENSIONS } }, j.registerPlugin = function(d) { try { console.log("createjs.Sound.registerPlugin has been deprecated. Please use registerPlugins.") } catch (c) {} return j._registerPlugin(d) }, j._registerPlugin = function(b) { return j._pluginsRegistered = !0, null == b ? !1 : b.isSupported() ? (j.activePlugin = new b, !0) : !1 }, j.registerPlugins = function(f) { for (var e = 0, n = f.length; n > e; e++) { var m = f[e]; if (j._registerPlugin(m)) { return !0 } } return !1 }, j.initializeDefaultPlugins = function() { return null != j.activePlugin ? !0 : j._pluginsRegistered ? !1 : j.registerPlugins([createjs.WebAudioPlugin, createjs.HTMLAudioPlugin]) ? !0 : !1 }, j.isReady = function() { return null != j.activePlugin }, j.getCapabilities = function() { return null == j.activePlugin ? null : j.activePlugin._capabilities }, j.getCapability = function(b) { return null == j.activePlugin ? null : j.activePlugin._capabilities[b] }, j.initLoad = function(m, e, q, p, o) { m = m.replace(o, ""); var n = j.registerSound(m, q, p, !1, o); return null == n ? !1 : n }, j.registerSound = function(b, r, q, p, o) { if (!j.initializeDefaultPlugins()) { return !1 } if (b instanceof Object && (o = r, r = b.id, q = b.data, b = b.src), j.alternateExtensions.length) { var n = j._parsePath2(b, "sound", r, q) } else { var n = j._parsePath(b, "sound", r, q) } if (null == n) { return !1 } null != o && (b = o + b, n.src = o + n.src), null != r && (j._idHash[r] = n.src); var m = null; null != q && (isNaN(q.channels) ? isNaN(q) || (m = parseInt(q)) : m = parseInt(q.channels)); var e = j.activePlugin.register(n.src, m); if (null != e && (null != e.numChannels && (m = e.numChannels), g.create(n.src, m), null != q && isNaN(q) ? q.channels = n.data.channels = m || g.maxPerChannel() : q = n.data = m || g.maxPerChannel(), null != e.tag ? n.tag = e.tag : e.src && (n.src = e.src), null != e.completeHandler && (n.completeHandler = e.completeHandler), e.type && (n.type = e.type)), 0 != p) { if (j._preloadHash[n.src] || (j._preloadHash[n.src] = []), j._preloadHash[n.src].push({ src: b, id: r, data: q }), 1 == j._preloadHash[n.src].length) { j.activePlugin.preload(n.src, e) } else { if (1 == j._preloadHash[n.src][0]) { return !0 } } } return n }, j.registerManifest = function(m, f) { for (var p = [], o = 0, n = m.length; n > o; o++) { p[o] = createjs.Sound.registerSound(m[o].src, m[o].id, m[o].data, m[o].preload, f) } return p }, j.removeSound = function(b, n) { if (null == j.activePlugin) { return !1 } if (b instanceof Object && (b = b.src), b = j._getSrcById(b), j.alternateExtensions.length) { var m = j._parsePath2(b) } else { var m = j._parsePath(b) } if (null == m) { return !1 } null != n && (m.src = n + m.src), b = m.src; for (var e in j._idHash) { j._idHash[e] == b && delete j._idHash[e] } return g.removeSrc(b), delete j._preloadHash[b], j.activePlugin.removeSound(b), !0 }, j.removeManifest = function(m, f) { for (var p = [], o = 0, n = m.length; n > o; o++) { p[o] = createjs.Sound.removeSound(m[o].src, f) } return p }, j.removeAllSounds = function() { j._idHash = {}, j._preloadHash = {}, g.removeAll(), j.activePlugin.removeAllSounds() }, j.loadComplete = function(d) { if (j.alternateExtensions.length) { var c = j._parsePath2(d, "sound") } else { var c = j._parsePath(d, "sound") } return d = c ? j._getSrcById(c.src) : j._getSrcById(d), 1 == j._preloadHash[d][0] }, j._parsePath = function(B, A, z, y) { "string" != typeof B && (B = B.toString()); var x = B.split(j.DELIMITER); if (x.length > 1) { try { console.log('createjs.Sound.DELIMITER "|" loading approach has been deprecated. Please use the new alternateExtensions property.') } catch (w) {} } for (var v = { type: A || "sound", id: z, data: y }, u = j.getCapabilities(), t = 0, s = x.length; s > t; t++) { var r = x[t], q = r.match(j.FILE_PATTERN); if (null == q) { return !1 } var p = q[4], e = q[5]; if (u[e] && createjs.indexOf(j.SUPPORTED_EXTENSIONS, e) > -1) { return v.name = p, v.src = r, v.extension = e, v } } return null }, j._parsePath2 = function(u, t, s, r) { "string" != typeof u && (u = u.toString()); var q = u.match(j.FILE_PATTERN); if (null == q) { return !1 } for (var p = q[4], o = q[5], n = j.getCapabilities(), m = 0; !n[o];) { if (o = j.alternateExtensions[m++], m > j.alternateExtensions.length) { return null } } u = u.replace("." + q[5], "." + o); var e = { type: t || "sound", id: s, data: r }; return e.name = p, e.src = u, e.extension = o, e }, j.play = function(t, s, r, q, p, o, n) { var m = j.createInstance(t), e = j._playInstance(m, s, r, q, p, o, n); return e || m.playFailed(), m }, j.createInstance = function(e) { if (!j.initializeDefaultPlugins()) { return j._defaultSoundInstance } if (e = j._getSrcById(e), j.alternateExtensions.length) { var b = j._parsePath2(e, "sound") } else { var b = j._parsePath(e, "sound") } var a = null; return null != b && null != b.src ? (g.create(b.src), a = j.activePlugin.create(b.src)) : a = h._defaultSoundInstance, a.uniqueId = j._lastID++, a }, j.setVolume = function(f) { if (null == Number(f)) { return !1 } if (f = Math.max(0, Math.min(1, f)), j._masterVolume = f, !this.activePlugin || !this.activePlugin.setVolume || !this.activePlugin.setVolume(f)) { for (var e = this._instances, n = 0, m = e.length; m > n; n++) { e[n].setMasterVolume(f) } } }, j.getVolume = function() { return j._masterVolume }, j.setMute = function(f) { if (null == f || void 0 == f) { return !1 } if (this._masterMute = f, !this.activePlugin || !this.activePlugin.setMute || !this.activePlugin.setMute(f)) { for (var e = this._instances, n = 0, m = e.length; m > n; n++) { e[n].setMasterMute(f) } } return !0 }, j.getMute = function() { return this._masterMute }, j.stop = function() { for (var d = this._instances, c = d.length; c--;) { d[c].stop() } }, j._playInstance = function(t, s, r, q, p, o, n) { if (s instanceof Object && (r = s.delay, q = s.offset, p = s.loop, o = s.volume, n = s.pan, s = s.interrupt), s = s || j.defaultInterruptBehavior, null == r && (r = 0), null == q && (q = t.getPosition()), null == p && (p = 0), null == o && (o = t.volume), null == n && (n = t.pan), 0 == r) { var m = j._beginPlaying(t, s, q, p, o, n); if (!m) { return !1 } } else { var e = setTimeout(function() { j._beginPlaying(t, s, q, p, o, n) }, r); t._delayTimeoutId = e } return this._instances.push(t), !0 }, j._beginPlaying = function(b, s, r, q, p, o) { if (!g.add(b, s)) { return !1 } var n = b._beginPlaying(r, q, p, o); if (!n) { var m = createjs.indexOf(this._instances, b); return m > -1 && this._instances.splice(m, 1), !1 } return !0 }, j._getSrcById = function(b) { return null == j._idHash || null == j._idHash[b] ? b : j._idHash[b] }, j._playFinished = function(b) { g.remove(b); var d = createjs.indexOf(this._instances, b); d > -1 && this._instances.splice(d, 1) }, createjs.Sound = h, g.channels = {}, g.create = function(b, f) { var e = g.get(b); return null == e ? (g.channels[b] = new g(b, f), !0) : !1 }, g.removeSrc = function(b) { var d = g.get(b); return null == d ? !1 : (d.removeAll(), delete g.channels[b], !0) }, g.removeAll = function() { for (var b in g.channels) { g.channels[b].removeAll() } g.channels = {} }, g.add = function(b, f) { var e = g.get(b.src); return null == e ? !1 : e.add(b, f) }, g.remove = function(b) { var d = g.get(b.src); return null == d ? !1 : (d.remove(b), !0) }, g.maxPerChannel = function() { return i.maxDefault }, g.get = function(b) { return g.channels[b] }; var i = g.prototype; i.src = null, i.max = null, i.maxDefault = 100, i.length = 0, i.init = function(d, c) { this.src = d, this.max = c || this.maxDefault, -1 == this.max && (this.max = this.maxDefault), this._instances = [] }, i.get = function(b) { return this._instances[b] }, i.add = function(d, c) { return this.getSlot(c, d) ? (this._instances.push(d), this.length++, !0) : !1 }, i.remove = function(d) { var c = createjs.indexOf(this._instances, d); return -1 == c ? !1 : (this._instances.splice(c, 1), this.length--, !0) }, i.removeAll = function() { for (var b = this.length - 1; b >= 0; b--) { this._instances[b].stop() } }, i.getSlot = function(a) { for (var p, o, n = 0, m = this.max; m > n; n++) { if (p = this.get(n), null == p) { return !0 }(a != h.INTERRUPT_NONE || p.playState == h.PLAY_FINISHED) && (0 != n ? p.playState == h.PLAY_FINISHED || p.playState == h.PLAY_INTERRUPTED || p.playState == h.PLAY_FAILED ? o = p : (a == h.INTERRUPT_EARLY && p.getPosition() < o.getPosition() || a == h.INTERRUPT_LATE && p.getPosition() > o.getPosition()) && (o = p) : o = p) } return null != o ? (o._interrupt(), this.remove(o), !0) : !1 }, i.toString = function() { return "[Sound SoundChannel]" }, h._defaultSoundInstance = new l, k.init = function() { var b = window.navigator.userAgent; k.isFirefox = b.indexOf("Firefox") > -1, k.isOpera = null != window.opera, k.isChrome = b.indexOf("Chrome") > -1, k.isIOS = b.indexOf("iPod") > -1 || b.indexOf("iPhone") > -1 || b.indexOf("iPad") > -1, k.isAndroid = b.indexOf("Android") > -1, k.isBlackberry = b.indexOf("Blackberry") > -1 }, k.init(), createjs.Sound.BrowserDetect = k }(), this.createjs = this.createjs || {}, function() { function e() { this._init() } var d = e; d._capabilities = null, d.isSupported = function() { var b = createjs.Sound.BrowserDetect.isIOS || createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry; return "file:" != location.protocol || b || this._isFileXHRSupported() ? (d._generateCapabilities(), null == d.context ? !1 : !0) : !1 }, d._isFileXHRSupported = function() { var h = !0, g = new XMLHttpRequest; try { g.open("GET", "fail.fail", !1) } catch (i) { return h = !1 } g.onerror = function() { h = !1 }, g.onload = function() { h = 404 == this.status || 200 == this.status || 0 == this.status && "" != this.response }; try { g.send() } catch (i) { h = !1 } return h }, d._generateCapabilities = function() { if (null == d._capabilities) { var b = document.createElement("audio"); if (null == b.canPlayType) { return null } if (window.webkitAudioContext) { d.context = new webkitAudioContext } else { if (!window.AudioContext) { return null } d.context = new AudioContext } d._compatibilitySetUp(), d.playEmptySound(), d._capabilities = { panning: !0, volume: !0, tracks: -1 }; for (var n = createjs.Sound.SUPPORTED_EXTENSIONS, m = createjs.Sound.EXTENSION_MAP, l = 0, k = n.length; k > l; l++) { var j = n[l], i = m[j] || j; d._capabilities[j] = "no" != b.canPlayType("audio/" + j) && "" != b.canPlayType("audio/" + j) || "no" != b.canPlayType("audio/" + i) && "" != b.canPlayType("audio/" + i) } d.context.destination.numberOfChannels < 2 && (d._capabilities.panning = !1), d.dynamicsCompressorNode = d.context.createDynamicsCompressor(), d.dynamicsCompressorNode.connect(d.context.destination), d.gainNode = d.context.createGain(), d.gainNode.connect(d.dynamicsCompressorNode) } }, d._compatibilitySetUp = function() { if (!d.context.createGain) { d.context.createGain = d.context.createGainNode; var b = d.context.createBufferSource(); b.__proto__.start = b.__proto__.noteGrainOn, b.__proto__.stop = b.__proto__.noteOff, this._panningModel = 0 } }, d.playEmptySound = function() { var g = this.context.createBuffer(1, 1, 22050), c = this.context.createBufferSource(); c.buffer = g, c.connect(this.context.destination), c.start(0, 0, 0) }; var f = e.prototype; f._capabilities = null, f._volume = 1, f.context = null, f._panningModel = "equalpower", f.dynamicsCompressorNode = null, f.gainNode = null, f._arrayBuffers = null, f._init = function() { this._capabilities = d._capabilities, this._arrayBuffers = {}, this.context = d.context, this.gainNode = d.gainNode, this.dynamicsCompressorNode = d.dynamicsCompressorNode }, f.register = function(g) { this._arrayBuffers[g] = !0; var c = new createjs.WebAudioPlugin.Loader(g, this); return { tag: c } }, f.isPreloadStarted = function(b) { return null != this._arrayBuffers[b] }, f.isPreloadComplete = function(b) { return !(null == this._arrayBuffers[b] || 1 == this._arrayBuffers[b]) }, f.removeSound = function(b) { delete this._arrayBuffers[b] }, f.removeAllSounds = function() { this._arrayBuffers = {} }, f.addPreloadResults = function(g, c) { this._arrayBuffers[g] = c }, f._handlePreloadComplete = function() { createjs.Sound._sendFileLoadEvent(this.src) }, f.preload = function(g) { this._arrayBuffers[g] = !0; var c = new createjs.WebAudioPlugin.Loader(g, this); c.onload = this._handlePreloadComplete, c.load() }, f.create = function(b) { return this.isPreloadStarted(b) || this.preload(b), new createjs.WebAudioPlugin.SoundInstance(b, this) }, f.setVolume = function(b) { return this._volume = b, this._updateVolume(), !0 }, f._updateVolume = function() { var b = createjs.Sound._masterMute ? 0 : this._volume; b != this.gainNode.gain.value && (this.gainNode.gain.value = b) }, f.getVolume = function() { return this._volume }, f.setMute = function() { return this._updateVolume(), !0 }, f.toString = function() { return "[WebAudioPlugin]" }, createjs.WebAudioPlugin = e }(), function() { function e(g, c) { this._init(g, c) } var d = e.prototype = new createjs.EventDispatcher; d.src = null, d.uniqueId = -1, d.playState = null, d._owner = null, d._offset = 0, d._delay = 0, d._volume = 1; try { Object.defineProperty(d, "volume", { get: function() { return this._volume }, set: function(b) { return null == Number(b) ? !1 : (b = Math.max(0, Math.min(1, b)), this._volume = b, this._updateVolume(), void 0) } }) } catch (f) {} d._pan = 0; try { Object.defineProperty(d, "pan", { get: function() { return this._pan }, set: function(b) { return this._owner._capabilities.panning && null != Number(b) ? (b = Math.max(-1, Math.min(1, b)), this._pan = b, this.panNode.setPosition(b, 0, -0.5), void 0) : !1 } }) } catch (f) {} d._duration = 0, d._remainingLoops = 0, d._delayTimeoutId = null, d._soundCompleteTimeout = null, d.gainNode = null, d.panNode = null, d.sourceNode = null, d._sourceNodeNext = null, d._muted = !1, d._paused = !1, d._startTime = 0, d._endedHandler = null, d._sendEvent = function(g) { var c = new createjs.Event(g); this.dispatchEvent(c) }, d._init = function(g, c) { this._owner = c, this.src = g, this.gainNode = this._owner.context.createGain(), this.panNode = this._owner.context.createPanner(), this.panNode.panningModel = this._owner._panningModel, this.panNode.connect(this.gainNode), this._owner.isPreloadComplete(this.src) && (this._duration = 1000 * this._owner._arrayBuffers[this.src].duration), this._endedHandler = createjs.proxy(this._handleSoundComplete, this) }, d._cleanUp = function() { this.sourceNode && this.playState == createjs.Sound.PLAY_SUCCEEDED && (this.sourceNode = this._cleanUpAudioNode(this.sourceNode), this._sourceNodeNext = this._cleanUpAudioNode(this._sourceNodeNext)), 0 != this.gainNode.numberOfOutputs && this.gainNode.disconnect(0), clearTimeout(this._delayTimeoutId), clearTimeout(this._soundCompleteTimeout), this._startTime = 0, null != window.createjs && createjs.Sound._playFinished(this) }, d._cleanUpAudioNode = function(b) { return b && (b.stop(0), b.disconnect(this.panNode), b = null), b }, d._interrupt = function() { this._cleanUp(), this.playState = createjs.Sound.PLAY_INTERRUPTED, this._paused = !1, this._sendEvent("interrupted") }, d._handleSoundReady = function() { if (null != window.createjs) { if (1000 * this._offset > this.getDuration()) { return this.playFailed(), void 0 } this._offset < 0 && (this._offset = 0), this.playState = createjs.Sound.PLAY_SUCCEEDED, this._paused = !1, this.gainNode.connect(this._owner.gainNode); var b = this._owner._arrayBuffers[this.src].duration; this.sourceNode = this._createAndPlayAudioNode(this._owner.context.currentTime - b, this._offset), this._duration = 1000 * b, this._startTime = this.sourceNode.startTime - this._offset, this._soundCompleteTimeout = setTimeout(this._endedHandler, 1000 * (b - this._offset)), 0 != this._remainingLoops && (this._sourceNodeNext = this._createAndPlayAudioNode(this._startTime, 0)) } }, d._createAndPlayAudioNode = function(h, g) { var i = this._owner.context.createBufferSource(); return i.buffer = this._owner._arrayBuffers[this.src], i.connect(this.panNode), this._owner.context.currentTime, i.startTime = h + i.buffer.duration, i.start(i.startTime, g, i.buffer.duration - g), i }, d.play = function(h, g, l, k, j, i) { this._cleanUp(), createjs.Sound._playInstance(this, h, g, l, k, j, i) }, d._beginPlaying = function(h, g, j, i) { return null != window.createjs && this.src ? (this._offset = h / 1000, this._remainingLoops = g, this.volume = j, this.pan = i, this._owner.isPreloadComplete(this.src) ? (this._handleSoundReady(null), this._sendEvent("succeeded"), 1) : (this.playFailed(), void 0)) : void 0 }, d.pause = function() { return this._paused || this.playState != createjs.Sound.PLAY_SUCCEEDED ? !1 : (this._paused = !0, this._offset = this._owner.context.currentTime - this._startTime, this._cleanUpAudioNode(this.sourceNode), this._cleanUpAudioNode(this._sourceNodeNext), 0 != this.gainNode.numberOfOutputs && this.gainNode.disconnect(), clearTimeout(this._delayTimeoutId), clearTimeout(this._soundCompleteTimeout), !0) }, d.resume = function() { return this._paused ? (this._handleSoundReady(null), !0) : !1 }, d.stop = function() { return this._cleanUp(), this.playState = createjs.Sound.PLAY_FINISHED, this._offset = 0, !0 }, d.setVolume = function(b) { return this.volume = b, !0 }, d._updateVolume = function() { var b = this._muted ? 0 : this._volume; return b != this.gainNode.gain.value ? (this.gainNode.gain.value = b, !0) : !1 }, d.getVolume = function() { return this.volume }, d.setMute = function(b) { return null == b || void 0 == b ? !1 : (this._muted = b, this._updateVolume(), !0) }, d.getMute = function() { return this._muted }, d.setPan = function(b) { return this.pan = b, this.pan != b ? !1 : void 0 }, d.getPan = function() { return this.pan }, d.getPosition = function() { if (this._paused || null == this.sourceNode) { var b = this._offset } else { var b = this._owner.context.currentTime - this._startTime } return 1000 * b }, d.setPosition = function(b) { return this._offset = b / 1000, this.sourceNode && this.playState == createjs.Sound.PLAY_SUCCEEDED && (this._cleanUpAudioNode(this.sourceNode), this._cleanUpAudioNode(this._sourceNodeNext), clearTimeout(this._soundCompleteTimeout)), this._paused || this.playState != createjs.Sound.PLAY_SUCCEEDED || this._handleSoundReady(null), !0 }, d.getDuration = function() { return this._duration }, d._handleSoundComplete = function() { return this._offset = 0, 0 != this._remainingLoops ? (this._remainingLoops--, this._sourceNodeNext ? (this._cleanUpAudioNode(this.sourceNode), this.sourceNode = this._sourceNodeNext, this._startTime = this.sourceNode.startTime, this._sourceNodeNext = this._createAndPlayAudioNode(this._startTime, 0), this._soundCompleteTimeout = setTimeout(this._endedHandler, this._duration)) : this._handleSoundReady(null), this._sendEvent("loop"), void 0) : (null != window.createjs && (this._cleanUp(), this.playState = createjs.Sound.PLAY_FINISHED, this._sendEvent("complete")), void 0) }, d.playFailed = function() { null != window.createjs && (this._cleanUp(), this.playState = createjs.Sound.PLAY_FAILED, this._sendEvent("failed")) }, d.toString = function() { return "[WebAudioPlugin SoundInstance]" }, createjs.WebAudioPlugin.SoundInstance = e }(), function() { function d(f, e) { this._init(f, e) } var c = d.prototype; c.request = null, c.owner = null, c.progress = -1, c.src = null, c.originalSrc = null, c.result = null, c.onload = null, c.onprogress = null, c.onError = null, c._init = function(f, e) { this.src = f, this.originalSrc = f, this.owner = e }, c.load = function(b) { null != b && (this.src = b), this.request = new XMLHttpRequest, this.request.open("GET", this.src, !0), this.request.responseType = "arraybuffer", this.request.onload = createjs.proxy(this.handleLoad, this), this.request.onError = createjs.proxy(this.handleError, this), this.request.onprogress = createjs.proxy(this.handleProgress, this), this.request.send() }, c.handleProgress = function(f, e) { this.progress = f / e, null != this.onprogress && this.onprogress({ loaded: f, total: e, progress: this.progress }) }, c.handleLoad = function() { this.owner.context.decodeAudioData(this.request.response, createjs.proxy(this.handleAudioDecoded, this), createjs.proxy(this.handleError, this)) }, c.handleAudioDecoded = function(b) { this.progress = 1, this.result = b, this.src = this.originalSrc, this.owner.addPreloadResults(this.src, this.result), this.onload && this.onload() }, c.handleError = function(b) { this.owner.removeSound(this.src), this.onerror && this.onerror(b) }, c.toString = function() { return "[WebAudioPlugin Loader]" }, createjs.WebAudioPlugin.Loader = d }(), this.createjs = this.createjs || {}, function() { function e() { this._init() } var d = e; d.MAX_INSTANCES = 30, d._AUDIO_READY = "canplaythrough", d._AUDIO_ENDED = "ended", d._AUDIO_SEEKED = "seeked", d._AUDIO_STALLED = "stalled", d._capabilities = null, d.enableIOS = !1, d.isSupported = function() { if (createjs.Sound.BrowserDetect.isIOS && !d.enableIOS) { return !1 } d._generateCapabilities(); var b = d.tag; return null == b || null == d._capabilities ? !1 : !0 }, d._generateCapabilities = function() { if (null == d._capabilities) { var b = d.tag = document.createElement("audio"); if (null == b.canPlayType) { return null } d._capabilities = { panning: !0, volume: !0, tracks: -1 }; for (var n = createjs.Sound.SUPPORTED_EXTENSIONS, m = createjs.Sound.EXTENSION_MAP, l = 0, k = n.length; k > l; l++) { var j = n[l], i = m[j] || j; d._capabilities[j] = "no" != b.canPlayType("audio/" + j) && "" != b.canPlayType("audio/" + j) || "no" != b.canPlayType("audio/" + i) && "" != b.canPlayType("audio/" + i) } } }; var f = e.prototype; f._capabilities = null, f._audioSources = null, f.defaultNumChannels = 2, f.loadedHandler = null, f._init = function() { this._capabilities = d._capabilities, this._audioSources = {} }, f.register = function(i, h) { this._audioSources[i] = !0; for (var n = createjs.HTMLAudioPlugin.TagPool.get(i), m = null, l = h || this.defaultNumChannels, k = 0; l > k; k++) { m = this._createTag(i), n.add(m) } if (m.id = i, this.loadedHandler = createjs.proxy(this._handleTagLoad, this), m.addEventListener && m.addEventListener("canplaythrough", this.loadedHandler), null == m.onreadystatechange) { m.onreadystatechange = this.loadedHandler } else { var j = m.onreadystatechange; m.onreadystatechange = function() { j(), this.loadedHandler() } } return { tag: m, numChannels: l } }, f._handleTagLoad = function(b) { b.target.removeEventListener && b.target.removeEventListener("canplaythrough", this.loadedHandler), b.target.onreadystatechange = null, b.target.src != b.target.id && createjs.HTMLAudioPlugin.TagPool.checkSrc(b.target.id) }, f._createTag = function(g) { var c = document.createElement("audio"); return c.autoplay = !1, c.preload = "none", c.src = g, c }, f.removeSound = function(b) { delete this._audioSources[b], createjs.HTMLAudioPlugin.TagPool.remove(b) }, f.removeAllSounds = function() { this._audioSources = {}, createjs.HTMLAudioPlugin.TagPool.removeAll() }, f.create = function(h) { if (!this.isPreloadStarted(h)) { var g = createjs.HTMLAudioPlugin.TagPool.get(h), i = this._createTag(h); i.id = h, g.add(i), this.preload(h, { tag: i }) } return new createjs.HTMLAudioPlugin.SoundInstance(h, this) }, f.isPreloadStarted = function(b) { return null != this._audioSources[b] }, f.preload = function(g, c) { this._audioSources[g] = !0, new createjs.HTMLAudioPlugin.Loader(g, c.tag) }, f.toString = function() { return "[HTMLAudioPlugin]" }, createjs.HTMLAudioPlugin = e }(), function() { function e(g, c) { this._init(g, c) } var d = e.prototype = new createjs.EventDispatcher; d.src = null, d.uniqueId = -1, d.playState = null, d._owner = null, d.loaded = !1, d._offset = 0, d._delay = 0, d._volume = 1; try { Object.defineProperty(d, "volume", { get: function() { return this._volume }, set: function(b) { null != Number(b) && (b = Math.max(0, Math.min(1, b)), this._volume = b, this._updateVolume()) } }) } catch (f) {} d.pan = 0, d._duration = 0, d._remainingLoops = 0, d._delayTimeoutId = null, d.tag = null, d._muted = !1, d._paused = !1, d._endedHandler = null, d._readyHandler = null, d._stalledHandler = null, d.loopHandler = null, d._init = function(g, c) { this.src = g, this._owner = c, this._endedHandler = createjs.proxy(this._handleSoundComplete, this), this._readyHandler = createjs.proxy(this._handleSoundReady, this), this._stalledHandler = createjs.proxy(this._handleSoundStalled, this), this.loopHandler = createjs.proxy(this.handleSoundLoop, this) }, d._sendEvent = function(g) { var c = new createjs.Event(g); this.dispatchEvent(c) }, d._cleanUp = function() { var g = this.tag; if (null != g) { g.pause(), g.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_ENDED, this._endedHandler, !1), g.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_READY, this._readyHandler, !1), g.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this.loopHandler, !1); try { g.currentTime = 0 } catch (c) {} createjs.HTMLAudioPlugin.TagPool.setInstance(this.src, g), this.tag = null } clearTimeout(this._delayTimeoutId), null != window.createjs && createjs.Sound._playFinished(this) }, d._interrupt = function() { null != this.tag && (this.playState = createjs.Sound.PLAY_INTERRUPTED, this._cleanUp(), this._paused = !1, this._sendEvent("interrupted")) }, d.play = function(h, g, l, k, j, i) { this._cleanUp(), createjs.Sound._playInstance(this, h, g, l, k, j, i) }, d._beginPlaying = function(h, g, k, j) { if (null == window.createjs) { return -1 } var i = this.tag = createjs.HTMLAudioPlugin.TagPool.getInstance(this.src); return null == i ? (this.playFailed(), -1) : (i.addEventListener(createjs.HTMLAudioPlugin._AUDIO_ENDED, this._endedHandler, !1), this._offset = h, this.volume = k, this.pan = j, this._updateVolume(), this._remainingLoops = g, 4 !== i.readyState ? (i.addEventListener(createjs.HTMLAudioPlugin._AUDIO_READY, this._readyHandler, !1), i.addEventListener(createjs.HTMLAudioPlugin._AUDIO_STALLED, this._stalledHandler, !1), i.preload = "auto", i.load()) : this._handleSoundReady(null), this._sendEvent("succeeded"), 1) }, d._handleSoundStalled = function() { this._cleanUp(), this._sendEvent("failed") }, d._handleSoundReady = function() { if (null != window.createjs) { if (this._duration = 1000 * this.tag.duration, this.playState = createjs.Sound.PLAY_SUCCEEDED, this._paused = !1, this.tag.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_READY, this._readyHandler, !1), this._offset >= this.getDuration()) { return this.playFailed(), void 0 } this._offset > 0 && (this.tag.currentTime = 0.001 * this._offset), -1 == this._remainingLoops && (this.tag.loop = !0), 0 != this._remainingLoops && (this.tag.addEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this.loopHandler, !1), this.tag.loop = !0), this.tag.play() } }, d.pause = function() { return this._paused || this.playState != createjs.Sound.PLAY_SUCCEEDED || null == this.tag ? !1 : (this._paused = !0, this.tag.pause(), clearTimeout(this._delayTimeoutId), !0) }, d.resume = function() { return this._paused && null != this.tag ? (this._paused = !1, this.tag.play(), !0) : !1 }, d.stop = function() { return this._offset = 0, this.pause(), this.playState = createjs.Sound.PLAY_FINISHED, this._cleanUp(), !0 }, d.setMasterVolume = function() { return this._updateVolume(), !0 }, d.setVolume = function(b) { return this.volume = b, !0 }, d._updateVolume = function() { if (null != this.tag) { var b = this._muted || createjs.Sound._masterMute ? 0 : this._volume * createjs.Sound._masterVolume; return b != this.tag.volume && (this.tag.volume = b), !0 } return !1 }, d.getVolume = function() { return this.volume }, d.setMasterMute = function() { return this._updateVolume(), !0 }, d.setMute = function(b) { return null == b || void 0 == b ? !1 : (this._muted = b, this._updateVolume(), !0) }, d.getMute = function() { return this._muted }, d.setPan = function() { return !1 }, d.getPan = function() { return 0 }, d.getPosition = function() { return null == this.tag ? this._offset : 1000 * this.tag.currentTime }, d.setPosition = function(g) { if (null == this.tag) { this._offset = g } else { this.tag.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this.loopHandler, !1); try { this.tag.currentTime = 0.001 * g } catch (c) { return !1 } this.tag.addEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this.loopHandler, !1) } return !0 }, d.getDuration = function() { return this._duration }, d._handleSoundComplete = function() { this._offset = 0, null != window.createjs && (this.playState = createjs.Sound.PLAY_FINISHED, this._cleanUp(), this._sendEvent("complete")) }, d.handleSoundLoop = function() { this._offset = 0, this._remainingLoops--, 0 == this._remainingLoops && (this.tag.loop = !1, this.tag.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_SEEKED, this.loopHandler, !1)), this._sendEvent("loop") }, d.playFailed = function() { null != window.createjs && (this.playState = createjs.Sound.PLAY_FAILED, this._cleanUp(), this._sendEvent("failed")) }, d.toString = function() { return "[HTMLAudioPlugin SoundInstance]" }, createjs.HTMLAudioPlugin.SoundInstance = e }(), function() { function d(f, e) { this._init(f, e) } var c = d.prototype; c.src = null, c.tag = null, c.preloadTimer = null, c.loadedHandler = null, c._init = function(f, e) { if (this.src = f, this.tag = e, this.preloadTimer = setInterval(createjs.proxy(this.preloadTick, this), 200), this.loadedHandler = createjs.proxy(this.sendLoadedEvent, this), this.tag.addEventListener && this.tag.addEventListener("canplaythrough", this.loadedHandler), null == this.tag.onreadystatechange) { this.tag.onreadystatechange = createjs.proxy(this.sendLoadedEvent, this) } else { var g = this.tag.onreadystatechange; this.tag.onreadystatechange = function() { g(), this.tag.onreadystatechange = createjs.proxy(this.sendLoadedEvent, this) } } this.tag.preload = "auto", this.tag.load() }, c.preloadTick = function() { var f = this.tag.buffered, e = this.tag.duration; f.length > 0 && f.end(0) >= e - 1 && this.handleTagLoaded() }, c.handleTagLoaded = function() { clearInterval(this.preloadTimer) }, c.sendLoadedEvent = function() { this.tag.removeEventListener && this.tag.removeEventListener("canplaythrough", this.loadedHandler), this.tag.onreadystatechange = null, createjs.Sound._sendFileLoadEvent(this.src) }, c.toString = function() { return "[HTMLAudioPlugin Loader]" }, createjs.HTMLAudioPlugin.Loader = d }(), function() { function e(b) { this._init(b) } var d = e; d.tags = {}, d.get = function(b) { var a = d.tags[b]; return null == a && (a = d.tags[b] = new e(b)), a }, d.remove = function(b) { var g = d.tags[b]; return null == g ? !1 : (g.removeAll(), delete d.tags[b], !0) }, d.removeAll = function() { for (var b in d.tags) { d.tags[b].removeAll() } d.tags = {} }, d.getInstance = function(b) { var g = d.tags[b]; return null == g ? null : g.get() }, d.setInstance = function(b, h) { var g = d.tags[b]; return null == g ? null : g.set(h) }, d.checkSrc = function(b) { var g = d.tags[b]; return null == g ? null : (g.checkSrcChange(), void 0) }; var f = e.prototype; f.src = null, f.length = 0, f.available = 0, f.tags = null, f._init = function(b) { this.src = b, this.tags = [] }, f.add = function(b) { this.tags.push(b), this.length++, this.available++ }, f.removeAll = function() { for (; this.length--;) { delete this.tags[this.length] } this.src = null, this.tags.length = 0 }, f.get = function() { if (0 == this.tags.length) { return null } this.available = this.tags.length; var b = this.tags.pop(); return null == b.parentNode && document.body.appendChild(b), b }, f.set = function(g) { var c = createjs.indexOf(this.tags, g); - 1 == c && this.tags.push(g), this.available = this.tags.length }, f.checkSrcChange = function() { for (var g = this.tags.length - 1, c = this.tags[g].src; g--;) { this.tags[g].src = c } }, f.toString = function() { return "[HTMLAudioPlugin TagPool]" }, createjs.HTMLAudioPlugin.TagPool = e }(); /*! * @license PreloadJS * Visit http://createjs.com/ for documentation, updates and examples. * * Copyright (c) 2011-2013 gskinner.com, inc. * * Distributed under the terms of the MIT license. * http://www.opensource.org/licenses/mit-license.html * * This notice shall be included in all copies or substantial portions of the Software. */ ; this.createjs = this.createjs || {}, function() { var b = createjs.PreloadJS = createjs.PreloadJS || {}; b.version = "0.4.1", b.buildDate = "Thu, 12 Dec 2013 23:33:38 GMT" }(), this.createjs = this.createjs || {}, function() { var d = function(f, e, g) { this.initialize(f, e, g) }, c = d.prototype; c.type = null, c.target = null, c.currentTarget = null, c.eventPhase = 0, c.bubbles = !1, c.cancelable = !1, c.timeStamp = 0, c.defaultPrevented = !1, c.propagationStopped = !1, c.immediatePropagationStopped = !1, c.removed = !1, c.initialize = function(f, e, g) { this.type = f, this.bubbles = e, this.cancelable = g, this.timeStamp = (new Date).getTime() }, c.preventDefault = function() { this.defaultPrevented = !0 }, c.stopPropagation = function() { this.propagationStopped = !0 }, c.stopImmediatePropagation = function() { this.immediatePropagationStopped = this.propagationStopped = !0 }, c.remove = function() { this.removed = !0 }, c.clone = function() { return new d(this.type, this.bubbles, this.cancelable) }, c.toString = function() { return "[Event (type=" + this.type + ")]" }, createjs.Event = d }(), this.createjs = this.createjs || {}, function() { var d = function() {}, c = d.prototype; d.initialize = function(b) { b.addEventListener = c.addEventListener, b.on = c.on, b.removeEventListener = b.off = c.removeEventListener, b.removeAllEventListeners = c.removeAllEventListeners, b.hasEventListener = c.hasEventListener, b.dispatchEvent = c.dispatchEvent, b._dispatchEvent = c._dispatchEvent, b.willTrigger = c.willTrigger }, c._listeners = null, c._captureListeners = null, c.initialize = function() {}, c.addEventListener = function(g, f, j) { var i; i = j ? this._captureListeners = this._captureListeners || {} : this._listeners = this._listeners || {}; var h = i[g]; return h && this.removeEventListener(g, f, j), h = i[g], h ? h.push(f) : i[g] = [f], f }, c.on = function(h, g, l, k, j, i) { return g.handleEvent && (l = l || g, g = g.handleEvent), l = l || this, this.addEventListener(h, function(b) { g.call(l, b, j), k && b.remove() }, i) }, c.removeEventListener = function(i, h, n) { var m = n ? this._captureListeners : this._listeners; if (m) { var l = m[i]; if (l) { for (var k = 0, j = l.length; j > k; k++) { if (l[k] == h) { 1 == j ? delete m[i] : l.splice(k, 1); break } } } } }, c.off = c.removeEventListener, c.removeAllEventListeners = function(b) { b ? (this._listeners && delete this._listeners[b], this._captureListeners && delete this._captureListeners[b]) : this._listeners = this._captureListeners = null }, c.dispatchEvent = function(i, h) { if ("string" == typeof i) { var n = this._listeners; if (!n || !n[i]) { return !1 } i = new createjs.Event(i) } if (i.target = h || this, i.bubbles && this.parent) { for (var m = this, l = [m]; m.parent;) { l.push(m = m.parent) } var k, j = l.length; for (k = j - 1; k >= 0 && !i.propagationStopped; k--) { l[k]._dispatchEvent(i, 1 + (0 == k)) } for (k = 1; j > k && !i.propagationStopped; k++) { l[k]._dispatchEvent(i, 3) } } else { this._dispatchEvent(i, 2) } return i.defaultPrevented }, c.hasEventListener = function(f) { var e = this._listeners, g = this._captureListeners; return !!(e && e[f] || g && g[f]) }, c.willTrigger = function(f) { for (var e = this; e;) { if (e.hasEventListener(f)) { return !0 } e = e.parent } return !1 }, c.toString = function() { return "[EventDispatcher]" }, c._dispatchEvent = function(i, h) { var n, m = 1 == h ? this._captureListeners : this._listeners; if (i && m) { var l = m[i.type]; if (!l || !(n = l.length)) { return } i.currentTarget = this, i.eventPhase = h, i.removed = !1, l = l.slice(); for (var k = 0; n > k && !i.immediatePropagationStopped; k++) { var j = l[k]; j.handleEvent ? j.handleEvent(i) : j(i), i.removed && (this.off(i.type, j, 1 == h), i.removed = !1) } } }, createjs.EventDispatcher = d }(), this.createjs = this.createjs || {}, function() { createjs.indexOf = function(f, e) { for (var h = 0, g = f.length; g > h; h++) { if (e === f[h]) { return h } } return -1 } }(), this.createjs = this.createjs || {}, function() { createjs.proxy = function(e, d) { var f = Array.prototype.slice.call(arguments, 2); return function() { return e.apply(d, Array.prototype.slice.call(arguments, 0).concat(f)) } } }(), this.createjs = this.createjs || {}, function() { var e = function() { this.init() }; e.prototype = new createjs.EventDispatcher; var d = e.prototype, f = e; f.FILE_PATTERN = /^(?:(\w+:)\/{2}(\w+(?:\.\w+)*\/?)|(.{0,2}\/{1}))?([/.]*?(?:[^?]+)?\/)?((?:[^/?]+)\.(\w+))(?:\?(\S+)?)?$/, f.PATH_PATTERN = /^(?:(\w+:)\/{2})|(.{0,2}\/{1})?([/.]*?(?:[^?]+)?\/?)?$/, d.loaded = !1, d.canceled = !1, d.progress = 0, d._item = null, d.getItem = function() { return this._item }, d.init = function() {}, d.load = function() {}, d.close = function() {}, d._sendLoadStart = function() { this._isCanceled() || this.dispatchEvent("loadstart") }, d._sendProgress = function(g) { if (!this._isCanceled()) { var c = null; "number" == typeof g ? (this.progress = g, c = new createjs.Event("progress"), c.loaded = this.progress, c.total = 1) : (c = g, this.progress = g.loaded / g.total, (isNaN(this.progress) || 1 / 0 == this.progress) && (this.progress = 0)), c.progress = this.progress, this.hasEventListener("progress") && this.dispatchEvent(c) } }, d._sendComplete = function() { this._isCanceled() || this.dispatchEvent("complete") }, d._sendError = function(b) { !this._isCanceled() && this.hasEventListener("error") && (null == b && (b = new createjs.Event("error")), this.dispatchEvent(b)) }, d._isCanceled = function() { return null == window.createjs || this.canceled ? !0 : !1 }, d._parseURI = function(b) { return b ? b.match(f.FILE_PATTERN) : null }, d._parsePath = function(b) { return b ? b.match(f.PATH_PATTERN) : null }, d._formatQueryString = function(h, g) { if (null == h) { throw new Error("You must specify data.") } var j = []; for (var i in h) { j.push(i + "=" + escape(h[i])) } return g && (j = j.concat(g)), j.join("&") }, d.buildPath = function(h, g) { if (null == g) { return h } var k = [], j = h.indexOf("?"); if (-1 != j) { var i = h.slice(j + 1); k = k.concat(i.split("&")) } return -1 != j ? h.slice(0, j) + "?" + this._formatQueryString(g, k) : h + "?" + this._formatQueryString(g, k) }, d._isCrossDomain = function(h) { var g = document.createElement("a"); g.href = h.src; var j = document.createElement("a"); j.href = location.href; var i = "" != g.hostname && (g.port != j.port || g.protocol != j.protocol || g.hostname != j.hostname); return i }, d._isLocal = function(g) { var c = document.createElement("a"); return c.href = g.src, "" == c.hostname && "file:" == c.protocol }, d.toString = function() { return "[PreloadJS AbstractLoader]" }, createjs.AbstractLoader = e }(), this.createjs = this.createjs || {}, function() { var f = function(i, d, j) { this.init(i, d, j) }, e = f.prototype = new createjs.AbstractLoader, h = f; h.loadTimeout = 8000, h.LOAD_TIMEOUT = 0, h.BINARY = "binary", h.CSS = "css", h.IMAGE = "image", h.JAVASCRIPT = "javascript", h.JSON = "json", h.JSONP = "jsonp", h.MANIFEST = "manifest", h.SOUND = "sound", h.SVG = "svg", h.TEXT = "text", h.XML = "xml", h.POST = "POST", h.GET = "GET", e._basePath = null, e._crossOrigin = "", e.useXHR = !0, e.stopOnError = !1, e.maintainScriptOrder = !0, e.next = null, e._typeCallbacks = null, e._extensionCallbacks = null, e._loadStartWasDispatched = !1, e._maxConnections = 1, e._currentlyLoadingScript = null, e._currentLoads = null, e._loadQueue = null, e._loadQueueBackup = null, e._loadItemsById = null, e._loadItemsBySrc = null, e._loadedResults = null, e._loadedRawResults = null, e._numItems = 0, e._numItemsLoaded = 0, e._scriptOrder = null, e._loadedScripts = null, e.init = function(i, d, j) { this._numItems = this._numItemsLoaded = 0, this._paused = !1, this._loadStartWasDispatched = !1, this._currentLoads = [], this._loadQueue = [], this._loadQueueBackup = [], this._scriptOrder = [], this._loadedScripts = [], this._loadItemsById = {}, this._loadItemsBySrc = {}, this._loadedResults = {}, this._loadedRawResults = {}, this._typeCallbacks = {}, this._extensionCallbacks = {}, this._basePath = d, this.setUseXHR(i), this._crossOrigin = j === !0 ? "Anonymous" : j === !1 || null == j ? "" : j }, e.setUseXHR = function(b) { return this.useXHR = 0 != b && null != window.XMLHttpRequest, this.useXHR }, e.removeAll = function() { this.remove() }, e.remove = function(j) { var i = null; if (!j || j instanceof Array) { if (j) { i = j } else { if (arguments.length > 0) { return } } } else { i = [j] } var p = !1; if (i) { for (; i.length;) { var o = i.pop(), n = this.getResult(o); for (m = this._loadQueue.length - 1; m >= 0; m--) { if (l = this._loadQueue[m].getItem(), l.id == o || l.src == o) { this._loadQueue.splice(m, 1)[0].cancel(); break } } for (m = this._loadQueueBackup.length - 1; m >= 0; m--) { if (l = this._loadQueueBackup[m].getItem(), l.id == o || l.src == o) { this._loadQueueBackup.splice(m, 1)[0].cancel(); break } } if (n) { delete this._loadItemsById[n.id], delete this._loadItemsBySrc[n.src], this._disposeItem(n) } else { for (var m = this._currentLoads.length - 1; m >= 0; m--) { var l = this._currentLoads[m].getItem(); if (l.id == o || l.src == o) { this._currentLoads.splice(m, 1)[0].cancel(), p = !0; break } } } } p && this._loadNext() } else { this.close(); for (var k in this._loadItemsById) { this._disposeItem(this._loadItemsById[k]) } this.init(this.useXHR) } }, e.reset = function() { this.close(); for (var j in this._loadItemsById) { this._disposeItem(this._loadItemsById[j]) } for (var i = [], l = 0, k = this._loadQueueBackup.length; k > l; l++) { i.push(this._loadQueueBackup[l].getItem()) } this.loadManifest(i, !1) }, h.isBinary = function(b) { switch (b) { case createjs.LoadQueue.IMAGE: case createjs.LoadQueue.BINARY: return !0; default: return !1 } }, h.isText = function(b) { switch (b) { case createjs.LoadQueue.TEXT: case createjs.LoadQueue.JSON: case createjs.LoadQueue.MANIFEST: case createjs.LoadQueue.XML: case createjs.LoadQueue.HTML: case createjs.LoadQueue.CSS: case createjs.LoadQueue.SVG: case createjs.LoadQueue.JAVASCRIPT: return !0; default: return !1 } }, e.installPlugin = function(j) { if (null != j && null != j.getPreloadHandlers) { var i = j.getPreloadHandlers(); if (i.scope = j, null != i.types) { for (var l = 0, k = i.types.length; k > l; l++) { this._typeCallbacks[i.types[l]] = i } } if (null != i.extensions) { for (l = 0, k = i.extensions.length; k > l; l++) { this._extensionCallbacks[i.extensions[l]] = i } } } }, e.setMaxConnections = function(b) { this._maxConnections = b, !this._paused && this._loadQueue.length > 0 && this._loadNext() }, e.loadFile = function(j, i, l) { if (null == j) { var k = new createjs.Event("error"); return k.text = "PRELOAD_NO_FILE", this._sendError(k), void 0 } this._addItem(j, null, l), i !== !1 ? this.setPaused(!1) : this.setPaused(!0) }, e.loadManifest = function(j, c, p) { var o = null, n = null; if (j instanceof Array) { if (0 == j.length) { var m = new createjs.Event("error"); return m.text = "PRELOAD_MANIFEST_EMPTY", this._sendError(m), void 0 } o = j } else { if ("string" == typeof j) { o = [{ src: j, type: h.MANIFEST }] } else { if ("object" != typeof j) { var m = new createjs.Event("error"); return m.text = "PRELOAD_MANIFEST_NULL", this._sendError(m), void 0 } if (void 0 !== j.src) { if (null == j.type) { j.type = h.MANIFEST } else { if (j.type != h.MANIFEST) { var m = new createjs.Event("error"); m.text = "PRELOAD_MANIFEST_ERROR", this._sendError(m) } } o = [j] } else { void 0 !== j.manifest && (o = j.manifest, n = j.path) } } } for (var l = 0, k = o.length; k > l; l++) { this._addItem(o[l], n, p) } c !== !1 ? this.setPaused(!1) : this.setPaused(!0) }, e.load = function() { this.setPaused(!1) }, e.getItem = function(b) { return this._loadItemsById[b] || this._loadItemsBySrc[b] }, e.getResult = function(j, i) { var l = this._loadItemsById[j] || this._loadItemsBySrc[j]; if (null == l) { return null } var k = l.id; return i && this._loadedRawResults[k] ? this._loadedRawResults[k] : this._loadedResults[k] }, e.setPaused = function(b) { this._paused = b, this._paused || this._loadNext() }, e.close = function() { for (; this._currentLoads.length;) { this._currentLoads.pop().cancel() } this._scriptOrder.length = 0, this._loadedScripts.length = 0, this.loadStartWasDispatched = !1 }, e._addItem = function(j, i, m) { var l = this._createLoadItem(j, i, m); if (null != l) { var k = this._createLoader(l); null != k && (this._loadQueue.push(k), this._loadQueueBackup.push(k), this._numItems++, this._updateProgress(), this.maintainScriptOrder && l.type == createjs.LoadQueue.JAVASCRIPT && k instanceof createjs.XHRLoader && (this._scriptOrder.push(l), this._loadedScripts.push(null))) } }, e._createLoadItem = function(v, u, t) { var s = null; switch (typeof v) { case "string": s = { src: v }; break; case "object": s = window.HTMLAudioElement && v instanceof window.HTMLAudioElement ? { tag: v, src: s.tag.src, type: createjs.LoadQueue.SOUND } : v; break; default: return null } var r = this._parseURI(s.src); null != r && (s.ext = r[6]), null == s.type && (s.type = this._getTypeByExtension(s.ext)); var q = "", p = t || this._basePath, o = s.src; if (r && null == r[1] && null == r[3]) { if (u) { q = u; var n = this._parsePath(u); o = u + o, null != p && n && null == n[1] && null == n[2] && (q = p + q) } else { null != p && (q = p) } } if (s.src = q + s.src, s.path = q, (s.type == createjs.LoadQueue.JSON || s.type == createjs.LoadQueue.MANIFEST) && (s._loadAsJSONP = null != s.callback), s.type == createjs.LoadQueue.JSONP && null == s.callback) { throw new Error("callback is required for loading JSONP requests.") }(void 0 === s.tag || null === s.tag) && (s.tag = this._createTag(s)), (void 0 === s.id || null === s.id || "" === s.id) && (s.id = o); var m = this._typeCallbacks[s.type] || this._extensionCallbacks[s.ext]; if (m) { var l = m.callback.call(m.scope, s.src, s.type, s.id, s.data, q, this); if (l === !1) { return null } l === !0 || (null != l.src && (s.src = l.src), null != l.id && (s.id = l.id), null != l.tag && (s.tag = l.tag), null != l.completeHandler && (s.completeHandler = l.completeHandler), l.type && (s.type = l.type), r = this._parseURI(s.src), null != r && null != r[6] && (s.ext = r[6].toLowerCase())) } return this._loadItemsById[s.id] = s, this._loadItemsBySrc[s.src] = s, s }, e._createLoader = function(d) { var c = this.useXHR; switch (d.type) { case createjs.LoadQueue.JSON: case createjs.LoadQueue.MANIFEST: c = !d._loadAsJSONP; break; case createjs.LoadQueue.XML: case createjs.LoadQueue.TEXT: c = !0; break; case createjs.LoadQueue.SOUND: case createjs.LoadQueue.JSONP: c = !1; break; case null: return null } return c ? new createjs.XHRLoader(d, this._crossOrigin) : new createjs.TagLoader(d) }, e._loadNext = function() { if (!this._paused) { this._loadStartWasDispatched || (this._sendLoadStart(), this._loadStartWasDispatched = !0), this._numItems == this._numItemsLoaded ? (this.loaded = !0, this._sendComplete(), this.next && this.next.load && this.next.load()) : this.loaded = !1; for (var d = 0; d < this._loadQueue.length && !(this._currentLoads.length >= this._maxConnections); d++) { var c = this._loadQueue[d]; if (this.maintainScriptOrder && c instanceof createjs.TagLoader && c.getItem().type == createjs.LoadQueue.JAVASCRIPT) { if (this._currentlyLoadingScript) { continue } this._currentlyLoadingScript = !0 } this._loadQueue.splice(d, 1), d--, this._loadItem(c) } } }, e._loadItem = function(b) { b.on("progress", this._handleProgress, this), b.on("complete", this._handleFileComplete, this), b.on("error", this._handleFileError, this), this._currentLoads.push(b), this._sendFileStart(b.getItem()), b.load() }, e._handleFileError = function(i) { var d = i.target; this._numItemsLoaded++, this._updateProgress(); var j = new createjs.Event("error"); j.text = "FILE_LOAD_ERROR", j.item = d.getItem(), this._sendError(j), this.stopOnError || (this._removeLoadItem(d), this._loadNext()) }, e._handleFileComplete = function(j) { var i = j.target, l = i.getItem(); if (this._loadedResults[l.id] = i.getResult(), i instanceof createjs.XHRLoader && (this._loadedRawResults[l.id] = i.getResult(!0)), this._removeLoadItem(i), this.maintainScriptOrder && l.type == createjs.LoadQueue.JAVASCRIPT) { if (!(i instanceof createjs.TagLoader)) { return this._loadedScripts[createjs.indexOf(this._scriptOrder, l)] = l, this._checkScriptLoadOrder(i), void 0 } this._currentlyLoadingScript = !1 } if (delete l._loadAsJSONP, l.type == createjs.LoadQueue.MANIFEST) { var k = i.getResult(); null != k && void 0 !== k.manifest && this.loadManifest(k, !0) } this._processFinishedLoad(l, i) }, e._processFinishedLoad = function(d, c) { this._numItemsLoaded++, this._updateProgress(), this._sendFileComplete(d, c), this._loadNext() }, e._checkScriptLoadOrder = function() { for (var j = this._loadedScripts.length, i = 0; j > i; i++) { var l = this._loadedScripts[i]; if (null === l) { break } if (l !== !0) { var k = this._loadedResults[l.id]; (document.body || document.getElementsByTagName("body")[0]).appendChild(k), this._processFinishedLoad(l), this._loadedScripts[i] = !0 } } }, e._removeLoadItem = function(i) { for (var d = this._currentLoads.length, j = 0; d > j; j++) { if (this._currentLoads[j] == i) { this._currentLoads.splice(j, 1); break } } }, e._handleProgress = function(d) { var c = d.target; this._sendFileProgress(c.getItem(), c.progress), this._updateProgress() }, e._updateProgress = function() { var j = this._numItemsLoaded / this._numItems, i = this._numItems - this._numItemsLoaded; if (i > 0) { for (var m = 0, l = 0, k = this._currentLoads.length; k > l; l++) { m += this._currentLoads[l].progress } j += m / i * (i / this._numItems) } this._sendProgress(j) }, e._disposeItem = function(b) { delete this._loadedResults[b.id], delete this._loadedRawResults[b.id], delete this._loadItemsById[b.id], delete this._loadItemsBySrc[b.src] }, e._createTag = function(d) { var c = null; switch (d.type) { case createjs.LoadQueue.IMAGE: return c = document.createElement("img"), "" == this._crossOrigin || this._isLocal(d) || (c.crossOrigin = this._crossOrigin), c; case createjs.LoadQueue.SOUND: return c = document.createElement("audio"), c.autoplay = !1, c; case createjs.LoadQueue.JSON: case createjs.LoadQueue.JSONP: case createjs.LoadQueue.JAVASCRIPT: case createjs.LoadQueue.MANIFEST: return c = document.createElement("script"), c.type = "text/javascript", c; case createjs.LoadQueue.CSS: return c = this.useXHR ? document.createElement("style") : document.createElement("link"), c.rel = "stylesheet", c.type = "text/css", c; case createjs.LoadQueue.SVG: return this.useXHR ? c = document.createElement("svg") : (c = document.createElement("object"), c.type = "image/svg+xml"), c } return null }, e._getTypeByExtension = function(b) { if (null == b) { return createjs.LoadQueue.TEXT } switch (b.toLowerCase()) { case "jpeg": case "jpg": case "gif": case "png": case "webp": case "bmp": return createjs.LoadQueue.IMAGE; case "ogg": case "mp3": case "wav": return createjs.LoadQueue.SOUND; case "json": return createjs.LoadQueue.JSON; case "xml": return createjs.LoadQueue.XML; case "css": return createjs.LoadQueue.CSS; case "js": return createjs.LoadQueue.JAVASCRIPT; case "svg": return createjs.LoadQueue.SVG; default: return createjs.LoadQueue.TEXT } }, e._sendFileProgress = function(i, d) { if (this._isCanceled()) { return this._cleanUp(), void 0 } if (this.hasEventListener("fileprogress")) { var j = new createjs.Event("fileprogress"); j.progress = d, j.loaded = d, j.total = 1, j.item = i, this.dispatchEvent(j) } }, e._sendFileComplete = function(i, d) { if (!this._isCanceled()) { var j = new createjs.Event("fileload"); j.loader = d, j.item = i, j.result = this._loadedResults[i.id], j.rawResult = this._loadedRawResults[i.id], i.completeHandler && i.completeHandler(j), this.hasEventListener("fileload") && this.dispatchEvent(j) } }, e._sendFileStart = function(d) { var c = new createjs.Event("filestart"); c.item = d, this.hasEventListener("filestart") && this.dispatchEvent(c) }, e.toString = function() { return "[PreloadJS LoadQueue]" }, createjs.LoadQueue = f; var g = function() {}; g.init = function() { var b = navigator.userAgent; g.isFirefox = b.indexOf("Firefox") > -1, g.isOpera = null != window.opera, g.isChrome = b.indexOf("Chrome") > -1, g.isIOS = b.indexOf("iPod") > -1 || b.indexOf("iPhone") > -1 || b.indexOf("iPad") > -1 }, g.init(), createjs.LoadQueue.BrowserDetect = g }(), this.createjs = this.createjs || {}, function() { var d = function(b) { this.init(b) }, c = d.prototype = new createjs.AbstractLoader; c._loadTimeout = null, c._tagCompleteProxy = null, c._isAudio = !1, c._tag = null, c._jsonResult = null, c.init = function(b) { this._item = b, this._tag = b.tag, this._isAudio = window.HTMLAudioElement && b.tag instanceof window.HTMLAudioElement, this._tagCompleteProxy = createjs.proxy(this._handleLoad, this) }, c.getResult = function() { return this._item.type == createjs.LoadQueue.JSONP || this._item.type == createjs.LoadQueue.MANIFEST ? this._jsonResult : this._tag }, c.cancel = function() { this.canceled = !0, this._clean() }, c.load = function() { var f = this._item, e = this._tag; clearTimeout(this._loadTimeout); var h = createjs.LoadQueue.LOAD_TIMEOUT; 0 == h && (h = createjs.LoadQueue.loadTimeout), this._loadTimeout = setTimeout(createjs.proxy(this._handleTimeout, this), h), this._isAudio && (e.src = null, e.preload = "auto"), e.onerror = createjs.proxy(this._handleError, this), this._isAudio ? (e.onstalled = createjs.proxy(this._handleStalled, this), e.addEventListener("canplaythrough", this._tagCompleteProxy, !1)) : (e.onload = createjs.proxy(this._handleLoad, this), e.onreadystatechange = createjs.proxy(this._handleReadyStateChange, this)); var g = this.buildPath(f.src, f.values); switch (f.type) { case createjs.LoadQueue.CSS: e.href = g; break; case createjs.LoadQueue.SVG: e.data = g; break; default: e.src = g } if (f.type == createjs.LoadQueue.JSONP || f.type == createjs.LoadQueue.JSON || f.type == createjs.LoadQueue.MANIFEST) { if (null == f.callback) { throw new Error("callback is required for loading JSONP requests.") } if (null != window[f.callback]) { throw new Error('JSONP callback "' + f.callback + '" already exists on window. You need to specify a different callback. Or re-name the current one.') } window[f.callback] = createjs.proxy(this._handleJSONPLoad, this) }(f.type == createjs.LoadQueue.SVG || f.type == createjs.LoadQueue.JSONP || f.type == createjs.LoadQueue.JSON || f.type == createjs.LoadQueue.MANIFEST || f.type == createjs.LoadQueue.JAVASCRIPT || f.type == createjs.LoadQueue.CSS) && (this._startTagVisibility = e.style.visibility, e.style.visibility = "hidden", (document.body || document.getElementsByTagName("body")[0]).appendChild(e)), null != e.load && e.load() }, c._handleJSONPLoad = function(b) { this._jsonResult = b }, c._handleTimeout = function() { this._clean(); var b = new createjs.Event("error"); b.text = "PRELOAD_TIMEOUT", this._sendError(b) }, c._handleStalled = function() {}, c._handleError = function() { this._clean(); var b = new createjs.Event("error"); this._sendError(b) }, c._handleReadyStateChange = function() { clearTimeout(this._loadTimeout); var b = this.getItem().tag; ("loaded" == b.readyState || "complete" == b.readyState) && this._handleLoad() }, c._handleLoad = function() { if (!this._isCanceled()) { var f = this.getItem(), e = f.tag; if (!(this.loaded || this._isAudio && 4 !== e.readyState)) { switch (this.loaded = !0, f.type) { case createjs.LoadQueue.SVG: case createjs.LoadQueue.JSON: case createjs.LoadQueue.JSONP: case createjs.LoadQueue.MANIFEST: case createjs.LoadQueue.CSS: e.style.visibility = this._startTagVisibility, (document.body || document.getElementsByTagName("body")[0]).removeChild(e) } this._clean(), this._sendComplete() } } }, c._clean = function() { clearTimeout(this._loadTimeout); var f = this.getItem(), e = f.tag; null != e && (e.onload = null, e.removeEventListener && e.removeEventListener("canplaythrough", this._tagCompleteProxy, !1), e.onstalled = null, e.onprogress = null, e.onerror = null, null != e.parentNode && f.type == createjs.LoadQueue.SVG && f.type == createjs.LoadQueue.JSON && f.type == createjs.LoadQueue.MANIFEST && f.type == createjs.LoadQueue.CSS && f.type == createjs.LoadQueue.JSONP && e.parentNode.removeChild(e)); var f = this.getItem(); (f.type == createjs.LoadQueue.JSONP || f.type == createjs.LoadQueue.MANIFEST) && (window[f.callback] = null) }, c.toString = function() { return "[PreloadJS TagLoader]" }, createjs.TagLoader = d }(), this.createjs = this.createjs || {}, function() { var d = function(f, e) { this.init(f, e) }, c = d.prototype = new createjs.AbstractLoader; c._request = null, c._loadTimeout = null, c._xhrLevel = 1, c._response = null, c._rawResponse = null, c._crossOrigin = "", c.init = function(f, e) { this._item = f, this._crossOrigin = e, !this._createXHR(f) }, c.getResult = function(b) { return b && this._rawResponse ? this._rawResponse : this._response }, c.cancel = function() { this.canceled = !0, this._clean(), this._request.abort() }, c.load = function() { if (null == this._request) { return this._handleError(), void 0 } if (this._request.onloadstart = createjs.proxy(this._handleLoadStart, this), this._request.onprogress = createjs.proxy(this._handleProgress, this), this._request.onabort = createjs.proxy(this._handleAbort, this), this._request.onerror = createjs.proxy(this._handleError, this), this._request.ontimeout = createjs.proxy(this._handleTimeout, this), 1 == this._xhrLevel) { var f = createjs.LoadQueue.LOAD_TIMEOUT; if (0 == f) { f = createjs.LoadQueue.loadTimeout } else { try { console.warn("LoadQueue.LOAD_TIMEOUT has been deprecated in favor of LoadQueue.loadTimeout") } catch (e) {} } this._loadTimeout = setTimeout(createjs.proxy(this._handleTimeout, this), f) } this._request.onload = createjs.proxy(this._handleLoad, this), this._request.onreadystatechange = createjs.proxy(this._handleReadyStateChange, this); try { this._item.values && this._item.method != createjs.LoadQueue.GET ? this._item.method == createjs.LoadQueue.POST && this._request.send(this._formatQueryString(this._item.values)) : this._request.send() } catch (h) { var g = new createjs.Event("error"); g.error = h, this._sendError(g) } }, c.getAllResponseHeaders = function() { return this._request.getAllResponseHeaders instanceof Function ? this._request.getAllResponseHeaders() : null }, c.getResponseHeader = function(b) { return this._request.getResponseHeader instanceof Function ? this._request.getResponseHeader(b) : null }, c._handleProgress = function(f) { if (f && !(f.loaded > 0 && 0 == f.total)) { var e = new createjs.Event("progress"); e.loaded = f.loaded, e.total = f.total, this._sendProgress(e) } }, c._handleLoadStart = function() { clearTimeout(this._loadTimeout), this._sendLoadStart() }, c._handleAbort = function() { this._clean(); var b = new createjs.Event("error"); b.text = "XHR_ABORTED", this._sendError(b) }, c._handleError = function() { this._clean(); var b = new createjs.Event("error"); this._sendError(b) }, c._handleReadyStateChange = function() { 4 == this._request.readyState && this._handleLoad() }, c._handleLoad = function() { if (!this.loaded) { if (this.loaded = !0, !this._checkError()) { return this._handleError(), void 0 } this._response = this._getResponse(), this._clean(); var b = this._generateTag(); b && this._sendComplete() } }, c._handleTimeout = function(f) { this._clean(); var e = new createjs.Event("error"); e.text = "PRELOAD_TIMEOUT", this._sendError(f) }, c._checkError = function() { var b = parseInt(this._request.status); switch (b) { case 404: case 0: return !1 } return !0 }, c._getResponse = function() { if (null != this._response) { return this._response } if (null != this._request.response) { return this._request.response } try { if (null != this._request.responseText) { return this._request.responseText } } catch (b) {} try { if (null != this._request.responseXML) { return this._request.responseXML } } catch (b) {} return null }, c._createXHR = function(g) { var f = this._isCrossDomain(g), j = null; if (f && window.XDomainRequest) { j = new XDomainRequest } else { if (window.XMLHttpRequest) { j = new XMLHttpRequest } else { try { j = new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch (i) { try { j = new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch (i) { try { j = new ActiveXObject("Msxml2.XMLHTTP") } catch (i) { return !1 } } } } } createjs.LoadQueue.isText(g.type) && j.overrideMimeType && j.overrideMimeType("text/plain; charset=utf-8"), this._xhrLevel = "string" == typeof j.responseType ? 2 : 1; var h = null; return h = g.method == createjs.LoadQueue.GET ? this.buildPath(g.src, g.values) : g.src, j.open(g.method || createjs.LoadQueue.GET, h, !0), f && j instanceof XMLHttpRequest && 1 == this._xhrLevel && j.setRequestHeader("Origin", location.origin), g.values && g.method == createjs.LoadQueue.POST && j.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), createjs.LoadQueue.isBinary(g.type) && (j.responseType = "arraybuffer"), this._request = j, !0 }, c._clean = function() { clearTimeout(this._loadTimeout); var b = this._request; b.onloadstart = null, b.onprogress = null, b.onabort = null, b.onerror = null, b.onload = null, b.ontimeout = null, b.onloadend = null, b.onreadystatechange = null }, c._generateTag = function() { var i = this._item.type, h = this._item.tag; switch (i) { case createjs.LoadQueue.IMAGE: return h.onload = createjs.proxy(this._handleTagReady, this), "" != this._crossOrigin && (h.crossOrigin = "Anonymous"), h.src = this.buildPath(this._item.src, this._item.values), this._rawResponse = this._response, this._response = h, !1; case createjs.LoadQueue.JAVASCRIPT: return h = document.createElement("script"), h.text = this._response, this._rawResponse = this._response, this._response = h, !0; case createjs.LoadQueue.CSS: var n = document.getElementsByTagName("head")[0]; if (n.appendChild(h), h.styleSheet) { h.styleSheet.cssText = this._response } else { var m = document.createTextNode(this._response); h.appendChild(m) } return this._rawResponse = this._response, this._response = h, !0; case createjs.LoadQueue.XML: var l = this._parseXML(this._response, "text/xml"); return this._rawResponse = this._response, this._response = l, !0; case createjs.LoadQueue.SVG: var l = this._parseXML(this._response, "image/svg+xml"); return this._rawResponse = this._response, null != l.documentElement ? (h.appendChild(l.documentElement), this._response = h) : this._response = l, !0; case createjs.LoadQueue.JSON: case createjs.LoadQueue.MANIFEST: var k = {}; try { k = JSON.parse(this._response) } catch (j) { k = j } return this._rawResponse = this._response, this._response = k, !0 } return !0 }, c._parseXML = function(g, f) { var j = null; try { if (window.DOMParser) { var i = new DOMParser; j = i.parseFromString(g, f) } else { j = new ActiveXObject("Microsoft.XMLDOM"), j.async = !1, j.loadXML(g) } } catch (h) {} return j }, c._handleTagReady = function() { this._sendComplete() }, c.toString = function() { return "[PreloadJS XHRLoader]" }, createjs.XHRLoader = d }(), "object" != typeof JSON && (JSON = {}), function() { function f(a) { return 10 > a ? "0" + a : a } function quote(a) { return escapable.lastIndex = 0, escapable.test(a) ? '"' + a.replace(escapable, function(a) { var b = meta[a]; return "string" == typeof b ? b : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + a + '"' } function str(a, b) { var c, d, e, f, g, h = gap, i = b[a]; switch (i && "object" == typeof i && "function" == typeof i.toJSON && (i = i.toJSON(a)), "function" == typeof rep && (i = rep.call(b, a, i)), typeof i) { case "string": return quote(i); case "number": return isFinite(i) ? String(i) : "null"; case "boolean": case "null": return String(i); case "object": if (!i) { return "null" } if (gap += indent, g = [], "[object Array]" === Object.prototype.toString.apply(i)) { for (f = i.length, c = 0; f > c; c += 1) { g[c] = str(c, i) || "null" } return e = 0 === g.length ? "[]" : gap ? "[\n" + gap + g.join(",\n" + gap) + "\n" + h + "]" : "[" + g.join(",") + "]", gap = h, e } if (rep && "object" == typeof rep) { for (f = rep.length, c = 0; f > c; c += 1) { "string" == typeof rep[c] && (d = rep[c], e = str(d, i), e && g.push(quote(d) + (gap ? ": " : ":") + e)) } } else { for (d in i) { Object.prototype.hasOwnProperty.call(i, d) && (e = str(d, i), e && g.push(quote(d) + (gap ? ": " : ":") + e)) } } return e = 0 === g.length ? "{}" : gap ? "{\n" + gap + g.join(",\n" + gap) + "\n" + h + "}" : "{" + g.join(",") + "}", gap = h, e } } "function" != typeof Date.prototype.toJSON && (Date.prototype.toJSON = function() { return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z" : null }, String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function() { return this.valueOf() }); var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { "\b": "\\b", " ": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" }, rep; "function" != typeof JSON.stringify && (JSON.stringify = function(a, b, c) { var d; if (gap = "", indent = "", "number" == typeof c) { for (d = 0; c > d; d += 1) { indent += " " } } else { "string" == typeof c && (indent = c) } if (rep = b, b && "function" != typeof b && ("object" != typeof b || "number" != typeof b.length)) { throw new Error("JSON.stringify") } return str("", { "": a }) }), "function" != typeof JSON.parse && (JSON.parse = function(text, reviver) { function walk(a, b) { var c, d, e = a[b]; if (e && "object" == typeof e) { for (c in e) { Object.prototype.hasOwnProperty.call(e, c) && (d = walk(e, c), void 0 !== d ? e[c] = d : delete e[c]) } } return reviver.call(a, b, e) } var j; if (text = String(text), cx.lastIndex = 0, cx.test(text) && (text = text.replace(cx, function(a) { return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) })), /^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) { return j = eval("(" + text + ")"), "function" == typeof reviver ? walk({ "": j }, "") : j } throw new SyntaxError("JSON.parse") }) }(); function Preloader() { this.sceneManager } Preloader.prototype = new Preloader(); Preloader.prototype.constructor = Preloader; Preloader.staticLoader = null; Preloader.prototype.init = function() { this.sceneManager = new SceneManager(); this.sceneManager.init(); this.progress = 0; canvas = document.getElementById("canvas"); ctx = canvas.getContext("2d"); ctx.font = "normal normal normal " + 100 + "px chunkfive"; ctx.fillText("\u6587\u672c", 0, 0); ctx.clearRect(0, 0, canvas.width, canvas.height); this.logo = new Image(); this.logo.src = "content/textures/ui/preloaderLogo.png"; this.edge = new Image(); this.edge.src = "content/textures/ui/preloaderLogoEdge.png"; this.device = new Image(); this.device.src = "content/textures/preloaderDeviceSmall.png"; this.device.onload = this.onLoaded; this.loadingTextOffsetY = 0; this.orientationTextSize = 18; this.deviceOffsetY = 0; this.logoOffsetY = 0; Preloader.staticLoader = this; resizeGame() }; Preloader.prototype.onLoaded = function() { var c = new Drawable(); c.init(Preloader.staticLoader.logo, 0, 0); c.originX = c.sprite.width * 0.5; c.originY = c.sprite.height * 0.5; c.x = canvas.width * 0.5; c.y = canvas.height - 56; c.useCamera = false; Preloader.staticLoader.sceneManager.addEntity(c); var b = new Drawable(); b.init(Preloader.staticLoader.edge, 0, 0); b.originX = 1; b.x = c.x - 80; b.y = c.y - 6; b.scaleX = (canvas.width * 0.5 - 80); b.useCamera = false; Preloader.staticLoader.sceneManager.addEntity(b); b = new Drawable(); b.init(Preloader.staticLoader.edge, 0, 0); b.x = c.x + 80; b.y = c.y - 6; b.scaleX = canvas.width * 0.5 - 80; b.useCamera = false; Preloader.staticLoader.sceneManager.addEntity(b); var a = new Drawable(); a.init(Preloader.staticLoader.device, 0, 0); a.x = 0; a.y = 0; a.useCamera = false; Preloader.staticLoader.sceneManager.addEntity(a) }; Preloader.prototype.start = function() { var a = this; this.interval = window.setInterval(function() { a.update(0.033) }, 0.033) }; Preloader.prototype.end = function(b) { this.callback = b; this.sceneManager.entities[3].sprite = content.preloadDeviceLarge; this.sceneManager.entities[3].scaleX = 0.333; this.sceneManager.entities[3].scaleY = 0.333; var a = 36; if (canvas.width < 620) { a *= canvas.width / 620 } TweenLite.to(this, 0.5, { loadingTextOffsetY: -(canvas.height * 0.5 - 40) - 80, ease: Back.easeIn }); TweenLite.to(this.sceneManager.entities[3], 0.5, { scaleX: 1, scaleY: 1, ease: Expo.easeIn }); TweenLite.to(this, 0.5, { deviceOffsetY: -160, orientationTextSize: a, ease: Expo.easeIn, overwrite: 0 }); TweenLite.to(this, 0.25, { logoOffsetY: 100, deviceOffsetY: -canvas.height, orientationTextSize: 0, ease: Sine.easeIn, overwrite: 0, delay: 2.5, onCompleteParams: [this], onComplete: function(c) { if (c.interval) { window.clearInterval(c.interval) } if (c.callback) { c.callback() } } }) }; Preloader.prototype.update = function(a) { this.sceneManager.update(a); if (this.sceneManager.entityCount != 0) { this.sceneManager.entities[0].x = canvas.width * 0.5; this.sceneManager.entities[1].x = this.sceneManager.entities[0].x - 80; this.sceneManager.entities[2].x = this.sceneManager.entities[0].x + 80; this.sceneManager.entities[0].y = canvas.height - 56 + this.logoOffsetY; this.sceneManager.entities[1].y = this.sceneManager.entities[0].y - 6; this.sceneManager.entities[2].y = this.sceneManager.entities[0].y - 6; this.sceneManager.entities[1].scaleX = (canvas.width * 0.5 - 80); this.sceneManager.entities[2].scaleX = (canvas.width * 0.5 - 80); this.sceneManager.entities[3].x = (canvas.width * 0.5 - (this.sceneManager.entities[3].scaleX * this.sceneManager.entities[3].sprite.width * 0.5)); this.sceneManager.entities[3].y = (canvas.height * 0.5 + 64) + this.deviceOffsetY } this.draw() }; Preloader.prototype.draw = function() { ctx.fillStyle = "#fcb040"; ctx.fillRect(0, 0, canvas.width, canvas.height); this.sceneManager.masterAlpha = 1; this.sceneManager.draw(); var a = "\u52a0\u8f7d"; ctx.fillStyle = "#000000"; ctx.globalAlpha = 0.25; ctx.font = "normal normal normal " + 72 + "px chunkfive"; ctx.textAlign = "center"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 - 40 + 5 + this.loadingTextOffsetY); ctx.globalAlpha = 1; ctx.fillStyle = "#FFFFFF"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 - 40 + this.loadingTextOffsetY); ctx.globalAlpha = 1; a = Math.floor(this.progress * 100).toString() + "%"; ctx.fillStyle = "#000000"; ctx.globalAlpha = 0.25; ctx.font = "normal normal normal " + 36 + "px chunkfive"; ctx.textAlign = "center"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 + 5 + this.loadingTextOffsetY); ctx.globalAlpha = 1; ctx.fillStyle = "#FFFFFF"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 + this.loadingTextOffsetY); ctx.globalAlpha = 1; a = "\u6e38\u620f\u5373\u5c06\u5f00\u59cb\u2026"; ctx.fillStyle = "#000000"; ctx.globalAlpha = 0.25; ctx.font = "normal normal normal " + this.orientationTextSize + "px chunkfive"; ctx.textAlign = "center"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 + 3 + 160); ctx.globalAlpha = 1; ctx.fillStyle = "#FFFFFF"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 + 160); ctx.globalAlpha = 1; a = ""; ctx.fillStyle = "#000000"; ctx.globalAlpha = 0.25; ctx.font = "normal normal normal " + this.orientationTextSize + "px chunkfive"; ctx.textAlign = "center"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 + 3 + 160 + 22 * (this.orientationTextSize / 18)); ctx.globalAlpha = 1; ctx.fillStyle = "#FFFFFF"; ctx.fillText(a, canvas.width * 0.5, canvas.height * 0.5 + 160 + 22 * (this.orientationTextSize / 18)); ctx.globalAlpha = 1 }; var progressCallback; var completeCallback; var content = new function() { var b = false; var a = false; this.preload = new createjs.LoadQueue(false); createjs.Sound.alternateExtensions = ["mp3"]; this.preload.installPlugin(createjs.Sound); this.load = function() { this.preloader = new Preloader(); this.preloader.init(); var d = this; progressCallback = function(f) { d.handleProgress(f) }; completeCallback = function(f) { d.handleComplete(f) }; this.preload.addEventListener("progress", progressCallback); this.preload.addEventListener("complete", completeCallback); var c = [{ id: "crateHit", src: "content/sound/crateHit.ogg" }, { id: "dirtRoadRumble", src: "content/sound/dirtRoadRumble.ogg" }, { id: "explosion", src: "content/sound/explosion.ogg" }, { id: "hitCrash01", src: "content/sound/hitCrash01.ogg" }, { id: "hitCrash02", src: "content/sound/hitCrash02.ogg" }, { id: "hitCrash03", src: "content/sound/hitCrash03.ogg" }, { id: "impactCrash", src: "content/sound/impactCrash.ogg" }, { id: "pothole01", src: "content/sound/pothole01.ogg" }, { id: "pothole02", src: "content/sound/pothole02.ogg" }, { id: "pothole03", src: "content/sound/pothole03.ogg" }, { id: "roadBlockHit", src: "content/sound/roadBlockHit.ogg" }, { id: "siren", src: "content/sound/siren.ogg" }, { id: "skid", src: "content/sound/skid.ogg" }, { id: "wrench", src: "content/sound/wrench.ogg" }, { id: "menuLoop", src: "content/sound/menuloop.ogg" }, { id: "gameLoop", src: "content/sound/gameloop.ogg" }, { id: "pixel", src: "content/textures/pixel.png" }, { id: "black", src: "content/textures/black.png" }, { id: "roadStripe", src: "content/textures/world/roadStripe.png" }, { id: "road", src: "content/textures/world/road.png" }, { id: "preloaderLogo", src: "content/textures/ui/preloaderLogo.png" }, { id: "preloaderLogoEdge", src: "content/textures/ui/preloaderLogoEdge.png" }, { id: "carLayer0", src: "content/textures/world/carLayer0.png" }, { id: "carLayer1", src: "content/textures/world/carLayer1.png" }, { id: "carLayer2", src: "content/textures/world/carLayer2.png" }, { id: "carLayer3", src: "content/textures/world/carLayer3.png" }, { id: "carLayer4", src: "content/textures/world/carLayer4.png" }, { id: "carCrashLayer0", src: "content/textures/world/carCrashLayer0.png" }, { id: "carCrashLayer1", src: "content/textures/world/carCrashLayer1.png" }, { id: "carCrashLayer2", src: "content/textures/world/carCrashLayer2.png" }, { id: "carCrashLayer3", src: "content/textures/world/carCrashLayer3.png" }, { id: "carCrashLayer4", src: "content/textures/world/carCrashLayer4.png" }, { id: "carExplosionLayer", src: "content/textures/world/carExplosionLayer.png" }, { id: "copCar", src: "content/textures/world/copCar.png" }, { id: "truck", src: "content/textures/world/truck.png" }, { id: "copCarCrash", src: "content/textures/world/copCarCrash.png" }, { id: "truckCrash", src: "content/textures/world/truckCrash.png" }, { id: "truckExploded", src: "content/textures/world/truckExplosion.png" }, { id: "blueCopLight", src: "content/textures/world/blueCopLight.png" }, { id: "redCopLight", src: "content/textures/world/redCopLight.png" }, { id: "wall", src: "content/textures/world/wall.png" }, { id: "steeringBack", src: "content/textures/ui/steeringBack.png" }, { id: "steeringCircle", src: "content/textures/ui/steeringCircle.png" }, { id: "roadBacking", src: "content/textures/ui/roadBacking.png" }, { id: "crate", src: "content/textures/world/crate.png" }, { id: "explodingCrate", src: "content/textures/world/explodingCrate.png" }, { id: "dust", src: "content/textures/world/dust.png" }, { id: "smoke", src: "content/textures/particles/smoke.png" }, { id: "skid", src: "content/textures/world/skid.png" }, { id: "white4", src: "content/textures/world/white4.png" }, { id: "black4", src: "content/textures/world/black4.png" }, { id: "star", src: "content/textures/ui/star.png" }, { id: "circleTimerRing", src: "content/textures/ui/circleTimerRing.png" }, { id: "circleTimerBase", src: "content/textures/ui/circleTimerBase.png" }, { id: "restartBtnUp", src: "content/textures/ui/restartBtn_up.png" }, { id: "restartBtnDown", src: "content/textures/ui/restartBtn_down.png" }, { id: "homeBtnUp", src: "content/textures/ui/homeBtn_up.png" }, { id: "homeBtnDown", src: "content/textures/ui/homeBtn_down.png" }, { id: "playBtnUp", src: "content/textures/ui/playBtn_up.png" }, { id: "playBtnDown", src: "content/textures/ui/playBtn_down.png" }, { id: "bannerEdge", src: "content/textures/ui/bannerEdge.png" }, { id: "bannerSpread", src: "content/textures/ui/bannerSpread.png" }, { id: "bannerShine", src: "content/textures/ui/bannerShine.png" }, { id: "endFade", src: "content/textures/ui/endFade.png" }, { id: "bestGlow", src: "content/textures/ui/bestGlow.png" }, { id: "menuBack", src: "content/textures/ui/menuBack.png" }, { id: "menuSign", src: "content/textures/ui/menuSign.png" }, { id: "menuSignShadow", src: "content/textures/ui/menuSignShadow.png" }, { id: "cloudLine", src: "content/textures/ui/cloudline.png" }, { id: "heliBody", src: "content/textures/world/heliBody.png" }, { id: "heliBlades", src: "content/textures/world/heliBlades.png" }, { id: "rock01", src: "content/textures/world/rock01.png" }, { id: "rock02", src: "content/textures/world/rock02.png" }, { id: "rock03", src: "content/textures/world/rock03.png" }, { id: "rock04", src: "content/textures/world/rock04.png" }, { id: "sandEdge", src: "content/textures/world/sandEdge.png" }, { id: "pothole0", src: "content/textures/world/pothole0.png" }, { id: "pothole1", src: "content/textures/world/pothole1.png" }, { id: "pothole2", src: "content/textures/world/pothole2.png" }, { id: "oil", src: "content/textures/world/oil.png" }, { id: "warningStripe", src: "content/textures/ui/warningStripe.png" }, { id: "dirtArrow", src: "content/textures/ui/dirtArrow.png" }, { id: "dirtRoad", src: "content/textures/world/dirtRoad.png" }, { id: "dirtTransition", src: "content/textures/world/dirtTransition.png" }, { id: "dirtSkid", src: "content/textures/world/dirtSkid.png" }, { id: "blockStanding", src: "content/textures/world/blockStanding.png" }, { id: "blockFallen", src: "content/textures/world/blockFallen.png" }, { id: "wrenchParticle", src: "content/textures/particles/wrenchParticle.png" }, { id: "explosion", src: "content/textures/particles/explosion.png" }, { id: "explosionSpark", src: "content/textures/particles/explosionSpark.png" }, { id: "flash", src: "content/textures/particles/flash.png" }, { id: "pauseBtn", src: "content/textures/ui/pauseBtn.png" }, { id: "backBtn", src: "content/textures/ui/backBtn.png" }, { id: "pauseBack", src: "content/textures/ui/pauseBack.png" }, { id: "pauseText", src: "content/textures/ui/pauseText.png" }, { id: "tut01", src: "content/textures/ui/tut01.png" }, { id: "tut02", src: "content/textures/ui/tut02.png" }, { id: "tutArrow", src: "content/textures/ui/tutArrow.png" }, { id: "wrench", src: "content/textures/world/wrench.png" }, { id: "wrenchStar", src: "content/textures/world/wrenchStar.png" }, { id: "hitOn", src: "content/textures/ui/hitOn.png" }, { id: "hitOff", src: "content/textures/ui/hitOff.png" }, { id: "soundOff", src: "content/textures/ui/soundOffBtn.png" }, { id: "soundOn", src: "content/textures/ui/soundOnBtn.png" }, { id: "preloadDeviceLarge", src: "content/textures/preloaderDeviceLarge.png" }, { id: "ffBadge", src: "content/textures/branding/ffBadge.png" }, { id: "moreGames", src: "content/textures/ui/moreGames.png" }]; switch (gCurrentBrand) { case BRAND.ADDICTING: c.push({ id: "addictingEnd", src: "content/textures/branding/AddictingGames/addictingEnd.png" }); c.push({ id: "addictingMenu", src: "content/textures/branding/AddictingGames/addictingMenu.png" }); c.push({ id: "addictingSplash", src: "content/textures/branding/AddictingGames/addictingSplash.png" }); break; case BRAND.MRG: // c.push({ // id: "mrgEnd", // src: "content/textures/branding/MyRealGames/mrgEnd.png" // }); c.push({ id: "mrgMenu", src: "content/textures/branding/MyRealGames/mrgMenu.png" }); c.push({ id: "mrgSplash", src: "content/textures/branding/MyRealGames/mrgSplash.png" }); break } this.preload.loadManifest(c); this.preloader.start() }; this.handleProgress = function(c) { if (this.preloader) { this.preloader.progress = c.progress } }; this.handleComplete = function(d) { this.preload.removeEventListener("progress", progressCallback); this.preload.removeEventListener("complete", completeCallback); this.pixel = this.preload.getResult("pixel"); this.black = this.preload.getResult("black"); this.road = this.preload.getResult("road"); this.roadStripe = this.preload.getResult("roadStripe"); this.preloaderLogo = this.preload.getResult("preloaderLogo"); this.preloaderLogoEdge = this.preload.getResult("preloaderLogoEdge"); this.carLayer0 = this.preload.getResult("carLayer0"); this.carLayer1 = this.preload.getResult("carLayer1"); this.carLayer2 = this.preload.getResult("carLayer2"); this.carLayer3 = this.preload.getResult("carLayer3"); this.carLayer4 = this.preload.getResult("carLayer4"); this.carCrashLayer0 = this.preload.getResult("carCrashLayer0"); this.carCrashLayer1 = this.preload.getResult("carCrashLayer1"); this.carCrashLayer2 = this.preload.getResult("carCrashLayer2"); this.carCrashLayer3 = this.preload.getResult("carCrashLayer3"); this.carCrashLayer4 = this.preload.getResult("carCrashLayer4"); this.carExplosionLayer = this.preload.getResult("carExplosionLayer"); this.copCar = this.preload.getResult("copCar"); this.truck = this.preload.getResult("truck"); this.copCarCrash = this.preload.getResult("copCarCrash"); this.truckCrash = this.preload.getResult("truckCrash"); this.truckExploded = this.preload.getResult("truckExploded"); this.blueCopLight = this.preload.getResult("blueCopLight"); this.redCopLight = this.preload.getResult("redCopLight"); this.wall = this.preload.getResult("wall"); this.steeringBack = this.preload.getResult("steeringBack"); this.steeringCircle = this.preload.getResult("steeringCircle"); this.roadBacking = this.preload.getResult("roadBacking"); this.crate = this.preload.getResult("crate"); this.explodingCrate = this.preload.getResult("explodingCrate"); this.dust = this.preload.getResult("dust"); this.smoke = this.preload.getResult("smoke"); this.skid = this.preload.getResult("skid"); this.white4 = this.preload.getResult("white4"); this.black4 = this.preload.getResult("black4"); this.star = this.preload.getResult("star"); this.circleTimerRing = this.preload.getResult("circleTimerRing"); this.circleTimerBase = this.preload.getResult("circleTimerBase"); this.homeBtnDown = this.preload.getResult("homeBtnDown"); this.homeBtnUp = this.preload.getResult("homeBtnUp"); this.restartBtnDown = this.preload.getResult("restartBtnDown"); this.restartBtnUp = this.preload.getResult("restartBtnUp"); this.playBtnDown = this.preload.getResult("playBtnDown"); this.playBtnUp = this.preload.getResult("playBtnUp"); this.bannerEdge = this.preload.getResult("bannerEdge"); this.bannerSpread = this.preload.getResult("bannerSpread"); this.bannerShine = this.preload.getResult("bannerShine"); this.endFade = this.preload.getResult("endFade"); this.bestGlow = this.preload.getResult("bestGlow"); this.menuBack = this.preload.getResult("menuBack"); this.menuSign = this.preload.getResult("menuSign"); this.menuSignShadow = this.preload.getResult("menuSignShadow"); this.cloudLine = this.preload.getResult("cloudLine"); this.explosion = this.preload.getResult("explosion"); this.explosionSpark = this.preload.getResult("explosionSpark"); this.flash = this.preload.getResult("flash"); this.dust = this.preload.getResult("dust"); this.heliBody = this.preload.getResult("heliBody"); this.heliBlades = this.preload.getResult("heliBlades"); this.rock01 = this.preload.getResult("rock01"); this.rock02 = this.preload.getResult("rock02"); this.rock03 = this.preload.getResult("rock03"); this.rock04 = this.preload.getResult("rock04"); this.sandEdge = this.preload.getResult("sandEdge"); this.pothole0 = this.preload.getResult("pothole0"); this.pothole1 = this.preload.getResult("pothole1"); this.pothole2 = this.preload.getResult("pothole2"); this.oil = this.preload.getResult("oil"); this.warningStripe = this.preload.getResult("warningStripe"); this.dirtArrow = this.preload.getResult("dirtArrow"); this.dirtRoad = this.preload.getResult("dirtRoad"); this.dirtTransition = this.preload.getResult("dirtTransition"); this.dirtSkid = this.preload.getResult("dirtSkid"); this.blockStanding = this.preload.getResult("blockStanding"); this.blockFallen = this.preload.getResult("blockFallen"); this.wrenchParticle = this.preload.getResult("wrenchParticle"); this.pauseBtn = this.preload.getResult("pauseBtn"); this.backBtn = this.preload.getResult("backBtn"); this.pauseBack = this.preload.getResult("pauseBack"); this.pauseText = this.preload.getResult("pauseText"); this.tut01 = this.preload.getResult("tut01"); this.tut02 = this.preload.getResult("tut02"); this.tutArrow = this.preload.getResult("tutArrow"); this.wrench = this.preload.getResult("wrench"); this.wrenchStar = this.preload.getResult("wrenchStar"); this.hitOn = this.preload.getResult("hitOn"); this.hitOff = this.preload.getResult("hitOff"); this.soundOn = this.preload.getResult("soundOn"); this.soundOff = this.preload.getResult("soundOff"); this.preloadDeviceLarge = this.preload.getResult("preloadDeviceLarge"); this.ffBadge = this.preload.getResult("ffBadge"); this.moreGames = this.preload.getResult("moreGames"); this.blueCar = this.createCar("#009bc9"); this.greenCar = this.createCar("#1e9c30"); this.redCar = this.createCar("#c90000"); this.purpleCar = this.createCar("#613c73"); this.silverCar = this.createCar("#dbdbdb"); this.orangeCar = this.createCar("#ff9607"); this.blueCarCrash = this.createCar("#009bc9", "crash"); this.greenCarCrash = this.createCar("#1e9c30", "crash"); this.redCarCrash = this.createCar("#c90000", "crash"); this.purpleCarCrash = this.createCar("#613c73", "crash"); this.silverCarCrash = this.createCar("#dbdbdb", "crash"); this.orangeCarCrash = this.createCar("#ff9607", "crash"); this.blueCarExploded = this.createCar("#009bc9", "exploded"); this.greenCarExploded = this.createCar("#1e9c30", "exploded"); this.redCarExploded = this.createCar("#c90000", "exploded"); this.purpleCarExploded = this.createCar("#613c73", "exploded"); this.silverCarExploded = this.createCar("#dbdbdb", "exploded"); this.orangeCarExploded = this.createCar("#ff9607", "exploded"); this.copCarExploded = document.createElement("canvas"); this.copCarExploded.width = this.copCar.width; this.copCarExploded.height = this.copCar.height; var c = this.copCarExploded.getContext("2d"); c.drawImage(this.copCar, 0, 0); c.drawImage(this.carExplosionLayer, 0, 0); this.carSprites = []; this.carSprites.push(this.blueCar); this.carSprites.push(this.greenCar); this.carSprites.push(this.redCar); this.carSprites.push(this.purpleCar); this.carSprites.push(this.silverCar); this.carSprites.push(this.orangeCar); this.crashSprites = []; this.crashSprites.push(this.blueCarCrash); this.crashSprites.push(this.greenCarCrash); this.crashSprites.push(this.redCarCrash); this.crashSprites.push(this.purpleCarCrash); this.crashSprites.push(this.silverCarCrash); this.crashSprites.push(this.orangeCarCrash); this.explodeSprites = []; this.explodeSprites.push(this.blueCarExploded); this.explodeSprites.push(this.greenCarExploded); this.explodeSprites.push(this.redCarExploded); this.explodeSprites.push(this.purpleCarExploded); this.explodeSprites.push(this.silverCarExploded); this.explodeSprites.push(this.orangeCarExploded); switch (gCurrentBrand) { case BRAND.ADDICTING: this.addictingEnd = this.preload.getResult("addictingEnd"); this.addictingMenu = this.preload.getResult("addictingMenu"); this.addictingSplash = this.preload.getResult("addictingSplash"); break; case BRAND.MRG: this.mrgEnd = this.preload.getResult("mrgEnd"); this.mrgMenu = this.preload.getResult("mrgMenu"); this.mrgSplash = this.preload.getResult("mrgSplash"); break } if (this.preloader) { this.preloader.end(init); this.preloader = null } }; this.createCar = function(h, j) { if (j == null) { j = "" } var d = 97; var m = 65; switch (j) { case "crash": d = 101; m = 71; break } var i = document.createElement("canvas"); i.width = d; i.height = m; var e = i.getContext("2d"); var l = this.carLayer0; switch (j) { case "crash": l = this.carCrashLayer0; break } e.drawImage(l, 0, 0); var k = hexToRGB(h); var f = [k.r / 255, 0, 0, 0, 0, 0, k.g / 255, 0, 0, 0, 0, 0, k.b / 255, 0, 0, 0, 0, 0, 1, 0]; var n = document.createElement("canvas"); n.width = d; n.height = m; var c = n.getContext("2d"); l = this.carLayer1; switch (j) { case "crash": l = this.carCrashLayer1; break } c.drawImage(l, 0, 0); var g = colorMatrixFilter(c.getImageData(0, 0, d, m), f); c.clearRect(0, 0, d, m); c.putImageData(g, 0, 0); e.drawImage(n, 0, 0); f[0] *= 0.6667; f[6] *= 0.6667; f[12] *= 0.6667; c.clearRect(0, 0, d, m); l = this.carLayer2; switch (j) { case "crash": l = this.carCrashLayer2; break } c.drawImage(l, 0, 0); g = colorMatrixFilter(c.getImageData(0, 0, d, m), f); c.clearRect(0, 0, d, m); c.putImageData(g, 0, 0); e.drawImage(n, 0, 0); f[0] = Math.min(1, k.r / 255 * 2); f[6] = Math.min(1, k.g / 255 * 2); f[12] = Math.min(1, k.b / 255 * 2); c.clearRect(0, 0, d, m); l = this.carLayer3; switch (j) { case "crash": l = this.carCrashLayer3; break } c.drawImage(l, 0, 0); g = colorMatrixFilter(c.getImageData(0, 0, d, m), f); c.clearRect(0, 0, d, m); c.putImageData(g, 0, 0); e.drawImage(n, 0, 0); l = this.carLayer4; switch (j) { case "crash": l = this.carCrashLayer4; break } e.drawImage(l, 0, 0); if (j == "exploded") { e.drawImage(content.carExplosionLayer, 0, 0) } return i } }; var AUDIO_STATE = { NONE: 0, MENULOOP: 1, GAMELOOP: 2 }; var currentAudioState = AUDIO_STATE.NONE; var musicInstance = null; var soundMuted = false; var musicMuted = false; function setAudioState(a) { currentAudioState = a; if (musicInstance) { musicInstance.stop() } switch (currentAudioState) { case AUDIO_STATE.NONE: break; case AUDIO_STATE.MENULOOP: musicInstance = createjs.Sound.play("menuLoop", { loop: -1 }); break; case AUDIO_STATE.GAMELOOP: musicInstance = createjs.Sound.play("gameLoop", { loop: -1 }); break } if (musicInstance && musicMuted) { musicInstance.setVolume(0) } } function playSound(a) { createjs.Sound.play(a, { volume: soundMuted ? 0 : 1 }) } function setSoundMute(a) { soundMuted = a; if (gStorageAvailable) { setLocalVar("soundMuted", soundMuted) } } function setMusicMute(a) { musicMuted = a; if (gStorageAvailable) { setLocalVar("musicMuted", musicMuted) } if (musicInstance) { if (musicMuted) { musicInstance.setVolume(0) } else { musicInstance.setVolume(1) } } } var ColliderType = { NULL: 0, CIRCLE: 1, LINE: 2 }; function Collider() { this.active; this.colliding; this.sensor; this.lastCollisionObject; this.initialized = false; this.type = ColliderType.NULL } Collider.prototype.init = function() { this.active = true; this.sensor = false; this.initialized = true; this.colliding = false; this.lastCollisionObject = null }; Collider.prototype.draw = function(a) {}; var Collision = new function() { this.getCollision = function(d, c) { if (!d.active || !c.active) { return null } if (d.type === ColliderType.CIRCLE) { if (c.type === ColliderType.CIRCLE) { return this.intersectCircleCircle(d, c) } else { if (c.type === ColliderType.LINE) { return this.intersectCircleLine(d, c) } } } else { if (d.type === ColliderType.LINE) { if (c.type === ColliderType.CIRCLE) { return this.intersectCircleLine(c, d) } else { return this.intersectLineLine(d, c) } } } return null }; this.intersectCircleLine = function(b, a) { this.dirX = a.x1 - a.x0; this.dirY = a.y1 - a.y0; this.diffX = b.x - a.x0; this.diffY = b.y - a.y0; this.t = (this.diffX * this.dirX + this.diffY * this.dirY) / (this.dirX * this.dirX + this.dirY * this.dirY); if (this.t < 0) { this.t = 0 } if (this.t > 1) { this.t = 1 } this.closestX = a.x0 + this.dirX * this.t; this.closestY = a.y0 + this.dirY * this.t; this.closestX -= b.x; this.closestY -= b.y; this.r = b.radius; this.dot = (this.closestX * this.closestX) + (this.closestY * this.closestY); if (this.dot <= this.r * this.r) { b.colliding = true; a.colliding = true; if (b.sensor || a.sensor) { return null } this.dirX = -this.closestX; this.dirY = -this.closestY; this.len = Math.sqrt((this.dirX * this.dirX) + (this.dirY * this.dirY)); if (this.len != 0) { this.dirX /= this.len; this.dirY /= this.len } else { this.dirX = 1; this.dirY = 0 } this.mag = this.r - this.len; if (!this.result) { this.result = new CollisionResult() } this.result.set(this.mag, this.dirX, this.dirY, this.closestX + b.x, this.closestY + b.y); return this.result } return null }; this.intersectCircleCircle = function(b, a) { this.a = b.x - a.x; this.b = b.y - a.y; this.r = b.radius + a.radius; if (Math.abs(b.x - a.x) > this.r || Math.abs(b.y - a.y) > this.r) { return null } this.dirX = b.x - a.x; this.dirY = b.y - a.y; this.d = (this.a * this.a + this.b * this.b); if (this.d < this.r * this.r && this.d != 0) { b.colliding = true; a.colliding = true; if (b.sensor || a.sensor) { return null } this.d = Math.sqrt(this.d); this.dirX /= this.d; this.dirY /= this.d; this.mag = this.r - this.d; if (!this.result) { this.result = new CollisionResult() } this.result.set(this.mag, this.dirX, this.dirY, b.x + this.dirX * b.radius, b.y + this.dirY * b.radius); return this.result } return null }; this.intersectLineLine = function(b, a) { if (!b.active || !a.active) { return null } if ((b.x0 == a.x0 && b.y0 == a.y0) || (b.x1 == a.x1 && b.y1 == a.y1)) { return null } this.min1 = Number.MAX_VALUE; this.min2 = Number.MAX_VALUE; this.max1 = -Number.MAX_VALUE; this.max2 = -Number.MAX_VALUE; this.minOverlap = Number.MAX_VALUE; this.overlapAxisX = 0; this.overlapAxisY = 0; this.axisX = 0; this.axisY = 0; this.vertX = 0; this.vertY = 0; for (var c = 0; c < 2; c++) { this.axisX = 0; this.axisY = 0; this.min1 = Number.MAX_VALUE; this.min2 = Number.MAX_VALUE; this.max1 = -Number.MAX_VALUE; this.max2 = -Number.MAX_VALUE; if (c == 0) { this.axisX = -(b.y1 - b.y0); this.axisY = b.x1 - b.x0 } else { this.axisX = -(a.y1 - a.y0); this.axisY = a.x1 - a.x0 } this.len = Math.sqrt(this.axisX * this.axisX + this.axisY * this.axisY); this.axisX /= this.len; this.axisY /= this.len; for (var d = 0; d < (c == 0 ? 1 : 2); d++) { this.vertX = 0; this.vertY = 0; switch (d) { case 0: this.vertX = b.x0; this.vertY = b.y0; break; case 1: this.vertX = b.x1; this.vertY = b.y1; break } this.max1 = Math.max((this.vertX * this.axisX + this.vertY * this.axisY), this.max1); this.min1 = Math.min((this.vertX * this.axisX + this.vertY * this.axisY), this.min1) } for (var d = 0; d < (c == 1 ? 1 : 2); d++) { this.vertX = 0; this.vertY = 0; switch (d) { case 0: this.vertX = a.x0; this.vertY = a.y0; break; case 1: this.vertX = a.x1; this.vertY = a.y1; break } this.max2 = Math.max((this.vertX * this.axisX + this.vertY * this.axisY), this.max2); this.min2 = Math.min((this.vertX * this.axisX + this.vertY * this.axisY), this.min2) } if (this.min1 < this.min2) { if (c == 0) { this.minOverlap = this.min2 - this.max1; this.overlapAxisX = this.axisX; this.overlapAxisY = this.axisY } if (this.min2 - this.max1 > 0) { return null } else { if (this.min2 - this.max1 > this.minOverlap) { this.minOverlap = this.min2 - this.max1; this.overlapAxisX = this.axisX; this.overlapAxisY = this.axisY } } } else { if (c == 0) { this.minOverlap = this.min1 - this.max2; this.overlapAxisX = -this.axisX; this.overlapAxisY = -this.axisY } if (this.min1 - this.max2 > 0) { return null } else { if (this.min1 - this.max2 > this.minOverlap) { this.minOverlap = this.min1 - this.max2; this.overlapAxisX = -this.axisX; this.overlapAxisY = -this.axisY } } } } if (!this.result) { this.result = new CollisionResult() } this.result.set(-this.minOverlap, this.overlapAxisX, this.overlapAxisY, 0, 0); return this.result } }; function CollisionResult() { this.magnitude = 0; this.directionX = 1; this.directionY = 0; this.x = 0; this.y = 0 } CollisionResult.prototype.set = function(d, c, b, a, e) { this.magnitude = d; this.directionX = c; this.directionY = b; this.x = a; this.y = e }; function CircleCollider() { this.radius; this.x; this.y } CircleCollider.prototype = new Collider(); CircleCollider.prototype.constructor = CircleCollider; CircleCollider.prototype.init = function(b, c, a) { this.type = ColliderType.CIRCLE; this.active = true; this.initialized = true; this.sensor = false; this.colliding = false; this.radius = a; this.x = b; this.y = c }; CircleCollider.prototype.draw = function(c) { if (!this.initialized) { return } var b = document.createElement("canvas"); b.width = this.radius * 2; b.height = this.radius * 2; var a = b.getContext("2d"); a.strokeStyle = "#00FF00"; a.lineWidth = 2; a.lineWidth = 0; a.beginPath(); a.arc(this.radius, this.radius, this.radius, 0, Math.PI * 2); a.stroke(); var e = new Drawable(); e.init(b, this.x, this.y); e.originX = this.radius; e.originY = this.radius; e.sceneManager = c; e.draw() }; function LineCollider() { this.x0; this.y0; this.x1; this.y1 } LineCollider.prototype = new Collider(); LineCollider.prototype.constructor = LineCollider; LineCollider.prototype.init = function(b, d, a, c) { this.type = ColliderType.LINE; this.active = true; this.initialized = true; this.sensor = false; this.colliding = false; this.x0 = b; this.y0 = d; this.x1 = a; this.y1 = c; this.basex0 = b; this.basey0 = d; this.basex1 = a; this.basey1 = c; this.offsetX = 0; this.offsetY = 0 }; LineCollider.prototype.update = function() { this.x0 = this.basex0 + this.offsetX; this.y0 = this.basey0 + this.offsetY; this.x1 = this.basex1 + this.offsetX; this.y1 = this.basey1 + this.offsetY }; LineCollider.prototype.draw = function(a) { if (!this.initialized) { return } var b = Math.sqrt(((this.x1 - this.x0) * (this.x1 - this.x0)) + ((this.y1 - this.y0) * (this.y1 - this.y0))); var e = Math.atan2(this.y1 - this.y0, this.x1 - this.x0); var c = new Drawable(); c.init(content.pixel, this.x0, this.y0); c.originY = 0.5; c.scaleX = b; c.scaleY = 4; c.angle = e; c.sceneManager = a; c.update(0); c.draw() }; var OnFinishAnimation = { STOP: 0, LOOP: 1, REWIND: 2, REWINDLOOP: 3, RESET: 4 }; var AnimationState = { STOPPED: 0, PLAYING: 1, REWINDING: 2 }; function Animation() { this.name = ""; this.framesPerSecond = 1; this.currentFrame = 0; this.frames = []; this.finishAction = OnFinishAnimation.STOP; this.currentState = AnimationState.STOPPED; this.timer = 0; this.frameSwitched = false } Animation.prototype.init = function(a, b, d, c) { this.name = a; this.frames = b; this.framesPerSecond = d; this.finishAction = c; this.currentState = AnimationState.STOPPED; this.currentFrame = 0; this.frameSwitched = false; this.timer = 0 }; Animation.prototype.update = function(a) { this.frameSwitched = false; switch (this.currentState) { case AnimationState.PLAYING: this.timer += a; while (this.timer >= 1 / this.framesPerSecond) { this.timer -= 1 / this.framesPerSecond; this.currentFrame++; this.frameSwitched = true; if (this.currentFrame >= this.frames.length) { this.AnimationFinished() } } break; case AnimationState.STOPPED: break; case AnimationState.REWINDING: this.timer += a; while (this.timer >= 1 / this.framesPerSecond) { this.timer -= 1 / this.framesPerSecond; this.currentFrame--; this.frameSwitched = true; if (this.currentFrame < 0) { this.AnimationFinished() } } break; default: break } }; Animation.prototype.ResetTimer = function() { this.timer = 0 }; Animation.prototype.SetState = function(a) { this.currentState = a }; Animation.prototype.SetFrame = function(a) { this.currentFrame = a }; Animation.prototype.AnimationFinished = function() { switch (this.finishAction) { case OnFinishAnimation.LOOP: this.currentFrame = 0; this.timer = 0; this.currentState = AnimationState.PLAYING; break; case OnFinishAnimation.REWIND: if (this.currentState != AnimationState.REWINDING) { this.timer = 0; this.currentFrame -= 2; this.currentState = AnimationState.REWINDING } else { this.currentFrame = 0; this.currentState = AnimationState.STOPPED } break; case OnFinishAnimation.REWINDLOOP: if (this.currentState != AnimationState.REWINDING) { this.timer = 0; this.currentFrame -= 2; this.currentState = AnimationState.REWINDING } else { this.timer = 0; this.currentFrame += 2; this.currentState = AnimationState.PLAYING } break; case OnFinishAnimation.STOP: this.currentFrame = this.frames.length - 1; this.currentState = AnimationState.STOPPED; break; case OnFinishAnimation.RESET: this.currentFrame = 0; this.currentState = AnimationState.STOPPED; break; default: break } }; function Camera() { this.active; this.originX; this.originY; this.lockX; this.lockY; this.pixelSnap; this.internalMatrix; this.useTarget; this.useAcceleration; this.positionX; this.positionY; this.velocityX; this.velocityY; this.accelerationX; this.accelerationY; this.dragX; this.dragY; this.targetPositionX; this.targetPositionY; this.directionX; this.directionY; this.movementSpeed; this.lockStartX; this.lockStartY; this.angle; this.rotationSpeed; this.rotationVelocity; this.targetAngle; this.zoom; this.zoomTarget; this.zoomSpeed; this.shakeTimer; this.shakeTime; this.shakeFrequency; this.shakeStartTime; this.shakeSamplesX = []; this.shakeSamplesY = []; this.isShaking = false; this.shakeMagnitude; this.init = function(a, d, c, b) { this.originX = 400; this.originY = 240; this.setPosition(a, d); this.setAngle(c); this.setZoom(b); this.active = true; this.lockX = false; this.lockY = false; this.pixelSnap = false; this.useTarget = true; this.useAcceleration = true; this.velocityX = 0; this.velocityY = 0; this.oldVelocityX = 0; this.oldVelocityY = 0; this.accelerationX = 0; this.accelerationY = 0; this.movementSpeed = 40; this.dragX = 0.001; this.dragY = 0.001; this.directionX = 0; this.directionY = 0; this.directionLength; this.displacement; this.force; this.rotationSpeed = 0.5; this.rotationVelocity = 0; this.zoomSpeed = 0.75; this.shakeTimer = 0; this.shakeTime = 0; this.shakeMagnitude = 0; this.shakeOffsetX = 0; this.shakeOffsetY = 0; this.internalMatrix = mat2d.create(); mat2d.identity(this.internalMatrix) }; this.update = function(a) { this.originX = canvas.width * 0.5; this.originY = canvas.height * 0.5; if (this.active) { if (this.useTarget) { this.displacement = distanceBetweenPoints(this.positionX, this.positionY, this.targetPositionX, this.targetPositionY); if (this.useAcceleration) { if (this.displacement !== 0) { this.force = -this.displacement * this.movementSpeed; this.directionX = this.positionX - this.targetPositionX; this.directionY = this.positionY - this.targetPositionY; this.directionLength = distanceBetweenPoints(0, 0, this.directionX, this.directionY); this.directionX /= this.directionLength; this.directionY /= this.directionLength; this.accelerationX += this.directionX * this.force; this.accelerationY += this.directionY * this.force } this.oldVelocityX = this.velocityX; this.oldVelocityY = this.velocityY; this.velocityX += this.accelerationX * a; this.velocityY += this.accelerationY * a; this.positionX += ((this.oldVelocityX + this.velocityX) * (0.5 * a) * (this.lockX ? 0 : 1)); this.positionY += ((this.oldVelocityY + this.velocityY) * (0.5 * a) * (this.lockY ? 0 : 1)); this.accelerationX = 0; this.accelerationY = 0; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, a) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, a) } } else { this.positionX = this.targetPositionX; this.positionY = this.targetPositionY } } if (this.angle < this.targetAngle) { this.angle = Math.min(this.targetAngle, this.angle + this.rotationSpeed * a) } else { if (this.angle > this.targetAngle) { this.angle = Math.max(this.targetAngle, this.angle - this.rotationSpeed * a) } } this.angle = normalizeAngle(this.angle); if (this.pixelSnap) { this.positionX = Math.floor(this.positionX); this.positionY = Math.floor(this.positionY) } } }; this.setPosition = function(a, b) { this.setTargetPosition(a, b); this.positionX = this.targetPositionX; this.positionY = this.targetPositionY; this.velocityX = 0; this.velocityY = 0 }; this.setTargetPosition = function(a, b) { this.targetPositionX = -a; this.targetPositionY = -b }; this.moveTargetPosition = function(b, a) { this.targetPositionX += b; this.targetPositionY += a }; this.setZoom = function(a) { this.setZoomTarget(a); this.zoom = a }; this.setZoomTarget = function(a) { this.zoomTarget = a }; this.setAngle = function(b) { this.setTargetAngle(b); this.angle = b }; this.setTargetAngle = function(b) { this.targetAngle = b }; this.shake = function(e, d, c) { this.shakeTime = e; this.shakeTimer = e; this.shakeFrequency = d; this.shakeMagnitude = c; var a = (this.shakeTime) * d; this.shakeSamplesX = []; this.shakeSamplesY = []; for (var b = 0; b < a; b++) { this.shakeSamplesX.push(Math.random() * 2 - 1); this.shakeSamplesY.push(Math.random() * 2 - 1) } }; this.getShakeX = function() { var d = (1 - (this.shakeTimer / this.shakeTime)) * (this.shakeSamplesX.length - 2); var c = Math.floor(d); var b = c + 1; var a = this.shakeDecay(this.shakeTimer); return (this.shakeSamplesX[c] + (d - c) * (this.shakeSamplesX[b] - this.shakeSamplesX[c])) * a * this.shakeMagnitude }; this.getShakeY = function() { var d = (1 - (this.shakeTimer / this.shakeTime)) * (this.shakeSamplesY.length - 2); var c = Math.floor(d); var b = c + 1; var a = this.shakeDecay(this.shakeTimer); var e = (this.shakeSamplesY[c] + (d - c) * (this.shakeSamplesY[b] - this.shakeSamplesY[c])) * a * this.shakeMagnitude; return e }; this.shakeDecay = function(a) { if (this.shakeTimer <= 0) { return 0 } return this.shakeTimer / this.shakeTime } } function Entity() { this.x = 0; this.y = 0; this.canvasWidth = 0; this.canvasHeight = 0; this.useCamera = true; this.toBeRemoved = false; this.depth = 0; this.visible = true; this.useDepthSort = true; this.sceneManager = null; this.hasUpdated = true } Entity.prototype.init = function() { this.x = 0; this.y = 0; this.toBeRemoved = false; this.useCamera = true }; Entity.prototype.update = function(a) {}; Entity.prototype.draw = function() {}; Entity.prototype.onAddedToSceneManager = function() {}; Entity.prototype.flagForRemoval = function() { this.toBeRemoved = true }; function Drawable() { Entity.call(this); this.sprite = null; this.angle = 0; this.originX = 0; this.originY = 0; this.scaleX = 1; this.scaleY = 1; this.alpha = 1; this.sourceRectX = 0; this.sourceRectY = 0; this.sourceRectW = 0; this.sourceRectH = 0; this.useSourceRect = false; this.useParallax = false; this.parent = null; this.visible = true; this.active = true; this.worldX = 0; this.worldY = 0; this.hasUpdated = true; this.useMask = false; this.mask = null; this.maskX = 0; this.maskY = 0; this.maskOriginX = 0; this.maskOriginY = 0; this.maskAngle = 0; this.maskCanvas; this.drawingSM; this.sceneAlpha; this.internalMatrix; this._originTransformVec2; this._scaleTransformVec2; this._translateTransformVec2 } Drawable.prototype = new Entity(); Drawable.prototype.constructor = Drawable; Drawable.prototype.init = function(b, a, c) { this.sprite = b; this.x = a; this.y = c; this.toBeRemoved = false; this.useCamera = true; this._originTransformVec2 = vec2.create(); this._scaleTransformVec2 = vec2.create(); this._translateTransformVec2 = vec2.create() }; Drawable.prototype.update = function(a) { if (!this.active) { return } this.hasUpdated = true }; Drawable.prototype.draw = function(c) { if (!this.visible || this.alpha <= 0 || !this.sprite) { return } if (this.sprite.width <= 0 || this.sprite.height <= 0) { return } c = (c ? c : ctx); c.save(); this.worldX = 0; this.worldY = 0; this.drawingSM = this.sceneManager; var b = false; if (this.parent && this.parent.sceneManager) { this.drawingSM = this.parent.sceneManager } this.sceneAlpha = 1; if (this.drawingSM) { this.sceneAlpha = this.drawingSM.masterAlpha } c.globalAlpha = this.alpha * this.sceneAlpha; var a = this.x; var e = this.y; if (this.parent) { a += this.parent.x; e += this.parent.y } this.worldX += a; this.worldY += e; if (!this.internalMatrix) { this.internalMatrix = mat2d.create() } mat2d.identity(this.internalMatrix); if (this.originX != 0 || this.originY != 0) { if (!this._originTransformVec2) { this._originTransformVec2 = vec2.create() } this._originTransformVec2[0] = -this.originX; this._originTransformVec2[1] = -this.originY; mat2d.translate(this.internalMatrix, this.internalMatrix, this._originTransformVec2) } if (this.scaleX != 1 || this.scaleY != 1) { if (!this._scaleTransformVec2) { this._scaleTransformVec2 = vec2.create() } this._scaleTransformVec2[0] = this.scaleX; this._scaleTransformVec2[1] = this.scaleY; mat2d.scale(this.internalMatrix, this.internalMatrix, this._scaleTransformVec2) } if (this.angle != 0) { mat2d.rotate(this.internalMatrix, this.internalMatrix, -this.angle) } if (a != 0 || e != 0) { if (!this._translateTransformVec2) { this._translateTransformVec2 = vec2.create() } this._translateTransformVec2[0] = a; this._translateTransformVec2[1] = e; mat2d.translate(this.internalMatrix, this.internalMatrix, this._translateTransformVec2) } if (this.drawingSM) { if ((!this.parent && this.useCamera) || (this.parent && this.parent.useCamera)) { mat2d.multiply(this.internalMatrix, this.internalMatrix, this.drawingSM.camera.internalMatrix) } } c.setTransform(this.internalMatrix[0], this.internalMatrix[1], this.internalMatrix[2], this.internalMatrix[3], this.internalMatrix[4], this.internalMatrix[5]); if (this.useMask && this.mask) { if (!this.maskCanvas) { this.maskCanvas = document.createElement("canvas"); this.maskCanvas.width = Math.max(this.sprite.width * this.scaleX + this.scaleX * this.originX, this.mask.width); this.maskCanvas.height = Math.max(this.sprite.height * this.scaleY + this.scaleY * this.originY, this.mask.height) } var d = this.maskCanvas.getContext("2d"); d.clearRect(0, 0, this.maskCanvas.width, this.maskCanvas.height); d.save(); d.translate(this.maskX, this.maskY); d.rotate(this.maskAngle); d.translate(-this.maskOriginX, -this.maskOriginY); d.drawImage(this.mask, 0, 0); d.restore(); d.save(); d.globalCompositeOperation = "source-in"; if (this.useSourceRect) { d.drawImage(this.sprite, this.sourceRectX, this.sourceRectY, this.sourceRectW, this.sourceRectH, 0, 0, this.sourceRectW, this.sourceRectH) } else { d.drawImage(this.sprite, 0, 0) } d.restore(); if (this.useSourceRect) { c.drawImage(this.maskCanvas, this.sourceRectX, this.sourceRectY, this.sourceRectW, this.sourceRectH, 0, 0, this.sourceRectW, this.sourceRectH) } else { c.drawImage(this.maskCanvas, 0, 0) } c.globalCompositeOperation = "source-over" } else { if (this.useSourceRect) { c.drawImage(this.sprite, this.sourceRectX, this.sourceRectY, this.sourceRectW, this.sourceRectH, 0, 0, this.sourceRectW, this.sourceRectH) } else { c.drawImage(this.sprite, 0, 0) } } c.restore() }; Drawable.prototype.mouseOver = function() { var e = mouseX; var d = mouseY; if ((this.useCamera && !this.parent) || (this.parent && this.parent.useCamera)) { var g = this.sceneManager; if (!g) { if (this.parent) { g = this.parent.sceneManager } else { return false } } if (!g) { return false } e = g.worldMouseX; d = g.worldMouseY } var a = this.x - this.originX * this.scaleX; var f = this.y - this.originY * this.scaleY; if (this.parent) { a += this.parent.x; f += this.parent.y } var b = this.sprite.width * this.scaleX; var c = this.sprite.height * this.scaleY; if (e < a || d < f || e > a + b || d > f + c) { return false } return true }; Drawable.prototype.touchOver = function() { var b = null; if ((this.useCamera && !this.parent) || (this.parent && this.parent.useCamera)) { b = this.sceneManager; if (!b) { if (this.parent) { b = this.parent.sceneManager } else { return { touched: false, id: -1 } } } if (!b) { return { touched: false, id: -1 } } } for (var d = 0; d < currentTouches.length; d++) { var c = currentTouches[d].x; var a = currentTouches[d].y; if (b) { var k = b.viewToWorld(currentTouches[d].x, currentTouches[d].y); c = k.x; a = k.y } var g = this.x - this.originX * this.scaleX; var f = this.y - this.originY * this.scaleY; if (this.parent) { g += this.parent.x; f += this.parent.y } var j = this.sprite.width * this.scaleX; var e = this.sprite.height * this.scaleY; if (c < g || a < f || c > g + j || a > f + e) { continue } currentTouches[d].moved = true; return { touched: true, id: currentTouches[d].id } } return { touched: false, id: -1 } }; (function(b) { var a = {}; typeof exports == "undefined" ? typeof define == "function" && typeof define.amd == "object" && define.amd ? (a.exports = {}, define(function() { return a.exports })) : a.exports = typeof window != "undefined" ? window : b : a.exports = exports, function(x) { if (!B) { var B = 0.000001 } if (!k) { var k = typeof Float32Array != "undefined" ? Float32Array : Array } if (!d) { var d = Math.random } var q = {}; q.setMatrixArrayType = function(c) { k = c }, typeof x != "undefined" && (x.glMatrix = q); var C = Math.PI / 180; q.toRadian = function(c) { return c * C }; var j = {}; j.create = function() { var c = new k(2); return c[0] = 0, c[1] = 0, c }, j.clone = function(f) { var c = new k(2); return c[0] = f[0], c[1] = f[1], c }, j.fromValues = function(h, c) { var f = new k(2); return f[0] = h, f[1] = c, f }, j.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f }, j.set = function(f, c, h) { return f[0] = c, f[1] = h, f }, j.add = function(f, c, h) { return f[0] = c[0] + h[0], f[1] = c[1] + h[1], f }, j.subtract = function(f, c, h) { return f[0] = c[0] - h[0], f[1] = c[1] - h[1], f }, j.sub = j.subtract, j.multiply = function(f, c, h) { return f[0] = c[0] * h[0], f[1] = c[1] * h[1], f }, j.mul = j.multiply, j.divide = function(f, c, h) { return f[0] = c[0] / h[0], f[1] = c[1] / h[1], f }, j.div = j.divide, j.min = function(f, c, h) { return f[0] = Math.min(c[0], h[0]), f[1] = Math.min(c[1], h[1]), f }, j.max = function(f, c, h) { return f[0] = Math.max(c[0], h[0]), f[1] = Math.max(c[1], h[1]), f }, j.scale = function(f, c, h) { return f[0] = c[0] * h, f[1] = c[1] * h, f }, j.scaleAndAdd = function(h, c, i, f) { return h[0] = c[0] + i[0] * f, h[1] = c[1] + i[1] * f, h }, j.distance = function(h, c) { var i = c[0] - h[0], f = c[1] - h[1]; return Math.sqrt(i * i + f * f) }, j.dist = j.distance, j.squaredDistance = function(h, c) { var i = c[0] - h[0], f = c[1] - h[1]; return i * i + f * f }, j.sqrDist = j.squaredDistance, j.length = function(f) { var c = f[0], h = f[1]; return Math.sqrt(c * c + h * h) }, j.len = j.length, j.squaredLength = function(f) { var c = f[0], h = f[1]; return c * c + h * h }, j.sqrLen = j.squaredLength, j.negate = function(f, c) { return f[0] = -c[0], f[1] = -c[1], f }, j.normalize = function(l, f) { var o = f[0], h = f[1], c = o * o + h * h; return c > 0 && (c = 1 / Math.sqrt(c), l[0] = f[0] * c, l[1] = f[1] * c), l }, j.dot = function(f, c) { return f[0] * c[0] + f[1] * c[1] }, j.cross = function(h, c, i) { var f = c[0] * i[1] - c[1] * i[0]; return h[0] = h[1] = 0, h[2] = f, h }, j.lerp = function(o, f, p, l) { var c = f[0], h = f[1]; return o[0] = c + l * (p[0] - c), o[1] = h + l * (p[1] - h), o }, j.random = function(f, c) { c = c || 1; var h = d() * 2 * Math.PI; return f[0] = Math.cos(h) * c, f[1] = Math.sin(h) * c, f }, j.transformMat2 = function(l, f, o) { var h = f[0], c = f[1]; return l[0] = o[0] * h + o[2] * c, l[1] = o[1] * h + o[3] * c, l }, j.transformMat2d = function(l, f, o) { var h = f[0], c = f[1]; return l[0] = o[0] * h + o[2] * c + o[4], l[1] = o[1] * h + o[3] * c + o[5], l }, j.transformMat3 = function(l, f, o) { var h = f[0], c = f[1]; return l[0] = o[0] * h + o[3] * c + o[6], l[1] = o[1] * h + o[4] * c + o[7], l }, j.transformMat4 = function(l, f, o) { var h = f[0], c = f[1]; return l[0] = o[0] * h + o[4] * c + o[12], l[1] = o[1] * h + o[5] * c + o[13], l }, j.forEach = function() { var c = j.create(); return function(l, F, D, h, p, E) { var f, e; F || (F = 2), D || (D = 0), h ? e = Math.min(h * F + D, l.length) : e = l.length; for (f = D; f < e; f += F) { c[0] = l[f], c[1] = l[f + 1], p(c, c, E), l[f] = c[0], l[f + 1] = c[1] } return l } }(), j.str = function(c) { return "vec2(" + c[0] + ", " + c[1] + ")" }, typeof x != "undefined" && (x.vec2 = j); var A = {}; A.create = function() { var c = new k(3); return c[0] = 0, c[1] = 0, c[2] = 0, c }, A.clone = function(f) { var c = new k(3); return c[0] = f[0], c[1] = f[1], c[2] = f[2], c }, A.fromValues = function(l, f, h) { var c = new k(3); return c[0] = l, c[1] = f, c[2] = h, c }, A.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f }, A.set = function(h, c, i, f) { return h[0] = c, h[1] = i, h[2] = f, h }, A.add = function(f, c, h) { return f[0] = c[0] + h[0], f[1] = c[1] + h[1], f[2] = c[2] + h[2], f }, A.subtract = function(f, c, h) { return f[0] = c[0] - h[0], f[1] = c[1] - h[1], f[2] = c[2] - h[2], f }, A.sub = A.subtract, A.multiply = function(f, c, h) { return f[0] = c[0] * h[0], f[1] = c[1] * h[1], f[2] = c[2] * h[2], f }, A.mul = A.multiply, A.divide = function(f, c, h) { return f[0] = c[0] / h[0], f[1] = c[1] / h[1], f[2] = c[2] / h[2], f }, A.div = A.divide, A.min = function(f, c, h) { return f[0] = Math.min(c[0], h[0]), f[1] = Math.min(c[1], h[1]), f[2] = Math.min(c[2], h[2]), f }, A.max = function(f, c, h) { return f[0] = Math.max(c[0], h[0]), f[1] = Math.max(c[1], h[1]), f[2] = Math.max(c[2], h[2]), f }, A.scale = function(f, c, h) { return f[0] = c[0] * h, f[1] = c[1] * h, f[2] = c[2] * h, f }, A.scaleAndAdd = function(h, c, i, f) { return h[0] = c[0] + i[0] * f, h[1] = c[1] + i[1] * f, h[2] = c[2] + i[2] * f, h }, A.distance = function(l, f) { var o = f[0] - l[0], h = f[1] - l[1], c = f[2] - l[2]; return Math.sqrt(o * o + h * h + c * c) }, A.dist = A.distance, A.squaredDistance = function(l, f) { var o = f[0] - l[0], h = f[1] - l[1], c = f[2] - l[2]; return o * o + h * h + c * c }, A.sqrDist = A.squaredDistance, A.length = function(h) { var c = h[0], i = h[1], f = h[2]; return Math.sqrt(c * c + i * i + f * f) }, A.len = A.length, A.squaredLength = function(h) { var c = h[0], i = h[1], f = h[2]; return c * c + i * i + f * f }, A.sqrLen = A.squaredLength, A.negate = function(f, c) { return f[0] = -c[0], f[1] = -c[1], f[2] = -c[2], f }, A.normalize = function(o, f) { var p = f[0], l = f[1], c = f[2], h = p * p + l * l + c * c; return h > 0 && (h = 1 / Math.sqrt(h), o[0] = f[0] * h, o[1] = f[1] * h, o[2] = f[2] * h), o }, A.dot = function(f, c) { return f[0] * c[0] + f[1] * c[1] + f[2] * c[2] }, A.cross = function(p, F, h) { var c = F[0], l = F[1], G = F[2], f = h[0], E = h[1], D = h[2]; return p[0] = l * D - G * E, p[1] = G * f - c * D, p[2] = c * E - l * f, p }, A.lerp = function(p, f, D, l) { var c = f[0], h = f[1], u = f[2]; return p[0] = c + l * (D[0] - c), p[1] = h + l * (D[1] - h), p[2] = u + l * (D[2] - u), p }, A.random = function(l, f) { f = f || 1; var o = d() * 2 * Math.PI, c = d() * 2 - 1, h = Math.sqrt(1 - c * c) * f; return l[0] = Math.cos(o) * h, l[1] = Math.sin(o) * h, l[2] = c * f, l }, A.transformMat4 = function(o, f, p) { var l = f[0], c = f[1], h = f[2]; return o[0] = p[0] * l + p[4] * c + p[8] * h + p[12], o[1] = p[1] * l + p[5] * c + p[9] * h + p[13], o[2] = p[2] * l + p[6] * c + p[10] * h + p[14], o }, A.transformMat3 = function(o, f, p) { var l = f[0], c = f[1], h = f[2]; return o[0] = l * p[0] + c * p[3] + h * p[6], o[1] = l * p[1] + c * p[4] + h * p[7], o[2] = l * p[2] + c * p[5] + h * p[8], o }, A.transformQuat = function(L, P, G) { var D = P[0], I = P[1], Q = P[2], F = G[0], O = G[1], N = G[2], K = G[3], H = K * D + O * Q - N * I, M = K * I + N * D - F * Q, J = K * Q + F * I - O * D, E = -F * D - O * I - N * Q; return L[0] = H * K + E * -F + M * -N - J * -O, L[1] = M * K + E * -O + J * -F - H * -N, L[2] = J * K + E * -N + H * -O - M * -F, L }, A.forEach = function() { var c = A.create(); return function(l, F, D, h, p, E) { var f, e; F || (F = 3), D || (D = 0), h ? e = Math.min(h * F + D, l.length) : e = l.length; for (f = D; f < e; f += F) { c[0] = l[f], c[1] = l[f + 1], c[2] = l[f + 2], p(c, c, E), l[f] = c[0], l[f + 1] = c[1], l[f + 2] = c[2] } return l } }(), A.str = function(c) { return "vec3(" + c[0] + ", " + c[1] + ", " + c[2] + ")" }, typeof x != "undefined" && (x.vec3 = A); var z = {}; z.create = function() { var c = new k(4); return c[0] = 0, c[1] = 0, c[2] = 0, c[3] = 0, c }, z.clone = function(f) { var c = new k(4); return c[0] = f[0], c[1] = f[1], c[2] = f[2], c[3] = f[3], c }, z.fromValues = function(n, f, l, c) { var h = new k(4); return h[0] = n, h[1] = f, h[2] = l, h[3] = c, h }, z.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[3], f }, z.set = function(l, f, o, h, c) { return l[0] = f, l[1] = o, l[2] = h, l[3] = c, l }, z.add = function(f, c, h) { return f[0] = c[0] + h[0], f[1] = c[1] + h[1], f[2] = c[2] + h[2], f[3] = c[3] + h[3], f }, z.subtract = function(f, c, h) { return f[0] = c[0] - h[0], f[1] = c[1] - h[1], f[2] = c[2] - h[2], f[3] = c[3] - h[3], f }, z.sub = z.subtract, z.multiply = function(f, c, h) { return f[0] = c[0] * h[0], f[1] = c[1] * h[1], f[2] = c[2] * h[2], f[3] = c[3] * h[3], f }, z.mul = z.multiply, z.divide = function(f, c, h) { return f[0] = c[0] / h[0], f[1] = c[1] / h[1], f[2] = c[2] / h[2], f[3] = c[3] / h[3], f }, z.div = z.divide, z.min = function(f, c, h) { return f[0] = Math.min(c[0], h[0]), f[1] = Math.min(c[1], h[1]), f[2] = Math.min(c[2], h[2]), f[3] = Math.min(c[3], h[3]), f }, z.max = function(f, c, h) { return f[0] = Math.max(c[0], h[0]), f[1] = Math.max(c[1], h[1]), f[2] = Math.max(c[2], h[2]), f[3] = Math.max(c[3], h[3]), f }, z.scale = function(f, c, h) { return f[0] = c[0] * h, f[1] = c[1] * h, f[2] = c[2] * h, f[3] = c[3] * h, f }, z.scaleAndAdd = function(h, c, i, f) { return h[0] = c[0] + i[0] * f, h[1] = c[1] + i[1] * f, h[2] = c[2] + i[2] * f, h[3] = c[3] + i[3] * f, h }, z.distance = function(o, f) { var p = f[0] - o[0], l = f[1] - o[1], c = f[2] - o[2], h = f[3] - o[3]; return Math.sqrt(p * p + l * l + c * c + h * h) }, z.dist = z.distance, z.squaredDistance = function(o, f) { var p = f[0] - o[0], l = f[1] - o[1], c = f[2] - o[2], h = f[3] - o[3]; return p * p + l * l + c * c + h * h }, z.sqrDist = z.squaredDistance, z.length = function(l) { var f = l[0], o = l[1], h = l[2], c = l[3]; return Math.sqrt(f * f + o * o + h * h + c * c) }, z.len = z.length, z.squaredLength = function(l) { var f = l[0], o = l[1], h = l[2], c = l[3]; return f * f + o * o + h * h + c * c }, z.sqrLen = z.squaredLength, z.negate = function(f, c) { return f[0] = -c[0], f[1] = -c[1], f[2] = -c[2], f[3] = -c[3], f }, z.normalize = function(p, f) { var D = f[0], l = f[1], c = f[2], h = f[3], u = D * D + l * l + c * c + h * h; return u > 0 && (u = 1 / Math.sqrt(u), p[0] = f[0] * u, p[1] = f[1] * u, p[2] = f[2] * u, p[3] = f[3] * u), p }, z.dot = function(f, c) { return f[0] * c[0] + f[1] * c[1] + f[2] * c[2] + f[3] * c[3] }, z.lerp = function(D, h, F, p) { var f = h[0], l = h[1], E = h[2], c = h[3]; return D[0] = f + p * (F[0] - f), D[1] = l + p * (F[1] - l), D[2] = E + p * (F[2] - E), D[3] = c + p * (F[3] - c), D }, z.random = function(f, c) { return c = c || 1, f[0] = d(), f[1] = d(), f[2] = d(), f[3] = d(), z.normalize(f, f), z.scale(f, f, c), f }, z.transformMat4 = function(p, f, D) { var l = f[0], c = f[1], h = f[2], u = f[3]; return p[0] = D[0] * l + D[4] * c + D[8] * h + D[12] * u, p[1] = D[1] * l + D[5] * c + D[9] * h + D[13] * u, p[2] = D[2] * l + D[6] * c + D[10] * h + D[14] * u, p[3] = D[3] * l + D[7] * c + D[11] * h + D[15] * u, p }, z.transformQuat = function(L, P, G) { var D = P[0], I = P[1], Q = P[2], F = G[0], O = G[1], N = G[2], K = G[3], H = K * D + O * Q - N * I, M = K * I + N * D - F * Q, J = K * Q + F * I - O * D, E = -F * D - O * I - N * Q; return L[0] = H * K + E * -F + M * -N - J * -O, L[1] = M * K + E * -O + J * -F - H * -N, L[2] = J * K + E * -N + H * -O - M * -F, L }, z.forEach = function() { var c = z.create(); return function(l, F, D, h, p, E) { var f, e; F || (F = 4), D || (D = 0), h ? e = Math.min(h * F + D, l.length) : e = l.length; for (f = D; f < e; f += F) { c[0] = l[f], c[1] = l[f + 1], c[2] = l[f + 2], c[3] = l[f + 3], p(c, c, E), l[f] = c[0], l[f + 1] = c[1], l[f + 2] = c[2], l[f + 3] = c[3] } return l } }(), z.str = function(c) { return "vec4(" + c[0] + ", " + c[1] + ", " + c[2] + ", " + c[3] + ")" }, typeof x != "undefined" && (x.vec4 = z); var w = {}; w.create = function() { var c = new k(4); return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 1, c }, w.clone = function(f) { var c = new k(4); return c[0] = f[0], c[1] = f[1], c[2] = f[2], c[3] = f[3], c }, w.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[3], f }, w.identity = function(c) { return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 1, c }, w.transpose = function(f, c) { if (f === c) { var h = c[1]; f[1] = c[2], f[2] = h } else { f[0] = c[0], f[1] = c[2], f[2] = c[1], f[3] = c[3] } return f }, w.invert = function(p, f) { var D = f[0], l = f[1], c = f[2], h = f[3], u = D * h - c * l; return u ? (u = 1 / u, p[0] = h * u, p[1] = -l * u, p[2] = -c * u, p[3] = D * u, p) : null }, w.adjoint = function(f, c) { var h = c[0]; return f[0] = c[3], f[1] = -c[1], f[2] = -c[2], f[3] = h, f }, w.determinant = function(c) { return c[0] * c[3] - c[2] * c[1] }, w.multiply = function(G, J, p) { var c = J[0], E = J[1], K = J[2], h = J[3], I = p[0], H = p[1], F = p[2], D = p[3]; return G[0] = c * I + E * F, G[1] = c * H + E * D, G[2] = K * I + h * F, G[3] = K * H + h * D, G }, w.mul = w.multiply, w.rotate = function(p, F, h) { var c = F[0], l = F[1], G = F[2], f = F[3], E = Math.sin(h), D = Math.cos(h); return p[0] = c * D + l * E, p[1] = c * -E + l * D, p[2] = G * D + f * E, p[3] = G * -E + f * D, p }, w.scale = function(p, F, h) { var c = F[0], l = F[1], G = F[2], f = F[3], E = h[0], D = h[1]; return p[0] = c * E, p[1] = l * D, p[2] = G * E, p[3] = f * D, p }, w.str = function(c) { return "mat2(" + c[0] + ", " + c[1] + ", " + c[2] + ", " + c[3] + ")" }, typeof x != "undefined" && (x.mat2 = w); var m = {}; m.create = function() { var c = new k(6); return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 1, c[4] = 0, c[5] = 0, c }, m.clone = function(f) { var c = new k(6); return c[0] = f[0], c[1] = f[1], c[2] = f[2], c[3] = f[3], c[4] = f[4], c[5] = f[5], c }, m.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[3], f[4] = c[4], f[5] = c[5], f }, m.identity = function(c) { return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 1, c[4] = 0, c[5] = 0, c }, m.invert = function(p, F) { var h = F[0], c = F[1], l = F[2], G = F[3], f = F[4], E = F[5], D = h * G - c * l; return D ? (D = 1 / D, p[0] = G * D, p[1] = -c * D, p[2] = -l * D, p[3] = h * D, p[4] = (l * E - G * f) * D, p[5] = (c * f - h * E) * D, p) : null }, m.determinant = function(c) { return c[0] * c[3] - c[1] * c[2] }, m.multiply = function(L, Q, G) { var D = Q[0], I = Q[1], R = Q[2], F = Q[3], P = Q[4], O = Q[5], K = G[0], H = G[1], N = G[2], J = G[3], E = G[4], M = G[5]; return L[0] = D * K + I * N, L[1] = D * H + I * J, L[2] = R * K + F * N, L[3] = R * H + F * J, L[4] = K * P + N * O + E, L[5] = H * P + J * O + M, L }, m.mul = m.multiply, m.rotate = function(G, J, p) { var c = J[0], E = J[1], K = J[2], h = J[3], I = J[4], H = J[5], F = Math.sin(p), D = Math.cos(p); return G[0] = c * D + E * F, G[1] = -c * F + E * D, G[2] = K * D + h * F, G[3] = -K * F + D * h, G[4] = D * I + F * H, G[5] = D * H - F * I, G }, m.scale = function(l, f, o) { var h = o[0], c = o[1]; return l[0] = f[0] * h, l[1] = f[1] * c, l[2] = f[2] * h, l[3] = f[3] * c, l[4] = f[4] * h, l[5] = f[5] * c, l }, m.translate = function(f, c, h) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[3], f[4] = c[4] + h[0], f[5] = c[5] + h[1], f }, m.str = function(c) { return "mat2d(" + c[0] + ", " + c[1] + ", " + c[2] + ", " + c[3] + ", " + c[4] + ", " + c[5] + ")" }, typeof x != "undefined" && (x.mat2d = m); var y = {}; y.create = function() { var c = new k(9); return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 0, c[4] = 1, c[5] = 0, c[6] = 0, c[7] = 0, c[8] = 1, c }, y.fromMat4 = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[4], f[4] = c[5], f[5] = c[6], f[6] = c[8], f[7] = c[9], f[8] = c[10], f }, y.clone = function(f) { var c = new k(9); return c[0] = f[0], c[1] = f[1], c[2] = f[2], c[3] = f[3], c[4] = f[4], c[5] = f[5], c[6] = f[6], c[7] = f[7], c[8] = f[8], c }, y.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[3], f[4] = c[4], f[5] = c[5], f[6] = c[6], f[7] = c[7], f[8] = c[8], f }, y.identity = function(c) { return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 0, c[4] = 1, c[5] = 0, c[6] = 0, c[7] = 0, c[8] = 1, c }, y.transpose = function(l, f) { if (l === f) { var o = f[1], h = f[2], c = f[5]; l[1] = f[3], l[2] = f[6], l[3] = o, l[5] = f[7], l[6] = h, l[7] = c } else { l[0] = f[0], l[1] = f[3], l[2] = f[6], l[3] = f[1], l[4] = f[4], l[5] = f[7], l[6] = f[2], l[7] = f[5], l[8] = f[8] } return l }, y.invert = function(L, Q) { var G = Q[0], D = Q[1], I = Q[2], R = Q[3], F = Q[4], P = Q[5], O = Q[6], K = Q[7], H = Q[8], N = H * F - P * K, J = -H * R + P * O, E = K * R - F * O, M = G * N + D * J + I * E; return M ? (M = 1 / M, L[0] = N * M, L[1] = (-H * D + I * K) * M, L[2] = (P * D - I * F) * M, L[3] = J * M, L[4] = (H * G - I * O) * M, L[5] = (-P * G + I * R) * M, L[6] = E * M, L[7] = (-K * G + D * O) * M, L[8] = (F * G - D * R) * M, L) : null }, y.adjoint = function(G, J) { var p = J[0], c = J[1], E = J[2], K = J[3], h = J[4], I = J[5], H = J[6], F = J[7], D = J[8]; return G[0] = h * D - I * F, G[1] = E * F - c * D, G[2] = c * I - E * h, G[3] = I * H - K * D, G[4] = p * D - E * H, G[5] = E * K - p * I, G[6] = K * F - h * H, G[7] = c * H - p * F, G[8] = p * h - c * K, G }, y.determinant = function(E) { var H = E[0], l = E[1], c = E[2], p = E[3], I = E[4], h = E[5], G = E[6], F = E[7], D = E[8]; return H * (D * I - h * F) + l * (-D * p + h * G) + c * (F * p - I * G) }, y.multiply = function(T, H, M) { var J = H[0], P = H[1], I = H[2], L = H[3], G = H[4], X = H[5], S = H[6], O = H[7], V = H[8], Q = M[0], K = M[1], U = M[2], F = M[3], N = M[4], R = M[5], D = M[6], W = M[7], E = M[8]; return T[0] = Q * J + K * L + U * S, T[1] = Q * P + K * G + U * O, T[2] = Q * I + K * X + U * V, T[3] = F * J + N * L + R * S, T[4] = F * P + N * G + R * O, T[5] = F * I + N * X + R * V, T[6] = D * J + W * L + E * S, T[7] = D * P + W * G + E * O, T[8] = D * I + W * X + E * V, T }, y.mul = y.multiply, y.translate = function(L, P, G) { var D = P[0], I = P[1], Q = P[2], F = P[3], O = P[4], N = P[5], K = P[6], H = P[7], M = P[8], J = G[0], E = G[1]; return L[0] = D, L[1] = I, L[2] = Q, L[3] = F, L[4] = O, L[5] = N, L[6] = J * D + E * F + K, L[7] = J * I + E * O + H, L[8] = J * Q + E * N + M, L }, y.rotate = function(L, P, G) { var D = P[0], I = P[1], Q = P[2], F = P[3], O = P[4], N = P[5], K = P[6], H = P[7], M = P[8], J = Math.sin(G), E = Math.cos(G); return L[0] = E * D + J * F, L[1] = E * I + J * O, L[2] = E * Q + J * N, L[3] = E * F - J * D, L[4] = E * O - J * I, L[5] = E * N - J * Q, L[6] = K, L[7] = H, L[8] = M, L }, y.scale = function(l, f, o) { var h = o[0], c = o[1]; return l[0] = h * f[0], l[1] = h * f[1], l[2] = h * f[2], l[3] = c * f[3], l[4] = c * f[4], l[5] = c * f[5], l[6] = f[6], l[7] = f[7], l[8] = f[8], l }, y.fromMat2d = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = 0, f[3] = c[2], f[4] = c[3], f[5] = 0, f[6] = c[4], f[7] = c[5], f[8] = 1, f }, y.fromQuat = function(R, F) { var K = F[0], H = F[1], N = F[2], G = F[3], J = K + K, E = H + H, U = N + N, Q = K * J, M = H * J, T = H * E, O = N * J, I = N * E, S = N * U, D = G * J, L = G * E, P = G * U; return R[0] = 1 - T - S, R[3] = M - P, R[6] = O + L, R[1] = M + P, R[4] = 1 - Q - S, R[7] = I - D, R[2] = O - L, R[5] = I + D, R[8] = 1 - Q - T, R }, y.normalFromMat4 = function(aj, U) { var ab = U[0], X = U[1], af = U[2], V = U[3], aa = U[4], Q = U[5], an = U[6], ai = U[7], ad = U[8], al = U[9], ag = U[10], Z = U[11], ak = U[12], P = U[13], ac = U[14], ah = U[15], J = ab * Q - X * aa, am = ab * an - af * aa, M = ab * ai - V * aa, R = X * an - af * Q, F = X * ai - V * Q, K = af * ai - V * an, D = ad * P - al * ak, H = ad * ac - ag * ak, W = ad * ah - Z * ak, ae = al * ac - ag * P, I = al * ah - Z * P, Y = ag * ah - Z * ac, G = J * Y - am * I + M * ae + R * W - F * H + K * D; return G ? (G = 1 / G, aj[0] = (Q * Y - an * I + ai * ae) * G, aj[1] = (an * W - aa * Y - ai * H) * G, aj[2] = (aa * I - Q * W + ai * D) * G, aj[3] = (af * I - X * Y - V * ae) * G, aj[4] = (ab * Y - af * W + V * H) * G, aj[5] = (X * W - ab * I - V * D) * G, aj[6] = (P * K - ac * F + ah * R) * G, aj[7] = (ac * M - ak * K - ah * am) * G, aj[8] = (ak * F - P * M + ah * J) * G, aj) : null }, y.str = function(c) { return "mat3(" + c[0] + ", " + c[1] + ", " + c[2] + ", " + c[3] + ", " + c[4] + ", " + c[5] + ", " + c[6] + ", " + c[7] + ", " + c[8] + ")" }, typeof x != "undefined" && (x.mat3 = y); var v = {}; v.create = function() { var c = new k(16); return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 0, c[4] = 0, c[5] = 1, c[6] = 0, c[7] = 0, c[8] = 0, c[9] = 0, c[10] = 1, c[11] = 0, c[12] = 0, c[13] = 0, c[14] = 0, c[15] = 1, c }, v.clone = function(f) { var c = new k(16); return c[0] = f[0], c[1] = f[1], c[2] = f[2], c[3] = f[3], c[4] = f[4], c[5] = f[5], c[6] = f[6], c[7] = f[7], c[8] = f[8], c[9] = f[9], c[10] = f[10], c[11] = f[11], c[12] = f[12], c[13] = f[13], c[14] = f[14], c[15] = f[15], c }, v.copy = function(f, c) { return f[0] = c[0], f[1] = c[1], f[2] = c[2], f[3] = c[3], f[4] = c[4], f[5] = c[5], f[6] = c[6], f[7] = c[7], f[8] = c[8], f[9] = c[9], f[10] = c[10], f[11] = c[11], f[12] = c[12], f[13] = c[13], f[14] = c[14], f[15] = c[15], f }, v.identity = function(c) { return c[0] = 1, c[1] = 0, c[2] = 0, c[3] = 0, c[4] = 0, c[5] = 1, c[6] = 0, c[7] = 0, c[8] = 0, c[9] = 0, c[10] = 1, c[11] = 0, c[12] = 0, c[13] = 0, c[14] = 0, c[15] = 1, c }, v.transpose = function(D, h) { if (D === h) { var F = h[1], p = h[2], f = h[3], l = h[6], E = h[7], c = h[11]; D[1] = h[4], D[2] = h[8], D[3] = h[12], D[4] = F, D[6] = h[9], D[7] = h[13], D[8] = p, D[9] = l, D[11] = h[14], D[12] = f, D[13] = E, D[14] = c } else { D[0] = h[0], D[1] = h[4], D[2] = h[8], D[3] = h[12], D[4] = h[1], D[5] = h[5], D[6] = h[9], D[7] = h[13], D[8] = h[2], D[9] = h[6], D[10] = h[10], D[11] = h[14], D[12] = h[3], D[13] = h[7], D[14] = h[11], D[15] = h[15] } return D }, v.invert = function(aj, U) { var ab = U[0], X = U[1], af = U[2], V = U[3], aa = U[4], Q = U[5], an = U[6], ai = U[7], ad = U[8], al = U[9], ag = U[10], Z = U[11], ak = U[12], P = U[13], ac = U[14], ah = U[15], J = ab * Q - X * aa, am = ab * an - af * aa, M = ab * ai - V * aa, R = X * an - af * Q, F = X * ai - V * Q, K = af * ai - V * an, D = ad * P - al * ak, H = ad * ac - ag * ak, W = ad * ah - Z * ak, ae = al * ac - ag * P, I = al * ah - Z * P, Y = ag * ah - Z * ac, G = J * Y - am * I + M * ae + R * W - F * H + K * D; return G ? (G = 1 / G, aj[0] = (Q * Y - an * I + ai * ae) * G, aj[1] = (af * I - X * Y - V * ae) * G, aj[2] = (P * K - ac * F + ah * R) * G, aj[3] = (ag * F - al * K - Z * R) * G, aj[4] = (an * W - aa * Y - ai * H) * G, aj[5] = (ab * Y - af * W + V * H) * G, aj[6] = (ac * M - ak * K - ah * am) * G, aj[7] = (ad * K - ag * M + Z * am) * G, aj[8] = (aa * I - Q * W + ai * D) * G, aj[9] = (X * W - ab * I - V * D) * G, aj[10] = (ak * F - P * M + ah * J) * G, aj[11] = (al * M - ad * F - Z * J) * G, aj[12] = (Q * H - aa * ae - an * D) * G, aj[13] = (ab * ae - X * H + af * D) * G, aj[14] = (P * am - ak * R - ac * J) * G, aj[15] = (ad * R - al * am + ag * J) * G, aj) : null }, v.adjoint = function(R, F) { var K = F[0], H = F[1], N = F[2], G = F[3], J = F[4], E = F[5], U = F[6], Q = F[7], M = F[8], T = F[9], O = F[10], I = F[11], S = F[12], D = F[13], L = F[14], P = F[15]; return R[0] = E * (O * P - I * L) - T * (U * P - Q * L) + D * (U * I - Q * O), R[1] = -(H * (O * P - I * L) - T * (N * P - G * L) + D * (N * I - G * O)), R[2] = H * (U * P - Q * L) - E * (N * P - G * L) + D * (N * Q - G * U), R[3] = -(H * (U * I - Q * O) - E * (N * I - G * O) + T * (N * Q - G * U)), R[4] = -(J * (O * P - I * L) - M * (U * P - Q * L) + S * (U * I - Q * O)), R[5] = K * (O * P - I * L) - M * (N * P - G * L) + S * (N * I - G * O), R[6] = -(K * (U * P - Q * L) - J * (N * P - G * L) + S * (N * Q - G * U)), R[7] = K * (U * I - Q * O) - J * (N * I - G * O) + M * (N * Q - G * U), R[8] = J * (T * P - I * D) - M * (E * P - Q * D) + S * (E * I - Q * T), R[9] = -(K * (T * P - I * D) - M * (H * P - G * D) + S * (H * I - G * T)), R[10] = K * (E * P - Q * D) - J * (H * P - G * D) + S * (H * Q - G * E), R[11] = -(K * (E * I - Q * T) - J * (H * I - G * T) + M * (H * Q - G * E)), R[12] = -(J * (T * L - O * D) - M * (E * L - U * D) + S * (E * O - U * T)), R[13] = K * (T * L - O * D) - M * (H * L - N * D) + S * (H * O - N * T), R[14] = -(K * (E * L - U * D) - J * (H * L - N * D) + S * (H * U - N * E)), R[15] = K * (E * O - U * T) - J * (H * O - N * T) + M * (H * U - N * E), R }, v.determinant = function(ag) { var Q = ag[0], Y = ag[1], V = ag[2], ac = ag[3], R = ag[4], X = ag[5], O = ag[6], ak = ag[7], af = ag[8], aa = ag[9], ai = ag[10], ad = ag[11], W = ag[12], ah = ag[13], M = ag[14], Z = ag[15], ae = Q * X - Y * R, I = Q * O - V * R, aj = Q * ak - ac * R, K = Y * O - V * X, P = Y * ak - ac * X, F = V * ak - ac * O, J = af * ah - aa * W, D = af * M - ai * W, G = af * Z - ad * W, U = aa * M - ai * ah, ab = aa * Z - ad * ah, H = ai * Z - ad * M; return ae * H - I * ab + aj * U + K * G - P * D + F * J }, v.multiply = function(X, K, P) { var M = K[0], T = K[1], L = K[2], O = K[3], I = K[4], ab = K[5], W = K[6], R = K[7], Z = K[8], U = K[9], N = K[10], Y = K[11], H = K[12], Q = K[13], V = K[14], F = K[15], aa = P[0], G = P[1], J = P[2], D = P[3]; return X[0] = aa * M + G * I + J * Z + D * H, X[1] = aa * T + G * ab + J * U + D * Q, X[2] = aa * L + G * W + J * N + D * V, X[3] = aa * O + G * R + J * Y + D * F, aa = P[4], G = P[5], J = P[6], D = P[7], X[4] = aa * M + G * I + J * Z + D * H, X[5] = aa * T + G * ab + J * U + D * Q, X[6] = aa * L + G * W + J * N + D * V, X[7] = aa * O + G * R + J * Y + D * F, aa = P[8], G = P[9], J = P[10], D = P[11], X[8] = aa * M + G * I + J * Z + D * H, X[9] = aa * T + G * ab + J * U + D * Q, X[10] = aa * L + G * W + J * N + D * V, X[11] = aa * O + G * R + J * Y + D * F, aa = P[12], G = P[13], J = P[14], D = P[15], X[12] = aa * M + G * I + J * Z + D * H, X[13] = aa * T + G * ab + J * U + D * Q, X[14] = aa * L + G * W + J * N + D * V, X[15] = aa * O + G * R + J * Y + D * F, X }, v.mul = v.multiply, v.translate = function(V, J, O) { var L = O[0], R = O[1], K = O[2], N, H, Z, U, Q, X, S, M, W, G, P, T, D, Y, F, I; return N = J[0], H = J[1], Z = J[2], U = J[3], Q = J[4], X = J[5], S = J[6], M = J[7], W = J[8], G = J[9], P = J[10], T = J[11], D = J[12], Y = J[13], F = J[14], I = J[15], V[0] = N + U * L, V[1] = H + U * R, V[2] = Z + U * K, V[3] = U, V[4] = Q + M * L, V[5] = X + M * R, V[6] = S + M * K, V[7] = M, V[8] = W + T * L, V[9] = G + T * R, V[10] = P + T * K, V[11] = T, V[12] = D + I * L, V[13] = Y + I * R, V[14] = F + I * K, V[15] = I, V }, v.scale = function(o, f, p) { var l = p[0], c = p[1], h = p[2]; return o[0] = f[0] * l, o[1] = f[1] * l, o[2] = f[2] * l, o[3] = f[3] * l, o[4] = f[4] * c, o[5] = f[5] * c, o[6] = f[6] * c, o[7] = f[7] * c, o[8] = f[8] * h, o[9] = f[9] * h, o[10] = f[10] * h, o[11] = f[11] * h, o[12] = f[12], o[13] = f[13], o[14] = f[14], o[15] = f[15], o }, v.rotate = function(aj, ab, X, af) { var V = af[0], aa = af[1], R = af[2], an = Math.sqrt(V * V + aa * aa + R * R), ai, ad, al, ag, Z, ak, Q, ac, ah, J, am, P, U, D, K, t, G, W, ae, I, Y, F, H, ao; return Math.abs(an) < B ? null : (an = 1 / an, V *= an, aa *= an, R *= an, ai = Math.sin(X), ad = Math.cos(X), al = 1 - ad, ag = ab[0], Z = ab[1], ak = ab[2], Q = ab[3], ac = ab[4], ah = ab[5], J = ab[6], am = ab[7], P = ab[8], U = ab[9], D = ab[10], K = ab[11], t = V * V * al + ad, G = aa * V * al + R * ai, W = R * V * al - aa * ai, ae = V * aa * al - R * ai, I = aa * aa * al + ad, Y = R * aa * al + V * ai, F = V * R * al + aa * ai, H = aa * R * al - V * ai, ao = R * R * al + ad, aj[0] = ag * t + ac * G + P * W, aj[1] = Z * t + ah * G + U * W, aj[2] = ak * t + J * G + D * W, aj[3] = Q * t + am * G + K * W, aj[4] = ag * ae + ac * I + P * Y, aj[5] = Z * ae + ah * I + U * Y, aj[6] = ak * ae + J * I + D * Y, aj[7] = Q * ae + am * I + K * Y, aj[8] = ag * F + ac * H + P * ao, aj[9] = Z * F + ah * H + U * ao, aj[10] = ak * F + J * H + D * ao, aj[11] = Q * F + am * H + K * ao, ab !== aj && (aj[12] = ab[12], aj[13] = ab[13], aj[14] = ab[14], aj[15] = ab[15]), aj) }, v.rotateX = function(J, N, E) { var p = Math.sin(E), G = Math.cos(E), O = N[4], D = N[5], M = N[6], L = N[7], I = N[8], F = N[9], K = N[10], H = N[11]; return N !== J && (J[0] = N[0], J[1] = N[1], J[2] = N[2], J[3] = N[3], J[12] = N[12], J[13] = N[13], J[14] = N[14], J[15] = N[15]), J[4] = O * G + I * p, J[5] = D * G + F * p, J[6] = M * G + K * p, J[7] = L * G + H * p, J[8] = I * G - O * p, J[9] = F * G - D * p, J[10] = K * G - M * p, J[11] = H * G - L * p, J }, v.rotateY = function(J, N, E) { var p = Math.sin(E), G = Math.cos(E), O = N[0], D = N[1], M = N[2], L = N[3], I = N[8], F = N[9], K = N[10], H = N[11]; return N !== J && (J[4] = N[4], J[5] = N[5], J[6] = N[6], J[7] = N[7], J[12] = N[12], J[13] = N[13], J[14] = N[14], J[15] = N[15]), J[0] = O * G - I * p, J[1] = D * G - F * p, J[2] = M * G - K * p, J[3] = L * G - H * p, J[8] = O * p + I * G, J[9] = D * p + F * G, J[10] = M * p + K * G, J[11] = L * p + H * G, J }, v.rotateZ = function(J, N, E) { var p = Math.sin(E), G = Math.cos(E), O = N[0], D = N[1], M = N[2], L = N[3], I = N[4], F = N[5], K = N[6], H = N[7]; return N !== J && (J[8] = N[8], J[9] = N[9], J[10] = N[10], J[11] = N[11], J[12] = N[12], J[13] = N[13], J[14] = N[14], J[15] = N[15]), J[0] = O * G + I * p, J[1] = D * G + F * p, J[2] = M * G + K * p, J[3] = L * G + H * p, J[4] = I * G - O * p, J[5] = F * G - D * p, J[6] = K * G - M * p, J[7] = H * G - L * p, J }, v.fromRotationTranslation = function(S, G, L) { var I = G[0], O = G[1], H = G[2], K = G[3], F = I + I, V = O + O, R = H + H, N = I * F, U = I * V, P = I * R, J = O * V, T = O * R, E = H * R, M = K * F, Q = K * V, D = K * R; return S[0] = 1 - (J + E), S[1] = U + D, S[2] = P - Q, S[3] = 0, S[4] = U - D, S[5] = 1 - (N + E), S[6] = T + M, S[7] = 0, S[8] = P + Q, S[9] = T - M, S[10] = 1 - (N + J), S[11] = 0, S[12] = L[0], S[13] = L[1], S[14] = L[2], S[15] = 1, S }, v.fromQuat = function(R, F) { var K = F[0], H = F[1], N = F[2], G = F[3], J = K + K, E = H + H, U = N + N, Q = K * J, M = H * J, T = H * E, O = N * J, I = N * E, S = N * U, D = G * J, L = G * E, P = G * U; return R[0] = 1 - T - S, R[1] = M + P, R[2] = O - L, R[3] = 0, R[4] = M - P, R[5] = 1 - Q - S, R[6] = I + D, R[7] = 0, R[8] = O + L, R[9] = I - D, R[10] = 1 - Q - T, R[11] = 0, R[12] = 0, R[13] = 0, R[14] = 0, R[15] = 1, R }, v.frustum = function(E, H, l, c, p, I, h) { var G = 1 / (l - H), F = 1 / (p - c), D = 1 / (I - h); return E[0] = I * 2 * G, E[1] = 0, E[2] = 0, E[3] = 0, E[4] = 0, E[5] = I * 2 * F, E[6] = 0, E[7] = 0, E[8] = (l + H) * G, E[9] = (p + c) * F, E[10] = (h + I) * D, E[11] = -1, E[12] = 0, E[13] = 0, E[14] = h * I * 2 * D, E[15] = 0, E }, v.perspective = function(p, f, D, l, c) { var h = 1 / Math.tan(f / 2), u = 1 / (l - c); return p[0] = h / D, p[1] = 0, p[2] = 0, p[3] = 0, p[4] = 0, p[5] = h, p[6] = 0, p[7] = 0, p[8] = 0, p[9] = 0, p[10] = (c + l) * u, p[11] = -1, p[12] = 0, p[13] = 0, p[14] = 2 * c * l * u, p[15] = 0, p }, v.ortho = function(E, H, l, c, p, I, h) { var G = 1 / (H - l), F = 1 / (c - p), D = 1 / (I - h); return E[0] = -2 * G, E[1] = 0, E[2] = 0, E[3] = 0, E[4] = 0, E[5] = -2 * F, E[6] = 0, E[7] = 0, E[8] = 0, E[9] = 0, E[10] = 2 * D, E[11] = 0, E[12] = (H + l) * G, E[13] = (p + c) * F, E[14] = (h + I) * D, E[15] = 1, E }, v.lookAt = function(W, O, L, R) { var K, N, I, aa, V, Q, Y, M, X, H, P = O[0], U = O[1], D = O[2], Z = R[0], G = R[1], J = R[2], t = L[0], F = L[1], h = L[2]; return Math.abs(P - t) < B && Math.abs(U - F) < B && Math.abs(D - h) < B ? v.identity(W) : (Y = P - t, M = U - F, X = D - h, H = 1 / Math.sqrt(Y * Y + M * M + X * X), Y *= H, M *= H, X *= H, K = G * X - J * M, N = J * Y - Z * X, I = Z * M - G * Y, H = Math.sqrt(K * K + N * N + I * I), H ? (H = 1 / H, K *= H, N *= H, I *= H) : (K = 0, N = 0, I = 0), aa = M * I - X * N, V = X * K - Y * I, Q = Y * N - M * K, H = Math.sqrt(aa * aa + V * V + Q * Q), H ? (H = 1 / H, aa *= H, V *= H, Q *= H) : (aa = 0, V = 0, Q = 0), W[0] = K, W[1] = aa, W[2] = Y, W[3] = 0, W[4] = N, W[5] = V, W[6] = M, W[7] = 0, W[8] = I, W[9] = Q, W[10] = X, W[11] = 0, W[12] = -(K * P + N * U + I * D), W[13] = -(aa * P + V * U + Q * D), W[14] = -(Y * P + M * U + X * D), W[15] = 1, W) }, v.str = function(c) { return "mat4(" + c[0] + ", " + c[1] + ", " + c[2] + ", " + c[3] + ", " + c[4] + ", " + c[5] + ", " + c[6] + ", " + c[7] + ", " + c[8] + ", " + c[9] + ", " + c[10] + ", " + c[11] + ", " + c[12] + ", " + c[13] + ", " + c[14] + ", " + c[15] + ")" }, typeof x != "undefined" && (x.mat4 = v); var g = {}; g.create = function() { var c = new k(4); return c[0] = 0, c[1] = 0, c[2] = 0, c[3] = 1, c }, g.rotationTo = function() { var f = A.create(), c = A.fromValues(1, 0, 0), h = A.fromValues(0, 1, 0); return function(n, e, l) { var p = A.dot(e, l); return p < -0.999999 ? (A.cross(f, c, e), A.length(f) < 0.000001 && A.cross(f, h, e), A.normalize(f, f), g.setAxisAngle(n, f, Math.PI), n) : p > 0.999999 ? (n[0] = 0, n[1] = 0, n[2] = 0, n[3] = 1, n) : (A.cross(f, e, l), n[0] = f[0], n[1] = f[1], n[2] = f[2], n[3] = 1 + p, g.normalize(n, n)) } }(), g.setAxes = function() { var c = y.create(); return function(f, l, h, e) { return c[0] = h[0], c[3] = h[1], c[6] = h[2], c[1] = e[0], c[4] = e[1], c[7] = e[2], c[2] = -l[0], c[5] = -l[1], c[8] = -l[2], g.normalize(f, g.fromMat3(f, c)) } }(), g.clone = z.clone, g.fromValues = z.fromValues, g.copy = z.copy, g.set = z.set, g.identity = function(c) { return c[0] = 0, c[1] = 0, c[2] = 0, c[3] = 1, c }, g.setAxisAngle = function(h, c, i) { i *= 0.5; var f = Math.sin(i); return h[0] = f * c[0], h[1] = f * c[1], h[2] = f * c[2], h[3] = Math.cos(i), h }, g.add = z.add, g.multiply = function(G, J, p) { var c = J[0], E = J[1], K = J[2], h = J[3], I = p[0], H = p[1], F = p[2], D = p[3]; return G[0] = c * D + h * I + E * F - K * H, G[1] = E * D + h * H + K * I - c * F, G[2] = K * D + h * F + c * H - E * I, G[3] = h * D - c * I - E * H - K * F, G }, g.mul = g.multiply, g.scale = z.scale, g.rotateX = function(p, F, h) { h *= 0.5; var c = F[0], l = F[1], G = F[2], f = F[3], E = Math.sin(h), D = Math.cos(h); return p[0] = c * D + f * E, p[1] = l * D + G * E, p[2] = G * D - l * E, p[3] = f * D - c * E, p }, g.rotateY = function(p, F, h) { h *= 0.5; var c = F[0], l = F[1], G = F[2], f = F[3], E = Math.sin(h), D = Math.cos(h); return p[0] = c * D - G * E, p[1] = l * D + f * E, p[2] = G * D + c * E, p[3] = f * D - l * E, p }, g.rotateZ = function(p, F, h) { h *= 0.5; var c = F[0], l = F[1], G = F[2], f = F[3], E = Math.sin(h), D = Math.cos(h); return p[0] = c * D + l * E, p[1] = l * D - c * E, p[2] = G * D + f * E, p[3] = f * D - G * E, p }, g.calculateW = function(l, f) { var o = f[0], h = f[1], c = f[2]; return l[0] = o, l[1] = h, l[2] = c, l[3] = -Math.sqrt(Math.abs(1 - o * o - h * h - c * c)), l }, g.dot = z.dot, g.lerp = z.lerp, g.slerp = function(M, S, G, D) { var J = S[0], T = S[1], F = S[2], R = S[3], P = G[0], L = G[1], I = G[2], O = G[3], K, E, N, Q, H; return E = J * P + T * L + F * I + R * O, E < 0 && (E = -E, P = -P, L = -L, I = -I, O = -O), 1 - E > 0.000001 ? (K = Math.acos(E), N = Math.sin(K), Q = Math.sin((1 - D) * K) / N, H = Math.sin(D * K) / N) : (Q = 1 - D, H = D), M[0] = Q * J + H * P, M[1] = Q * T + H * L, M[2] = Q * F + H * I, M[3] = Q * R + H * O, M }, g.invert = function(D, h) { var F = h[0], p = h[1], f = h[2], l = h[3], E = F * F + p * p + f * f + l * l, c = E ? 1 / E : 0; return D[0] = -F * c, D[1] = -p * c, D[2] = -f * c, D[3] = l * c, D }, g.conjugate = function(f, c) { return f[0] = -c[0], f[1] = -c[1], f[2] = -c[2], f[3] = c[3], f }, g.length = z.length, g.len = g.length, g.squaredLength = z.squaredLength, g.sqrLen = g.squaredLength, g.normalize = z.normalize, g.fromMat3 = function(p, f) { var D = f[0] + f[4] + f[8], l; if (D > 0) { l = Math.sqrt(D + 1), p[3] = 0.5 * l, l = 0.5 / l, p[0] = (f[7] - f[5]) * l, p[1] = (f[2] - f[6]) * l, p[2] = (f[3] - f[1]) * l } else { var c = 0; f[4] > f[0] && (c = 1), f[8] > f[c * 3 + c] && (c = 2); var h = (c + 1) % 3, u = (c + 2) % 3; l = Math.sqrt(f[c * 3 + c] - f[h * 3 + h] - f[u * 3 + u] + 1), p[c] = 0.5 * l, l = 0.5 / l, p[3] = (f[u * 3 + h] - f[h * 3 + u]) * l, p[h] = (f[h * 3 + c] + f[c * 3 + h]) * l, p[u] = (f[u * 3 + c] + f[c * 3 + u]) * l } return p }, g.str = function(c) { return "quat(" + c[0] + ", " + c[1] + ", " + c[2] + ", " + c[3] + ")" }, typeof x != "undefined" && (x.quat = g) }(a.exports) })(this); var mouseX = 0; var mouseY = 0; var mouseDown = false; var mouseDownLast = false; var mouseWheelDelta = 0; var touchDown = false; var touchDownLast = false; var currentTouches = []; var Input = new function() { this.update = function() { mouseWheelDelta = 0; mouseDownLast = mouseDown; touchDownLast = touchDown; for (var a = 0; a < 255; a++) { Key._prevPressed[a] = Key._pressed[a] } for (var a = 0; a < currentTouches.length; a++) { currentTouches[a].moved = false } }; this.mouseClick = function() { return (mouseDown && !mouseDownLast) || (touchDown && !touchDownLast) }; this.mouseUp = function() { return (!mouseDown && mouseDownLast) || (!touchDown && touchDownLast) } }; function handle_mousemove(b) { rawMouseX = b.layerX; rawMouseY = b.layerY; var a = Math.min(parseFloat(canvas.style.width) / 480, parseFloat(canvas.style.height) / 720); mouseX = b.layerX / a; mouseY = b.layerY / a } function handle_mousedown(a) { mouseDown = true } function handle_mouseup(a) { mouseDown = false } function handle_touchstart(d) { d.preventDefault(); var b = Math.min(parseFloat(canvas.style.width) / canvas.width, parseFloat(canvas.style.height) / canvas.height); for (var c = 0; c < d.changedTouches.length; c++) { var a = d.changedTouches[c].pageX; var e = d.changedTouches[c].pageY; a -= canvas.offsetLeft; e -= canvas.offsetTop; a /= b; e /= b; currentTouches.push({ x: a, y: e, id: d.changedTouches[c].identifier, moved: false }) } touchDown = true } function handle_touchend(c) { c.preventDefault(); for (var b = 0; b < c.changedTouches.length; b++) { for (var a = 0; a < currentTouches.length; a++) { if (currentTouches[a].id == c.changedTouches[b].identifier) { currentTouches.splice(a, 1); break } } } if (currentTouches.length == 0 || c.targetTouches.length == 0) { touchDown = false } } function handle_touchmove(e) { e.preventDefault(); var b = Math.min(parseFloat(canvas.style.width) / canvas.width, parseFloat(canvas.style.height) / canvas.height); for (var d = 0; d < e.changedTouches.length; d++) { for (var c = 0; c < currentTouches.length; c++) { if (currentTouches[c].id == e.changedTouches[d].identifier) { var a = e.changedTouches[d].pageX; var f = e.changedTouches[d].pageY; a -= canvas.offsetLeft; f -= canvas.offsetTop; a /= b; f /= b; currentTouches[c].x = a; currentTouches[c].y = f; currentTouches[c].moved = true; break } } } } function handle_mousewheel(a) { var b = window.event || b; mouseWheelDelta = Math.max(-1, Math.min(1, (b.wheelDelta || -b.detail))) } var Key = { _pressed: {}, _prevPressed: {}, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, SPACE: 32, Q: 81, E: 69, W: 87, A: 65, S: 83, D: 68, isDown: function(a) { return this._pressed[a] }, isPressed: function(a) { return (this._pressed[a] && !this._prevPressed[a]) }, onKeydown: function(a) { this._pressed[a.keyCode] = true }, onKeyup: function(a) { delete this._pressed[a.keyCode] } }; var debugText = ""; var context = null; var focused = true; var viewScale = 1; var firstRun = true; var gRedrawActive = true; var gFirstDraw = true; var gWrongOrientation = false; var gMobile = false; function Game() { var a; this.init = function() { canvas = document.getElementById("canvas"); vectorResizeEvent = document.createEvent("Event"); vectorResizeEvent.initEvent("vectorResize", true, true); if (canvas.getContext) { gMobile = queryIsTouchDevice(); gStorageAvailable = supports_html5_storage(); if (gStorageAvailable) { soundMuted = (queryLocalVar("soundMuted") == "true"); musicMuted = (queryLocalVar("musicMuted") == "true") } document.addEventListener("mousemove", handle_mousemove); document.addEventListener("mousedown", handle_mousedown); document.addEventListener("mouseup", handle_mouseup); document.addEventListener("touchstart", handle_touchstart, false); document.addEventListener("touchend", handle_touchend, false); document.addEventListener("touchmove", handle_touchmove, true); document.addEventListener("keyup", function(d) { Key.onKeyup(d) }, false); document.addEventListener("keydown", function(d) { Key.onKeydown(d) }, false); document.addEventListener("mousewheel", handle_mousewheel, false); document.addEventListener("DOMMouseScroll", handle_mousewheel, false); window.addEventListener("resize", resizeGame, false); ctx = canvas.getContext("2d"); this.stateManager = new StateManager(); this.stateManager.init(); switch (gCurrentBrand) { case BRAND.ADDICTING: case BRAND.MRG: var c = new SplashState(); c.init(); this.stateManager.setState(c); break; default: var b = new MainMenuState(); b.init(); this.stateManager.setState(b); break } return true } else { return false } }; this.start = function() { canvas.style.width = "480px"; canvas.style.height = "720px"; resizeGame(); tick() } } var lastFrame = Date.now(); function tick() { requestAnimFrame(tick); if (!gFirstDraw) { gRedrawActive = false } gFirstDraw = false; var a = 1 / 60; var d = Date.now(); var c = (d - lastFrame) / 1000; lastFrame = d; var b = c; if (c < 0.5) { while (b > 0) { if (b < a) { game.stateManager.update(a); b = 0 } else { game.stateManager.update(a); b -= a } Input.update() } ctx.fillStyle = "#fcb040"; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.globalAlpha = 1; game.stateManager.draw() } ctx.fillStyle = "#000000"; Input.update() } function setCursor(a) { document.body.style.cursor = a } window.onfocus = function() { createjs.Sound.setMute(false) }; window.onblur = function() { createjs.Sound.setMute(true) }; function resizeGame() { gRedrawActive = true; gFirstDraw = true; var c = 0.6666666666667; var d = window.innerWidth; var a = window.innerHeight; canvas.style.height = a + "px"; canvas.style.width = d + "px"; canvas.height = a; canvas.width = d; viewH = a; viewW = d; var b = viewW / 480; var e = viewH / 720; if (b < e) { canvas.height = a / b; canvas.width = d / b; canvas.style.width = (canvas.width * b) + "px"; canvas.style.height = (canvas.height * b) + "px"; viewW = 480; viewH = 720 } else { canvas.height = a / e; canvas.width = d / e; canvas.style.width = (canvas.width * e) + "px"; canvas.style.height = (canvas.height * e) + "px"; viewW = 480; viewH = 720 } styleW = d; styleH = a; docToCanv = Math.min(styleW / 480, styleH / 720); window.scrollTo(0, 1) } function orientationChanged(a) { console.log(window.orientation); gWrongOrientation = false; if (window.orientation != 0) { gWrongOrientation = true } } window.requestAnimFrame = (function() { return (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(a) { window.setTimeout(a, 1000 / 60) }) })(); var game = new Game(); this.loadContent = function() { resizeGame(); content.load() }; function queryIsTouchDevice() { return "ontouchstart" in window || "onmsgesturechange" in window } function init() { if (game.init()) { game.start() } } function checkSL() { var b = []; var d = gCurrentBrand; switch (d) { default: case BRAND.NONE: break; case BRAND.ADDICTING: b.push("addictinggames.com"); break; case BRAND.MRG: b.push("myrealgames.com"); break } if (b.length != 0) { for (var c = 0; c < b.length; c++) { if (window.top.location.hostname.indexOf(b[c]) != -1) { break } } if (c >= b.length) { throw "This game cannot be played from this domain"; invalid = true } } } function Particle() { Drawable.call(this); this.started = false; this.velocityX = 0; this.velocityY = 0; this.dragX = 1; this.dragY = 1; this.timer = 0; this.lifetime = 0; this.gravityX = 0; this.gravityY = 0; this.angularVelocity = 0; this.accelerationX = 0; this.accelerationY = 0; this.startScaleX = 1; this.startScaleY = 1; this.endScaleX = 1; this.endScaleY = 1; this.startAlpha = 1; this.endAlpha = 1; this.angle = 0; this.followVelocity = false } Particle.prototype = new Drawable(); Particle.prototype.constructor = Particle; Particle.prototype.init = function(b, a) { this.sprite = b; this.lifetime = a; this.started = false; this.useCamera = true }; Particle.prototype.update = function(b) { if (this.started && !this.toBeRemoved) { this.timer += b; if (this.timer >= this.lifetime) { this.flagForRemoval(); return } var a = this.timer / this.lifetime; this.alpha = this.startAlpha + (this.endAlpha - this.startAlpha) * a; this.scaleX = this.startScaleX + (this.endScaleX - this.startScaleX) * a; this.scaleY = this.startScaleY + (this.endScaleY - this.startScaleY) * a; this.angle += this.angularVelocity; this.accelerationX += this.gravityX; this.accelerationY += this.gravityY; var d = this.velocityX; var c = this.velocityY; this.velocityX += this.accelerationX * b; this.velocityY += this.accelerationY * b; this.x += d + this.velocityX * 0.5 * b; this.y += c + this.velocityY * 0.5 * b; this.accelerationX = 0; this.accelerationY = 0; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, b) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, b) } if (this.followVelocity) { this.angle = Math.atan2(this.velocityY, this.velocityX) } } this.hasUpdated = true }; Particle.prototype.start = function(a) { if (!a) { a = this } a.started = true; a.timer = 0; a.scaleX = a.startScaleX; a.scaleY = a.startScaleY }; function SceneObject() { Entity.call(this); this.children = []; this.childCount = 0 } SceneObject.prototype = new Entity(); SceneObject.prototype.constructor = SceneObject; SceneObject.prototype.init = function(a, b) { this.x = a; this.y = b; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true }; SceneObject.prototype.update = function(b) { this.removeChildren(); for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } }; SceneObject.prototype.draw = function(b) { if (!this.visible) { return } for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } }; SceneObject.prototype.addChild = function(a) { a.parent = this; a.sceneManager = this.sceneManager; this.children.push(a); this.childCount++ }; SceneObject.prototype.removeChildren = function() { for (var a = 0; a < this.childCount; a++) { if (this.children[a].toBeRemoved) { this.children.splice(a, 1); this.childCount--; return } } }; function SceneManager() { this.entities = []; this.entityCount = 0; this.camera; this.masterAlpha; this.timeMultiplier; this.inverseMatrix; this.mousePoint; this.init = function() { this.camera = new Camera(); this.camera.init(0, 0, 0, 1); this.masterAlpha = 1; this.timeMultiplier = 1; this.parallaxMagnitudeX = 1; this.parallaxMagnitudeY = 1; this.worldMouseX = 0; this.worldMouseY = 0 }; this.update = function(b) { b *= this.timeMultiplier; this.camera.update(b); for (var a = 0; a < this.entityCount; a++) { if (this.entities[a].toBeRemoved) { this.entities.splice(a, 1); this.entityCount--; a--; continue } this.entities[a].update(b) } this.sort(); this.updateWorldMouse() }; this.updateWorldMouse = function() { if (!this.inverseMatrix) { this.inverseMatrix = mat2d.create() } mat2d.copy(this.inverseMatrix, this.camera.internalMatrix); mat2d.invert(this.inverseMatrix, this.inverseMatrix); if (!this.mousePoint) { this.mousePoint = vec2.create() } if (gMobile && currentTouches.length != 0) { this.mousePoint[0] = currentTouches[0].x; this.mousePoint[1] = currentTouches[0].y } else { if (gMobile) { return } else { this.mousePoint[0] = mouseX; this.mousePoint[1] = mouseY } } vec2.transformMat2d(this.mousePoint, this.mousePoint, this.inverseMatrix); this.worldMouseX = this.mousePoint[0]; this.worldMouseY = this.mousePoint[1] }; this.draw = function() { mat2d.identity(this.camera.internalMatrix); if (this.camera.originX != 0 || this.camera.originY != 0) { mat2d.translate(this.camera.internalMatrix, this.camera.internalMatrix, [this.camera.originX, this.camera.originY]) } if (this.camera.zoom != 1) { mat2d.scale(this.camera.internalMatrix, this.camera.internalMatrix, [this.camera.zoom, this.camera.zoom]) } if (this.camera.angle != 0) { mat2d.rotateZ(this.camera.internalMatrix, this.camera.internalMatrix, this.camera.angle) } if (this.camera.positionX != 0 || this.camera.positionY != 0) { mat2d.translate(this.camera.internalMatrix, this.camera.internalMatrix, [this.camera.positionX, this.camera.positionY]) } if (this.camera.shakeOffsetX != 0 || this.camera.shakeOffsetY != 0) { mat2d.translate(this.camera.internalMatrix, this.camera.internalMatrix, [this.camera.shakeOffsetX, this.camera.shakeOffsetY]) } ctx.save(); for (var a = 0; a < this.entityCount; a++) { this.entities[a].draw() } ctx.restore() }; this.addEntity = function(a) { a.sceneManager = this; this.entities.push(a); a.onAddedToSceneManager(); this.entityCount++ }; this.sort = function() { this.entities.sort(this.depthSort) }; this.removeEntity = function(a) { for (var b = 0; b < this.entityCount; b++) { if (this.entities[b].toBeRemoved) { var a = this.entities[b]; this.entities.splice(b, 1); this.entityCount--; delete a; return } } }; this.depthSort = function(d, c) { if (d.depth > c.depth) { return -1 } else { if (d.depth < c.depth) { return 1 } } return 0 }; this.clear = function() { while (this.entities.length) { this.entities[0].flagForRemoval(); this.entities.splice(0, 1) } this.entityCount = 0 }; this.viewToWorld = function(d, c) { var b = mat2.create(this.camera.internalMatrix); mat2.invert(b, b); var a = vec2.create(); a[0] = d; a[1] = c; vec2.transformMat2d(a, a, b); return { x: a[0], y: a[1] } } } function SpriteSheet() { Drawable.call(this); this.animations = []; this.animationCount = 0; this.currentAnimation = -1; this.frameWidth = 0; this.frameHeight = 0; this.textureWidth = 0; this.textureHeight = 0; this.speedModifier = 1; this.removeWhenStopped = false } SpriteSheet.prototype = new Drawable(); SpriteSheet.prototype.constructor = SpriteSheet; SpriteSheet.prototype.init = function(c, a, b) { this.sprite = c; this.frameWidth = a; this.frameHeight = b; this.sourceRectX = 0; this.sourceRectY = 0; this.sourceRectW = a; this.sourceRectH = b; this.useSourceRect = true; this.useCamera = true }; SpriteSheet.prototype.update = function(e) { if (!this.active || !this.visible) { return } if (this.currentAnimation > -1 && this.currentAnimation < this.animationCount) { var g = this.animations[this.currentAnimation].currentFrame; var c = this.animations[this.currentAnimation].frames[g]; this.animations[this.currentAnimation].update(e * this.speedModifier); var a = this.sprite.width; var b = this.sprite.height; var f = this.frameWidth * this.animations[this.currentAnimation].frames[g]; var d = 0; while (f >= a) { d += this.frameHeight * Math.floor((f / a)); f = (f) % a } this.sourceRectX = f; this.sourceRectY = d; this.sourceRectW = this.frameWidth; this.sourceRectH = this.frameHeight; if (this.removeWhenStopped && this.animations[this.currentAnimation].currentState == AnimationState.STOPPED) { this.flagForRemoval(); return } } }; SpriteSheet.prototype.currentAnimationState = function() { if (this.currentAnimation > -1 && this.currentAnimation < this.animationCount) { return this.animations[this.currentAnimation].currentState } return null }; SpriteSheet.prototype.addAnimation = function(b, e, g, f, a) { var d = new Animation(); d.init(b, e, g, f); for (var c = 0; c < this.animationCount; c++) { if (this.animations[c].name == b) { if (a) { this.animations.splice(c, 1); this.animationCount--; break } else { return } } } this.animations.push(d); this.animationCount++ }; SpriteSheet.prototype.playAnimation = function(b, a) { for (var c = 0; c < this.animationCount; c++) { if (this.animations[c].name == b) { if (a) { this.animations[c].ResetTimer(); this.animations[c].SetFrame(0) } this.animations[c].SetState(AnimationState.PLAYING); this.currentAnimation = c; break } } this.update(0) }; SpriteSheet.prototype.stopAnimation = function(a) { for (var b = 0; b < this.animationCount; b++) { if (this.animations[b].name == a) { this.animations[b].SetState(AnimationState.STOPPED); this.currentAnimation = -1; break } } }; SpriteSheet.prototype.rewindAnimation = function(a) { for (var b = 0; b < this.animationCount; b++) { if (this.animations[b].name == a) { this.animations[b].SetState(AnimationState.REWINDING); this.currentAnimation = b; break } } }; var TO_DEGREES = 180 / Math.PI; var TO_RADIANS = Math.PI / 180; function randIntRange(b, a) { return Math.floor(randFloatRange(b, a)) } function randFloatRange(b, a) { return (Math.random() * (a - b)) + b } function distanceBetweenPoints(b, d, a, c) { return Math.sqrt(((a - b) * (a - b)) + ((c - d) * (c - d))) } function normalizeAngle(b) { while (b > Math.PI * 2) { b -= Math.PI * 2 } while (b < 0) { b += Math.PI * 2 } return b } function supports_html5_storage() { try { return "localStorage" in window && window.localStorage !== null } catch (a) { return false } } function queryLocalVar(a) { if (!gStorageAvailable) { return null } a = "MATTER." + a; var b = localStorage.getItem(a); return b } function setLocalVar(a, b) { if (!gStorageAvailable) { return } a = "MATTER." + a; localStorage.setItem(a, b) } function submitScore(b, c, d) { leaderboard = new Clay.Leaderboard({ id: 1866 }); var a = { score: c, name: b, hideUI: true }; leaderboard.post(a, d) } function getFormattedTime(c) { var a = ""; if (c < 0) { c *= -1; a += "-" } if (c >= 60) { if (c / 60 < 10) { a += "0" } a += Math.floor(c / 60).toString() } else { a += "00" } a += ":"; if (c >= 1) { if (c % 60 < 10) { a += "0" } a += Math.floor(c % 60).toString() } else { a += "00" } a += ":"; var b = (c % 1).toString(); a += b.substring(2, 4); return a } function hexToRGB(b) { var a = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(b); return a ? { r: parseInt(a[1], 16), g: parseInt(a[2], 16), b: parseInt(a[3], 16) } : null } function colorMatrixFilter(n, e) { var l = n.data; for (var h = 0; h < l.length; h += 4) { var k = l[h]; var j = l[h + 1]; var c = l[h + 2]; var f = l[h + 3]; l[h] = k * e[0] + j * e[1] + c * e[2] + f * e[3] + e[4]; l[h + 1] = k * e[5] + j * e[6] + c * e[7] + f * e[8] + e[9]; l[h + 2] = k * e[10] + j * e[11] + c * e[12] + f * e[13] + e[14]; l[h + 3] = k * e[15] + j * e[16] + c * e[17] + f * e[18] + e[19] } return n } var Trigger = { IN: 0, OUT: 1 }; function Transition() { this.time = 1; this.delay = 0; this.ease = null; this.reverse = false; this.last = 0; this.state = null; this.nextState = null; this.previousState = null; this.drawable = false; this.done = false; this.started = false } Transition.prototype.init = function(d, e, f, b, g, c, a) { this.time = e; this.delay = a; this.reverse = b; this.ease = f; this.state = d; if (this.state) { this.state.progress = g } this.nextState = c }; Transition.prototype.trigger = function(b, a) { if (!this.state) { return false } this.done = false; this.started = true; if (b == Trigger.IN && this.state.progress == 1) { return false } else { if (b == Trigger.OUT && this.state.progress === 0) { return false } } if (b == Trigger.OUT) { this.nextState = a } else { this.previousState = a } this.last = b; if (this.time === 0) { this.state.progress = (b == Trigger.IN ? 1 : 0); this.onTransitionDone(this); return false } if (b == Trigger.IN) { this.state.transitionState = TransitionState.ENTERING } else { this.state.transitionState = TransitionState.EXITING } this.last = b; TweenLite.to(this.state, this.time, { progress: (b == Trigger.IN ? 1 : 0), onComplete: this.onTransitionDone, ease: this.ease, overwrite: false, delay: this.delay, data: this }); return true }; Transition.prototype.onTransitionDone = function(a) { if (this.data) { a = this.data } if (a.last === Trigger.IN) { a.state.onEnter() } else { if (a.last === Trigger.OUT) { a.state.onExit() } } if (a.nextState) { a.nextState.onPrevStateFinished() } a.done = true }; Transition.prototype.draw = function() { if (this.done) { return false } if (!this.drawable) { return false } return true }; Transition.prototype.kill = function() { this.done = true; this.OnTransitionDone(); TweenLite.killTweensOf(this.state); this.state.progress = (this.direction == TRIGGER.IN ? 1 : 0) }; function FadeToBlackTransition() { Transition.call(this); this.time = 1; this.delay = 0; this.ease = null; this.reverse = false; this.last = 0; this.state = null; this.nextState = null; this.previousState = null; this.drawable = true; this.done = false; this.started = false } FadeToBlackTransition.prototype = new Transition(); FadeToBlackTransition.prototype.constructor = FadeToBlackTransition; FadeToBlackTransition.prototype.init = function(d, e, f, b, g, c, a) { this.time = e; this.delay = a; this.reverse = b; this.ease = f; this.state = d; if (this.state) { this.state.progress = g } this.nextState = c; this.black = content.black4 }; FadeToBlackTransition.prototype.draw = function() { if (this.done) { return false } ctx.save(); ctx.globalAlpha = 1 - this.state.progress; ctx.scale(canvas.width, canvas.height); ctx.drawImage(this.black, 0, 0); ctx.restore(); return true }; var ButtonHover = { MOVERIGHT16: 0, MOVELEFT16: 1, MOVERIGHT32: 2, MOVELEFT32: 3, GROW: 4, TURNLEFT: 5, TURNRIGHT: 6, SKEWRIGHT: 7 }; var ButtonHit = { PULSE: 0, SHIFTRIGHT: 1, SHIFTLEFT: 2 }; function reactIn(a, b) { switch (b) { case ButtonHover.MOVERIGHT16: TweenLite.to(a, 0.15, { reactOffsetX: 16, ease: Sine.easeOut }); break; case ButtonHover.MOVELEFT16: TweenLite.to(a, 0.15, { reactOffsetX: -16, ease: Sine.easeOut }); break; case ButtonHover.MOVERIGHT32: TweenLite.to(a, 0.15, { reactOffsetX: 32, ease: Sine.easeOut }); break; case ButtonHover.MOVELEFT32: TweenLite.to(a, 0.15, { reactOffsetX: -32, ease: Sine.easeOut }); break; case ButtonHover.GROW: TweenLite.to(a, 0.15, { reactScaleX: 1.15, reactScaleY: 1.15, ease: Sine.easeOut }); break; case ButtonHover.TURNLEFT: TweenLite.to(a, 0.15, { reactAngle: -0.2, ease: Sine.easeOut }); break; case ButtonHover.TURNRIGHT: TweenLite.to(a, 0.15, { reactAngle: 0.2, ease: Sine.easeOut }); break; case ButtonHover.SKEWRIGHT: TweenLite.to(a, 0.15, { reactSkewX: 0.2, ease: Sine.easeOut }); TweenLite.to(a.reactOffset, 0.15, { x: 16, ease: Sine.easeOut }); break } } function reactOut(a, b) { switch (b) { case ButtonHover.MOVERIGHT16: case ButtonHover.MOVELEFT16: case ButtonHover.MOVERIGHT32: case ButtonHover.MOVELEFT32: TweenLite.to(a, 0.25, { reactOffsetX: 0, ease: Sine.easeOut }); break; case ButtonHover.GROW: TweenLite.to(a, 0.25, { reactScaleX: 1, reactScaleY: 1, ease: Sine.easeOut }); break; case ButtonHover.TURNLEFT: case ButtonHover.TURNRIGHT: TweenLite.to(a, 0.25, { reactAngle: 0, ease: Sine.easeOut }); break; case ButtonHover.SKEWRIGHT: TweenLite.to(a, 0.15, { reactSkewX: 0, ease: Sine.easeOut }); TweenLite.to(a, 0.15, { reactOffsetX: 0, ease: Sine.easeOut }); break } } function hitReact(b, c) { switch (c) { case ButtonHit.PULSE: b.reactScaleX = 1.4; b.reactScaleY = 1.4; TweenLite.to(b, 0.45, { reactScaleX: 1, reactScaleY: 1, ease: Elastic.easeOut }); break; case ButtonHit.SHIFTRIGHT: var a = b.reactOffsetX; b.reactOffsetX = b.reactOffsetX - 8; TweenLite.to(b, 0.45, { reactOffsetX: a, ease: Sine.easeOut }); break; case ButtonHit.SHIFTLEFT: var a = b.reactOffsetX; b.reactOffsetX = b.reactOffsetX + 8; TweenLite.to(b, 0.45, { reactOffsetX: a, ease: Sine.easeOut }); break } } var ButtonState = { DEFAULT: 0, HOVER: 1, HIT: 2, UP: 3, INACTIVE: 4 }; function Button() { Drawable.call(this); this.currentBitmap = null; this.defaultGraphic = null; this.hoverGraphic = null; this.hitGraphic = null; this.inactiveGraphic = null; this.buttonText = ""; this.textColor = "#000000"; this.textFont = "sans-serif"; this.textSize = "18px"; this.active = true; this.buttonState = ButtonState.DEFAULT; this.prevButtonState = ButtonState.INACTIVE; this.visible = true; this.dirty = true; this.forceUpdate = false; this.mouseOver = false; this.prevMouseOver = false; this.parentState = null; this.callback = null; this.hoverCallback = null; this.leaveCallback = null; this.hitAreaX = 0; this.hitAreaY = 0; this.hitAreaW = 128; this.hitAreaH = 64; this.hitReact = -1; this.hoverReact = -1; this.screenSizeOffsetX = 0; this.screenSizeOffsetY = 0; this.reactOffsetX = 0; this.reactOffsetY = 0; this.reactAngle = 0; this.reactScaleX = 1; this.reactScaleY = 1; this.reactSkewX = 0; this.reactSkewY = 0 } Button.prototype = new Drawable(); Button.prototype.constructor = Button; Button.prototype.init = function() { this.useCamera = false; if (this.buttonText === undefined || this.buttonText == "") { this.hitAreaX = -this.defaultGraphic.width * 0.5; this.hitAreaY = -this.defaultGraphic.height * 0.5; this.hitAreaW = this.defaultGraphic.width; this.hitAreaH = this.defaultGraphic.height; this.originX = this.defaultGraphic.width * 0.5; this.originY = this.defaultGraphic.height * 0.5 } else { var a = this.MeasureText(this.buttonText, false, this.textFont, this.textSize); this.hitAreaX = 0; this.hitAreaY = 0; this.hitAreaW = a[0] * 0.75; this.hitAreaH = a[1] * 0.75 } }; Button.prototype.checkMouseCoords = function() { if (gMobile) { for (var a = 0; a < currentTouches.length; a++) { if (currentTouches[a].x >= (this.x + this.screenSizeOffsetX) + this.hitAreaX && currentTouches[a].x <= (this.x + this.screenSizeOffsetX) + this.hitAreaX + this.hitAreaW && currentTouches[a].y >= (this.y + this.screenSizeOffsetY) + this.hitAreaY && currentTouches[a].y <= (this.y + this.screenSizeOffsetY) + this.hitAreaY + this.hitAreaH) { return true } } } else { if (mouseX >= (this.x + this.screenSizeOffsetX) + this.hitAreaX && mouseX <= (this.x + this.screenSizeOffsetX) + this.hitAreaX + this.hitAreaW && mouseY >= (this.y + this.screenSizeOffsetY) + this.hitAreaY && mouseY <= (this.y + this.screenSizeOffsetY) + this.hitAreaY + this.hitAreaH) { return true } } return false }; Button.prototype.onMouseOver = function() { if (!this.active) { return } this.buttonState = ButtonState.HOVER; setCursor("pointer"); if (this.hoverReact != -1) { reactIn(this, this.hoverReact) } if (this.hoverCallback) { this.hoverCallback(this.parentState) } }; Button.prototype.onMouseDown = function() { if (!this.active) { return } this.buttonState = ButtonState.HIT; setCursor("default"); if (this.hitReact != -1) { hitReact(this, this.hitReact) } if (this.callback) { this.callback(this.parentState) } }; Button.prototype.onMouseUp = function() { if (!this.active) { return } this.buttonState = ButtonState.HOVER }; Button.prototype.onMouseOff = function() { if (!this.active) { return } this.buttonState = ButtonState.DEFAULT; setCursor("default"); if (this.hoverReact != -1) { reactOut(this, this.hoverReact) } if (this.leaveCallback) { this.leaveCallback(this.parentState) } }; Button.prototype.update = function(a) { if (this.active) { this.mouseOver = this.checkMouseCoords(); if (this.mouseOver && !this.prevMouseOver) { this.onMouseOver() } else { if (!this.mouseOver && this.prevMouseOver) { this.onMouseOff() } } if (this.mouseOver) { if (gMobile) { if (touchDown && !touchDownLast) { this.onMouseDown() } else { if (!touchDown && touchDownLast) { this.onMouseUp() } } } else { if (mouseDown && !mouseDownLast) { this.onMouseDown() } else { if (!mouseDown && mouseDownLast) { this.onMouseUp() } } } } } this.prevMouseOver = this.mouseOver; if (this.prevButtonState != this.buttonState || this.forceUpdate) { this.forceUpdate = false; if (this.buttonText === undefined || this.buttonText === "") { switch (this.buttonState) { case ButtonState.DEFAULT: this.currentBitmap = this.defaultGraphic; break; case ButtonState.HOVER: this.currentBitmap = this.hoverGraphic; break; case ButtonState.HIT: this.currentBitmap = this.hitGraphic; break; case ButtonState.INACTIVE: this.currentBitmap = this.inactiveGraphic; break } if (this.currentBitmap === null) { this.currentBitmap = this.defaultGraphic } } else {} } this.prevButtonState = this.buttonState }; Button.prototype.draw = function() { if (!this.visible) { return } ctx.save(); ctx.translate(this.x + this.reactOffsetX + this.screenSizeOffsetX, this.y + this.reactOffsetY + this.screenSizeOffsetY); if (this.parent) { ctx.translate(this.parent.x, this.parent.y) } ctx.rotate(this.angle + this.reactAngle); ctx.scale(this.scaleX * this.reactScaleX, this.scaleY * this.reactScaleY); ctx.translate(-this.originX, -this.originY); ctx.globalAlpha = this.alpha; if (this.currentBitmap) { if (this.useSourceRect) { ctx.drawImage(this.currentBitmap, this.sourceRectX, this.sourceRectY, this.sourceRectW, this.sourceRectH, 0, 0, this.sourceRectW, this.sourceRectH) } else { ctx.drawImage(this.currentBitmap, 0, 0) } } else { if (this.buttonText != "") { ctx.textBaseline = "top"; ctx.fillStyle = this.textColor; ctx.font = this.textSize + "px regular " + this.textFont; ctx.fillText(this.buttonText, 0, 0) } } ctx.restore() }; Button.prototype.MeasureText = function(e, c, a, b) { var d = e + ":" + c + ":" + a + ":" + b; if (typeof(__measuretext_cache__) == "object" && __measuretext_cache__[d]) { return __measuretext_cache__[d] } var f = document.createElement("DIV"); f.innerHTML = e; f.style.position = "absolute"; f.style.top = "-100px"; f.style.left = "-100px"; f.style.fontFamily = a; f.style.fontWeight = c ? "bold" : "normal"; f.style.fontSize = b + "pt"; document.body.appendChild(f); var b = [f.offsetWidth, f.offsetHeight]; document.body.removeChild(f); if (typeof(__measuretext_cache__) != "object") { __measuretext_cache__ = [] } __measuretext_cache__[d] = b; return b }; var TransitionState = { NULL: 0, ENTERING: 1, EXITING: 2, ENTERED: 3, EXITED: 4 }; function State() { this.stateManager = null; this.initialized = false; this.destroyed = false; this.isOverlay = false; this.buttons = []; this.inTransition = null; this.outTransition = null; this.transitionState = TransitionState.NULL; this.progress = 0 } State.prototype.init = function() { this.initialized = true; this.destroyed = false; this.inTransition = new Transition(); this.inTransition.init(this, 1, Sine.easeOut, false, 0, null, 0); this.outTransition = new Transition(); this.outTransition.init(this, 1, Sine.easeOut, false, 0, null, 0) }; State.prototype.onEnter = function() { if (!this.initialized) { return } this.transitionState = TransitionState.ENTERED }; State.prototype.onExit = function() { if (!this.initialized) { return } this.transitionState = TransitionState.EXITED }; State.prototype.triggerEnter = function() { if (!this.initialized) { return } this.inTransition.trigger(Trigger.IN) }; State.prototype.triggerExit = function(a) { if (!this.initialized) { return } this.outTransition.trigger(Trigger.OUT, a) }; State.prototype.onPrevStateFinished = function() {}; State.prototype.update = function(b) { if (this.transitionState != TransitionState.ENTERED) { gRedrawActive = true } for (var a = 0; a < this.buttons.length; a++) { this.buttons[a].update(b) } }; State.prototype.draw = function() {}; State.prototype.destroy = function() { this.destroyed = true }; State.prototype.onRestored = function() {}; function StateManager() { this.currentState = null; this.previousStates = null; this.desiredState = null; this.destroyed = false; this.initialized = false } StateManager.prototype.init = function() { this.destroyed = false; this.initialized = true; this.popping = false; this.currentState = null; this.previousStates = []; this.desiredState = null }; StateManager.prototype.update = function(a) { if (!this.initialized) { return } if (this.desiredState && this.desiredState !== this.currentState) { if (this.currentState) { if (this.currentState.transitionState !== TransitionState.EXITING) { if (this.currentState.transitionState === TransitionState.EXITED) { if (this.previousStates.length != 0 && !this.desiredState.isOverlay) { this.previousStates.length = 0 } if (!this.popping) { this.previousStates.push(this.currentState); if (this.previousStates.length != 0) { this.removeChild(this.previousStates[this.previousStates.length - 1]) } } else { this.previousStates.pop() } this.popping = false; this.currentState = this.desiredState; this.addChild(this.currentState); this.currentState.triggerEnter() } else { this.currentState.triggerExit() } } } else { this.currentState = this.desiredState; this.addChild(this.currentState); this.currentState.triggerEnter() } } if (this.desiredState && this.desiredState !== this.currentState && this.currentState.outTransition.done) { this.desiredState.update(a) } if (this.currentState) { this.currentState.update(a) } }; StateManager.prototype.addChild = function(a) {}; StateManager.prototype.removeChild = function(a) {}; StateManager.prototype.draw = function() { if (this.desiredState !== this.currentState && this.desiredState !== null && this.desiredState.parent !== null) { this.desiredState.draw() } if (this.currentState !== null) { this.currentState.draw() } if (this.currentState && !this.currentState.outTransition.done && this.currentState.outTransition.started) { this.currentState.outTransition.draw() } if (this.desiredState && !this.desiredState.inTransition.done && this.desiredState.inTransition.started) { this.desiredState.inTransition.draw() } }; StateManager.prototype.destroy = function() { if (!this.initialized) { return } for (var a = 0; a < this.previousStates.length; a++) { this.previousStates[a].destroy() } if (this.currentState) { this.currentState.destroy() } if (this.desiredState) { this.desiredState.destroy() } this.destroyed = true }; StateManager.prototype.setState = function(a) { if (!this.initialized) { return } if (this.desiredState != this.currentState) { return } if (!a.initialized) { a.init() } this.desiredState = a; this.desiredState.stateManager = this; if (this.desiredState.inTransition) { this.desiredState.inTransition.previousState = this.currentState } }; StateManager.prototype.restoreLastState = function() { if (this.previousStates.length != 0) { this.popping = true; this.previousStates[this.previousStates.length - 1].onRestored(); this.setState(this.previousStates[this.previousStates.length - 1]) } }; function MainMenuState() { State.call(this); this.stateManager = null; this.initialized = false; this.destroyed = false; this.buttons = []; this.inTransition = null; this.outTransition = null; this.transitionState = TransitionState.NULL; this.progress = 0 } MainMenuState.prototype = new State(); MainMenuState.prototype.constructor = MainMenuState; MainMenuState.prototype.init = function() { this.initialized = true; this.destroyed = false; this.sceneManager = new SceneManager(); this.sceneManager.init(); this.background = new Drawable(); this.background.init(content.menuBack, 0, 0); this.background.useCamera = true; this.background.originX = this.background.sprite.width * 0.5; this.background.originY = this.background.sprite.height * 0.5; this.sceneManager.addEntity(this.background); this.cloudLine = new Drawable(); this.cloudLine.init(null, 0, 0); this.cloudLine.useCamera = true; this.sceneManager.addEntity(this.cloudLine); this.cloudLine.sprite = document.createElement("canvas"); this.cloudLine.sprite.width = canvas.width; this.cloudLine.sprite.height = 150; var a = this.cloudLine.sprite.getContext("2d"); this.cloudPattern = a.createPattern(content.cloudLine, "repeat"); this.cloudScroll = 0; this.canvasChanged = false; this.sign = new Drawable(); this.sign.init(content.menuSign, 0, 0); this.sign.originX = this.sign.sprite.width * 0.5; this.sign.originY = this.sign.sprite.height; this.sceneManager.addEntity(this.sign); this.shadow = new Drawable(); this.shadow.init(content.menuSignShadow, 0, 0); this.shadow.useCamera = true; this.shadow.originX = this.shadow.sprite.width * 0.5; this.shadow.originY = 0; this.sceneManager.addEntity(this.shadow); this.playBtn = new Button(); this.playBtn.defaultGraphic = content.playBtnUp; this.playBtn.hitGraphic = content.playBtnDown; this.playBtn.callback = this.onPlayHit; this.playBtn.parentState = this; this.playBtn.init(); this.playBtn.originX = this.playBtn.defaultGraphic.width * 0.5; this.playBtn.originY = this.playBtn.defaultGraphic.height * 0.5; this.buttons.push(this.playBtn); this.soundButton = new Button(); this.soundButton.defaultGraphic = content.soundOff; this.soundButton.callback = this.onSoundHit; this.soundButton.parentState = this; this.soundButton.init(); this.soundButton.originX = this.soundButton.defaultGraphic.width * 0.5; this.soundButton.originY = this.soundButton.defaultGraphic.height * 0.5; this.soundButton.scaleX = 0.95; this.soundButton.scaleY = 0.95; this.buttons.push(this.soundButton); if (!soundMuted) { this.soundButton.defaultGraphic = content.soundOn } switch (gCurrentBrand) { case BRAND.ADDICTING: this.addictingLogo = new Drawable(); this.addictingLogo.init(content.addictingMenu, canvas.width - 4, canvas.height - 8); this.addictingLogo.originX = this.addictingLogo.sprite.width; this.addictingLogo.originY = this.addictingLogo.sprite.height; this.addictingLogo.useCamera = false; this.sceneManager.addEntity(this.addictingLogo); this.badge = new Drawable(); this.badge.init(content.ffBadge, 4, canvas.height - 8); this.badge.originX = 0; this.badge.originY = this.badge.sprite.height; this.badge.useCamera = false; this.sceneManager.addEntity(this.badge); break; case BRAND.MRG: this.mrgLogo = new Drawable(); this.mrgLogo.init(content.mrgMenu, canvas.width - 4, canvas.height - 8); this.mrgLogo.originX = this.mrgLogo.sprite.width; this.mrgLogo.originY = this.mrgLogo.sprite.height; this.mrgLogo.useCamera = false; this.sceneManager.addEntity(this.mrgLogo); this.moreBtn = new Button(); this.moreBtn.defaultGraphic = content.moreGames; this.moreBtn.parentState = this; this.moreBtn.init(); this.moreBtn.originX = this.moreBtn.defaultGraphic.width * 0.5; this.moreBtn.originY = this.moreBtn.defaultGraphic.height * 0.5; this.buttons.push(this.moreBtn); window.addEventListener("click", this.onMoreHit); window.addEventListener("touchend", this.onMoreHit); this.badge = new Drawable(); this.badge.init(content.ffBadge, 4, canvas.height - 8); this.badge.originX = 0; this.badge.originY = this.badge.sprite.height; this.badge.useCamera = false; this.sceneManager.addEntity(this.badge); break } this.inTransition = new FadeToBlackTransition(); this.inTransition.init(this, 1, Sine.easeOut, false, 0, null, 0); this.outTransition = new FadeToBlackTransition(); this.outTransition.init(this, 1, Sine.easeOut, false, 0, null, 0); setAudioState(AUDIO_STATE.MENULOOP) }; MainMenuState.prototype.onPlayHit = function(b) { var a = new GameplayState(); a.init(); b.stateManager.setState(a) }; MainMenuState.prototype.onMoreHit = function(b) { var a = this.game.stateManager.currentState || this.game.stateManager.desiredState; if (!a || !a.moreBtn) { return } if (a.moreBtn.buttonState == ButtonState.HIT) { // Play68.goHome(); gotomore(); try { parent.moregame(); } catch (e) {} } }; MainMenuState.prototype.onSoundHit = function(a) { setSoundMute(!soundMuted); setMusicMute(soundMuted); if (soundMuted) { a.soundButton.defaultGraphic = content.soundOff } else { a.soundButton.defaultGraphic = content.soundOn } }; MainMenuState.prototype.update = function(b) { if (!focused) { this.tweensPaused = true; return } else { if (this.tweensPaused) { this.tweensPaused = false } } for (var a = 0; a < this.buttons.length; a++) { this.buttons[a].update(b) } this.cloudScroll += b * 10; while (this.cloudScroll > 669) { this.cloudScroll -= 669 } this.cloudLine.x = -canvas.width * 0.5; this.playBtn.screenSizeOffsetX = canvas.width * 0.5; this.playBtn.screenSizeOffsetY = canvas.height - 92; this.soundButton.screenSizeOffsetX = canvas.width - this.soundButton.defaultGraphic.width * 0.5; this.soundButton.screenSizeOffsetY = 36; this.background.scaleX = canvas.width / 4; this.background.scaleY = canvas.height / 720; this.sign.y = canvas.height * 0.5 - (125 * this.background.scaleY); this.shadow.x = -2; this.shadow.y = this.sign.y; this.shadow.scaleY = 200; switch (gCurrentBrand) { case BRAND.ADDICTING: this.addictingLogo.x = canvas.width - 4; this.addictingLogo.y = canvas.height - 8; this.badge.x = 6; this.badge.y = canvas.height - 6; break; case BRAND.MRG: this.mrgLogo.x = canvas.width - 4; this.mrgLogo.y = canvas.height - 8; this.moreBtn.x = canvas.width * 0.5; this.moreBtn.y = canvas.height * 0.5 + this.sign.y - 256; this.badge.x = 6; this.badge.y = canvas.height - 6 } this.sceneManager.update(b); if (this.lastCanvasWidth != canvas.width) { this.cloudLine.sprite.width = canvas.width } this.lastCanvasWidth = canvas.width }; MainMenuState.prototype.draw = function() { this.sceneManager.masterAlpha = 1; if (this.inTransition.previousState) { if (!this.inTransition.previousState.done) { this.sceneManager.masterAlpha = 0 } } var b = this.cloudLine.sprite.getContext("2d"); b.clearRect(0, 0, canvas.width, 150); b.save(); b.globalAlpha = this.sceneManager.masterAlpha; b.fillStyle = this.cloudPattern; b.translate(-this.cloudScroll, 0); b.fillRect(this.cloudScroll, 0, canvas.width, 150); b.restore(); this.sceneManager.draw(); for (var a = 0; a < this.buttons.length; a++) { this.buttons[a].alpha = this.sceneManager.masterAlpha; this.buttons[a].draw() } if (this.paused) {} }; var PlayState = { TUTORIAL: 0, INTRO: 1, GAME: 2, DYING: 3, END: 4 }; function GameplayState() { State.call(this); this.sceneManager; this.stateManager = null; this.initialized = false; this.destroyed = false; this.playState = PlayState.GAME; this.buttons = []; this.inTransition = null; this.outTransition = null; this.transitionState = TransitionState.NULL; this.progress = 0; this.road; this.player; this.cars = []; this.walls = []; this.crates = []; this.detritus = []; this.potholes = []; this.oilSlicks = []; this.roadBlocks = []; this.wrenches = []; this.steeringUI; this.homeBtn; this.restartBtn; this.hud; this.paused = false; this.pauseOverlay; this.tweensPaused } GameplayState.prototype = new State(); GameplayState.prototype.constructor = GameplayState; GameplayState.prototype.init = function() { this.initialized = true; this.destroyed = false; this.sceneManager = new SceneManager(); this.sceneManager.init(); this.pauseOverlay = new SceneObject(); this.pauseOverlay.init(0, 0); this.pauseOverlay.depth = -1; this.pauseOverlay.useCamera = false; var a = new Drawable(); a.init(content.pauseBack, 0, 0); a.originX = a.sprite.width * 0.5; a.originY = a.sprite.height * 0.5; this.pauseOverlay.addChild(a); a = new Drawable(); a.init(content.pauseText, 0, 0); a.originX = a.sprite.width * 0.5; a.originY = a.sprite.height * 0.5; this.pauseOverlay.addChild(a); this.pauseOverlay.visible = false; this.sceneManager.addEntity(this.pauseOverlay); this.leftEdge = new Drawable(); this.leftEdge.init(content.sandEdge, 0, 0); this.leftEdge.useCamera = false; this.leftEdge.depth = 0.1; this.sceneManager.addEntity(this.leftEdge); this.rightEdge = new Drawable(); this.rightEdge.init(content.sandEdge, canvas.width, 0); this.rightEdge.useCamera = false; this.rightEdge.depth = 0.1; this.rightEdge.scaleX = -1; this.sceneManager.addEntity(this.rightEdge); this.road = new Road(); this.road.init(this); this.road.x = 512; this.sceneManager.addEntity(this.road); this.player = new PlayerCar(); this.player.init(-80, 0, this); this.sceneManager.addEntity(this.player); this.cars.push(this.player); this.sceneManager.camera.setPosition(0, this.cars[0].y - 128); this.steeringUI = new SteerController(); this.steeringUI.init(this); this.sceneManager.addEntity(this.steeringUI); this.hud = new Hud(); this.hud.init(this); this.sceneManager.addEntity(this.hud); this.homeBtn = new Button(); this.homeBtn.defaultGraphic = content.homeBtnUp; this.homeBtn.hitGraphic = content.homeBtnDown; this.homeBtn.callback = this.onHomeHit; this.homeBtn.parentState = this; this.homeBtn.init(); this.homeBtn.originX = this.homeBtn.defaultGraphic.width * 0.5; this.homeBtn.originY = this.homeBtn.defaultGraphic.height * 0.5; this.homeBtn.visible = false; this.homeBtn.active = false; this.buttons.push(this.homeBtn); this.replayBtn = new Button(); this.replayBtn.defaultGraphic = content.restartBtnUp; this.replayBtn.hitGraphic = content.restartBtnDown; this.replayBtn.callback = this.onReplayHit; this.replayBtn.parentState = this; this.replayBtn.init(); this.replayBtn.originX = this.replayBtn.defaultGraphic.width * 0.5; this.replayBtn.originY = this.replayBtn.defaultGraphic.height * 0.5; this.replayBtn.visible = false; this.replayBtn.active = false; this.buttons.push(this.replayBtn); this.inTransition = new FadeToBlackTransition(); this.inTransition.init(this, 0.5, Sine.easeOut, false, 0, null, 0); this.outTransition = new FadeToBlackTransition(); this.outTransition.init(this, 0.5, Sine.easeOut, false, 0, null, 0); this.generator = new GameGenerator(); this.generator.init(this); this.lastCameraY = 0; this.bestGlowTime = 0.15; this.bestGlowTimer = this.bestGlowTime; this.tutorialStage = 0; this.tut01 = new Drawable(); this.tut01.init(content.tut01, 0, 0); this.tut01.useCamera = false; this.tut01.originX = this.tut01.sprite.width * 0.5; this.tut01.originY = this.tut01.sprite.height; this.tutSteerDot = new Drawable(); this.tutSteerDot.init(content.steeringCircle, 0, 0); this.tutSteerDot.useCamera = false; this.tutSteerDot.originX = this.tutSteerDot.sprite.width * 0.5; this.tutSteerDot.originY = this.tutSteerDot.sprite.height * 0.5; this.tutSteerDot.alpha = 0.5; this.steerTutSine = 0; this.tutTimer = 0; this.tutEndPosition = 0; if (firstRun) { this.playState = PlayState.TUTORIAL; this.sceneManager.addEntity(this.tut01); this.sceneManager.addEntity(this.tutSteerDot); firstRun = false } setAudioState(AUDIO_STATE.GAMELOOP) }; GameplayState.prototype.reset = function() {}; GameplayState.prototype.onHomeHit = function(a) { var b = new MainMenuState(); b.init(); a.stateManager.setState(b) }; GameplayState.prototype.onReplayHit = function(b) { var a = new GameplayState(); a.init(); b.stateManager.setState(a) }; GameplayState.prototype.update = function(c) { if (this.paused) { if ((touchDown && !touchDownLast) || (mouseDown && !mouseDownLast)) { this.paused = false } this.pauseOverlay.visible = true; this.pauseOverlay.x = canvas.width * 0.5; this.pauseOverlay.y = canvas.height * 0.5; this.pauseOverlay.children[0].scaleX = (canvas.width / this.pauseOverlay.children[0].sprite.width) * 1.1; this.pauseOverlay.children[0].scaleY = (canvas.height / this.pauseOverlay.children[0].sprite.height) * 1.1 } else { this.pauseOverlay.visible = false } if (this.paused) { this.tweensPaused = true; return } else { if (this.tweensPaused) { this.tweensPaused = false } } for (var d = 0; d < this.buttons.length; d++) { this.buttons[d].update(c) } this.road.x = canvas.width * 0.5; var f = 0; var e = this.cars[0].y - 160; switch (this.playState) { case PlayState.TUTORIAL: this.tutEndPosition = this.player.y; this.hud.distance = 1; this.steeringUI.x = canvas.width * 0.5; this.steeringUI.y = canvas.height - 64; this.tut01.x = canvas.width * 0.5; this.tut01.y = this.steeringUI.y - 64; this.steerTutSine += c; while (this.steerTutSine > Math.PI * 2) { this.steerTutSine -= Math.PI * 2 } switch (this.tutorialStage) { case 0: this.tutSteerDot.x = this.steeringUI.x + Math.sin(this.steerTutSine) * 96; this.tutSteerDot.y = this.steeringUI.y; if (this.steeringUI.inUse) { this.tutorialStage++; TweenLite.to(this.tut01, 0.25, { alpha: 0, ease: Sine.easeOut, onCompleteParams: [this.tut01], onComplete: function(i) { i.flagForRemoval() } }); TweenLite.to(this.tutSteerDot, 0.25, { alpha: 0, ease: Sine.easeOut, onCompleteParams: [this.tutSteerDot], onComplete: function(i) { i.flagForRemoval() } }); this.tut02 = new Drawable(); this.tut02.init(content.tut02, canvas.width * 0.5 + 66, 56); this.tut02.useCamera = false; this.tut02.originX = 0; this.tut02.originY = 0; this.sceneManager.addEntity(this.tut02); this.tutArrow = new Drawable(); this.tutArrow.init(content.tutArrow, canvas.width * 0.5 + 42, 70 + Math.sin(this.steerTutSine) * 8); this.tutArrow.useCamera = false; this.tutArrow.originX = this.tutArrow.sprite.width * 0.5; this.tutArrow.originY = this.tutArrow.sprite.height * 0.5; this.sceneManager.addEntity(this.tutArrow); this.tutTimer = 6; for (var d = 0; d < this.hud.hits.length; d++) { this.hud.hits[d].sprite = content.hitOff; var a = new Particle(); a.init(content.hitOn, 1.5); a.x = this.hud.x + this.hud.hits[d].x; a.y = this.hud.y + this.hud.hits[d].y; a.originX = a.sprite.width * 0.5; a.originY = a.sprite.height * 0.5; a.startScaleX = 2; a.startScaleY = 2; a.endScaleX = 0; a.endScaleY = 0; a.startAlpha = 1; a.endAlpha = 0; a.depth = this.hud.depth - 0.01; a.useCamera = false; a.alpha = 0; TweenLite.to(a, 1, { alpha: 1, ease: Sine.easeOut }); TweenLite.delayedCall(1 + d * 0.5, a.start, [a]); this.sceneManager.addEntity(a) } } break; case 1: this.steerTutSine += c * 4; this.tutArrow.x = canvas.width * 0.5 + 42; this.tutArrow.y = 70 + Math.sin(this.steerTutSine) * 8; this.tut02.x = canvas.width * 0.5 + 66; this.tut02.y = 56; this.tutTimer -= c; if (this.tutTimer <= 0) { this.playState = PlayState.GAME; TweenLite.to(this.tut02, 0.25, { alpha: 0, ease: Sine.easeOut, onCompleteParams: [this.tut02], onComplete: function(i) { i.flagForRemoval() } }); TweenLite.to(this.tutArrow, 0.25, { alpha: 0, ease: Sine.easeOut, onCompleteParams: [this.tutArrow], onComplete: function(i) { i.flagForRemoval() } }) } break } break; case PlayState.INTRO: break; case PlayState.GAME: this.hud.distance = -(this.player.y - this.tutEndPosition) / 30; this.steeringUI.x = canvas.width * 0.5; this.steeringUI.y = canvas.height - 64; this.generator.update(c); this.updateCars(c); break; case PlayState.DYING: if (this.best) { this.bestGlowTimer -= c; while (this.bestGlowTimer <= 0) { this.bestGlowTimer += this.bestGlowTime; var g = new Particle(); g.init(content.bestGlow, randFloatRange(0.25, 0.75) * 8); g.useCamera = false; g.x = this.best.x + randFloatRange(-115, 115); g.y = this.best.y + randFloatRange(-12, 12); g.originX = g.sprite.width * 0.5; g.originY = g.sprite.height * 0.5; var j = randFloatRange(0.75, 1) * 2; g.startScaleX = 4; g.startScaleY = 4; g.endScaleX = 0; g.endScaleY = 0; g.startAlpha = 0; g.endAlpha = 1; g.depth = this.best.depth + 0.01; g.dragX = 0.1; g.dragY = g.dragX; g.angularVelocity = randFloatRange(-1, 1) * 0.01; var b = randFloatRange(0, Math.PI * 2); var h = 0; g.velocityX = h * Math.cos(b); g.velocityY = h * Math.sin(b); g.start(); this.sceneManager.addEntity(g) } } this.homeBtn.screenSizeOffsetX = canvas.width * 0.5 - 128; this.homeBtn.screenSizeOffsetY = canvas.height - 92; this.replayBtn.screenSizeOffsetX = canvas.width * 0.5 + 128; this.replayBtn.screenSizeOffsetY = canvas.height - 92; this.endFadeTop.scaleX = canvas.width / 4; this.endFadeBottom.scaleX = canvas.width / 4; this.endBanner.x = canvas.width * 0.5; this.endBanner.y = 90; this.distanceTitle.x = canvas.width * 0.5; this.distanceTitle.y = this.endBanner.y + 140; if (this.best) { this.best.x = canvas.width * 0.5; this.best.y = this.endBanner.y + 190 } e = this.cars[0].y - 40; this.endFadeBottom.y = canvas.height; switch (gCurrentBrand) { case BRAND.ADDICTING: if (this.addictingGamesLogo) { this.addictingGamesLogo.x = canvas.width * 0.5 } break; case BRAND.MRG: if (this.mrgLogo) { this.mrgLogo.x = canvas.width * 0.5 } break } break; case PlayState.END: break } this.leftEdge.x = 0; this.rightEdge.x = canvas.width; this.updatePhysics(c); this.sceneManager.camera.shakeOffsetX = 0; this.sceneManager.camera.shakeOffsetY = 0; if (this.player.offroad && (this.player.currentState != CarState.BROKENDOWN && this.player.currentState != CarState.SPINNING)) { this.hud.offroad.open(); this.sceneManager.camera.shakeOffsetX = randFloatRange(-2, 2); this.sceneManager.camera.shakeOffsetY = randFloatRange(-2, 2) } else { this.hud.offroad.close() } if (this.player.dirtRoad && (this.player.currentState != CarState.BROKENDOWN && this.player.currentState != CarState.SPINNING)) { this.sceneManager.camera.shakeOffsetX = randFloatRange(-2, 2); this.sceneManager.camera.shakeOffsetY = randFloatRange(-2, 2); if (!this.player.dirtLoopInstance && !soundMuted) { this.player.dirtLoopInstance = createjs.Sound.play("dirtRoadRumble") } } this.sceneManager.camera.setTargetPosition(f, e); this.sceneManager.update(c); this.cullObjects() }; GameplayState.prototype.updatePhysics = function(e) { for (var b = 0; b < this.cars.length; b++) { for (var f = b + 1; f < this.cars.length; f++) { this.cars[b].checkCollision(this.cars[f]) } for (var a = 0; a < this.walls.length; a++) { this.cars[b].checkCollision(this.walls[a]) } for (var d = 0; d < this.roadBlocks.length; d++) { this.cars[b].checkCollision(this.roadBlocks[d]) } for (var j = 0; j < this.crates.length; j++) { if (this.crates[j].spawner === this.cars[b]) { continue } this.cars[b].checkCollision(this.crates[j]) } for (var g = 0; g < this.potholes.length; g++) { this.cars[b].checkCollision(this.potholes[g]) } for (var h = 0; h < this.oilSlicks.length; h++) { this.cars[b].checkCollision(this.oilSlicks[h]) } } for (var a = 0; a < this.wrenches.length; a++) { this.player.checkCollision(this.wrenches[a]) } for (var b = 0; b < this.crates.length; b++) { for (var j = b + 1; j < this.crates.length; j++) { this.crates[b].checkCollision(this.crates[j]) } for (var a = 0; a < this.walls.length; a++) { this.crates[b].checkCollision(this.walls[a]) } } }; GameplayState.prototype.updateCars = function(b) { for (var a = 0; a < this.cars.length; a++) { if (Math.abs(this.cars[a].y - -this.sceneManager.camera.positionY) > 1024) { this.cars[a].flagForRemoval() } } }; GameplayState.prototype.cullObjects = function() { var b = -this.sceneManager.camera.positionY; for (var a = 0; a < this.cars.length; a++) { if (this.cars[a].toBeRemoved) { this.cars.splice(a, 1); a--; continue } } for (var a = 0; a < this.walls.length; a++) { if (this.walls[a].y > b && Math.abs(this.walls[a].y - b) > 1024) { this.walls[a].flagForRemoval() } if (this.walls[a].toBeRemoved) { this.walls.splice(a, 1); a--; continue } } for (var a = 0; a < this.roadBlocks.length; a++) { if (this.roadBlocks[a].y > b && Math.abs(this.roadBlocks[a].y - b) > 1024) { this.roadBlocks[a].flagForRemoval() } if (this.roadBlocks[a].toBeRemoved) { this.roadBlocks.splice(a, 1); a--; continue } } for (var a = 0; a < this.crates.length; a++) { if (this.crates[a].y > b && Math.abs(this.crates[a].y - b) > 1024) { this.crates[a].flagForRemoval() } if (this.crates[a].toBeRemoved) { this.crates.splice(a, 1); a--; continue } } for (var a = 0; a < this.detritus.length; a++) { if (this.detritus[a].y > b && Math.abs(this.detritus[a].y - b) > 1024) { this.detritus[a].flagForRemoval() } if (this.detritus[a].toBeRemoved) { this.detritus.splice(a, 1); a--; continue } } for (var a = 0; a < this.potholes.length; a++) { if (this.potholes[a].y > b && Math.abs(this.potholes[a].y - b) > 1024) { this.potholes[a].flagForRemoval() } if (this.potholes[a].toBeRemoved) { this.potholes.splice(a, 1); a--; continue } } for (var a = 0; a < this.oilSlicks.length; a++) { if (this.oilSlicks[a].y > b && Math.abs(this.oilSlicks[a].y - b) > 1024) { this.oilSlicks[a].flagForRemoval() } if (this.oilSlicks[a].toBeRemoved) { this.oilSlicks.splice(a, 1); a--; continue } } for (var a = 0; a < this.wrenches.length; a++) { if (this.wrenches[a].y > b && Math.abs(this.wrenches[a].y - b) > 1024) { this.wrenches[a].flagForRemoval() } if (this.wrenches[a].toBeRemoved) { this.wrenches.splice(a, 1); a--; continue } } }; GameplayState.prototype.draw = function() { this.sceneManager.masterAlpha = 1; if (this.inTransition.previousState) { if (!this.inTransition.previousState.done) { this.sceneManager.masterAlpha = 0 } } this.sceneManager.draw(); for (var a = 0; a < this.buttons.length; a++) { this.buttons[a].alpha = this.sceneManager.masterAlpha; this.buttons[a].draw() } }; GameplayState.prototype.onExit = function() { if (!this.initialized) { return } this.transitionState = TransitionState.EXITED; this.sceneManager.clear() }; GameplayState.prototype.crashFlash = function() { this.flash = new Drawable(); this.flash.init(content.white4, canvas.width * 0.5, canvas.height * 0.5); this.flash.scaleX = canvas.width / 4; this.flash.scaleY = canvas.height / 4; this.flash.originX = 2; this.flash.originY = 2; this.flash.depth = -0.95; this.flash.useCamera = false; this.sceneManager.addEntity(this.flash); TweenLite.to(this.flash, 0.5, { alpha: 0, ease: Sine.easeOut, onCompleteParams: [this.flash], onComplete: function(a) { a.flagForRemoval() } }) }; GameplayState.prototype.endGame = function(b) { if (this.playState == PlayState.DYING || this.playState == PlayState.END) { return } var c = queryLocalVar("BEST_DISTANCE"); var e = false; if (c == null || this.hud.distance > c) { e = true; setLocalVar("BEST_DISTANCE", this.hud.distance) } this.playState = PlayState.DYING; this.steeringUI.hide(); this.hud.endGame(b); this.endFadeBottom = new Drawable(); this.endFadeBottom.init(content.endFade, 0, 0); this.endFadeBottom.useCamera = false; this.endFadeBottom.scaleX = canvas.width / 4; this.endFadeBottom.originY = this.endFadeBottom.sprite.height; this.endFadeBottom.y = canvas.height; this.endFadeBottom.depth = -0.98; this.endFadeBottom.alpha = 0; this.sceneManager.addEntity(this.endFadeBottom); TweenLite.to(this.endFadeBottom, 1, { alpha: 1, ease: Sine.easeOut, overwrite: 1 }); this.endFadeTop = new Drawable(); this.endFadeTop.init(content.endFade, 0, 0); this.endFadeTop.useCamera = false; this.endFadeTop.scaleX = canvas.width / 4; this.endFadeTop.scaleY = -1; this.endFadeTop.originY = this.endFadeTop.sprite.height; this.endFadeTop.depth = -0.98; this.endFadeTop.alpha = 0; this.sceneManager.addEntity(this.endFadeTop); TweenLite.to(this.endFadeTop, 1, { alpha: 1, ease: Sine.easeOut, overwrite: 1 }); this.replayBtn.visible = true; this.replayBtn.active = true; this.homeBtn.visible = true; this.homeBtn.active = true; this.replayBtn.y = 256; TweenLite.to(this.replayBtn, 0.5, { y: 0, ease: Sine.easeOut, overwrite: 1 }); this.homeBtn.y = 256; TweenLite.to(this.homeBtn, 0.5, { y: 0, ease: Sine.easeOut, overwrite: 1 }); this.endBanner = new EndBanner(); this.endBanner.init(b); this.endBanner.x = canvas.width * 0.5; this.endBanner.y = 90; this.sceneManager.addEntity(this.endBanner); this.endBanner.open(); this.distanceTitle = new Drawable(); this.distanceTitle.init(null, 0, 0); this.distanceTitle.sprite = document.createElement("canvas"); this.distanceTitle.sprite.width = 348; this.distanceTitle.sprite.height = 50; this.distanceTitle.useCamera = false; this.distanceTitle.originX = this.distanceTitle.sprite.width * 0.5; this.distanceTitle.originY = this.distanceTitle.sprite.height * 0.5; this.distanceTitle.depth = -0.985; this.sceneManager.addEntity(this.distanceTitle); var a = this.distanceTitle.sprite.getContext("2d"); a.font = "normal normal normal " + 48 + "px chunkfive"; a.textAlign = "center"; a.textBaseline = "middle"; a.fillStyle = "#000000"; a.fillText(this.hud.lastDistanceText, this.distanceTitle.sprite.width * 0.5 + 5, this.distanceTitle.sprite.height * 0.5 + 5); a.fillStyle = "#dfdfdf"; a.fillText(this.hud.lastDistanceText, this.distanceTitle.sprite.width * 0.5, this.distanceTitle.sprite.height * 0.5); if (e) { this.best = new Drawable(); this.best.init(null, 0, 0); this.best.sprite = document.createElement("canvas"); this.best.sprite.width = 275; this.best.sprite.height = 60; this.best.useCamera = false; this.best.originX = this.best.sprite.width * 0.5; this.best.originY = this.best.sprite.height * 0.5; this.best.depth = -0.985; this.sceneManager.addEntity(this.best); var d = this.best.sprite.getContext("2d"); d.font = "normal normal normal " + 36 + "px chunkfive"; d.textAlign = "center"; d.textBaseline = "middle"; d.fillStyle = "#000000"; d.globalAlpha = 0.75; d.fillText("\u6700\u597d\u6210\u7ee9 !", this.best.sprite.width * 0.5 + 5, this.best.sprite.height * 0.5 + 5); d.fillStyle = "#a5ff5d"; d.globalAlpha = 1; d.fillText("\u6700\u597d\u6210\u7ee9 !", this.best.sprite.width * 0.5, this.best.sprite.height * 0.5) } switch (gCurrentBrand) { case BRAND.ADDICTING: this.addictingGamesLogo = new Drawable(); this.addictingGamesLogo.init(content.addictingEnd, 0, 0); this.addictingGamesLogo.originX = this.addictingGamesLogo.sprite.width * 0.5; this.addictingGamesLogo.originY = 0; this.addictingGamesLogo.scaleX = 1; this.addictingGamesLogo.scaleY = 1; this.addictingGamesLogo.useCamera = false; this.addictingGamesLogo.depth = -1; this.sceneManager.addEntity(this.addictingGamesLogo); this.addictingGamesLogo.x = canvas.width * 0.5; this.addictingGamesLogo.y = -this.addictingGamesLogo.sprite.height; TweenLite.to(this.addictingGamesLogo, 0.5, { y: 16, ease: Sine.easeIn }); break; case BRAND.MRG: this.mrgLogo = new Drawable(); this.mrgLogo.init(content.mrgEnd, 0, 0); this.mrgLogo.originX = this.mrgLogo.sprite.width * 0.5; this.mrgLogo.originY = 0; this.mrgLogo.scaleX = 1; this.mrgLogo.scaleY = 1; this.mrgLogo.useCamera = false; this.mrgLogo.depth = -1; this.sceneManager.addEntity(this.mrgLogo); this.mrgLogo.x = canvas.width * 0.5; this.mrgLogo.y = -this.mrgLogo.sprite.height; TweenLite.to(this.mrgLogo, 0.5, { y: 7, ease: Sine.easeIn }); break } }; function SplashState() { State.call(this); this.stateManager = null; this.initialized = false; this.destroyed = false; this.buttons = []; this.inTransition = null; this.outTransition = null; this.transitionState = TransitionState.NULL; this.progress = 0; this.timer = 0; this.addictingGamesLogo; this.mrgLogo } SplashState.prototype = new State(); SplashState.prototype.constructor = SplashState; SplashState.prototype.init = function() { this.initialized = true; this.destroyed = false; this.sceneManager = new SceneManager(); this.sceneManager.init(); this.sceneManager.camera.useTarget = false; switch (gCurrentBrand) { case BRAND.ADDICTING: this.setupAddictingGames(); break; case BRAND.MRG: this.setupMRG(); break } this.inTransition = new FadeToBlackTransition(); this.inTransition.init(this, 1, Sine.easeOut, false, 0, null, 0); this.outTransition = new FadeToBlackTransition(); this.outTransition.init(this, 1, Sine.easeOut, false, 0, null, 0); setAudioState(AUDIO_STATE.NONE) }; SplashState.prototype.setupAddictingGames = function(a) { this.addictingGamesLogo = new Drawable(); this.addictingGamesLogo.init(content.addictingSplash, 0, 0); this.addictingGamesLogo.originX = this.addictingGamesLogo.sprite.width * 0.5 - 8; this.addictingGamesLogo.originY = this.addictingGamesLogo.sprite.height * 0.5; this.addictingGamesLogo.scaleX = 1; this.addictingGamesLogo.scaleY = 1; this.sceneManager.addEntity(this.addictingGamesLogo); this.timer = 4 }; SplashState.prototype.setupMRG = function(a) { this.mrgLogo = new Drawable(); this.mrgLogo.init(content.mrgSplash, 0, 0); this.mrgLogo.originX = this.mrgLogo.sprite.width * 0.5 - 8; this.mrgLogo.originY = this.mrgLogo.sprite.height * 0.5; this.mrgLogo.scaleX = 1; this.mrgLogo.scaleY = 1; this.sceneManager.addEntity(this.mrgLogo); this.timer = 4 }; SplashState.prototype.update = function(b) { for (var a = 0; a < this.buttons.length; a++) { this.buttons[a].update(b) } switch (gCurrentBrand) { case BRAND.ADDICTING: case BRAND.MRG: this.timer -= b; if (this.timer <= 0) { if (this.transitionState != TransitionState.ENTERED) { return } var c = new MainMenuState(); c.init(); this.stateManager.setState(c); return } break } this.sceneManager.update(b); gRedrawActive = true }; SplashState.prototype.draw = function() { ctx.fillStyle = "#FFFFFF"; ctx.fillRect(0, 0, canvas.width, canvas.height); this.sceneManager.masterAlpha = this.progress; this.sceneManager.draw(); for (var a = 0; a < this.buttons.length; a++) { this.buttons[a].alpha = this.sceneManager.masterAlpha; this.buttons[a].draw() } }; SplashState.prototype.onPrevStateFinished = function() {}; function Explosion() { SceneObject.call(this) } Explosion.prototype = new SceneObject(); Explosion.prototype.constructor = Explosion; Explosion.prototype.init = function(a, d, b, c) { this.x = a; this.y = d; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.magnitude = b; this.scale = c; this.triggered = false }; Explosion.prototype.update = function(b) { for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } if (this.triggered) { this.flagForRemoval() } else { if (this.timer > 0) { this.timer -= b; if (this.timer <= 0) { this.trigger() } } } }; Explosion.prototype.trigger = function(b, g, e) { if (this.triggered) { return } if (b > 0) { this.timer = b; return } this.triggered = true; for (var c = 0; c < 5; c++) { var f = new Particle(); if (f) { f.init(content.smoke, 4); f.depth = this.depth + randFloatRange(-1, 1) * 0.01; f.angle = randFloatRange(0, Math.PI * 2); f.originX = f.sprite.width * 0.5; f.originY = f.sprite.height * 0.5; f.x = this.x; f.y = this.y; f.startScaleX = 0.33 * this.scale; f.startScaleY = 0.33 * this.scale; f.endScaleX = 4 * this.scale; f.endScaleY = 4 * this.scale; f.startAlpha = 1; f.endAlpha = 0; f.angularVelocity = randFloatRange(-1, 1) * 0.01; var a = randFloatRange(0, Math.PI * 2); var d = 2 * this.scale; f.velocityX = Math.cos(a) * d; f.velocityY = Math.sin(a) * d; f.dragX = 0.001; f.dragY = 0.001; f.start(); this.sceneManager.addEntity(f) } } for (var c = 0; c < 4; c++) { var f = new Particle(); if (f) { f.init(content.flash, randFloatRange(0.2, 0.3)); f.depth = this.depth + randFloatRange(-1, 1) * 0.01; f.originX = f.sprite.width * 0.5; f.originY = f.sprite.height * 0.5; f.x = this.x; f.y = this.y; f.startScaleX = 3 * this.scale; f.startScaleY = 3 * this.scale; f.endScaleX = 0; f.endScaleY = 0; f.startAlpha = 1; f.endAlpha = 1; f.angle = randFloatRange(0, Math.PI * 2); f.start(); this.sceneManager.addEntity(f) } } for (var c = 0; c < 5; c++) { var f = new Particle(); if (f) { f.init(content.explosion, randFloatRange(1, 1.25) * 0.25); f.depth = this.depth + randFloatRange(-1, 1) * 0.01; f.angle = randFloatRange(0, Math.PI * 2); f.originX = f.sprite.width * 0.5; f.originY = f.sprite.height * 0.5; f.x = this.x; f.y = this.y; f.startScaleX = 0.33 * this.scale; f.startScaleY = 0.33 * this.scale; f.endScaleX = 2 * this.scale; f.endScaleY = 2 * this.scale; f.startAlpha = randFloatRange(0.5, 1); f.endAlpha = 0; f.angularVelocity = randFloatRange(-1, 1) * 0.05; var a = randFloatRange(0, Math.PI * 2); var d = 10 * this.scale; f.velocityX = Math.cos(a) * d; f.velocityY = Math.sin(a) * d; f.dragX = 0.0001; f.dragY = 0.0001; f.start(); this.sceneManager.addEntity(f) } } for (var c = 0; c < 10; c++) { var f = new Particle(); if (f) { f.init(content.explosionSpark, randFloatRange(0.5, 1.5) * 0.25); f.depth = this.depth + randFloatRange(-1, 1) * 0.01; f.originX = 116; f.originY = 8; f.x = this.x; f.y = this.y; f.startScaleX = 0; f.startScaleY = 0; var h = randFloatRange(0.45 * this.scale, 0.85 * this.scale); f.endScaleX = this.scale; f.endScaleY = this.scale; f.startAlpha = 1; f.endAlpha = 0; var a = randFloatRange(0, Math.PI * 2); var d = 10 * this.scale; f.velocityX = Math.sin(a) * d; f.velocityY = Math.cos(a) * d; f.followVelocity = true; f.dragX = 0.001; f.dragY = 0.001; f.start(); this.sceneManager.addEntity(f) } } }; var explosionSoundCount = 0; onExplosionSoundComplete = function() { explosionSoundCount-- }; function Road() { Drawable.call(this); this.pattern; this.dirtPattern; this.roadCtx } Road.prototype = new Drawable(); Road.prototype.constructor = Road; Road.prototype.init = function(a) { this.scroll = 0; this.useCamera = false; this.gameState = a; this.sprite = document.createElement("canvas"); this.sprite.width = 349; this.sprite.height = 720; this.originX = this.sprite.width * 0.5; this.roadCtx = this.sprite.getContext("2d"); this.pattern = this.roadCtx.createPattern(content.roadStripe, "repeat"); this.dirtPattern = this.roadCtx.createPattern(content.dirtRoad, "repeat"); this.roadCtx.save(); this.roadCtx.scale(1, 720); this.roadCtx.drawImage(content.road, 0, 0); this.roadCtx.restore(); this.depth = 0.1; this.dirtRoad = false; this.dirtRoadStart = 0; this.dirtRoadEnd = 0 }; Road.prototype.update = function(a) { this.hasUpdated = true }; Road.prototype.draw = function(d) { d = (d ? d : ctx); if (canvas.height != this.sprite.height) { this.sprite.height = canvas.height; this.roadCtx.save(); this.roadCtx.scale(1, this.sprite.height); this.roadCtx.drawImage(content.road, 0, 0); this.roadCtx.restore() } this.roadCtx.save(); this.roadCtx.fillStyle = "#1e1207"; this.roadCtx.fillRect(168.5, 0, 12, this.sprite.height); this.roadCtx.fillStyle = this.pattern; this.roadCtx.translate(this.sceneManager.camera.positionX, this.sceneManager.camera.positionY); this.roadCtx.fillRect(-this.sceneManager.camera.positionX + 174.5 - 3, -this.sceneManager.camera.positionY, 6, this.sprite.height); this.roadCtx.restore(); this.gameState.player.dirtRoad = false; if (this.dirtRoad) { this.roadCtx.save(); var g = 0; var e = this.sceneManager.camera.positionY - this.dirtRoadStart; var c = canvas.height / 720; if (e < 0) { g = e; if (e > -640 * c) { this.gameState.hud.dirtroad.close() } } if (e > -300 * c && e < Math.abs(this.dirtRoadStart - this.dirtRoadEnd) - 240 * c) { this.gameState.player.dirtRoad = true } if (e > (this.dirtRoadEnd - this.dirtRoadStart)) { this.roadCtx.save(); this.dirtRoad = false; this.roadCtx.scale(1, canvas.height); this.roadCtx.drawImage(content.road, 0, 0); this.roadCtx.restore() } else { this.roadCtx.save(); this.roadCtx.translate(this.sceneManager.camera.positionX, this.sceneManager.camera.positionY); this.roadCtx.clearRect(-this.sceneManager.camera.positionX, -this.sceneManager.camera.positionY + g, this.sprite.width, this.sprite.height); this.roadCtx.fillStyle = this.dirtPattern; this.roadCtx.fillRect(-this.sceneManager.camera.positionX, -this.sceneManager.camera.positionY + g, this.sprite.width, this.sprite.height); this.roadCtx.drawImage(content.dirtTransition, 0, -this.sceneManager.camera.positionY + g + this.sprite.height); this.roadCtx.restore() } if (this.dirtRoad && e > (this.dirtRoadEnd - this.dirtRoadStart) - canvas.height) { this.roadCtx.save(); this.roadCtx.translate(0, e - ((this.dirtRoadEnd - this.dirtRoadStart) - canvas.height) - canvas.height); this.roadCtx.scale(1, canvas.height); this.roadCtx.drawImage(content.road, 0, 0); this.roadCtx.restore(); this.roadCtx.save(); this.roadCtx.translate(0, e - ((this.dirtRoadEnd - this.dirtRoadStart) - canvas.height)); this.roadCtx.scale(1, -1); this.roadCtx.drawImage(content.dirtTransition, 0, 0); this.roadCtx.restore(); this.roadCtx.fillStyle = this.pattern; this.roadCtx.translate(this.sceneManager.camera.positionX, this.sceneManager.camera.positionY); this.roadCtx.fillRect(-this.sceneManager.camera.positionX + 174.5 - 3, -this.sceneManager.camera.positionY, 6, this.sprite.height + (this.sceneManager.camera.positionY - this.dirtRoadEnd)) } this.roadCtx.restore() } d.save(); this.worldX = 0; this.worldY = 0; this.drawingSM = this.sceneManager; var b = false; if (this.parent && this.parent.sceneManager) { this.drawingSM = this.parent.sceneManager } this.sceneAlpha = 1; if (this.drawingSM) { this.sceneAlpha = this.drawingSM.masterAlpha } d.globalAlpha = this.alpha * this.sceneAlpha; var a = this.x; var f = this.y; if (this.parent) { a += this.parent.x; f += this.parent.y } this.worldX += a; this.worldY += f; if (!this.internalMatrix) { this.internalMatrix = mat2d.create() } mat2d.identity(this.internalMatrix); if (this.originX != 0 || this.originY != 0) { if (!this._originTransformVec2) { this._originTransformVec2 = vec2.create() } this._originTransformVec2[0] = -this.originX; this._originTransformVec2[1] = -this.originY; mat2d.translate(this.internalMatrix, this.internalMatrix, this._originTransformVec2) } if (this.scaleX != 1 || this.scaleY != 1) { if (!this._scaleTransformVec2) { this._scaleTransformVec2 = vec2.create() } this._scaleTransformVec2[0] = this.scaleX; this._scaleTransformVec2[1] = this.scaleY; mat2d.scale(this.internalMatrix, this.internalMatrix, this._scaleTransformVec2) } if (this.angle != 0) { mat2d.rotate(this.internalMatrix, this.internalMatrix, -this.angle) } if (a != 0 || f != 0) { if (!this._translateTransformVec2) { this._translateTransformVec2 = vec2.create() } this._translateTransformVec2[0] = a; this._translateTransformVec2[1] = f; mat2d.translate(this.internalMatrix, this.internalMatrix, this._translateTransformVec2) } if (this.drawingSM) { mat2d.translate(this.internalMatrix, this.internalMatrix, [this.drawingSM.camera.shakeOffsetX, this.drawingSM.camera.shakeOffsetY]) } d.setTransform(this.internalMatrix[0], this.internalMatrix[1], this.internalMatrix[2], this.internalMatrix[3], this.internalMatrix[4], this.internalMatrix[5]); d.drawImage(this.sprite, 0, 0); d.restore() }; Road.prototype.startDirtRoad = function(a, b) { this.dirtRoad = true; this.dirtRoadStart = a; this.dirtRoadEnd = this.dirtRoadStart + b; this.gameState.hud.dirtroad.open() }; CarState = { NULL: -1, IDLE: 0, PULLINGOVER: 1, PARKED: 2, CRUSING: 3, BROKENDOWN: 4, CHASING: 5, EVADING: 6, SPINNING: 7 }; FailType = { SPIN: 0, CRASH: 1, EXPLODED: 2, BROKEDOWN: 3 }; Car.rightLaneX = 80; Car.leftLaneX = -80; function Car() { SceneObject.call(this); this.carColorIndex; this.body; this.gameState; this.currentState = CarState.NULL; this.desiredState = CarState.IDLE; this.previousState = CarState.IDLE; this.colliders; this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0 } Car.prototype = new SceneObject(); Car.prototype.constructor = Car; Car.prototype.init = function(a, d, c) { this.x = a; this.y = d; this.gameState = c; this.children = []; this.childCount = 0; this.leftDustTimer = randFloatRange(0, 0.25); this.rightDustTimer = randFloatRange(0, 0.25); this.offroadTimer = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 1; this.restitution = 1; this.immovable = false; this.contactLessCollision = false; this.chaseTarget = null; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 28); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 28); this.colliders.push(b); this.updateColliders(); this.cruiseSpeed = 200 + randIntRange(-50, 50); this.topSpeed = 300; this.trafficSpeed = this.cruiseSpeed; this.defaultDrag = 0.25; this.turnSpeed = 0.975; this.carAngle = Math.PI * 1.5; this.wheelAngle = Math.PI * 1.5; this.stuckBehindCar = false; this.changingLanes = false; this.laneChangeCorrectionTimer = 1; this.desiredLaneX = 0; this.randomLaneChangeChance = 0.001; this.offroad = false; this.parkTargetX = 0; this.parkTargetY = 0; this.parkAngle = 0; this.oldVelocityX = 0; this.oldVelocityY = 0; this.velocityX = 0; this.velocityY = -1; this.accelerationX = 0; this.accelerationY = 0; this.dragX = this.defaultDrag; this.dragY = this.defaultDrag; this.angularAcceleration = 0; this.angularVelocity = 0; this.angularDrag = 1; this.oldAngularVelocity = 0; this.skidmarkBuffer; this.skidStartX; this.skidStartY; this.smokeTime = 0.25; this.smokeTimer = this.smokeTime; this.body = new Drawable(); this.carColorIndex = randIntRange(0, content.carSprites.length); this.body.init(content.carSprites[this.carColorIndex], 0, 0); this.body.originX = this.body.sprite.width * 0.5; this.body.originY = this.body.sprite.height * 0.5; this.addChild(this.body); this.depth = -0.2 + randFloatRange(-0.01, 0.01); this.wasOffroad = false; this.dirtRoad = false }; Car.prototype.update = function(b) { if (!this.immovable) { if (isNaN(this.collisionVelocityAccumulatorX) || isNaN(this.collisionVelocityAccumulatorY)) { this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0 } this.velocityX += this.collisionVelocityAccumulatorX; this.velocityY += this.collisionVelocityAccumulatorY; if (this.currentState != CarState.BROKENDOWN) { if (this.collisionVelocityAccumulatorX != 0 || this.collisionVelocityAccumulatorY != 0) { var c = Math.atan2(this.collisionVelocityAccumulatorY, this.collisionVelocityAccumulatorX) + Math.PI; while (Math.abs(c - this.wheelAngle) > Math.PI) { if (c > this.wheelAngle) { c -= Math.PI * 2 } else { c += Math.PI * 2 } } if (this.colliders[0].colliding) { this.wheelAngle -= (c - this.wheelAngle) * 0.5 } else { this.wheelAngle += (c - this.wheelAngle) * 0.5 } } } this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.oldVelocityX = this.velocityX; this.oldVelocityY = this.velocityY; this.velocityX += this.accelerationX * b; this.velocityY += this.accelerationY * b; this.x += (this.oldVelocityX + this.velocityX) * 0.5 * b; this.y += (this.oldVelocityY + this.velocityY) * 0.5 * b; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, b) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, b) } if (this.angularDrag != 1) { this.angularVelocity *= Math.pow(this.angularDrag, b) } } this.accelerationX = 0; this.accelerationY = 0; this.angularAcceleration = 0; this.updateColliders(); this.updateSteering(b); for (var a = 0; a < this.childCount; a++) { this.children[a].angle = this.carAngle; this.children[a].update(b) } if (this.desiredState != this.currentState) { this.onExitState(this.currentState); this.currentState = this.desiredState; this.onEnterState(this.currentState) } this.tickState(this.currentState, b); this.updateDust(b); if (this.offroad) { if (!this.wasOffroad) { this.offroadTimer = 0 } this.offroadTimer += b; if (this.offroadTimer >= 3) { this.spinOut() } } this.wasOffroad = this.offroad }; Car.prototype.draw = function(b) { if (!this.visible) { return } for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } }; Car.prototype.setDesiredState = function(a) { if (this.desiredState == a) { return } this.desiredState = a }; Car.prototype.onEnterState = function(a) { switch (a) { case CarState.NULL: break; case CarState.IDLE: break; case CarState.PARKED: this.dragX = 0.1; this.dragY = 0.1; break; case CarState.PULLINGOVER: break; case CarState.CRUSING: break; case CarState.CHASING: break; case CarState.EVADING: break; case CarState.BROKENDOWN: while (this.carAngle > Math.PI * 2) { this.carAngle -= Math.PI * 2 } while (this.carAngle < 0) { this.carAngle += Math.PI * 2 } while (this.wheelAngle > Math.PI * 2) { this.wheelAngle -= Math.PI * 2 } while (this.wheelAngle < 0) { this.wheelAngle += Math.PI * 2 } break; case CarState.SPINNING: this.dragX = 0.5; this.dragY = 0.5; this.skidStartX = this.x; this.skidStartY = this.y; this.skidmarkBuffer = new Drawable(); this.skidmarkBuffer.init(null, 0, 0); this.skidmarkBuffer.sprite = document.createElement("canvas"); this.skidmarkBuffer.sprite.width = canvas.width; this.skidmarkBuffer.sprite.height = 720; this.skidmarkBuffer.originX = this.skidmarkBuffer.sprite.width * 0.5; this.skidmarkBuffer.originY = 720; this.skidmarkBuffer.depth = 0.099; this.skidmarkBuffer.parent = this; this.sceneManager.addEntity(this.skidmarkBuffer); break } }; Car.prototype.onExitState = function(a) { switch (a) { case CarState.NULL: break; case CarState.IDLE: break; case CarState.PARKED: this.dragX = this.defaultDrag; this.dragY = this.defaultDrag; break; case CarState.PULLINGOVER: break; case CarState.CRUSING: break; case CarState.CHASING: break; case CarState.EVADING: break; case CarState.BROKENDOWN: break; case CarState.SPINNING: break } }; Car.prototype.tickState = function(e, n) { switch (e) { case CarState.NULL: break; case CarState.IDLE: break; case CarState.PARKED: break; case CarState.PULLINGOVER: var d = (this.parkTargetX - this.x); var c = (this.parkTargetY - this.y); var y = Math.sqrt(d * d + c * c); var f = Math.abs(this.carAngle - this.parkAngle); if (f > Math.PI) { if (this.carAngle < this.parkAngle) { this.carAngle += Math.PI * 2 } else { this.carAngle -= Math.PI * 2 } f = Math.abs(this.carAngle - this.parkAngle) } if (y < 80 && f < Math.PI * 0.25) { this.setDesiredState(CarState.PARKED) } else { var m = this.parkTargetX - Math.cos(this.parkAngle) * 128; var l = this.parkTargetY - Math.sin(this.parkAngle) * 128; d = (m - this.x); c = (l - this.y); y = Math.sqrt(d * d + c * c); if (y < 80) { this.wheelAngle = this.parkAngle; this.accelerationX += Math.cos(this.wheelAngle) * this.cruiseSpeed * 0.1; this.accelerationY += Math.sin(this.wheelAngle) * this.cruiseSpeed * 0.1 } else { this.wheelAngle = Math.atan2(c, d); this.accelerationX += Math.cos(this.wheelAngle) * this.cruiseSpeed; this.accelerationY += Math.sin(this.wheelAngle) * this.cruiseSpeed } } break; case CarState.CRUSING: var q = this.cruiseSpeed; if (this.stuckBehindCar) { q = this.trafficSpeed } this.wheelAngle = (Math.PI * 1.5) + (this.wheelAngle - (Math.PI * 1.5)) * 0.95; this.accelerationX += Math.cos(this.wheelAngle) * q; this.accelerationY += Math.sin(this.wheelAngle) * q; if (this.changingLanes) { var t = Math.abs(this.x - this.desiredLaneX); if (t < 16) { this.wheelAngle = Math.PI * 1.5; this.laneChangeCorrectionTimer -= n; if (this.laneChangeCorrectionTimer <= 0) { this.changingLanes = false; this.laneChangeCorrectionTimer = 1 } } else { if (this.desiredLaneX > this.x) { this.wheelAngle = Math.PI * 1.65 } else { this.wheelAngle = Math.PI * 1.35 } } } else { if (this.obstructionAhead() || (randFloatRange(0, 1) < this.randomLaneChangeChance && this.isAdjacentLaneOpen())) { this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } } this.stuckBehindCar = false; if (!this.changingLanes) { for (var p = 0; p < this.gameState.cars.length; p++) { if (this.gameState.cars[p] === this) { continue } var g = Math.abs(this.gameState.cars[p].y - this.y); if (g >= 160 || this.gameState.cars[p].y >= this.y) { continue } if (Math.abs(this.gameState.cars[p].x - this.x) < 80 && Math.abs(this.gameState.cars[p].velocityY) < Math.abs(this.velocityY)) { var z = this.isAdjacentLaneOpen(); if (z) { this.stuckBehindCar = false; this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } else { this.stuckBehindCar = true; this.trafficSpeed = this.gameState.cars[p].trafficSpeed } } } } break; case CarState.CHASING: break; case CarState.EVADING: this.accelerationX += Math.cos(this.wheelAngle) * this.topSpeed; this.accelerationY += Math.sin(this.wheelAngle) * this.topSpeed; break; case CarState.BROKENDOWN: this.smokeTimer -= n; if (this.smokeTimer <= 0) { this.smokeTimer = this.smokeTime; var x = new Particle(); x.init(content.smoke, randFloatRange(0.25, 0.75) * 6); x.x = this.x + Math.cos(this.carAngle) * 30; x.y = this.y + Math.sin(this.carAngle) * 30; x.originX = x.sprite.width * 0.5; x.originY = x.sprite.height * 0.5; var k = randFloatRange(0.75, 1) * 2; x.startScaleX = 0; x.startScaleY = 0; x.endScaleX = k; x.endScaleY = k; x.startAlpha = 0.65; x.endAlpha = 0; x.depth = this.depth - 0.01; x.dragX = 1; x.dragY = 1; var h = randFloatRange(0, 0.25); var o = randFloatRange(0, Math.PI * 2); x.velocityX = Math.cos(o) * h; x.velocityY = Math.sin(o) * h; x.start(); this.sceneManager.addEntity(x) } break; case CarState.SPINNING: this.skidmarkBuffer.x = -this.x; this.skidmarkBuffer.originX = this.skidmarkBuffer.sprite.width * 0.5; this.skidmarkBuffer.originY = 720 + (this.y - this.skidStartY); var j = Math.sqrt(this.velocityX * this.velocityX + this.velocityY * this.velocityY); if (j < 1) { this.setDesiredState(CarState.BROKENDOWN); break } var b = this.skidmarkBuffer.sprite.getContext("2d"); var w = this.skidmarkBuffer.sprite.width * 0.5; var u = 720; w += this.x; u += (this.y - this.skidStartY); var a = content.skid; if (this.dirtRoad) { a = content.dirtSkid } for (var p = 0; p < 4; p++) { b.drawImage(a, w + Math.cos(this.carAngle + Math.PI * 0.25 + p * Math.PI * 0.5) * 28, u + Math.sin(this.carAngle + Math.PI * 0.25 + p * Math.PI * 0.5) * 28) } break } }; Car.prototype.updateDust = function(d) { this.offroad = false; if (this.currentState == CarState.SPINNING || this.currentState == CarState.BROKENDOWN) { return } if (this.x < -160 || this.x > (160 + 32) || this.dirtRoad) { if (this.x < -160 || this.x > (160 + 32)) { this.offroad = true } this.leftDustTimer -= d; if (this.leftDustTimer <= 0) { this.leftDustTimer = 0.25 + randFloatRange(-0.05, 0.05); var c = new Particle(); c.init(content.dust, randFloatRange(0.25, 0.75) * 2); c.x = this.x + Math.cos(this.carAngle + (-Math.PI + 0.4)) * 48; c.y = this.y + Math.sin(this.carAngle + (-Math.PI + 0.4)) * 48; c.originX = c.sprite.width * 0.5; c.originY = c.sprite.height * 0.5; var b = randFloatRange(0.75, 1) * 2; c.startScaleX = 0.5; c.startScaleY = 0.5; c.endScaleX = b; c.endScaleY = b; c.startAlpha = 1; c.endAlpha = 0; c.depth = this.depth + 0.01; c.dragX = 0.5 + randFloatRange(-0.25, 0.25); c.dragY = c.dragX; var a = 0; c.velocityX = Math.cos(this.carAngle) * a; c.velocityY = Math.sin(this.carAngle) * a; c.start(); this.sceneManager.addEntity(c) } } if (this.x < -(160 + 32) || this.x > (160) || this.dirtRoad) { if (this.x < -(160 + 32) || this.x > (160)) { this.offroad = true } this.rightDustTimer -= d; if (this.rightDustTimer <= 0) { this.rightDustTimer = 0.25 + randFloatRange(-0.05, 0.05); var c = new Particle(); c.init(content.dust, randFloatRange(0.25, 0.75) * 2); c.x = this.x + Math.cos(this.carAngle + (Math.PI - 0.4)) * 48; c.y = this.y + Math.sin(this.carAngle + (Math.PI - 0.4)) * 48; c.originX = c.sprite.width * 0.5; c.originY = c.sprite.height * 0.5; var b = randFloatRange(0.75, 1) * 2; c.startScaleX = 0.5; c.startScaleY = 0.5; c.endScaleX = b; c.endScaleY = b; c.startAlpha = 1; c.endAlpha = 0; c.depth = this.depth + 0.01; c.dragX = 0.5 + randFloatRange(-0.25, 0.25); c.dragY = c.dragX; var a = 0; c.velocityX = Math.cos(this.carAngle) * a; c.velocityY = Math.sin(this.carAngle) * a; c.start(); this.sceneManager.addEntity(c) } } }; Car.prototype.updateSteering = function(b) { if (this.currentState == CarState.BROKENDOWN) { return } this.carAngle = this.wheelAngle + (this.carAngle - this.wheelAngle) * (this.turnSpeed); if (this.currentState == CarState.SPINNING) { this.wheelAngle += 0.01 * Math.sqrt(this.velocityX * this.velocityX + this.velocityY * this.velocityY) * b; return } while (this.wheelAngle > Math.PI * 2) { this.wheelAngle -= Math.PI * 2 } while (this.wheelAngle < 0) { this.wheelAngle += Math.PI * 2 } if (this.dirtRoad) { var a = randFloatRange(-2, 2); this.wheelAngle += a; this.accelerationY += Math.sin(this.wheelAngle) * this.speed } }; Car.prototype.updateColliders = function() { if (!this.colliders) { return } var b = Math.cos(this.carAngle); var c = Math.sin(this.carAngle); this.colliders[0].x = this.x + b * 14; this.colliders[0].y = this.y + c * 14; this.colliders[1].x = this.x - b * 14; this.colliders[1].y = this.y - c * 14; for (var a = 0; a < this.colliders.length; a++) { this.colliders[a].colliding = false } }; Car.prototype.checkCollision = function(f) { if (!this.colliders || !f.colliders) { return } for (var e = 0; e < this.colliders.length; e++) { for (var d = 0; d < f.colliders.length; d++) { var c = Collision.getCollision(this.colliders[e], f.colliders[d]); if (this.colliders[e].colliding && !this.colliders[e].lastCollisionObject) { this.colliders[e].lastCollisionObject = f } if (f.colliders[d].colliding && !f.colliders[d].lastCollisionObject) { f.colliders[d].lastCollisionObject = this } if (c) { this.onCollision(c, f); c.directionX *= -1; c.directionY *= -1; f.onCollision(c, this) } } } }; Car.prototype.onCollision = function(p, h) { if (!this.collisionEnabled || this.immovable) { return } if (!this.colliders) { this.collisionEnabled = false; return } if (Wall.prototype.isPrototypeOf(h)) { this.crash() } else { if (!CopCar.prototype.isPrototypeOf(this) && PlayerCar.prototype.isPrototypeOf(h)) { for (var l = 0; l < this.gameState.cars.length; l++) { var o = this.gameState.cars[l]; if (o === this || !CopCar.prototype.isPrototypeOf(o) || o.lightActive) { continue } var a = Math.sqrt((o.x - this.x) * (o.x - this.x) + (o.y - this.y) * (o.y - this.y)); if (a < 256) { o.chaseTarget = this; o.setDesiredState(CarState.CHASING) } } } } this.x += p.directionX * p.magnitude; this.y += p.directionY * p.magnitude; if (this.mass == 0) { return } var f = this.velocityX - h.velocityX; var d = this.velocityY - h.velocityY; var n = (f * p.directionX) + (d * p.directionY); var b = Math.min(this.restitution, h.restitution); var k = -(1 + b) * n; if (h.mass == 0) { k /= (1 / this.mass) } else { k /= (1 / this.mass) + (1 / h.mass) } var e = k * p.directionX; var c = k * p.directionY; var g = 1 / this.mass; this.collisionVelocityAccumulatorX += g * e; this.collisionVelocityAccumulatorY += g * c; this.updateColliders(); if (PlayerCar.prototype.isPrototypeOf(this)) { if (this.gameState.playState == PlayState.GAME) { this.incrementHit() } if (!soundMuted) { var m = "hitCrash01"; switch (randIntRange(0, 3)) { case 0: m = "hitCrash01"; break; case 1: m = "hitCrash02"; break; case 2: m = "hitCrash03"; break } playSound(m) } } }; Car.prototype.isAdjacentLaneOpen = function() { for (var f = 0; f < this.gameState.cars.length; f++) { if (this.gameState.cars[f] === this) { continue } var d = this.gameState.cars[f]; var e = Math.abs(d.y - this.y); if (e >= 128) { continue } if ((this.x < 0 && d.x > 0 && d.x < 160) || (this.x > 0 && d.x < 0 && d.x > -160)) { return false; break } } for (var b = 0; b < this.gameState.walls.length; b++) { if (this.gameState.walls[b] === this) { continue } var a = this.gameState.walls[b]; var e = Math.abs(a.y - this.y); if (e >= 128) { continue } if ((this.x < 0 && a.x > 0 && a.x < 160) || (this.x > 0 && a.x < 0 && a.x > -160)) { return false; break } } return true }; Car.prototype.obstructionAhead = function() { for (var b = 0; b < this.gameState.walls.length; b++) { var a = this.gameState.walls[b]; var c = (a.y - this.y); if (c >= 1024) { continue } if ((this.x < 0 && a.x < 0) || (this.x > 0 && a.x > 0)) { return true } } for (var d = 0; d < this.gameState.roadBlocks.length; d++) { var e = this.gameState.roadBlocks[d]; var c = (e.y - this.y); if (c >= 512) { continue } if ((this.x < 0 && e.x < 0) || (this.x > 0 && e.x > 0)) { return true } } return false }; Car.prototype.spinOut = function() { if ((this.currentState == CarState.SPINNING || this.desiredState == CarState.SPINNING) || (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN)) { return } this.setDesiredState(CarState.SPINNING); this.depth = -0.19 + randFloatRange(-0.01, 0.01); if (!soundMuted && PlayerCar.prototype.isPrototypeOf(this)) { var a = "skid"; playSound(a) } }; Car.prototype.crash = function() { if (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN) { return } this.body.sprite = content.crashSprites[this.carColorIndex]; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.01; this.setDesiredState(CarState.BROKENDOWN); if (!soundMuted) { var a = "impactCrash"; playSound(a) } }; Car.prototype.explode = function() { if (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN) { return } this.body.sprite = content.explodeSprites[this.carColorIndex]; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.001; this.setDesiredState(CarState.BROKENDOWN) }; Car.prototype.flagForRemoval = function() { this.toBeRemoved = true; if (this.skidmarkBuffer) { this.skidmarkBuffer.flagForRemoval() } if (this.dirtLoopInstance) { this.dirtLoopInstance.stop(); this.dirtLoopInstance = null } }; function Truck() { Car.call(this) } Truck.prototype = new Car(); Truck.prototype.constructor = Truck; Truck.prototype.init = function(a, d, c) { this.x = a; this.y = d; this.gameState = c; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.lightActive = true; this.lightSine = randFloatRange(0, Math.PI * 2); this.rammingTimer = 0; this.rammingDirection = 0; this.collider = null; this.collisionEnabled = true; this.mass = 4; this.restitution = 1; this.immovable = false; this.contactLessCollision = false; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 34); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 34); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 34); this.colliders.push(b); this.updateColliders(); this.cruiseSpeed = 200; this.topSpeed = 275; this.trafficSpeed = this.cruiseSpeed; this.defaultDrag = 0.25; this.turnSpeed = 0.995; this.carAngle = Math.PI * 1.5; this.wheelAngle = Math.PI * 1.5; this.stuckBehindCar = false; this.changingLanes = false; this.laneChangeCorrectionTimer = 1; this.desiredLaneX = 0; this.randomLaneChangeChance = 0.001; this.parkTargetX = 0; this.parkTargetY = 0; this.parkAngle = 0; this.oldVelocityX = 0; this.oldVelocityY = 0; this.velocityX = 0; this.velocityY = -1; this.accelerationX = 0; this.accelerationY = 0; this.dragX = this.defaultDrag; this.dragY = this.defaultDrag; this.angularAcceleration = 0; this.angularVelocity = 0; this.angularDrag = 1; this.oldAngularVelocity = 0; this.speed = 250; this.body = new Drawable(); this.body.init(content.truck, 0, 0); this.body.originX = 128; this.body.originY = this.body.sprite.height * 0.5; this.addChild(this.body); this.depth = -0.2 + randFloatRange(-0.01, 0.01); this.crateDroppingActive = false; this.explodingCrates = false; this.crateTimer = 0; this.crateRate = 2.5; this.crateChance = 0.5 }; Truck.prototype.updateColliders = function() { if (!this.colliders) { return } var a = Math.cos(this.carAngle); var b = Math.sin(this.carAngle); this.colliders[0].x = this.x + a * (44 - 42); this.colliders[0].y = this.y + b * (44 - 42); this.colliders[1].x = this.x + a * (-44 - 42); this.colliders[1].y = this.y + b * (-44 - 42); this.colliders[2].x = this.x + a * (0 - 42); this.colliders[2].y = this.y + b * (0 - 42) }; Truck.prototype.tickState = function(f, p) { switch (f) { case CarState.NULL: break; case CarState.IDLE: break; case CarState.PARKED: break; case CarState.PULLINGOVER: var e = (this.parkTargetX - this.x); var d = (this.parkTargetY - this.y); var z = Math.sqrt(e * e + d * d); var g = Math.abs(this.carAngle - this.parkAngle); if (g > Math.PI) { if (this.carAngle < this.parkAngle) { this.carAngle += Math.PI * 2 } else { this.carAngle -= Math.PI * 2 } g = Math.abs(this.carAngle - this.parkAngle) } if (z < 80 && g < Math.PI * 0.25) { this.setDesiredState(CarState.PARKED) } else { var o = this.parkTargetX - Math.cos(this.parkAngle) * 128; var m = this.parkTargetY - Math.sin(this.parkAngle) * 128; e = (o - this.x); d = (m - this.y); z = Math.sqrt(e * e + d * d); if (z < 80) { this.wheelAngle = this.parkAngle; this.accelerationX += Math.cos(this.wheelAngle) * this.cruiseSpeed * 0.1; this.accelerationY += Math.sin(this.wheelAngle) * this.cruiseSpeed * 0.1 } else { this.wheelAngle = Math.atan2(d, e); this.accelerationX += Math.cos(this.wheelAngle) * this.cruiseSpeed; this.accelerationY += Math.sin(this.wheelAngle) * this.cruiseSpeed } } break; case CarState.CRUSING: if (this.crateDroppingActive) { this.crateTimer -= p; while (this.crateTimer <= 0) { this.crateTimer = this.crateRate; if (randFloatRange(0, 1) < this.crateChance) { var b = new Crate(); b.init(this.x - Math.cos(this.carAngle) * 64, this.y - Math.sin(this.carAngle) * 64, randFloatRange(0, Math.PI * 2), this.gameState); b.spawner = this; b.doSpawnAnimation(); if (this.explodingCrates && randFloatRange(0, 1) < 0.5) { b.setExplosive(true) } this.sceneManager.addEntity(b); this.gameState.crates.push(b); b.accelerationX = this.velocityX * 70; b.accelerationY = this.velocityY * 70; b.angularAcceleration += randFloatRange(-1, 1) * 200 } } } var t = this.cruiseSpeed; if (this.stuckBehindCar) { t = this.trafficSpeed } this.wheelAngle = (Math.PI * 1.5) + (this.wheelAngle - (Math.PI * 1.5)) * 0.95; this.accelerationX += Math.cos(this.wheelAngle) * t; this.accelerationY += Math.sin(this.wheelAngle) * t; if (this.changingLanes) { var u = Math.abs(this.x - this.desiredLaneX); if (u < 16) { this.wheelAngle = Math.PI * 1.5; this.laneChangeCorrectionTimer -= p; if (this.laneChangeCorrectionTimer <= 0) { this.changingLanes = false; this.laneChangeCorrectionTimer = 1 } } else { if (this.desiredLaneX > this.x) { this.wheelAngle = Math.PI * 1.65 } else { this.wheelAngle = Math.PI * 1.35 } } } else { if (this.obstructionAhead() || (randFloatRange(0, 1) < this.randomLaneChangeChance && this.isAdjacentLaneOpen())) { this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } } this.stuckBehindCar = false; if (!this.changingLanes) { for (var q = 0; q < this.gameState.cars.length; q++) { if (this.gameState.cars[q] === this) { continue } var h = Math.abs(this.gameState.cars[q].y - this.y); if (h >= 160 || this.gameState.cars[q].y >= this.y) { continue } if (Math.abs(this.gameState.cars[q].x - this.x) < 80 && Math.abs(this.gameState.cars[q].velocityY) < Math.abs(this.velocityY)) { var A = this.isAdjacentLaneOpen(); if (A) { this.stuckBehindCar = false; this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } else { this.stuckBehindCar = true; this.trafficSpeed = this.gameState.cars[q].trafficSpeed } } } } break; case CarState.CHASING: break; case CarState.EVADING: this.accelerationX += Math.cos(this.wheelAngle) * this.topSpeed; this.accelerationY += Math.sin(this.wheelAngle) * this.topSpeed; break; case CarState.BROKENDOWN: this.smokeTimer -= p; if (this.smokeTimer <= 0) { this.smokeTimer = this.smokeTime; var y = new Particle(); y.init(content.smoke, randFloatRange(0.25, 0.75) * 6); y.x = this.x + Math.cos(this.carAngle) * 30; y.y = this.y + Math.sin(this.carAngle) * 30; y.originX = y.sprite.width * 0.5; y.originY = y.sprite.height * 0.5; var l = randFloatRange(0.75, 1) * 2; y.startScaleX = 0; y.startScaleY = 0; y.endScaleX = l; y.endScaleY = l; y.startAlpha = 0.65; y.endAlpha = 0; y.depth = this.depth - 0.01; y.dragX = 1; y.dragY = 1; var j = randFloatRange(0, 0.25); var n = randFloatRange(0, Math.PI * 2); y.velocityX = Math.cos(n) * j; y.velocityY = Math.sin(n) * j; y.start(); this.sceneManager.addEntity(y) } break; case CarState.SPINNING: this.skidmarkBuffer.x = -this.x; this.skidmarkBuffer.originX = this.skidmarkBuffer.sprite.width * 0.5; this.skidmarkBuffer.originY = 360 + (this.y - this.skidStartY); var k = Math.sqrt(this.velocityX * this.velocityX + this.velocityY * this.velocityY); if (k < 1) { this.setDesiredState(CarState.BROKENDOWN); break } var c = this.skidmarkBuffer.sprite.getContext("2d"); var x = this.skidmarkBuffer.sprite.width * 0.5; var w = 360; x += this.x; w += (this.y - this.skidStartY); x += Math.cos(this.carAngle) * -42; w += Math.sin(this.carAngle) * -42; var a = content.skid; if (this.dirtRoad) { a = content.dirtSkid } for (var q = 0; q < 4; q++) { c.drawImage(a, x + Math.cos(this.carAngle + Math.PI * 0.25 + q * Math.PI * 0.5) * 56, w + Math.sin(this.carAngle + Math.PI * 0.25 + q * Math.PI * 0.5) * 56) } break } }; Truck.prototype.updateDust = function(d) { this.offroad = false; if (this.currentState === CarState.SPINNING || this.currentState === CarState.BROKENDOWN) { return } if (this.x < -160 || this.x > (160 + 32)) { this.offroad = true; this.leftDustTimer -= d; if (this.leftDustTimer <= 0) { this.leftDustTimer = 0.25; var c = new Particle(); c.init(content.dust, randFloatRange(0.25, 0.75) * 2); c.x = this.x + Math.cos(this.carAngle + (-Math.PI + 0.4)) * 48; c.y = this.y + Math.sin(this.carAngle + (-Math.PI + 0.4)) * 48; c.originX = c.sprite.width * 0.5; c.originY = c.sprite.height * 0.5; var b = randFloatRange(0.75, 1) * 2; c.startScaleX = 0.5; c.startScaleY = 0.5; c.endScaleX = b; c.endScaleY = b; c.startAlpha = 1; c.endAlpha = 0; c.depth = this.depth + 0.01; c.dragX = 0.5 + randFloatRange(-0.25, 0.25); c.dragY = c.dragX; var a = 0; c.velocityX = Math.cos(this.carAngle) * a; c.velocityY = Math.sin(this.carAngle) * a; c.start(); this.sceneManager.addEntity(c) } } if (this.x < -(160 + 32) || this.x > (160)) { this.offroad = true; this.rightDustTimer -= d; if (this.rightDustTimer <= 0) { this.rightDustTimer = 0.25; var c = new Particle(); c.init(content.dust, randFloatRange(0.25, 0.75) * 2); c.x = this.x + Math.cos(this.carAngle + (Math.PI - 0.4)) * 48; c.y = this.y + Math.sin(this.carAngle + (Math.PI - 0.4)) * 48; c.originX = c.sprite.width * 0.5; c.originY = c.sprite.height * 0.5; var b = randFloatRange(0.75, 1) * 2; c.startScaleX = 0.5; c.startScaleY = 0.5; c.endScaleX = b; c.endScaleY = b; c.startAlpha = 1; c.endAlpha = 0; c.depth = this.depth + 0.01; c.dragX = 0.5 + randFloatRange(-0.25, 0.25); c.dragY = c.dragX; var a = 0; c.velocityX = Math.cos(this.carAngle) * a; c.velocityY = Math.sin(this.carAngle) * a; c.start(); this.sceneManager.addEntity(c) } } }; Truck.prototype.crash = function() { if (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN) { return } this.body.sprite = content.truckCrash; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.001; this.setDesiredState(CarState.BROKENDOWN) }; Truck.prototype.explode = function() { if (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN) { return } this.body.sprite = content.truckExploded; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.001; this.setDesiredState(CarState.BROKENDOWN) }; function PlayerCar() { Car.call(this) } PlayerCar.prototype = new Car(); PlayerCar.prototype.constructor = PlayerCar; PlayerCar.prototype.init = function(a, d, c) { this.x = a; this.y = d; this.gameState = c; this.children = []; this.childCount = 0; this.leftDustTimer = 0; this.rightDustTimer = 0; this.offroadTimer = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 1; this.restitution = 1; this.immovable = false; this.contactLessCollision = false; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 28); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 28); this.colliders.push(b); this.updateColliders(); this.oldVelocityX = 0; this.oldVelocityY = 0; this.velocityX = 0; this.velocityY = 0; this.accelerationX = 0; this.accelerationY = 0; this.dragX = 0.25; this.dragY = 0.25; this.angularAcceleration = 0; this.angularVelocity = 0; this.angularDrag = 1; this.oldAngularVelocity = 0; this.carAngle = Math.PI * 1.5; this.wheelAngle = Math.PI * 1.5; this.speed = 450; this.turnSpeed = 0.01; this.trafficSpeed = this.speed; this.smokeTime = 0.25; this.smokeTimer = this.smokeTime; this.reversing = false; this.body = new Drawable(); this.carColorIndex = randIntRange(0, content.carSprites.length); this.body.init(content.carSprites[this.carColorIndex], 0, 0); this.body.originX = this.body.sprite.width * 0.5; this.body.originY = this.body.sprite.height * 0.5; this.addChild(this.body); this.wasOffroad = false; this.dirtRoad = false; this.depth = -0.2 + randFloatRange(-0.01, 0.01); this.hitCount = 0; this.dirtLoopInstance }; PlayerCar.prototype.update = function(b) { if (!this.immovable) { if (isNaN(this.collisionVelocityAccumulatorX) || isNaN(this.collisionVelocityAccumulatorY)) { this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0 } this.velocityX += this.collisionVelocityAccumulatorX; this.velocityY += this.collisionVelocityAccumulatorY; if (this.collisionVelocityAccumulatorX != 0 || this.collisionVelocityAccumulatorY != 0) { var c = Math.atan2(this.collisionVelocityAccumulatorY, this.collisionVelocityAccumulatorX) + Math.PI; while (Math.abs(c - this.wheelAngle) > Math.PI) { if (c > this.wheelAngle) { c -= Math.PI * 2 } else { c += Math.PI * 2 } } if (this.colliders[0].colliding) { this.wheelAngle -= (c - this.wheelAngle) * 0.5 } else { this.wheelAngle += (c - this.wheelAngle) * 0.5 } } this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.oldVelocityX = this.velocityX; this.oldVelocityY = this.velocityY; this.velocityX += this.accelerationX * b; this.velocityY += this.accelerationY * b; this.x += (this.oldVelocityX + this.velocityX) * 0.5 * b; this.y += (this.oldVelocityY + this.velocityY) * 0.5 * b; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, b) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, b) } } this.accelerationX = 0; this.accelerationY = 0; this.angularAcceleration = 0; for (var a = 0; a < this.colliders.length; a++) { if (this.colliders[a].colliding) { if (Wrench.prototype.isPrototypeOf(this.colliders[a].lastCollisionObject)) { if (this.colliders[a].lastCollisionObject.wrenchActive) { this.decrementHit(); this.colliders[a].lastCollisionObject.onPickup(); this.colliders[a].colliding = false; this.colliders[a].lastCollisionObject = null } } else { this.colliders[a].lastCollisionObject = null } } } this.updateColliders(); this.updateSteering(b); for (var a = 0; a < this.childCount; a++) { this.children[a].angle = this.carAngle; this.children[a].update(b) } if (this.desiredState != this.currentState) { this.onExitState(this.currentState); this.currentState = this.desiredState; this.onEnterState(this.currentState) } this.tickState(this.currentState, b); this.updateDust(b); if (this.offroad) { if (!this.wasOffroad) { this.gameState.hud.offroad.timer = 0; if (this.dirtLoopInstance) { this.dirtLoopInstance.stop(); this.dirtLoopInstance = null } if (!soundMuted) { this.dirtLoopInstance = createjs.Sound.play("dirtRoadRumble") } } this.gameState.hud.offroad.baseTime = 3; this.gameState.hud.offroad.timer += b; if (this.gameState.hud.offroad.timerProgress >= 1) { this.spinOut(); this.gameState.endGame(FailType.SPIN) } } else { if (!this.dirtRoad) { if (this.dirtLoopInstance) { this.dirtLoopInstance.stop(); this.dirtLoopInstance = null } } } this.wasOffroad = this.offroad }; PlayerCar.prototype.handleDirtLoop = function(a) {}; PlayerCar.prototype.updateSteering = function(c) { if (!this.gameState) { return } if (this.currentState === CarState.BROKENDOWN) { return } this.carAngle = this.wheelAngle + (this.carAngle - this.wheelAngle) * 0.915; if (this.currentState === CarState.SPINNING) { this.wheelAngle += 0.01 * Math.sqrt(this.velocityX * this.velocityX + this.velocityY * this.velocityY) * c; return } var a = this.gameState.steeringUI.value; this.wheelAngle = (a * Math.PI * 0.45) + Math.PI * 1.5; while (this.wheelAngle > Math.PI * 2) { this.wheelAngle -= Math.PI * 2 } while (this.wheelAngle < 0) { this.wheelAngle += Math.PI * 2 } if (this.dirtRoad) { var b = randFloatRange(-2, 2); this.wheelAngle += b; this.accelerationY += Math.sin(this.wheelAngle) * this.speed } this.accelerationX += Math.cos(this.wheelAngle) * this.speed; this.accelerationY += Math.sin(this.wheelAngle) * this.speed }; PlayerCar.prototype.crash = function() { if (this.currentState === CarState.BROKENDOWN || this.desiredState === CarState.BROKENDOWN) { return } this.body.sprite = content.crashSprites[this.carColorIndex]; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.setDesiredState(CarState.BROKENDOWN); this.gameState.crashFlash(); this.gameState.endGame(FailType.CRASH) }; PlayerCar.prototype.incrementHit = function() { if (this.hitCount >= 3) { return } this.hitCount++; this.gameState.hud.setHitCount(this.hitCount); if (this.hitCount >= 3) { this.breakDown(); if (!soundMuted) { var a = "impactCrash"; playSound(a) } } }; PlayerCar.prototype.breakDown = function() { if ((this.currentState == CarState.SPINNING || this.desiredState == CarState.SPINNING) || (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN)) { return } this.body.sprite = content.crashSprites[this.carColorIndex]; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.001; this.setDesiredState(CarState.BROKENDOWN); this.gameState.crashFlash(); this.gameState.endGame(FailType.BROKEDOWN) }; PlayerCar.prototype.decrementHit = function() { if (this.hitCount <= 0 || this.currentState == CarState.SPINNING || this.currentState == CarState.BROKENDOWN) { return } this.hitCount--; this.gameState.hud.setHitCount(this.hitCount) }; function CopCar() { Car.call(this); this.leftLight; this.rightLight; this.lightActive } CopCar.prototype = new Car(); CopCar.prototype.constructor = CopCar; CopCar.prototype.init = function(a, d, c) { this.x = a; this.y = d; this.gameState = c; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.lightActive = false; this.lightSine = randFloatRange(0, Math.PI * 2); this.rammingTimer = 0; this.rammingDirection = 0; this.collider = null; this.collisionEnabled = true; this.mass = 1; this.restitution = 1; this.immovable = false; this.contactLessCollision = false; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 23); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 23); this.colliders.push(b); this.updateColliders(); this.cruiseSpeed = 300; this.topSpeed = 375; this.trafficSpeed = this.cruiseSpeed; this.defaultDrag = 0.25; this.turnSpeed = 0.975; this.carAngle = Math.PI * 1.5; this.wheelAngle = Math.PI * 1.5; this.stuckBehindCar = false; this.changingLanes = false; this.laneChangeCorrectionTimer = 1; this.desiredLaneX = 0; this.randomLaneChangeChance = 0.001; this.parkTargetX = 0; this.parkTargetY = 0; this.parkAngle = 0; this.oldVelocityX = 0; this.oldVelocityY = 0; this.velocityX = 0; this.velocityY = -1; this.accelerationX = 0; this.accelerationY = 0; this.dragX = this.defaultDrag; this.dragY = this.defaultDrag; this.angularAcceleration = 0; this.angularVelocity = 0; this.angularDrag = 1; this.oldAngularVelocity = 0; this.speed = 350; this.body = new Drawable(); this.body.init(content.copCar, 0, 0); this.body.originX = this.body.sprite.width * 0.5; this.body.originY = this.body.sprite.height * 0.5; this.addChild(this.body); this.leftLight = new Drawable(); this.leftLight.init(content.redCopLight, 0, 0); this.leftLight.originX = this.leftLight.sprite.width * 0.5; this.leftLight.originY = this.leftLight.sprite.height * 0.65; this.leftLight.visible = false; this.leftLight.alpha = 0; this.addChild(this.leftLight); this.rightLight = new Drawable(); this.rightLight.init(content.blueCopLight, 0, 0); this.rightLight.originX = this.rightLight.sprite.width * 0.5; this.rightLight.originY = this.rightLight.sprite.height * 0.35; this.rightLight.visible = false; this.rightLight.alpha = 0; this.addChild(this.rightLight); this.depth = -0.2 + randFloatRange(-0.01, 0.01); this.sirenLoopInstance }; CopCar.prototype.update = function(b) { if (!this.immovable) { this.velocityX += this.collisionVelocityAccumulatorX; this.velocityY += this.collisionVelocityAccumulatorY; if (this.currentState != CarState.BROKENDOWN) { if (this.collisionVelocityAccumulatorX != 0 || this.collisionVelocityAccumulatorY != 0) { var c = Math.atan2(this.collisionVelocityAccumulatorY, this.collisionVelocityAccumulatorX) + Math.PI; while (Math.abs(c - this.wheelAngle) > Math.PI) { if (c > this.wheelAngle) { c -= Math.PI * 2 } else { c += Math.PI * 2 } } if (this.colliders[0].colliding) { this.wheelAngle -= (c - this.wheelAngle) * 0.5 } else { this.wheelAngle += (c - this.wheelAngle) * 0.5 } } } this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.oldVelocityX = this.velocityX; this.oldVelocityY = this.velocityY; this.velocityX += this.accelerationX * b; this.velocityY += this.accelerationY * b; this.x += (this.oldVelocityX + this.velocityX) * 0.5 * b; this.y += (this.oldVelocityY + this.velocityY) * 0.5 * b; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, b) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, b) } if (this.angularDrag != 1) { this.angularVelocity *= Math.pow(this.angularDrag, b) } } this.accelerationX = 0; this.accelerationY = 0; this.angularAcceleration = 0; this.updateColliders(); this.updateSteering(b); if (this.lightActive) { this.leftLight.visible = true; this.rightLight.visible = true; this.leftLight.alpha = 0.35; this.rightLight.alpha = 0.35; this.lightSine += b * 2; while (this.lightSine > Math.PI * 2) { this.lightSine -= Math.PI * 2 } this.leftLight.scaleX = Math.abs(Math.sin(this.lightSine)); this.leftLight.scaleY = this.leftLight.scaleX; this.rightLight.scaleX = Math.abs(Math.cos(this.lightSine)); this.rightLight.scaleY = this.rightLight.scaleX; if (!soundMuted) { if (!this.sirenLoopInstance) { this.sirenLoopInstance = createjs.Sound.play("siren", { loop: -1 }) } else { this.sirenLoopInstance.setVolume(Math.min(1, Math.max(0, 1 - (Math.abs(this.y - -this.sceneManager.camera.positionY) / 640)))) } } } else { this.leftLight.visible = false; this.rightLight.visible = false; this.leftLight.alpha = 0; this.rightLight.alpha = 0; if (this.sirenLoopInstance) { this.sirenLoopInstance.stop(); this.sirenLoopInstance = null } } for (var a = 0; a < this.childCount; a++) { this.children[a].angle = this.carAngle; this.children[a].update(b) } if (this.desiredState != this.currentState) { this.onExitState(this.currentState); this.currentState = this.desiredState; this.onEnterState(this.currentState) } this.lightActive = false; this.tickState(this.currentState, b); this.updateDust(b) }; CopCar.prototype.handleSirenLoop = function(a) {}; CopCar.prototype.tickState = function(d, m) { switch (d) { case CarState.NULL: break; case CarState.IDLE: break; case CarState.PARKED: break; case CarState.PULLINGOVER: var c = (this.parkTargetX - this.x); var b = (this.parkTargetY - this.y); var x = Math.sqrt(c * c + b * b); var e = Math.abs(this.carAngle - this.parkAngle); if (e > Math.PI) { if (this.carAngle < this.parkAngle) { this.carAngle += Math.PI * 2 } else { this.carAngle -= Math.PI * 2 } e = Math.abs(this.carAngle - this.parkAngle) } if (x < 80 && e < Math.PI * 0.25) { this.setDesiredState(CarState.PARKED) } else { var l = this.parkTargetX - Math.cos(this.parkAngle) * 128; var k = this.parkTargetY - Math.sin(this.parkAngle) * 128; c = (l - this.x); b = (k - this.y); x = Math.sqrt(c * c + b * b); if (x < 80) { this.wheelAngle = this.parkAngle; this.accelerationX += Math.cos(this.wheelAngle) * this.cruiseSpeed * 0.1; this.accelerationY += Math.sin(this.wheelAngle) * this.cruiseSpeed * 0.1 } else { this.wheelAngle = Math.atan2(b, c); this.accelerationX += Math.cos(this.wheelAngle) * this.cruiseSpeed; this.accelerationY += Math.sin(this.wheelAngle) * this.cruiseSpeed } } break; case CarState.CRUSING: var p = this.cruiseSpeed; if (this.lightActive) { p = this.topSpeed } if (this.stuckBehindCar) { p = this.trafficSpeed } this.wheelAngle = (Math.PI * 1.5) + (this.wheelAngle - (Math.PI * 1.5)) * 0.95; this.accelerationX += Math.cos(this.wheelAngle) * p; this.accelerationY += Math.sin(this.wheelAngle) * p; if (this.changingLanes) { var q = Math.abs(this.x - this.desiredLaneX); if (q < 16) { this.wheelAngle = Math.PI * 1.5; this.laneChangeCorrectionTimer -= m; if (this.laneChangeCorrectionTimer <= 0) { this.changingLanes = false; this.laneChangeCorrectionTimer = 1 } } else { if (this.desiredLaneX > this.x) { this.wheelAngle = Math.PI * 1.65 } else { this.wheelAngle = Math.PI * 1.35 } } } else { if (this.obstructionAhead() || (randFloatRange(0, 1) < this.randomLaneChangeChance && this.isAdjacentLaneOpen())) { this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } } this.stuckBehindCar = false; if (!this.changingLanes) { for (var o = 0; o < this.gameState.cars.length; o++) { if (this.gameState.cars[o] === this) { continue } var f = Math.abs(this.gameState.cars[o].y - this.y); if (f >= 256 || this.gameState.cars[o].y >= this.y) { continue } if (Math.abs(this.gameState.cars[o].x - this.x) < 80 && Math.abs(this.gameState.cars[o].velocityY) < Math.abs(this.velocityY)) { var y = this.isAdjacentLaneOpen(); if (y) { this.stuckBehindCar = false; this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } else { this.stuckBehindCar = true; this.trafficSpeed = this.gameState.cars[o].trafficSpeed } } } } break; case CarState.CHASING: this.lightActive = true; if (!this.chaseTarget) { this.setDesiredState(CarState.CRUSING) } var p = this.topSpeed; this.wheelAngle = (Math.PI * 1.5) + (this.wheelAngle - (Math.PI * 1.5)) * 0.95; this.accelerationX += Math.cos(this.wheelAngle) * p; this.accelerationY += Math.sin(this.wheelAngle) * p; if (this.changingLanes) { var q = Math.abs(this.x - this.desiredLaneX); if (q < 16) { this.wheelAngle = Math.PI * 1.5; this.laneChangeCorrectionTimer -= m; if (this.laneChangeCorrectionTimer <= 0) { this.changingLanes = false; this.laneChangeCorrectionTimer = 1 } } else { if (this.desiredLaneX > this.x) { this.wheelAngle = Math.PI * 1.65 } else { this.wheelAngle = Math.PI * 1.35 } } } if (this.rammingTimer <= 0 && (this.chaseTarget.y >= this.y || (Math.abs(this.carAngle - (Math.PI * 1.5)) > 0.25 && this.chaseTarget.y - 64 >= this.y))) { this.rammingTimer = 1; if (this.chaseTarget.x > this.x) { this.rammingDirection = 1 } else { this.rammingDirection = -1 } } if (this.rammingTimer > 0) { this.rammingTimer -= m; if (this.rammingDirection > 0) { this.wheelAngle = Math.PI * 1.85 } else { this.wheelAngle = Math.PI * 1.15 } } this.stuckBehindCar = false; if (!this.changingLanes) { for (var o = 0; o < this.gameState.cars.length; o++) { if (this.gameState.cars[o] === this) { continue } var f = Math.abs(this.gameState.cars[o].y - this.y); if (f >= 256 || this.gameState.cars[o].y >= this.y) { continue } if (Math.abs(this.gameState.cars[o].x - this.x) < 80 && Math.abs(this.gameState.cars[o].velocityY) < Math.abs(this.velocityY)) { var y = this.isAdjacentLaneOpen(); if (y) { this.stuckBehindCar = false; this.changingLanes = true; if (this.x > 0) { this.desiredLaneX = Car.leftLaneX } else { this.desiredLaneX = Car.rightLaneX } } else { this.stuckBehindCar = true; this.trafficSpeed = this.gameState.cars[o].trafficSpeed } } } } break; case CarState.EVADING: this.accelerationX += Math.cos(this.wheelAngle) * this.topSpeed; this.accelerationY += Math.sin(this.wheelAngle) * this.topSpeed; break; case CarState.BROKENDOWN: this.smokeTimer -= m; if (this.smokeTimer <= 0) { this.smokeTimer = this.smokeTime; var w = new Particle(); w.init(content.smoke, randFloatRange(0.25, 0.75) * 6); w.x = this.x + Math.cos(this.carAngle) * 30; w.y = this.y + Math.sin(this.carAngle) * 30; w.originX = w.sprite.width * 0.5; w.originY = w.sprite.height * 0.5; var j = randFloatRange(0.75, 1) * 2; w.startScaleX = 0; w.startScaleY = 0; w.endScaleX = j; w.endScaleY = j; w.startAlpha = 0.65; w.endAlpha = 0; w.depth = this.depth - 0.01; w.dragX = 1; w.dragY = 1; var g = randFloatRange(0, 0.25); var n = randFloatRange(0, Math.PI * 2); w.velocityX = Math.cos(n) * g; w.velocityY = Math.sin(n) * g; w.start(); this.sceneManager.addEntity(w) } break; case CarState.SPINNING: this.skidmarkBuffer.x = -this.x; this.skidmarkBuffer.originX = this.skidmarkBuffer.sprite.width * 0.5; this.skidmarkBuffer.originY = 360 + (this.y - this.skidStartY); var h = Math.sqrt(this.velocityX * this.velocityX + this.velocityY * this.velocityY); if (h < 1) { this.setDesiredState(CarState.BROKENDOWN); break } var a = this.skidmarkBuffer.sprite.getContext("2d"); var u = this.skidmarkBuffer.sprite.width * 0.5; var t = 360; u += this.x; t += (this.y - this.skidStartY); for (var o = 0; o < 4; o++) { a.drawImage(content.skid, u + Math.cos(this.carAngle + Math.PI * 0.25 + o * Math.PI * 0.5) * 28, t + Math.sin(this.carAngle + Math.PI * 0.25 + o * Math.PI * 0.5) * 28) } break } }; CopCar.prototype.crash = function() { if (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN) { return } this.body.sprite = content.copCarCrash; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.001; this.setDesiredState(CarState.BROKENDOWN) }; CopCar.prototype.explode = function() { if (this.currentState == CarState.BROKENDOWN || this.desiredState == CarState.BROKENDOWN) { return } this.body.sprite = content.copCarExploded; this.restitution = 0.1; this.dragX = 0.01; this.dragY = 0.01; this.angularDrag = 0.001; this.setDesiredState(CarState.BROKENDOWN) }; CopCar.prototype.flagForRemoval = function() { this.toBeRemoved = true; if (this.skidmarkBuffer) { this.skidmarkBuffer.flagForRemoval() } if (this.dirtLoopInstance) { this.dirtLoopInstance.stop(); this.dirtLoopInstance = null } if (this.sirenLoopInstance) { this.sirenLoopInstance.stop(); this.sirenLoopInstance = null } }; function SteerController() { SceneObject.call(this); this.backing; this.circle; this.value; this.inUse; this.touchID; this.usingCar } SteerController.prototype = new SceneObject(); SteerController.prototype.constructor = SteerController; SteerController.prototype.init = function(a) { this.x = canvas.width * 0.5; this.y = 0; this.gameState = a; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = false; this.backing = new Drawable(); this.backing.init(content.steeringBack, 0, 0); this.backing.originX = 217; this.backing.originY = 49; this.addChild(this.backing); this.circle = new Drawable(); this.circle.init(content.steeringCircle, 0, 0); this.circle.originX = this.circle.sprite.width * 0.5; this.circle.originY = this.circle.sprite.height * 0.5; this.addChild(this.circle); this.value = 0; this.touchID = -1; this.inUse = false; this.desiredValue = 0; this.desiredCircleScale = 1; this.depth = -1; this.masterAlpha = 1; this.usingCar = false }; SteerController.prototype.update = function(b) { this.updateTouch(b); this.value = this.value + ((this.desiredValue) - this.value) * 0.25; this.circle.x = this.value * 165; this.desiredCircleScale = 1; if (this.inUse) { this.desiredCircleScale = 1.15 } this.circle.scaleX = this.circle.scaleX + ((this.desiredCircleScale) - this.circle.scaleX) * 0.25; this.circle.scaleX *= this.masterAlpha; if (this.circle.scaleX < 0.1) { this.circle.scaleX = 0 } this.circle.scaleY = this.circle.scaleX; if (this.usingCar) { this.masterAlpha = this.masterAlpha + (0.1 - this.masterAlpha) * 0.1 } else { this.masterAlpha = this.masterAlpha + (1 - this.masterAlpha) * 0.1 } for (var a = 0; a < this.childCount; a++) { this.children[a].alpha = this.masterAlpha; this.children[a].update(b) } }; SteerController.prototype.updateTouch = function(c) { if (!this.inUse) { this.desiredValue = 0; if ((touchDown && !touchDownLast) || (mouseDown && !mouseDownLast)) { if (gMobile) { var a = this.backing.touchOver(); if (a.touched) { this.inUse = true; this.touchID = a.id; this.usingCar = false } else { a = this.gameState.player.body.touchOver(); if (a.touched) { this.inUse = true; this.touchID = a.id; this.usingCar = true } } } else { var a = this.backing.mouseOver(); if (a) { this.inUse = true; this.usingCar = false } else { if (this.gameState.player.body.mouseOver()) { this.inUse = true; this.usingCar = true } } } } } if (this.inUse) { if (gMobile) { if (!touchDown) { this.inUse = false } else { var d; for (var b = 0; b < currentTouches.length; b++) { if (currentTouches[b].id == this.touchID) { d = currentTouches[b]; break } } if (d) { if (this.usingCar) { this.desiredValue = (this.gameState.sceneManager.worldMouseX - this.gameState.player.x) / 165; this.desiredValue = Math.max(-1, Math.min(1, this.desiredValue)) } else { this.desiredValue = Math.max(-1, Math.min(1, (d.x - this.x) / 165)) } } else { this.inUse = false } } } else { if (!mouseDown) { this.inUse = false } else { if (this.usingCar) { this.desiredValue = (this.gameState.sceneManager.worldMouseX - this.gameState.player.x) / 165; this.desiredValue = Math.max(-1, Math.min(1, this.desiredValue)) } else { this.desiredValue = Math.max(-1, Math.min(1, (mouseX - this.x) / 165)) } } } } }; SteerController.prototype.hide = function() { TweenLite.to(this, 1, { y: canvas.height + 180, ease: Sine.easeOut, onCompleteParams: [this], onComplete: function(a) { a.visible = false } }) }; var OffroadNotificationState = { OPEN: 0, CLOSED: 1, OPENING: 2, CLOSING: 3 }; function OffroadNotification() { SceneObject.call(this) } OffroadNotification.prototype = new SceneObject(); OffroadNotification.prototype.constructor = OffroadNotification; OffroadNotification.prototype.init = function() { this.state = OffroadNotificationState.CLOSED; this.useCamera = false; this.x = 0; this.y = 0; this.stars = []; this.starTime = 0.05; this.starTimer = this.starTime; this.starBuffer = new Drawable(); this.starBuffer.init(null, 0, 0); this.addChild(this.starBuffer); this.starBuffer.sprite = document.createElement("canvas"); this.starBuffer.sprite.width = 320; this.starBuffer.sprite.height = 140; this.starBuffer.originX = this.starBuffer.sprite.width * 0.5; this.starBuffer.originY = this.starBuffer.sprite.height * 0.5; var b = this.starBuffer.sprite.getContext("2d"); b.fillStyle = "#FF0000"; b.fillRect(0, 0, 260, 140); this.offroadText = new Drawable(); this.offroadText.init(null, 0, 0); this.addChild(this.offroadText); this.offroadText.sprite = document.createElement("canvas"); this.offroadText.sprite.width = 232; this.offroadText.sprite.height = 50; this.offroadText.originX = this.offroadText.sprite.width * 0.5; this.offroadText.originY = this.offroadText.sprite.height * 0.5; var a = this.offroadText.sprite.getContext("2d"); a.font = "normal normal normal " + 41 + "px chunkfive"; a.textAlign = "center"; a.textBaseline = "middle"; a.fillStyle = "#000000"; a.fillText("\u504f\u79bb\u9053\u8def !", this.offroadText.sprite.width * 0.5 + 3, this.offroadText.sprite.height * 0.5 + 3); a.fillStyle = "#FFFFFF"; a.fillText("\u504f\u79bb\u9053\u8def !", this.offroadText.sprite.width * 0.5, this.offroadText.sprite.height * 0.5); this.offroadText.scaleX = 0; this.offroadText.scaleY = 0; this.timerBase = new Drawable(); this.timerBase.init(content.circleTimerBase, 0, 48); this.timerBase.originX = this.timerBase.sprite.width * 0.5; this.timerBase.originY = this.timerBase.sprite.height * 0.5; this.timerBase.scaleX = 0; this.timerBase.scaleY = 0; this.addChild(this.timerBase); this.timerRing = new Drawable(); this.timerRing.init(content.circleTimerRing, 0, 48); this.timerRing.originX = this.timerRing.sprite.width * 0.5; this.timerRing.originY = this.timerRing.sprite.height * 0.5; this.timerRing.scaleX = 0; this.timerRing.scaleY = 0; this.timerRing.useMask = true; this.addChild(this.timerRing); this.timerRingMask = document.createElement("canvas"); this.timerRingMask.width = this.timerRing.sprite.width; this.timerRingMask.height = this.timerRing.sprite.height; this.timerRing.mask = this.timerRingMask; this.timerProgress = 0; this.baseTime = 1; this.timer = 0; this.x = canvas.width * 0.5; this.y = 160 }; OffroadNotification.prototype.update = function(e) { this.timerProgress = Math.min(1, this.timer / this.baseTime); if (this.state === OffroadNotificationState.OPEN || this.state === OffroadNotificationState.OPENING) { this.starTimer -= e; while (this.starTimer <= 0) { this.starTimer += this.starTime; var f = new Particle(); f.init(content.star, randFloatRange(0.25, 0.75) * 4); f.useCamera = false; f.x = this.starBuffer.sprite.width * 0.5 + randFloatRange(-115, 115); f.y = this.starBuffer.sprite.height * 0.5 + randFloatRange(-18, 18); f.originX = f.sprite.width * 0.5; f.originY = f.sprite.height * 0.5; var c = randFloatRange(0.75, 1) * 2; f.startScaleX = 0.15; f.startScaleY = 0.15; f.endScaleX = c; f.endScaleY = c; f.startAlpha = 3; f.endAlpha = 0; f.depth = this.depth + 0.01; f.dragX = 0.1; f.dragY = f.dragX; f.angularVelocity = randFloatRange(-1, 1) * 0.01; var d = randFloatRange(0, Math.PI * 2); var a = 0; f.velocityX = a * Math.cos(d); f.velocityY = a * Math.sin(d); f.sceneManager = this.sceneManager; f.start(); this.stars.push(f) } this.updateTimerMask(e) } this.x = canvas.width * 0.5; for (var b = 0; b < this.stars.length; b++) { if (this.stars[b].toBeRemoved) { this.stars.splice(b, 1); b--; continue } this.stars[b].update(e) } this.removeChildren(); for (var b = 0; b < this.childCount; b++) { this.children[b].update(e) } }; OffroadNotification.prototype.updateTimerMask = function(c) { var d = this.timerRingMask.getContext("2d"); d.clearRect(0, 0, this.timerRingMask.width, this.timerRingMask.height); d.fillStyle = "#FF0000"; d.beginPath(); d.moveTo(this.timerRingMask.width * 0.5, this.timerRingMask.height * 0.5); for (var b = 0; b < 5; b++) { if (this.timerProgress * 4 < b) { break } var a = b - 1; d.lineTo(this.timerRingMask.width * 0.5 + Math.cos(a * ((Math.PI * 2) / 4)) * this.timerRingMask.width * 0.75, this.timerRingMask.height * 0.5 + Math.sin(a * ((Math.PI * 2) / 4)) * this.timerRingMask.height * 0.75) } var a = (this.timerProgress * 4) - 1; d.lineTo(this.timerRingMask.width * 0.5 + Math.cos(a * ((Math.PI * 2) / 4)) * this.timerRingMask.width * 0.75, this.timerRingMask.height * 0.5 + Math.sin(a * ((Math.PI * 2) / 4)) * this.timerRingMask.height * 0.75); d.closePath(); d.fill() }; OffroadNotification.prototype.draw = function(b) { if (!this.visible) { return } var c = this.starBuffer.sprite.getContext("2d"); c.clearRect(0, 0, this.starBuffer.sprite.width, this.starBuffer.sprite.height); for (var a = 0; a < this.stars.length; a++) { this.stars[a].draw(c) } for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } }; OffroadNotification.prototype.open = function() { if (this.state === OffroadNotificationState.OPEN || this.state === OffroadNotificationState.OPENING) { return } this.state = OffroadNotificationState.OPENING; TweenLite.to(this.starBuffer, 0.25, { alpha: 1, ease: Elastic.easeOut, overwrite: 1 }); TweenLite.to(this.timerRing, 0.65, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut, overwrite: 1 }); TweenLite.to(this.timerBase, 0.65, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut, overwrite: 1 }); TweenLite.to(this.offroadText, 0.5, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut, overwrite: 1, onCompleteParams: [this], onComplete: function(a) { a.state = OffroadNotificationState.OPEN } }) }; OffroadNotification.prototype.close = function() { if (this.state === OffroadNotificationState.CLOSED || this.state === OffroadNotificationState.CLOSING) { return } this.state = OffroadNotificationState.CLOSING; TweenLite.to(this.starBuffer, 0.25, { alpha: 0, ease: Expo.easeOut, overwrite: 1 }); TweenLite.to(this.timerRing, 0.25, { scaleX: 0, scaleY: 0, ease: Elastic.easeOut, overwrite: 1 }); TweenLite.to(this.timerBase, 0.25, { scaleX: 0, scaleY: 0, ease: Elastic.easeOut, overwrite: 1 }); TweenLite.to(this.offroadText, 0.5, { scaleX: 0, scaleY: 0, ease: Expo.easeOut, overwrite: 1, onCompleteParams: [this], onComplete: function(a) { a.state = OffroadNotificationState.CLOSED } }) }; var DirtroadNotificationState = { OPEN: 0, CLOSED: 1, OPENING: 2, CLOSING: 3 }; function DirtroadNotification() { SceneObject.call(this) } DirtroadNotification.prototype = new SceneObject(); DirtroadNotification.prototype.constructor = DirtroadNotification; DirtroadNotification.prototype.init = function() { this.state = DirtroadNotificationState.CLOSED; this.useCamera = false; this.x = 0; this.y = 0; this.banner = new Drawable(); this.banner.init(content.warningStripe, 0, 0); this.banner.originX = this.banner.sprite.width * 0.5; this.banner.originY = this.banner.sprite.height * 0.5; this.banner.scaleY = 0; this.addChild(this.banner); this.leftArrow = new Drawable(); this.leftArrow.init(content.dirtArrow, -800, 0); this.leftArrow.originX = this.leftArrow.sprite.width * 0.5; this.leftArrow.originY = this.leftArrow.sprite.height * 0.5; this.addChild(this.leftArrow); this.rightArrow = new Drawable(); this.rightArrow.init(content.dirtArrow, 800, 0); this.rightArrow.originX = this.rightArrow.sprite.width * 0.5; this.rightArrow.originY = this.rightArrow.sprite.height * 0.5; this.addChild(this.rightArrow); this.sine = 0; this.dirtroadText = new Drawable(); this.dirtroadText.init(null, 0, 0); this.addChild(this.dirtroadText); this.dirtroadText.sprite = document.createElement("canvas"); this.dirtroadText.sprite.width = 256; this.dirtroadText.sprite.height = 50; this.dirtroadText.originX = this.dirtroadText.sprite.width * 0.5; this.dirtroadText.originY = this.dirtroadText.sprite.height * 0.5; var a = this.dirtroadText.sprite.getContext("2d"); a.font = "normal normal normal " + 41 + "px chunkfive"; a.textAlign = "center"; a.textBaseline = "middle"; a.fillStyle = "#000000"; a.fillText("\u571f\u8def !", this.dirtroadText.sprite.width * 0.5 + 3, this.dirtroadText.sprite.height * 0.5 + 3); a.fillStyle = "#FFFFFF"; a.fillText("\u571f\u8def !", this.dirtroadText.sprite.width * 0.5, this.dirtroadText.sprite.height * 0.5); this.dirtroadText.scaleX = 0; this.dirtroadText.scaleY = 0 }; DirtroadNotification.prototype.update = function(b) { if (this.state === DirtroadNotificationState.OPEN || this.state === DirtroadNotificationState.OPENING) { this.sine += b * 12; while (this.sine > Math.PI * 2) { this.sine -= Math.PI * 2 } this.banner.scaleX = 1 + Math.sin(this.sine) * 0.01 } this.rightArrow.y = -3 + Math.sin(this.sine) * 2; this.leftArrow.y = -3 + Math.sin(this.sine) * 2; this.x = canvas.width * 0.5; this.y = 160; this.removeChildren(); for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } }; DirtroadNotification.prototype.draw = function(b) { if (!this.visible) { return } for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } }; DirtroadNotification.prototype.open = function() { if (this.state === DirtroadNotificationState.OPEN || this.state === DirtroadNotificationState.OPENING) { return } this.state = DirtroadNotificationState.OPENING; TweenLite.to(this.leftArrow, 0.35, { x: -150, ease: Sine.easeOut, overwrite: 1 }); TweenLite.to(this.rightArrow, 0.35, { x: 150, ease: Sine.easeOut, overwrite: 1 }); TweenLite.to(this.banner, 0.5, { scaleY: 1, ease: Elastic.easeOut, overwrite: 1 }); TweenLite.to(this.dirtroadText, 0.5, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut, overwrite: 1, onCompleteParams: [this], onComplete: function(a) { a.state = DirtroadNotificationState.OPEN } }) }; DirtroadNotification.prototype.close = function() { if (this.state === DirtroadNotificationState.CLOSED || this.state === DirtroadNotificationState.CLOSING) { return } this.state = DirtroadNotificationState.CLOSING; TweenLite.to(this.leftArrow, 0.35, { x: -800, ease: Sine.easeOut, overwrite: 1 }); TweenLite.to(this.rightArrow, 0.35, { x: 800, ease: Sine.easeOut, overwrite: 1 }); TweenLite.to(this.banner, 0.5, { scaleY: 0, ease: Expo.easeOut, overwrite: 1 }); TweenLite.to(this.dirtroadText, 0.5, { scaleX: 0, scaleY: 0, ease: Expo.easeOut, overwrite: 1, onCompleteParams: [this], onComplete: function(a) { a.state = DirtroadNotificationState.CLOSED } }) }; var EndBannerState = { OPEN: 0, CLOSED: 1, OPENING: 2, CLOSING: 3 }; function EndBanner() { SceneObject.call(this) } EndBanner.prototype = new SceneObject(); EndBanner.prototype.constructor = EndBanner; EndBanner.prototype.init = function(c) { //updateShare(parseFloat(window.score) * 1000); window.score = parseFloat(window.score) * 1000; //Play68.setRankingScoreDesc(window.score); this.state = EndBannerState.CLOSED; this.useCamera = false; this.x = 0; this.y = 0; this.depth = -0.99; this.width = 300; this.leftEdge = new Drawable(); this.leftEdge.init(content.bannerEdge, 0, 0); this.leftEdge.originX = this.leftEdge.sprite.width; this.addChild(this.leftEdge); this.rightEdge = new Drawable(); this.rightEdge.init(content.bannerEdge, 0, 0); this.rightEdge.originX = this.rightEdge.sprite.width; this.rightEdge.scaleX = -1; this.addChild(this.rightEdge); this.spread = new Drawable(); this.spread.init(content.bannerSpread, 0, 0); this.spread.originX = this.spread.sprite.width * 0.5; this.spread.scaleX = (28 * 2) / 4; this.addChild(this.spread); this.shine = new Drawable(); this.shine.init(content.bannerShine, -128, 0); this.shine.originY = -8; this.shine.alpha = 0; this.addChild(this.shine); this.text = new Drawable(); this.text.init(null, 0, 54); this.addChild(this.text); this.text.sprite = document.createElement("canvas"); this.text.sprite.width = 392; this.text.sprite.height = 64; this.text.scaleX = 0; this.text.scaleY = 0; this.text.originX = this.text.sprite.width * 0.5; this.text.originY = this.text.sprite.height * 0.5; var b = this.text.sprite.getContext("2d"); var a = "NULL"; switch (c) { case FailType.CRASH: a = "\u649e\u6bc1 !"; b.font = "normal normal normal " + 68 + "px chunkfive"; break; case FailType.SPIN: a = "\u7ed3\u675f !"; b.font = "normal normal normal " + 68 + "px chunkfive"; break; case FailType.EXPLODED: a = "\u7206\u70b8 !"; b.font = "normal normal normal " + 64 + "px chunkfive"; break; case FailType.BROKEDOWN: a = "\u6545\u969c !"; b.font = "normal normal normal " + 52 + "px chunkfive"; break; default: a = "NULL"; b.font = "normal normal normal " + 68 + "px chunkfive"; break } b.textAlign = "center"; b.textBaseline = "middle"; b.fillStyle = "#000000"; b.fillText(a, this.text.sprite.width * 0.5 + 4, this.text.sprite.height * 0.5 + 4); b.fillStyle = "#FFFFFF"; b.fillText(a, this.text.sprite.width * 0.5, this.text.sprite.height * 0.5) }; EndBanner.prototype.update = function(b) { this.removeChildren(); for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } }; EndBanner.prototype.draw = function(b) { if (!this.visible) { return } for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } }; EndBanner.prototype.open = function() { if (this.state === EndBannerState.OPEN || this.state === EndBannerState.OPENING) { return } this.state = EndBannerState.OPENING; var a = 0.35; TweenLite.to(this.leftEdge, a, { x: -this.width * 0.5, ease: Cubic.easeIn, overwrite: 1 }); TweenLite.to(this.rightEdge, a, { x: this.width * 0.5, ease: Cubic.easeIn, overwrite: 1 }); TweenLite.to(this.spread, a, { scaleX: (this.width + 28 * 2) / 4 + 1, ease: Cubic.easeIn, overwrite: 1 }); TweenLite.to(this.text, a * 2, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut, delay: a, overwrite: 1 }); TweenLite.to(this.shine, a, { alpha: 0.15, ease: Sine.easeOut, delay: a, overwrite: 1 }) }; EndBanner.prototype.close = function() { if (this.state === EndBannerState.CLOSED || this.state === EndBannerState.CLOSING) { return } this.state = EndBannerState.CLOSING; var a = 2; TweenLite.to(this.leftEdge, a, { x: 0, ease: Expo.easeOut, delay: 0.25, overwrite: 1 }); TweenLite.to(this.rightEdge, a, { x: 0, ease: Expo.easeOut, delay: 0.25, overwrite: 1 }); TweenLite.to(this.spread, a, { scaleX: 0, ease: Expo.easeOut, delay: 0.25, overwrite: 1 }); TweenLite.to(this.text, a, { scaleX: 0, scaleY: 0, ease: Expo.easeIn, overwrite: 1 }) }; function Hud() { SceneObject.call(this); this.buttons = []; this.state; this.pauseButton; this.backButton; this.backing; this.distance; this.distanceBuffer; this.distanceContext; this.lastDistanceText; this.offroad; this.dirtroad; this.hits = [] } Hud.prototype = new SceneObject(); Hud.prototype.constructor = Hud; Hud.prototype.init = function(c) { this.useCamera = false; this.state = c; this.distance = 0; this.depth = -0.99; this.backing = new Drawable(); this.backing.init(content.roadBacking, 0, 0); this.backing.originX = this.backing.sprite.width * 0.5; this.addChild(this.backing); this.distanceBuffer = document.createElement("canvas"); this.distanceBuffer.width = 175; this.distanceBuffer.height = 51; this.distanceContext = this.distanceBuffer.getContext("2d"); this.distanceX = 0; this.distanceY = 0; this.offroad = new OffroadNotification(); this.offroad.init(); this.dirtroad = new DirtroadNotification(); this.dirtroad.init(); this.soundButton = new Button(); this.soundButton.defaultGraphic = content.soundOff; this.soundButton.callback = this.onSoundHit; this.soundButton.parentState = this.state; this.soundButton.init(); this.soundButton.originX = this.soundButton.defaultGraphic.width * 0.5; this.soundButton.originY = this.soundButton.defaultGraphic.height * 0.5; this.soundButton.scaleX = 0.95; this.soundButton.scaleY = 0.95; this.buttons.push(this.soundButton); this.state.buttons.push(this.soundButton); if (!soundMuted) { this.soundButton.defaultGraphic = content.soundOn } this.backButton = new Button(); this.backButton.defaultGraphic = content.backBtn; this.backButton.callback = this.onBackHit; this.backButton.parentState = this.state; this.backButton.init(); this.backButton.originX = this.backButton.defaultGraphic.width * 0.5; this.backButton.originY = this.backButton.defaultGraphic.height * 0.5; this.backButton.scaleX = 0.95; this.backButton.scaleY = 0.95; this.buttons.push(this.backButton); this.state.buttons.push(this.backButton); this.lastDistanceText = "XXX"; for (var a = 0; a < 3; a++) { var b = new Drawable(); b.init(content.hitOff, 0, 0); b.originX = b.sprite.width * 0.5; b.originY = b.sprite.height * 0.5; this.hits.push(b); this.addChild(b) } this.hitCount = 0 }; Hud.prototype.onAddedToSceneManager = function() { this.offroad.sceneManager = this.sceneManager; this.dirtroad.sceneManager = this.sceneManager }; Hud.prototype.onPauseHit = function(a) { a.paused = !a.paused; a.pauseOverlay.children[1].scaleX = 0; a.pauseOverlay.children[1].scaleY = 0; TweenLite.to(a.pauseOverlay.children[1], 0.5, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut }) }; Hud.prototype.onSoundHit = function(a) { setSoundMute(!soundMuted); setMusicMute(soundMuted); if (soundMuted) { a.hud.soundButton.defaultGraphic = content.soundOff } else { a.hud.soundButton.defaultGraphic = content.soundOn } }; Hud.prototype.onBackHit = function(a) { var b = new MainMenuState(); b.init(); a.stateManager.setState(b) }; Hud.prototype.update = function(b) { if (this.state.paused) { this.soundButton.visible = false; this.backButton.visible = false } else { this.soundButton.visible = true; this.backButton.visible = true } this.soundButton.screenSizeOffsetX = canvas.width - this.soundButton.defaultGraphic.width * 0.5; this.soundButton.screenSizeOffsetY = 36; this.backButton.screenSizeOffsetX = this.backButton.defaultGraphic.width * 0.5; this.backButton.screenSizeOffsetY = 36; this.backing.x = canvas.width * 0.5; this.offroad.update(b); this.dirtroad.update(b); if (this.state.playState != PlayState.DYING) { for (var a = 0; a < this.hits.length; a++) { this.hits[a].x = canvas.width * 0.5 + 45 + a * 39; this.hits[a].y = 26 } } if (this.offroad.state === OffroadNotificationState.OPEN || this.offroad.state === OffroadNotificationState.OPENING) { if (this.dirtroad.state === DirtroadNotificationState.OPEN || this.dirtroad.state === DirtroadNotificationState.OPENING) { var c = 160 + 80; this.offroad.y = this.offroad.y + (c - this.offroad.y) * 0.1 } } else { var c = 160; this.offroad.y = this.offroad.y + (c - this.offroad.y) * 0.1 } for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } }; Hud.prototype.draw = function(b) { if (!this.visible) { return } for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } this.offroad.draw(b); this.dirtroad.draw(b); var c = (Math.floor(this.distance) / 1000).toString(); if (c.length > 4) { c = c.substring(0, 4) } while (c.length < 4) { c += "0" } c += " km"; window.score = c; console.log(c); if (c != this.lastDistanceText) { this.distanceContext.clearRect(0, 0, 175, 51); this.distanceContext.fillStyle = "#FFFFFF"; this.distanceContext.font = "normal normal normal " + 36 + "px chunkfive"; this.distanceContext.textAlign = "right"; this.distanceContext.fillText(c, 175 - 8, 38); this.distanceContext.globalAlpha = 1 } this.lastDistanceText = c; ctx.drawImage(this.distanceBuffer, (canvas.width * 0.5 - 175) + this.distanceX, this.distanceY) }; Hud.prototype.endGame = function(a) { this.offroad.close(); this.dirtroad.close(); this.soundButton.active = false; this.backButton.active = false; TweenLite.to(this.soundButton, 0.25, { y: -80, ease: Sine.easeOut, overwrite: 1 }); TweenLite.to(this.backButton, 0.25, { y: -80, ease: Sine.easeOut, overwrite: 1 }); TweenLite.to(this, 0.5, { distanceY: -80, ease: Sine.easeOut }); for (var b = 0; b < this.hits.length; b++) { if (a == FailType.BROKEDOWN) { TweenLite.to(this.hits[b], 1, { x: canvas.width * 0.5 + (b - 1) * 39, y: 64, ease: Sine.easeOut, delay: b * 0.25 }) } else { TweenLite.to(this.hits[b], 1, { y: -80, ease: Sine.easeOut }) } } }; Hud.prototype.setHitCount = function(b) { b = Math.max(0, Math.min(b)); if (this.hitCount == b) { return } if (b < this.hitCount) { for (var a = 0; a < this.hits.length; a++) { if (a + 1 > b) { this.hits[a].sprite = content.hitOff; var c = new Particle(); c.init(content.hitOn, 0.25); c.x = this.x + this.hits[a].x; c.y = this.y + this.hits[a].y; c.originX = c.sprite.width * 0.5; c.originY = c.sprite.height * 0.5; c.startScaleX = 1; c.startScaleY = 1; c.endScaleX = 0; c.endScaleY = 0; c.startAlpha = 1; c.endAlpha = 0; c.depth = this.depth - 0.01; c.useCamera = false; c.start(); this.sceneManager.addEntity(c); break } } } else { for (var a = this.hits.length - 1; a > -1; a--) { if (a < b) { this.hits[a].sprite = content.hitOn; this.hits[a].scaleX = 0; this.hits[a].scaleY = 0; TweenLite.to(this.hits[a], 0.75, { scaleX: 1, scaleY: 1, ease: Elastic.easeOut, overwrite: 1 }); break } } } this.hitCount = b }; function Crate() { SceneObject.call(this); this.currentAngle = 0 } Crate.prototype = new SceneObject(); Crate.prototype.constructor = Crate; Crate.prototype.init = function(a, g, f, c) { this.x = a; this.y = g; this.currentAngle = f; this.gameState = c; this.explosive = false; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 0.35; this.restitution = 1; this.immovable = false; this.contactLessCollision = false; this.oldVelocityX = 0; this.oldVelocityY = 0; this.velocityX = 0; this.velocityY = 0; this.accelerationX = 0; this.accelerationY = 0; this.dragX = 0.25; this.dragY = 0.25; this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.angularAcceleration = 0; this.angularVelocity = 0; this.angularDrag = 0.45; this.oldAngularVelocity = 0; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 18.5); this.colliders.push(b); this.updateColliders(); var e = new Drawable(); e.init(content.crate, 0, 0); e.originX = e.sprite.width * 0.5; e.originY = e.sprite.height * 0.5; this.addChild(e); this.depth = -0.1 + randFloatRange(-0.01, 0.01); this.spawner = null }; Crate.prototype.doSpawnAnimation = function() { this.children[0].scaleX = 1.15; this.children[0].scaleY = 1.15; TweenLite.to(this.children[0], 0.5, { scaleX: 1, scaleY: 1, delay: 0.25, ease: Bounce.easeOut }) }; Crate.prototype.setExplosive = function(a) { if (this.explosive === a) { return } this.explosive = a; if (this.explosive) { this.children[0].sprite = content.explodingCrate } else { this.children[0].sprite = content.crate } }; Crate.prototype.update = function(c) { if (!this.immovable) { if (isNaN(this.collisionVelocityAccumulatorX) || isNaN(this.collisionVelocityAccumulatorY)) { this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0 } this.velocityX += this.collisionVelocityAccumulatorX; this.velocityY += this.collisionVelocityAccumulatorY; if (this.collisionVelocityAccumulatorX != 0 || this.collisionVelocityAccumulatorY != 0) { var d = Math.sqrt((this.collisionVelocityAccumulatorX * this.collisionVelocityAccumulatorX) + (this.collisionVelocityAccumulatorY * this.collisionVelocityAccumulatorY)); this.angularVelocity = d * c; var a = ((this.collisionVelocityAccumulatorX / d) * (1)) + ((this.collisionVelocityAccumulatorY / d) * (0)); if (a < 0) { this.angularVelocity *= -1 } } this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.oldVelocityX = this.velocityX; this.oldVelocityY = this.velocityY; this.velocityX += this.accelerationX * c; this.velocityY += this.accelerationY * c; this.x += (this.oldVelocityX + this.velocityX) * 0.5 * c; this.y += (this.oldVelocityY + this.velocityY) * 0.5 * c; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, c) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, c) } this.oldAngularVelocity = this.angularVelocity; this.angularVelocity += this.angularAcceleration * c; this.currentAngle += (this.oldAngularVelocity + this.angularVelocity) * 0.5 * c; if (this.angularDrag != 1) { this.angularVelocity *= Math.pow(this.angularDrag, c) } } this.accelerationX = 0; this.accelerationY = 0; this.angularAcceleration = 0; this.updateColliders(); for (var b = 0; b < this.childCount; b++) { this.children[b].angle = this.currentAngle; this.children[b].update(c) } }; Crate.prototype.draw = function() { for (var a = 0; a < this.childCount; a++) { this.children[a].draw() } }; Crate.prototype.updateColliders = function() { if (!this.colliders) { return } this.colliders[0].x = this.x; this.colliders[0].y = this.y }; Crate.prototype.checkCollision = function(f) { if (!this.colliders || !f.colliders) { return } for (var e = 0; e < this.colliders.length; e++) { for (var d = 0; d < f.colliders.length; d++) { var c = Collision.getCollision(this.colliders[e], f.colliders[d]); if (this.colliders[e].colliding) { this.colliders[e].lastCollisionObject = f } if (f.colliders[d].colliding) { f.colliders[d].lastCollisionObject = this } if (c) { this.onCollision(c, f); c.directionX *= -1; c.directionY *= -1; f.onCollision(c, this) } } } }; Crate.prototype.onCollision = function(m, g) { if (!this.collisionEnabled || this.immovable) { return } if (!this.colliders) { this.collisionEnabled = false; return } if (this.explosive && Car.prototype.isPrototypeOf(g)) { if (!soundMuted && PlayerCar.prototype.isPrototypeOf(g)) { var i = "explosion"; playSound(i) } var l = new Explosion(); l.init(this.x, this.y, 1, 2); l.depth = g.depth - 0.01; this.sceneManager.addEntity(l); l.trigger(0, null, this.gameState); this.flagForRemoval(); g.explode(); if (g === this.gameState.player) { g.gameState.endGame(FailType.EXPLODED) } return } if (!soundMuted && PlayerCar.prototype.isPrototypeOf(g)) { var i = "crateHit"; playSound(i) } this.x += m.directionX * m.magnitude; this.y += m.directionY * m.magnitude; if (this.mass == 0) { return } var e = this.velocityX - g.velocityX; var c = this.velocityY - g.velocityY; var k = (e * m.directionX) + (c * m.directionY); var a = Math.min(this.restitution, g.restitution); var h = -(1 + a) * k; if (g.mass == 0) { h /= (1 / this.mass) } else { h /= (1 / this.mass) + (1 / g.mass) } var d = h * m.directionX; var b = h * m.directionY; var f = 1 / this.mass; this.collisionVelocityAccumulatorX += f * d; this.collisionVelocityAccumulatorY += f * b; this.updateColliders() }; function Wall() { SceneObject.call(this) } Wall.prototype = new SceneObject(); Wall.prototype.constructor = Wall; Wall.prototype.init = function(a, f, c) { this.x = a; this.y = f; this.gameState = c; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 0; this.restitution = 1; this.immovable = true; this.contactLessCollision = false; this.velocityX = 0; this.velocityY = 0; this.colliders = []; var b = new LineCollider(); b.init(this.x - 81, this.y, this.x + 81, this.y); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 50); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 50); this.colliders.push(b); this.updateColliders(); var e = new Drawable(); e.init(content.wall, 0, 0); e.originX = 86; e.originY = 101; this.addChild(e); this.depth = -0.3 + randFloatRange(-0.01, 0.01) }; Wall.prototype.update = function(b) { this.updateColliders(); for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } }; Wall.prototype.draw = function() { for (var a = 0; a < this.childCount; a++) { this.children[a].draw() } }; Wall.prototype.updateColliders = function() { if (!this.colliders) { return } this.colliders[0].x0 = this.x - 72; this.colliders[0].y0 = this.y; this.colliders[0].x1 = this.x + 72; this.colliders[0].y1 = this.y; this.colliders[1].x = this.x - 32; this.colliders[1].y = this.y - 52; this.colliders[2].x = this.x + 32; this.colliders[2].y = this.y - 52 }; Wall.prototype.checkCollision = function(f) { if (!this.colliders || !f.colliders) { return } for (var e = 0; e < this.colliders.length; e++) { for (var d = 0; d < f.colliders.length; d++) { var c = Collision.getCollision(this.colliders[e], f.colliders[d]); if (this.colliders[e].colliding) { this.colliders[e].lastCollisionObject = f } if (f.colliders[d].colliding) { f.colliders[d].lastCollisionObject = this } if (c) { this.onCollision(c, f); c.directionX *= -1; c.directionY *= -1; f.onCollision(c, this) } } } }; Wall.prototype.onCollision = function(k, g) { if (!this.collisionEnabled || this.immovable) { return } if (!this.colliders) { this.collisionEnabled = false; return } this.x += k.directionX * k.magnitude; this.y += k.directionY * k.magnitude; if (this.mass == 0) { return } var d = this.velocityX - g.velocityX; var c = this.velocityY - g.velocityY; var i = (d * k.directionX) + (c * k.directionY); var a = Math.min(this.restitution, g.restitution); var h = -(1 + a) * i; if (g.mass == 0) { h /= (1 / this.mass) } else { h /= (1 / this.mass) + (1 / g.mass) } var e = h * k.directionX; var b = h * k.directionY; var f = 1 / this.mass; this.collisionVelocityAccumulatorX += f * e; this.collisionVelocityAccumulatorY += f * b; this.updateColliders() }; function Pothole() { SceneObject.call(this) } Pothole.prototype = new SceneObject(); Pothole.prototype.constructor = Pothole; Pothole.prototype.init = function(a, g, e) { this.x = a; this.y = g; this.gameState = e; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 0; this.restitution = 1; this.immovable = true; this.contactLessCollision = false; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 20); b.sensor = true; this.colliders.push(b); this.updateColliders(); var c = null; switch (randIntRange(0, 2)) { case 0: c = content.pothole0; break; case 1: c = content.pothole1; break; case 2: c = content.pothole2; break } var f = new Drawable(); f.init(c, 0, 0); f.originX = f.sprite.width * 0.5; f.originY = f.sprite.height * 0.5; this.addChild(f); this.depth = -0.1 + randFloatRange(-0.01, 0.01); this.potholeActive = true }; Pothole.prototype.update = function(d) { this.updateColliders(); for (var c = 0; c < this.childCount; c++) { this.children[c].update(d) } if (this.potholeActive) { if (this.colliders[0].colliding) { this.colliders[0].colliding = false; if (this.colliders[0].lastCollisionObject && Car.prototype.isPrototypeOf(this.colliders[0].lastCollisionObject)) { if (!soundMuted && PlayerCar.prototype.isPrototypeOf(this.colliders[0].lastCollisionObject)) { var b = "pothole01"; switch (randIntRange(0, 3)) { case 0: b = "pothole01"; break; case 1: b = "pothole02"; break; case 2: b = "pothole03"; break } playSound(b) } var a = 5000 / this.colliders[0].lastCollisionObject.mass; if (randFloatRange(0, 1) < 0.5) { a *= -1 } this.colliders[0].lastCollisionObject.accelerationX += a; this.colliders[0].lastCollisionObject.carAngle -= a * 0.00003; this.colliders[0].lastCollisionObject.velocityX *= 0.75; this.colliders[0].lastCollisionObject.velocityY *= 0.75; this.potholeActive = false; this.colliders[0].active = false } } } this.colliders[0].lastCollisionObject = null }; Pothole.prototype.updateColliders = function() { if (!this.colliders) { return } this.colliders[0].x = this.x; this.colliders[0].y = this.y }; function Oil() { SceneObject.call(this) } Oil.prototype = new SceneObject(); Oil.prototype.constructor = Oil; Oil.prototype.init = function(a, f, c) { this.x = a; this.y = f; this.gameState = c; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 0; this.restitution = 1; this.immovable = true; this.contactLessCollision = false; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 50); b.sensor = true; this.colliders.push(b); this.updateColliders(); var e = new Drawable(); e.init(content.oil, 0, 0); e.originX = e.sprite.width * 0.5; e.originY = e.sprite.height * 0.5; this.addChild(e); this.depth = -0.1 + randFloatRange(-0.01, 0.01) }; Oil.prototype.update = function(b) { this.updateColliders(); for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } if (true) { if (this.colliders[0].colliding) { this.colliders[0].colliding = false; if (this.colliders[0].lastCollisionObject && Car.prototype.isPrototypeOf(this.colliders[0].lastCollisionObject)) { this.colliders[0].lastCollisionObject.spinOut(); if (PlayerCar.prototype.isPrototypeOf(this.colliders[0].lastCollisionObject)) { this.gameState.endGame(FailType.SPIN) } } } } this.colliders[0].lastCollisionObject = null }; Oil.prototype.updateColliders = function() { if (!this.colliders) { return } this.colliders[0].x = this.x; this.colliders[0].y = this.y }; function HeliShadow() { SceneObject.call(this) } HeliShadow.prototype = new SceneObject(); HeliShadow.prototype.constructor = HeliShadow; HeliShadow.prototype.init = function(a, c, b) { this.x = a; this.y = c; this.gameState = b; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = false; this.collider = null; this.collisionEnabled = false; this.mass = 0; this.restitution = 1; this.immovable = true; this.contactLessCollision = false; this.velocityX = 0; this.velocityY = 0; this.colliders = []; this.body = new Drawable(); this.body.init(content.heliBody, 90, 90); this.body.originX = 95; this.body.originY = this.body.sprite.height * 0.5; this.blades = new Drawable(); this.blades.init(content.heliBlades, 90, 90); this.blades.originX = this.blades.sprite.width * 0.5; this.blades.originY = this.blades.sprite.height * 0.5; this.buffer = new Drawable(); this.buffer.init(null, 0, 0); this.buffer.sprite = document.createElement("canvas"); this.buffer.sprite.width = 180; this.buffer.sprite.height = 180; this.buffer.originX = this.buffer.sprite.width * 0.5; this.buffer.originY = this.buffer.sprite.height * 0.5; this.buffer.alpha = 0.5; this.addChild(this.buffer); this.depth = -0.9 }; HeliShadow.prototype.update = function(b) { this.body.angle = -Math.PI * 0.5; this.blades.angle += b * 8; while (this.blades.angle >= Math.PI * 2) { this.blades.angle -= Math.PI * 2 } for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } this.body.update(b); this.blades.update(b); this.x = mouseX; this.y = mouseY }; HeliShadow.prototype.draw = function(b) { if (!this.visible) { return } var c = this.buffer.sprite.getContext("2d"); c.clearRect(0, 0, 180, 180); this.body.draw(c); this.blades.draw(c); for (var a = 0; a < this.childCount; a++) { this.children[a].draw(b) } }; function RoadBlock() { SceneObject.call(this); this.currentAngle = 0 } RoadBlock.prototype = new SceneObject(); RoadBlock.prototype.constructor = RoadBlock; RoadBlock.prototype.init = function(a, f, c) { this.x = a; this.y = f; this.currentAngle = 0; this.gameState = c; this.children = []; this.childCount = 0; this.knockedOver = false; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 0.15; this.restitution = 1; this.immovable = false; this.contactLessCollision = false; this.oldVelocityX = 0; this.oldVelocityY = 0; this.velocityX = 0; this.velocityY = 0; this.accelerationX = 0; this.accelerationY = 0; this.dragX = 0.25; this.dragY = 0.25; this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.angularAcceleration = 0; this.angularVelocity = 0; this.angularDrag = 0.35; this.oldAngularVelocity = 0; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 19); this.colliders.push(b); b = new CircleCollider(); b.init(this.x, this.y, 19); this.colliders.push(b); this.updateColliders(); var e = new Drawable(); e.init(content.blockStanding, 0, 0); e.originX = e.sprite.width * 0.5; e.originY = e.sprite.height * 0.5; this.addChild(e); this.depth = -0.15 + randFloatRange(-0.01, 0.01) }; RoadBlock.prototype.update = function(c) { if (!this.immovable) { if (isNaN(this.collisionVelocityAccumulatorX) || isNaN(this.collisionVelocityAccumulatorY)) { this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0 } this.velocityX += this.collisionVelocityAccumulatorX; this.velocityY += this.collisionVelocityAccumulatorY; if (this.collisionVelocityAccumulatorX != 0 || this.collisionVelocityAccumulatorY != 0) { var d = Math.sqrt((this.collisionVelocityAccumulatorX * this.collisionVelocityAccumulatorX) + (this.collisionVelocityAccumulatorY * this.collisionVelocityAccumulatorY)); this.angularVelocity = d * c; var a = ((this.collisionVelocityAccumulatorX / d) * (1)) + ((this.collisionVelocityAccumulatorY / d) * (0)); if (a < 0) { this.angularVelocity *= -1 } } this.collisionVelocityAccumulatorX = 0; this.collisionVelocityAccumulatorY = 0; this.oldVelocityX = this.velocityX; this.oldVelocityY = this.velocityY; this.velocityX += this.accelerationX * c; this.velocityY += this.accelerationY * c; this.x += (this.oldVelocityX + this.velocityX) * 0.5 * c; this.y += (this.oldVelocityY + this.velocityY) * 0.5 * c; if (this.dragX != 1) { this.velocityX *= Math.pow(this.dragX, c) } if (this.dragY != 1) { this.velocityY *= Math.pow(this.dragY, c) } this.oldAngularVelocity = this.angularVelocity; this.angularVelocity += this.angularAcceleration * c; this.currentAngle += (this.oldAngularVelocity + this.angularVelocity) * 0.5 * c; if (this.angularDrag != 1) { this.angularVelocity *= Math.pow(this.angularDrag, c) } } this.accelerationX = 0; this.accelerationY = 0; this.angularAcceleration = 0; this.updateColliders(); for (var b = 0; b < this.childCount; b++) { this.children[b].angle = this.currentAngle; this.children[b].update(c) } }; RoadBlock.prototype.draw = function() { for (var a = 0; a < this.childCount; a++) { this.children[a].draw() } }; RoadBlock.prototype.updateColliders = function() { if (!this.colliders) { return } this.colliders[0].x = this.x + Math.cos(this.currentAngle) * 30; this.colliders[0].y = this.y + Math.sin(this.currentAngle) * 30; this.colliders[1].x = this.x - Math.cos(this.currentAngle) * 30; this.colliders[1].y = this.y - Math.sin(this.currentAngle) * 30 }; RoadBlock.prototype.checkCollision = function(f) { if (!this.colliders || !f.colliders) { return } for (var e = 0; e < this.colliders.length; e++) { for (var d = 0; d < f.colliders.length; d++) { var c = Collision.getCollision(this.colliders[e], f.colliders[d]); if (this.colliders[e].colliding) { this.colliders[e].lastCollisionObject = f } if (f.colliders[d].colliding) { f.colliders[d].lastCollisionObject = this } if (c) { this.onCollision(c, f); c.directionX *= -1; c.directionY *= -1; f.onCollision(c, this) } } } }; RoadBlock.prototype.onCollision = function(l, g) { if (!this.collisionEnabled || this.immovable) { return } if (!this.knockedOver) { this.children[0].sprite = content.blockFallen; this.children[0].originX = this.children[0].sprite.width * 0.5; this.children[0].originY = this.children[0].sprite.height * 0.35 } if (!this.colliders) { this.collisionEnabled = false; return } this.x += l.directionX * l.magnitude; this.y += l.directionY * l.magnitude; if (this.mass == 0) { return } var d = this.velocityX - g.velocityX; var c = this.velocityY - g.velocityY; var k = (d * l.directionX) + (c * l.directionY); var a = Math.min(this.restitution, g.restitution); var h = -(1 + a) * k; if (g.mass == 0) { h /= (1 / this.mass) } else { h /= (1 / this.mass) + (1 / g.mass) } var e = h * l.directionX; var b = h * l.directionY; var f = 1 / this.mass; this.collisionVelocityAccumulatorX += f * e; this.collisionVelocityAccumulatorY += f * b; this.updateColliders(); if (!soundMuted && PlayerCar.prototype.isPrototypeOf(g)) { var i = "roadBlockHit"; playSound(i) } }; function Wrench() { SceneObject.call(this) } Wrench.prototype = new SceneObject(); Wrench.prototype.constructor = Wrench; Wrench.prototype.init = function(a, f, c) { this.x = a; this.y = f; this.gameState = c; this.children = []; this.childCount = 0; this.toBeRemoved = false; this.useCamera = true; this.collider = null; this.collisionEnabled = true; this.mass = 0; this.restitution = 1; this.immovable = true; this.contactLessCollision = false; this.colliders = []; var b = new CircleCollider(); b.init(this.x, this.y, 64); b.sensor = true; this.colliders.push(b); this.updateColliders(); var e = new Drawable(); e.init(content.wrenchStar, 0, 0); e.originX = e.sprite.width * 0.5; e.originY = e.sprite.height * 0.5; this.addChild(e); e = new Drawable(); e.init(content.wrench, 0, 0); e.originX = e.sprite.width * 0.5; e.originY = e.sprite.height * 0.5; this.addChild(e); this.depth = -0.1 + randFloatRange(-0.01, 0.01); this.pulseSine = 0; this.wrenchActive = true }; Wrench.prototype.update = function(b) { this.updateColliders(); this.pulseSine += b * 4; while (this.pulseSine > Math.PI * 2) { this.pulseSine -= Math.PI * 2 } this.children[1].scaleX = 1 + Math.sin(this.pulseSine) * 0.025; this.children[1].scaleY = this.children[1].scaleX; this.children[0].angle += b; while (this.children[0].angle > Math.PI * 2) { this.children[0].angle -= Math.PI * 2 } for (var a = 0; a < this.childCount; a++) { this.children[a].update(b) } }; Wrench.prototype.updateColliders = function() { if (!this.colliders) { return } this.colliders[0].x = this.x; this.colliders[0].y = this.y }; Wrench.prototype.onPickup = function() { this.wrenchActive = false; this.flagForRemoval(); if (!soundMuted) { var c = "wrench"; playSound(c) } for (var d = 0; d < 8; d++) { var b = new Particle(); b.init(content.wrenchParticle, randFloatRange(0.5, 1)); b.x = this.x; b.y = this.y; b.originX = b.sprite.width * 0.5; b.originY = b.sprite.height * 0.5; var e = randFloatRange(0.75, 1.25) * 1.5; b.startScaleX = e; b.startScaleY = e; b.endScaleX = 0; b.endScaleY = 0; b.startAlpha = 1; b.endAlpha = 0; b.depth = -0.8; b.dragX = 0.001; b.dragY = 0.001; var f = randFloatRange(0, Math.PI * 2); var a = randFloatRange(5, 15) * 0.5; b.velocityX = Math.cos(f) * a; b.velocityY = Math.sin(f) * a; b.start(); this.sceneManager.addEntity(b) } }; function GameGenerator() {} GameGenerator.prototype = new GameGenerator(); GameGenerator.prototype.constructor = GameGenerator; GameGenerator.prototype.init = function(a) { this.gameState = a; this.rockDistanceTime = 32; this.rockDistanceTimer = this.rockDistanceTime * randFloatRange(0, 1); this.rockChance = 0.15; this.truckStartDistance = 1200; this.copStartDistance = 2750; this.regularCarChance = 0.005; this.truckChance = 0.002; this.copChance = 0.001; this.truckCrateDropStartDistance = this.truckStartDistance + 800; this.truckExplosiveCrateStartDistance = this.truckCrateDropStartDistance + 1000; this.wallStartDistance = 3300; this.wallDistanceTime = 800; this.wallDistanceTimer = this.wallDistanceTime * randFloatRange(0, 1); this.wallChance = 0.2; this.potholeStartDistance = 650; this.potholeDistanceTime = 256; this.potholeDistanceTimer = this.potholeDistanceTime * randFloatRange(0, 1); this.oilStartDistance = 2350; this.oilDistanceTime = 512; this.oilDistanceTimer = this.oilDistanceTime * randFloatRange(0, 1); this.dirtRoadStartDistance = 1400; this.dirtRoadDistanceTime = 2048; this.dirtRoadDistanceTimer = this.dirtRoadDistanceTime * randFloatRange(0, 1); this.dirtRoadChance = 0.25; this.roadBlockStartDistance = 225; this.roadBlockDistanceTime = 512; this.roadBlockDistanceTimer = this.roadBlockDistanceTime * randFloatRange(0, 1); this.wrenchStartDistance = 0; this.wrenchDistanceTime = 1024; this.wrenchDistanceTimer = this.wrenchDistanceTime * randFloatRange(0, 1); this.wrenchChance = 0.075; this.truckDistanceTime = 512; this.truckDistanceTimer = this.truckDistanceTime * randFloatRange(0, 1); this.copDistanceTime = 512; this.copDistanceTimer = this.copDistanceTime * randFloatRange(0, 1); this.lastCameraY = 0; this.diffY = 0; this.distance = 0 }; GameGenerator.prototype.reset = function() {}; GameGenerator.prototype.update = function(a) { if (this.gameState.playState != PlayState.GAME) { return } this.diffY = Math.max(0, this.gameState.sceneManager.camera.positionY - this.lastCameraY); this.lastCameraY = this.gameState.sceneManager.camera.positionY; this.distance = this.gameState.hud.distance; this.updateCarSpawning(a); this.updateObstacleSpawning(a); this.updateDetritusSpawning(a) }; GameGenerator.prototype.updateCarSpawning = function(b) { if (this.distance < this.truckStartDistance) { this.spawnRegularCar(b) } else { if (this.distance < this.copStartDistance) { if (randFloatRange(0, 1) < 0.5) { this.spawnRegularCar(b) } else { this.spawnTruck(b) } } else { var a = randFloatRange(0, 1); if (a < 0.33) { this.spawnRegularCar(b) } else { if (a < 0.66) { this.spawnTruck(b) } else { this.spawnCop(b) } } } } }; GameGenerator.prototype.spawnRegularCar = function(b) { if (this.gameState.cars.length < 7 && randFloatRange(0, 1) < this.regularCarChance) { var a = new Car(); a.init(randFloatRange(0, 1) < 0.5 ? 80 : -80, -this.gameState.sceneManager.camera.positionY - 768, this.gameState); this.gameState.sceneManager.addEntity(a); this.gameState.cars.push(a); a.setDesiredState(CarState.CRUSING) } }; GameGenerator.prototype.spawnTruck = function(a) { if (this.gameState.cars.length < 7 && randFloatRange(0, 1) < this.truckChance) { var b = new Truck(); b.init(randFloatRange(0, 1) < 0.5 ? 80 : -80, -this.gameState.sceneManager.camera.positionY - 768, this.gameState); this.gameState.sceneManager.addEntity(b); this.gameState.cars.push(b); b.setDesiredState(CarState.CRUSING); if (this.distance >= this.truckCrateDropStartDistance) { b.crateDroppingActive = true } if (this.distance >= this.truckExplosiveCrateStartDistance) { b.explodingCrates = true } } }; GameGenerator.prototype.spawnCop = function(a) { if (this.gameState.cars.length < 7 && randFloatRange(0, 1) < this.copChance) { var b = new CopCar(); b.init(randFloatRange(0, 1) < 0.5 ? 80 : -80, -this.gameState.sceneManager.camera.positionY - 768, this.gameState); this.gameState.sceneManager.addEntity(b); this.gameState.cars.push(b); b.setDesiredState(CarState.CRUSING) } }; GameGenerator.prototype.updateObstacleSpawning = function(a) { if (this.distance > this.roadBlockStartDistance) { this.spawnRoadBlock(a) } if (this.distance > this.dirtRoadStartDistance) { this.spawnDirtRoadSection(a) } if (this.distance > this.oilStartDistance) { this.spawnOil(a) } if (this.distance > this.potholeStartDistance) { this.spawnPothole(a) } if (this.distance > this.wallStartDistance) { this.spawnWall(a) } if (this.distance > this.wrenchStartDistance) { this.spawnWrench(a) } }; GameGenerator.prototype.spawnRoadBlock = function(b) { this.roadBlockChance = 0.35; if (this.distance > 650) { this.roadBlockChance = 0.175 } this.roadBlockDistanceTimer -= this.diffY; if (this.roadBlockDistanceTimer <= 0) { this.roadBlockDistanceTimer = this.roadBlockDistanceTime; if (randFloatRange(0, 1) <= this.roadBlockChance) { var a = new RoadBlock(); a.init((randFloatRange(0, 1) < 0.5 ? -1 : 1) * 80, -this.gameState.sceneManager.camera.positionY - 512, this.gameState); this.gameState.sceneManager.addEntity(a); this.gameState.roadBlocks.push(a) } } }; GameGenerator.prototype.spawnDirtRoadSection = function(a) { if (!this.gameState.road.dirtRoad) { this.dirtRoadDistanceTimer -= this.diffY; if (this.dirtRoadDistanceTimer <= 0) { this.dirtRoadDistanceTimer = this.dirtRoadDistanceTime; if (randFloatRange(0, 1) <= this.dirtRoadChance) { this.gameState.road.startDirtRoad(this.gameState.sceneManager.camera.positionY + 1600, randFloatRange(512, 2048)) } } } }; GameGenerator.prototype.spawnOil = function(a) { this.oilChance = 0.25; if (this.distance > 2800) { this.oilChance = 0.075 } this.oilDistanceTimer -= this.diffY; if (this.oilDistanceTimer <= 0) { this.oilDistanceTimer = this.oilDistanceTime; if (randFloatRange(0, 1) <= this.oilChance) { var b = new Oil(); b.init((randFloatRange(0, 1) < 0.5 ? -1 : 1) * 80, -this.gameState.sceneManager.camera.positionY - 512, this.gameState); this.gameState.sceneManager.addEntity(b); this.gameState.oilSlicks.push(b) } } }; GameGenerator.prototype.spawnPothole = function(a) { if (this.gameState.road.dirtRoad) { return } this.potholeChance = 0.25; if (this.distance > 1250) { this.potholeChance = 0.05 } this.potholeDistanceTimer -= this.diffY; if (this.potholeDistanceTimer <= 0) { this.potholeDistanceTimer = this.potholeDistanceTime; if (randFloatRange(0, 1) <= this.potholeChance) { var b = new Pothole(); b.init((randFloatRange(0, 1) < 0.5 ? -1 : 1) * 80, -this.gameState.sceneManager.camera.positionY - 512, this.gameState); this.gameState.sceneManager.addEntity(b); this.gameState.potholes.push(b) } } }; GameGenerator.prototype.spawnWall = function(b) { this.wallDistanceTimer -= this.diffY; if (this.wallDistanceTimer <= 0) { this.wallDistanceTimer = this.wallDistanceTime; if (randFloatRange(0, 1) <= this.wallChance) { var a = new Wall(); a.init((randFloatRange(0, 1) < 0.5 ? -1 : 1) * 80, -this.gameState.sceneManager.camera.positionY - 512, this.gameState); this.gameState.sceneManager.addEntity(a); this.gameState.walls.push(a) } } }; GameGenerator.prototype.spawnWrench = function(b) { if (this.gameState.player.hitCount <= 0) { return } this.wrenchDistanceTimer -= this.diffY; if (this.wrenchDistanceTimer <= 0) { this.wrenchDistanceTimer = this.wrenchDistanceTime; if (randFloatRange(0, 1) <= this.wrenchChance) { var a = new Wrench(); a.init((randFloatRange(0, 1) < 0.5 ? -1 : 1) * 80, -this.gameState.sceneManager.camera.positionY - 512, this.gameState); this.gameState.sceneManager.addEntity(a); this.gameState.wrenches.push(a) } } }; GameGenerator.prototype.updateDetritusSpawning = function(b) { this.rockDistanceTimer -= this.diffY; if (this.rockDistanceTimer <= 0) { this.rockDistanceTimer = this.rockDistanceTime; if (randFloatRange(0, 1) <= this.rockChance) { var c = new Drawable(); var a; switch (randIntRange(0, 4)) { case 0: a = content.rock01; break; case 1: a = content.rock02; break; case 2: a = content.rock03; break; case 3: a = content.rock04; break } if (randFloatRange(0, 1) < 0.5) { c.init(a, -200 - randFloatRange(0, 32), -this.gameState.sceneManager.camera.positionY - 512) } else { c.init(a, 200 + randFloatRange(0, 32), -this.gameState.sceneManager.camera.positionY - 512) } c.originX = c.sprite.width * 0.5; if (randFloatRange(0, 1) < 0.5) { c.scaleX = -1 } this.gameState.sceneManager.addEntity(c); this.gameState.detritus.push(c) } } };