| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- var s_iScaleFactor = 1;
- var s_bIsIphone = false;
- var s_oCanvasLeft;
- var s_oCanvasTop;
- var s_bFocus = true;
- var browserName = (function (agent) { switch (true) {
- case agent.indexOf("edge") > -1: return "MS Edge";
- case agent.indexOf("edg/") > -1: return "Edge ( chromium based)";
- case agent.indexOf("opr") > -1 && !!window.opr: return "Opera";
- case agent.indexOf("chrome") > -1 && !!window.chrome: return "Chrome";
- case agent.indexOf("trident") > -1: return "MS IE";
- case agent.indexOf("firefox") > -1: return "Mozilla Firefox";
- case agent.indexOf("safari") > -1: return "Safari";
- default: return "other";
- }
- })(window.navigator.userAgent.toLowerCase());
- window.addEventListener('resize', function(event) {
- sizeHandler();
- }, true);
- function trace(szMsg){
- console.log(szMsg);
- }
- function isChrome(){
- var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
- return isChrome;
- }
- function isIpad() {
- var isIpad = navigator.userAgent.toLowerCase().indexOf('ipad') !== -1;
- if (!isIpad && navigator.userAgent.match(/Mac/) && navigator.maxTouchPoints && navigator.maxTouchPoints > 2) {
- return true;
- }
- return isIpad;
- }
-
- function isMobile(){
- if(isIpad()){
- return true;
- }
-
- if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) {
- //MOBILE
- return true;
- }else{
- //DESKTOP
- return false;
- }
- };
- function isIOS() {
- var iDevices = [
- 'iPad Simulator',
- 'iPhone Simulator',
- 'iPod Simulator',
- 'iPad',
- 'iPhone',
- 'iPod'
- ];
- if (navigator.userAgent.toLowerCase().indexOf("iphone") !== -1){
- s_bIsIphone = true;
- return true;
- }
-
- while (iDevices.length) {
- if (navigator.platform === iDevices.pop()){
-
-
- return true;
- }
- }
- s_bIsIphone = false;
- return false;
- }
- function getSize(Name) {
- var size;
- var name = Name.toLowerCase();
- var document = window.document;
- var documentElement = document.documentElement;
- if (window["inner" + Name] === undefined) {
- // IE6 & IE7 don't have window.innerWidth or innerHeight
- size = documentElement["client" + Name];
- }
- else if (window["inner" + Name] != documentElement["client" + Name]) {
- // WebKit doesn't include scrollbars while calculating viewport size so we have to get fancy
- // Insert markup to test if a media query will match document.doumentElement["client" + Name]
- var bodyElement = document.createElement("body");
- bodyElement.id = "vpw-test-b";
- bodyElement.style.cssText = "overflow:scroll";
- var divElement = document.createElement("div");
- divElement.id = "vpw-test-d";
- divElement.style.cssText = "position:absolute;top:-1000px";
- // Getting specific on the CSS selector so it won't get overridden easily
- divElement.innerHTML = "<style>@media(" + name + ":" + documentElement["client" + Name] + "px){body#vpw-test-b div#vpw-test-d{" + name + ":7px!important}}</style>";
- bodyElement.appendChild(divElement);
- documentElement.insertBefore(bodyElement, document.head);
- if (divElement["offset" + Name] == 7) {
- // Media query matches document.documentElement["client" + Name]
- size = documentElement["client" + Name];
- }
- else {
- // Media query didn't match, use window["inner" + Name]
- size = window["inner" + Name];
- }
- // Cleanup
- documentElement.removeChild(bodyElement);
- }
- else {
- // Default to use window["inner" + Name]
- size = window["inner" + Name];
- }
- return size;
- };
- window.addEventListener("orientationchange", onOrientationChange);
- function onOrientationChange(){
- if (window.matchMedia("(orientation: portrait)").matches) {
- // you're in PORTRAIT mode
- sizeHandler();
- }
- if (window.matchMedia("(orientation: landscape)").matches) {
- // you're in LANDSCAPE mode
- sizeHandler();
- }
- }
- function getIOSWindowHeight() {
- // Get zoom level of mobile Safari
- // Note, that such zoom detection might not work correctly in other browsers
- // We use width, instead of height, because there are no vertical toolbars :)
- var zoomLevel = document.documentElement.clientWidth / window.innerWidth;
- // window.innerHeight returns height of the visible area.
- // We multiply it by zoom and get out real height.
- return window.innerHeight * zoomLevel;
- };
- // You can also get height of the toolbars that are currently displayed
- function getHeightOfIOSToolbars() {
- var tH = (window.orientation === 0 ? screen.height : screen.width) - getIOSWindowHeight();
- return tH > 1 ? tH : 0;
- };
- //THIS FUNCTION MANAGES THE CANVAS SCALING TO FIT PROPORTIONALLY THE GAME TO THE CURRENT DEVICE RESOLUTION
- function sizeHandler() {
- window.scrollTo(0, 1);
-
- if (!document.querySelector("#canvas")){
- return;
- }
- var h;
- if(platform.name !== null && platform.name.toLowerCase() === "safari"){
- h = getIOSWindowHeight();
- } else{
- h = getSize("Height");
- }
- var w = getSize("Width");
- if(s_bFocus){
- _checkOrientation(w,h);
- }
- var multiplier = Math.min((h / CANVAS_HEIGHT), (w / CANVAS_WIDTH));
- var destW = Math.round( CANVAS_WIDTH * multiplier );
- var destH = Math.round( CANVAS_HEIGHT * multiplier );
- var iAdd = 0;
- if (destH < h){
- iAdd = h - destH;
- destH += iAdd;
- destW += iAdd * (CANVAS_WIDTH / CANVAS_HEIGHT);
- } else if (destW < w){
- iAdd = w - destW;
- destW += iAdd;
- destH += iAdd * (CANVAS_HEIGHT / CANVAS_WIDTH);
- }
- var fOffsetY = ((h / 2) - (destH / 2));
- var fOffsetX = ((w / 2) - (destW / 2));
- var fGameInverseScaling = (CANVAS_WIDTH / destW);
- if (fOffsetX * fGameInverseScaling < - EDGEBOARD_X ||
- fOffsetY * fGameInverseScaling < - EDGEBOARD_Y){
- multiplier = Math.min(h / (CANVAS_HEIGHT - (EDGEBOARD_Y * 2)), w / (CANVAS_WIDTH - (EDGEBOARD_X * 2)));
- destW = Math.round( CANVAS_WIDTH * multiplier );
- destH = Math.round( CANVAS_HEIGHT * multiplier );
- fOffsetY = (h - destH) / 2;
- fOffsetX = (w - destW) / 2;
- fGameInverseScaling = (CANVAS_WIDTH / destW);
- }
- s_iOffsetX = ( - 1 * fOffsetX * fGameInverseScaling);
- s_iOffsetY = ( - 1 * fOffsetY * fGameInverseScaling);
- if (fOffsetY >= 0){
- s_iOffsetY = 0;
- }
- if (fOffsetX >= 0){
- s_iOffsetX = 0;
- }
- if (s_oInterface !== null){
- s_oInterface.refreshButtonPos(s_iOffsetX, s_iOffsetY);
- }
- if (s_oMenu !== null){
- s_oMenu.refreshButtonPos(s_iOffsetX, s_iOffsetY);
- }
- if (s_oLevelMenu !== null){
- s_oLevelMenu.refreshButtonPos(s_iOffsetX, s_iOffsetY);
- }
- if(s_bIsIphone && s_oStage){
- canvas = document.getElementById('canvas');
- s_oStage.canvas.width = destW*2;
- s_oStage.canvas.height = destH*2;
- canvas.style.width = destW+"px";
- canvas.style.height = destH+"px";
- s_iScaleFactor = Math.min(destW / CANVAS_WIDTH, destH / CANVAS_HEIGHT);
- s_iScaleFactor *= 2;
- s_oStage.scaleX = s_oStage.scaleY = s_iScaleFactor;
- }else if(s_bMobile || isChrome()){
- document.querySelector("#canvas").style.width = destW+"px";
- document.querySelector("#canvas").style.height = destH+"px";
- }else if(s_oStage){
- s_oStage.canvas.width = destW;
- s_oStage.canvas.height = destH;
- s_iScaleFactor = Math.min(destW / CANVAS_WIDTH, destH / CANVAS_HEIGHT);
- s_oStage.scaleX = s_oStage.scaleY = s_iScaleFactor;
- }
- if(fOffsetY >= 0){
- fOffsetY = (h - destH)/2;
- }
- document.querySelector("#canvas").style.top = fOffsetY+"px";
- document.querySelector("#canvas").style.left = fOffsetX+"px";
- fullscreenHandler();
- };
-
-
- function createBitmap(oSprite, iWidth, iHeight){
- var oBmp = new createjs.Bitmap(oSprite);
- var hitObject = new createjs.Shape();
- if (iWidth && iHeight){
- hitObject.graphics.beginFill("#fff").drawRect(0, 0, iWidth, iHeight);
- } else{
- hitObject.graphics.beginFill("#ff0").drawRect(0, 0, oSprite.width, oSprite.height);
- }
- oBmp.hitArea = hitObject;
- return oBmp;
- }
- function _checkOrientation(iWidth,iHeight){
- if(s_bMobile && ENABLE_CHECK_ORIENTATION){
- if( iWidth>iHeight ){
- if( document.querySelector(".orientation-msg-container").getAttribute("data-orientation") === "landscape" ){
- document.querySelector(".orientation-msg-container").style.display = "none";
- s_oMain.startUpdate();
- }else{
- document.querySelector(".orientation-msg-container").style.display = "block";
- s_oMain.stopUpdate();
- }
- }else{
- if( document.querySelector(".orientation-msg-container").getAttribute("data-orientation") === "portrait" ){
- document.querySelector(".orientation-msg-container").style.display = "none";
- s_oMain.startUpdate();
- }else{
- document.querySelector(".orientation-msg-container").style.display = "block";
- s_oMain.stopUpdate();
- }
- }
- }
- }
- function createSprite(oSpriteSheet, szState, iRegX, iRegY, iWidth, iHeight){
- if (szState !== null){
- var oRetSprite = new createjs.Sprite(oSpriteSheet, szState);
- } else{
- var oRetSprite = new createjs.Sprite(oSpriteSheet);
- }
- var hitObject = new createjs.Shape();
- hitObject.graphics.beginFill("#000000").drawRect( - iRegX, - iRegY, iWidth, iHeight);
- oRetSprite.hitArea = hitObject;
- return oRetSprite;
- }
- function randomFloatBetween(minValue, maxValue, precision){
- if (typeof (precision) === 'undefined'){
- precision = 2;
- }
- return parseFloat(Math.min(minValue + (Math.random() * (maxValue - minValue)), maxValue).toFixed(precision));
- }
- function formatTime(iTime){
- iTime /= 1000;
- var iMins = Math.floor(iTime / 60);
- var iSecs = Math.floor(iTime - (iMins * 60));
- //iSecs = parseFloat(iSecs).toFixed(1)
- var szRet = "";
- if (iMins < 10){
- szRet += "0" + iMins + ":";
- } else{
- szRet += iMins + ":";
- }
- if (iSecs < 10){
- szRet += "0" + iSecs;
- } else{
- szRet += iSecs;
- }
- return szRet;
- }
- function NoClickDelay(el) {
- this.element = el;
- if (window.Touch) this.element.addEventListener('touchstart', this, false);
- }
- //Fisher-Yates Shuffle
- function shuffle(array) {
- var counter = array.length, temp, index;
- // While there are elements in the array
- while (counter > 0) {
- // Pick a random index
- index = Math.floor(Math.random() * counter);
- // Decrease counter by 1
- counter--;
- // And swap the last element with it
- temp = array[counter];
- array[counter] = array[index];
- array[index] = temp;
- }
- return array;
- }
- NoClickDelay.prototype = {
- handleEvent: function(e) {
- switch (e.type) {
- case 'touchstart': this.onTouchStart(e); break;
- case 'touchmove': this.onTouchMove(e); break;
- case 'touchend': this.onTouchEnd(e); break;
- }
- },
- onTouchStart: function(e) {
- e.preventDefault();
- this.moved = false;
- this.element.addEventListener('touchmove', this, false);
- this.element.addEventListener('touchend', this, false);
- },
- onTouchMove: function(e) {
- this.moved = true;
- },
- onTouchEnd: function(e) {
- this.element.removeEventListener('touchmove', this, false);
- this.element.removeEventListener('touchend', this, false);
- if (!this.moved) {
- var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
- if (theTarget.nodeType == 3) theTarget = theTarget.parentNode;
- var theEvent = document.createEvent('MouseEvents');
- theEvent.initEvent('click', true, true);
- theTarget.dispatchEvent(theEvent);
- }
- }
- };
- function toRadian(n) {
- return ((n) * (Math.PI / 180));
- }
- function toDegree(n) {
- return ((n) * (180 / Math.PI));
- }
- function ctlArcadeResume(){
- if (s_oMain !== null){
- s_oMain.startUpdate();
- }
- }
- function ctlArcadePause(){
- if (s_oMain !== null){
- s_oMain.stopUpdate();
- }
- }
- function getParamValue(paramName){
- var url = window.location.search.substring(1);
- var qArray = url.split('&');
- for (var i = 0; i < qArray.length; i++)
- {
- var pArr = qArray[i].split('=');
- if (pArr[0] == paramName)
- return pArr[1];
- }
- }
- function playSound(szSound,iVolume,bLoop){
- if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
- s_aSounds[szSound].play();
- s_aSounds[szSound].volume(iVolume);
- s_aSounds[szSound].loop(bLoop);
- return s_aSounds[szSound];
- }
- return null;
- }
- function stopSound(szSound){
- if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
- s_aSounds[szSound].stop();
- }
- }
- function setVolume(szSound, iVolume){
- if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
- s_aSounds[szSound].volume(iVolume);
- }
- }
- function setMute(szSound, bMute){
- if(DISABLE_SOUND_MOBILE === false || s_bMobile === false){
- s_aSounds[szSound].mute(bMute);
- }
- }
- (function() {
- var hidden = "hidden";
- // Standards:
- if (hidden in document)
- document.addEventListener("visibilitychange", onchange);
- else if ((hidden = "mozHidden") in document)
- document.addEventListener("mozvisibilitychange", onchange);
- else if ((hidden = "webkitHidden") in document)
- document.addEventListener("webkitvisibilitychange", onchange);
- else if ((hidden = "msHidden") in document)
- document.addEventListener("msvisibilitychange", onchange);
- // IE 9 and lower:
- else if ('onfocusin' in document)
- document.onfocusin = document.onfocusout = onchange;
- // All others:
- else
- window.onpageshow = window.onpagehide
- = window.onfocus = window.onblur = onchange;
- function onchange (evt) {
- var v = 'visible', h = 'hidden',
- evtMap = {
- focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
- };
- evt = evt || window.event;
-
- if (evt.type in evtMap){
- document.body.className = evtMap[evt.type];
- }else{
- document.body.className = this[hidden] ? "hidden" : "visible";
- if(document.body.className === "hidden"){
- s_oMain.stopUpdate();
- s_bFocus = false;
- }else{
- s_oMain.startUpdate();
- s_bFocus = true;
- }
- }
-
-
-
- }
- })();
- function fullscreenHandler(){
- if (!ENABLE_FULLSCREEN || !screenfull.isEnabled){
- return;
- }
-
- s_bFullscreen = screenfull.isFullscreen;
- if (s_oInterface !== null){
- s_oInterface.resetFullscreenBut();
- }
- if (s_oMenu !== null){
- s_oMenu.resetFullscreenBut();
- }
- }
- if (screenfull.isEnabled) {
- screenfull.on('change', function(){
- s_bFullscreen = screenfull.isFullscreen;
- if (s_oInterface !== null){
- s_oInterface.resetFullscreenBut();
- }
- if (s_oMenu !== null){
- s_oMenu.resetFullscreenBut();
- }
- });
- }
- function saveItem(szItem,oValue){
- if(s_bStorageAvailable){
- localStorage.setItem(szItem, oValue);
- }
- }
- function getItem(szItem){
- if(s_bStorageAvailable){
- return localStorage.getItem(szItem);
- }
- return null;
- }
|