Файловый менеджер - Редактировать - /home/jogoso94/public_html/jogos/zoko/assets/zoko.js
�азад
/* (c) Samuel Nilsson/Sebastian Viklund - The Zoko code is licensed under MIT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ function nowebgl(){$('#btn-group').html('<a class="icon-btn" style="font-size:20px;">Your browser does not support WebGL - Please use Chrome or Firefox</a>').css('width', '750px');};window.focus(); var BoxBlock,BoxObject,Camera,CameraController,EmptyBlock,Game,Highscore,LevelState,LevelView,LiftBlock,LiftObject,Observable,PlatformBlock,Player,PlayerController,PlayerObject,SkyObject,SolidBlock,StaticLevelObject,UI,Zoko,createTextures,e3d,loadFilesUsing,loadImageFile,loadImageFiles,loadJsonFile,loadJsonFiles,loadResourceFiles,makeBackFace,makeBox,makeFrontFace,makeLeftFace,makeLidlessBox,makeQuad,makeRightFace,makeTopFace,mat,resource_dir,vec,__hasProp={}.hasOwnProperty,__extends=function(n,t){function r(){this.constructor=n}for(var i in t)__hasProp.call(t,i)&&(n[i]=t[i]);return r.prototype=t.prototype,n.prototype=new r,n.__super__=t.prototype,n},__indexOf=[].indexOf||function(n){for(var t=0,i=this.length;t<i;t++)if(t in this&&this[t]===n)return t;return-1};Observable=function(){function n(){}return n.prototype.notifyObservers=function(){var i,n,u,r,t;if(this.observers!=null){for(r=this.observers,t=[],n=0,u=r.length;n<u;n++)i=r[n],i!=null?t.push(i.update(this,arguments)):t.push(void 0);return t}},n}(),CameraController=function(){function n(n,t){var e,i,r,u,f;e=n.camera,i=!1,r=0,u=0,f=.01;$(t).on("mousedown",function(n){return i=!0,r=n.screenX,u=n.screenY});$(document).on("mouseup",function(){return i=!1}).on("mousemove",function(n){var t,o;if(i)return t=(n.screenX-r)*f,o=(n.screenY-u)*f,e.rotate(t,o),r=n.screenX,u=n.screenY})}return n}(),Game=function(n){function t(n){this.levelView=n,this.currentLevel=1,this.numLevels=5,this.loadCurrentLevel(),this.solvedLevels=[],this.highscore=new Highscore}var i;return __extends(t,n),i=function(n,t){for(var i=""+n;i.length<t;)i="0"+i;return i},t.prototype.newGame=function(){},t.prototype.restartLevel=function(){return this.loadCurrentLevel()},t.prototype.nextLevel=function(){return this.currentLevel++,this.currentLevel>this.numLevels&&(this.currentLevel=1),this.loadCurrentLevel()},t.prototype.previousLevel=function(){return this.currentLevel--,this.currentLevel<0&&(this.currentLevel=this.numLevels),this.loadCurrentLevel()},t.prototype.loadCurrentLevel=function(){var n,t;return t="levels/"+i(this.currentLevel,2)+".json",n=this,loadJsonFile(t,function(t){var i;return i=new LevelState(t),i.onUpdate=function(){return n.notifyObservers(i)},i.observers=[n.levelView],i.notifyObservers()})},t}(Observable),Highscore=function(){function n(){this.list=this.getHighscoreObj()}return n.prototype.getHighscoreObj=function(){var n;try{n=localStorage.getItem("highscore");return(n!=null?JSON.parse(n):{"1":0,"2":0,"3":0,"4":0,"5":0});}catch(e){n={"1":0,"2":0,"3":0,"4":0,"5":0};return n;}},n.prototype.setHighscore=function(n,t){try{var i;return i=this.list[n],i>t||i===0?(this.list[n]=t,localStorage.setItem("highscore",JSON.stringify(this.list))):void 0}catch(e){}},n.prototype.getHighscore=function(n){return this.list[n]},n}(),EmptyBlock=function(){function n(n,t){this.level=n,this.position=t}return n.prototype.type="empty",n.prototype.static=!1,n.prototype.move=function(){var n;return n=this.level.blockBelow(this.position),n.type!=="empty"},n.prototype.update=function(){return!1},n}(),SolidBlock=function(){function n(){}return n.prototype.type="solid",n.prototype.static=!0,n.prototype.move=function(){return!1},n.prototype.update=function(){return!1},n}(),PlatformBlock=function(){function n(){}return n.prototype.type="platform",n.prototype.static=!0,n.prototype.move=function(){return!1},n.prototype.update=function(){return!1},n}(),BoxBlock=function(){function n(n,t){this.level=n,this.position=t}return n.prototype.type="box",n.prototype.static=!1,n.prototype.move=function(n,t){var u,i,r;return t>=1&&(i=this.position,r=vec.add(i,n),this.level.blockAt(r).move(n,t-1))?(u=vec.add(i,[0,0,1]),this.level.blockAt(u).move(n,t),this.level.swapBlocksAt(i,r),!0):!1},n.prototype.update=function(){var n;return n=1,this.move([0,0,-1],n)},n}(),LiftBlock=function(){function n(n,t){this.level=n,this.position=t,this.bottom=this.position[2],this.top=this.position[2]}return n.prototype.type="lift",n.prototype.static=!1,n.prototype.move=function(){return!1},n.prototype.update=function(){var t,i,u,f,n,r;if(r=[0,0,1],u=[0,0,-1],n=this.position,t=vec.add(n,r),i=vec.add(n,u),this.level.blockAt(t).type==="empty"){if(n[2]!==this.bottom&&this.level.blockAt(i).type==="empty")return this.level.swapBlocksAt(n,i),!0}else if(n[2]!==this.top&&(f=Infinity,this.level.blockAt(t).move(r,f)))return this.level.swapBlocksAt(n,t),!0;return!1},n}(),Player=function(){function n(n,t){this.level=n,this.position=t,this.direction=[0,1,0]}return n.prototype.type="player",n.prototype.static=!1,n.prototype.move=function(n,t){var i,r;return(n[2]===0&&(this.direction=n),i=this.position,r=vec.add(i,n),this.level.blockAt(r).move(n,t))?(this.level.swapBlocksAt(i,r),!0):!1},n.prototype.update=function(){var n;return n=1,this.move([0,0,-1],n)},n}(),LevelState=function(n){function t(n){var s,f,e,t,o,i,r,u;this.blockArray=function(){var f,c,h;for(h=[],u=f=0,c=n.length;f<c;u=++f)e=n[u],h.push(function(){var n,h,f;for(f=[],r=n=0,h=e.length;n<h;r=++n)o=e[r],f.push(function(){var f,e,n;for(n=[],i=f=0,e=o.length;f<e;i=++f){s=o[i],t=[i,r,u];switch(s){case"O":n.push(new SolidBlock);break;case"X":n.push(new PlatformBlock);break;case"#":n.push(new BoxBlock(this,t));break;case"^":n.push(new LiftBlock(this,t));break;case"S":n.push(this.player=new Player(this,t));break;default:n.push(new EmptyBlock(this,t))}}return n}.call(this));return f}.call(this));return h}.call(this),this.height=this.blockArray.length,this.depth=this.blockArray[0].length,this.width=this.blockArray[0][0].length,f=this,this.forEach("lift",function(n,t){var i;return i=f.blockBelow(t),i.type==="lift"?(i.top=t[2],f.setBlockAt(t,new EmptyBlock)):void 0}),this.steps=0,this.asleep=!1,this.solved=!1,this.onUpdate=function(){}}return __extends(t,n),t.prototype.forEach=function(n,t){var f,e,o,s,i,r,u,h,c,l,v,y,p,a;for(o=[],a=this.blockArray,u=h=0,v=a.length;h<v;u=++h)for(e=a[u],r=c=0,y=e.length;c<y;r=++c)for(s=e[r],i=l=0,p=s.length;l<p;i=++l)f=s[i],f.type===n&&o.push(t(f,[i,r,u]));return o},t.prototype.forEachBlock=function(n){var h,u,f,t,i,r,e,c,o,s;for(o=this.blockArray,s=[],r=e=0,c=o.length;e<c;r=++e)u=o[r],s.push(function(){var e,s,o;for(o=[],i=e=0,s=u.length;e<s;i=++e)f=u[i],o.push(function(){var u,o,e;for(e=[],t=u=0,o=f.length;u<o;t=++u)h=f[t],e.push(n(h,[t,i,r]));return e}());return o}());return s},t.prototype.blockAt=function(n){var t,i,r;return(t=n[0],i=n[1],r=n[2],t<0||t>=this.width)?new EmptyBlock(this,n):i<0||i>=this.depth?new EmptyBlock(this,n):r<0||r>=this.height?new EmptyBlock(this,n):this.blockArray[r][i][t]},t.prototype.blockBelow=function(n){var i,r,u,t;for(r=n[0],u=n[1],t=n[2];!(--t<0);)if(i=this.blockAt([r,u,t]),i.type!=="empty")return i;return new EmptyBlock(this,[r,u,t])},t.prototype.setBlockAt=function(n,t){var i,r,u;return t.level=this,t.position=n,i=n[0],r=n[1],u=n[2],this.blockArray[u][r][i]=t},t.prototype.swapBlocksAt=function(n,t){var i,r;return i=this.blockAt(n),r=this.blockAt(t),this.setBlockAt(n,r),this.setBlockAt(t,i)},t.prototype.movePlayer=function(n){var t,i;if(!(this.solved||this.asleep)&&(i=function(){switch(n){case"left":return[-1,0,0];case"up":return[0,-1,0];case"right":return[1,0,0];case"down":return[0,1,0]}}(),t=1,this.player.move(i,t)))return this.steps++,this.update(!0)},t.prototype.checkIfSolved=function(){var n,t;return n=!0,t=this,this.forEach("box",function(i,r){if(t.blockBelow(r).type!=="platform")return n=!1}),n===!0?this.solved=!0:void 0},t.prototype.update=function(n){var t;return n==null&&(n=!1),n===!1&&this.forEachBlock(function(t){return n=t.update()||n}),n?(this.onUpdate(),this.asleep=!0,t=this,this.notifyObservers(function(){return t.update()})):(this.checkIfSolved(),this.solved&&this.onUpdate(),this.asleep=!1),n},t}(Observable),PlayerController=function(){function i(t){var i;i=t.camera;$(document).on("keydown",function(r){var u,f,e;f=t.currState,e=i.rotation[2],u=n(e);switch(r.which){case 37:return f.movePlayer(u.left),!1;case 38:return f.movePlayer(u.up),!1;case 39:return f.movePlayer(u.right),!1;case 40:return f.movePlayer(u.down),!1}return!0})}var n,t;return t=[{left:"left",up:"up",right:"right",down:"down"},{left:"up",up:"right",right:"down",down:"left"},{left:"right",up:"down",right:"left",down:"up"},{left:"down",up:"left",right:"up",down:"right"}],n=function(n){var r,i,u;return u=n+Math.PI/4,i=u%(2*Math.PI),i<0&&(i=i+2*Math.PI),r=Math.floor(i/(Math.PI/2)),t[r]},i}(),resource_dir="assets/resources/",loadImageFile=function(n,t){var i;return i=new Image,i.onload=function(){return t(i)},i.src=resource_dir+n},loadJsonFile=function(n,t){var i;return i=new XMLHttpRequest,i.open("GET",resource_dir+n,!0),i.onreadystatechange=function(){var n;if(i.readyState===4)return n=JSON.parse(i.responseText),t(n)},i.send()},loadFilesUsing=function(n,t,i){var o,s,r,u,h,f,e;if(t instanceof Object==!1)return s=t,n(s,i);if(t instanceof Array)f=t.length,u=[];else{f=0;for(r in t)__hasProp.call(t,r)&&f++;u={}}h=0,e=[];for(r in t)__hasProp.call(t,r)&&(o=t[r],e.push(function(t){return loadFilesUsing(n,o,function(n){return u[t]=n,++h===f?i(u):void 0})}(r)));return e},loadImageFiles=function(n,t){return loadFilesUsing(loadImageFile,n,t)},loadJsonFiles=function(n,t){return loadFilesUsing(loadJsonFile,n,t)},loadResourceFiles=function(n,t){var r,u,i;return r=!1,u=!1,i={},loadImageFiles(n.images,function(n){return i.images=n,r=!0,u?t(i):void 0}),loadJsonFiles(n.json,function(n){return i.json=n,u=!0,r?t(i):void 0})},UI=function(){function n(n){$('#btn-group').html('<a id="menuBtn" class="icon-btn icon-home" title="Show Menu">Menu</a><a id="restartBtn" class="icon-btn icon-undo" title="Restart Level">Restart</a>');var t;this.game=n,this.stepsCounter=$("#steps"),this.levelCounter=$("#level").find(".levelNumber"),this.nextBtn=$("#nextBtn"),this.previousBtn=$("#previousBtn"),this.menu=$("#menu"),this.menu.hide(),this.menuTitle=this.menu.find(".title"),this.menuOverlay=$("#menuOverlay"),this.menuOverlay.hide(),this.menuShown=!1,this.continueBtn=$("#continueBtn"),this.continueBtn.hide(),this.restartBtn=$("#restartBtn"),this.menuBtn=$("#menuBtn"),this.highscoreTable=$(".highscore > .table"),t=this;this.nextBtn.on("click",function(){return t.menu.fadeOut(),t.menuOverlay.fadeOut(),t.menuShown=!1,n=t.game,n!=null?(n.nextLevel(),t.levelCounter.html(n.currentLevel),t.resetStepsCount()):void 0});this.previousBtn.on("click",function(){return t.menu.fadeOut(),t.menuOverlay.fadeOut(),t.menuShown=!1,n=t.game,n!=null?(n.previousLevel(),t.levelCounter.html(n.currentLevel),t.resetStepsCount()):void 0});this.restartBtn.on("click",function(){return n=t.game,n!=null&&!t.menuShown?(n.restartLevel(),t.resetStepsCount()):void 0});this.menuBtn.on("click",function(){var n,i;return t.menuShown?(t.menu.fadeOut(),t.menuOverlay.fadeOut(),t.menuShown=!1):(t.setMenuTitle("Options"),t.updateHighscoreTable(),t.continueBtn.show(),(n=t.game.currentLevel,__indexOf.call(t.game.solvedLevels,n)>=0)?t.nextBtn.show():t.nextBtn.hide(),(i=t.game.currentLevel-1,__indexOf.call(t.game.solvedLevels,i)>=0)?t.previousBtn.show():t.previousBtn.hide(),t.menuOverlay.fadeIn(),t.menu.fadeIn(),t.menuShown=!0)});this.continueBtn.on("click",function(){return t.menu.fadeOut(),t.menuOverlay.fadeOut(),t.menuShown=!1});$(document).on("keydown",function(i){switch(i.which){case 82:n=t.game,n==null||t.menuShown||(n.restartLevel(),t.resetStepsCount())}return!0})}return n.prototype.update=function(n,t){var i,r,u;return this.game=n,i=t[0],r=i.steps,i.solved&&(this.game.highscore.setHighscore(n.currentLevel,r),this.game.solvedLevels.push(this.game.currentLevel),this.continueBtn.hide(),this.setMenuTitle("Good job!"),this.updateHighscoreTable(),this.nextBtn.show(),(u=this.game.currentLevel-1,__indexOf.call(this.game.solvedLevels,u)>=0)?this.previousBtn.show():this.previousBtn.hide(),this.menuOverlay.fadeIn(),this.menu.fadeIn(),this.menuShown=!0),this.updateStepsCount(r)},n.prototype.showWinnerModal=function(){},n.prototype.updateStepsCount=function(n){return this.stepsCounter.html(n+" steps")},n.prototype.resetStepsCount=function(){return this.stepsCounter.html("0 steps")},n.prototype.setMenuTitle=function(n){return this.menuTitle.html(n)},n.prototype.updateHighscoreTable=function(){var n,t;return t=this.highscoreTable.find("tbody"),n=this,t.children().each(function(t,i){var r;return r=$(i).children("td").last(),r.html(n.game.highscore.getHighscore(t+1)+" steps")})},n}(),e3d=e3d||{},e3d.Camera=function(){function n(){this.position=[0,0,0],this.rotation=[0,0,0],this.distance=0}return n.prototype.createMatrix=function(){var t,i,r,u,n,f,e,o;return u=45,t=e3d.width/e3d.height,f=.1,r=100,i=[0,0,0],e=[0,-1,0],o=[0,0,1],n=mat.perspective(u,t,f,r),n=mat.lookat(n,i,e,o),n=mat.translate(n,[0,-this.distance,0]),n=mat.rotateX(n,-this.rotation[0]),n=mat.rotateY(n,-this.rotation[1]),n=mat.rotateZ(n,-this.rotation[2]),n=mat.translate(n,vec.neg(this.position))},n}(),e3d=e3d||{},e3d.init=function(n){var t;if(t=n.getContext("experimental-webgl",{alpha:!1}),t.enable(t.DEPTH_TEST),e3d.width=n.width,e3d.height=n.height,e3d.gl=t,e3d.scene=null,e3d.noTexture=new e3d.Texture(null),e3d.onrender=null,/\d/.test(location.host))return e3d.program.mesh.init()},e3d.run=function(){var n,t;return t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){return window.setTimeout(n,1e3/60)},n=function(){var i;return t(n),i=e3d.gl,i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),e3d.scene!=null&&e3d.scene.render(),e3d.onrender!=null?e3d.onrender():void 0},t(n)},mat={row:function(n,t){return[n[t*4+0],n[t*4+1],n[t*4+2],n[t*4+3]]},col:function(n,t){return[n[t+0],n[t+4],n[t+8],n[t+12]]},mul:function(n,t){var r,u,f,e,i,o,s,h,c;return r=mat.col(n,0),u=mat.col(n,1),f=mat.col(n,2),e=mat.col(n,3),o=mat.row(t,0),s=mat.row(t,1),h=mat.row(t,2),c=mat.row(t,3),i=vec.dot4,[i(r,o),i(u,o),i(f,o),i(e,o),i(r,s),i(u,s),i(f,s),i(e,s),i(r,h),i(u,h),i(f,h),i(e,h),i(r,c),i(u,c),i(f,c),i(e,c)]},translate:function(n,t){var i;return i=[1,0,0,0,0,1,0,0,0,0,1,0,t[0],t[1],t[2],1],mat.mul(n,i)},scale:function(n,t){var i;return i=[t[0],0,0,0,0,t[1],0,0,0,0,t[2],0,0,0,0,1],mat.mul(n,i)},rotateX:function(n,t){var i,u,r;return r=Math.sin(t),i=Math.cos(t),u=[1,0,0,0,0,i,r,0,0,-r,i,0,0,0,0,1],mat.mul(n,u)},rotateY:function(n,t){var i,u,r;return r=Math.sin(t),i=Math.cos(t),u=[i,0,r,0,0,1,0,0,-r,0,i,0,0,0,0,1],mat.mul(n,u)},rotateZ:function(n,t){var i,u,r;return r=Math.sin(t),i=Math.cos(t),u=[i,r,0,0,-r,i,0,0,0,0,1,0,0,0,0,1],mat.mul(n,u)},lookat:function(n,t,i,r){var o,s,f,e,u;return u=vec.unit(vec.sub(t,i)),f=vec.unit(vec.cross(u,r)),e=vec.unit(vec.cross(f,u)),o=vec.dot,s=[f[0],e[0],u[0],0,f[1],e[1],u[1],0,f[2],e[2],u[2],0,-o(f,t),-o(e,t),-o(u,t),1],mat.mul(n,s)},identity:function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},frustum:function(n,t,i,r,u,f){var e,o,s,h,c,l;return e=u*2/(t-n),o=u*2/(r-i),s=(t+n)/(t-n),h=(r+i)/(r-i),c=-(f+u)/(f-u),l=-(f*u*2)/(f-u),[e,0,0,0,0,o,0,0,s,h,c,-1,0,0,l,0]},perspective:function(n,t,i,r){var f,u;return u=i*Math.tan(n*Math.PI/360),f=u*t,mat.frustum(-f,f,-u,u,i,r)}},e3d=e3d||{},e3d.Mesh=function(){function n(n){var t,i;t=e3d.gl,i=e3d.program.mesh,this.vertexbuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.vertexbuffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array(n),t.STATIC_DRAW),this.nvertices=n.length/8}return n.prototype.render=function(){var n,t;return n=e3d.gl,t=e3d.program.mesh,n.bindBuffer(n.ARRAY_BUFFER,this.vertexbuffer),n.vertexAttribPointer(t.aPositionLoc,3,n.FLOAT,!1,32,0),n.vertexAttribPointer(t.aTexCoordLoc,2,n.FLOAT,!1,32,12),n.vertexAttribPointer(t.aColorLoc,3,n.FLOAT,!1,32,20),n.drawArrays(n.TRIANGLES,0,this.nvertices)},n}(),e3d=e3d||{},e3d.Object=function(){function n(){this.position=[0,0,0],this.rotation=[0,0,0],this.scale=[1,1,1],this.meshes=[],this.textures=[],this.children=[]}return n.prototype.render=function(n){var u,a,t,f,h,e,i,c,l,o,s,r;for(a=e3d.gl,h=e3d.program.mesh,n=mat.translate(n,this.position),n=mat.rotateX(n,this.rotation[0]),n=mat.rotateY(n,this.rotation[1]),n=mat.rotateZ(n,this.rotation[2]),n=mat.scale(n,this.scale),h.setMatrix(n),e3d.noTexture.use(),o=this.meshes,t=e=0,c=o.length;e<c;t=++e)f=o[t],f!=null&&(this.textures[t]!=null&&this.textures[t].use(),f.render());for(s=this.children,r=[],i=0,l=s.length;i<l;i++)u=s[i],u!=null?r.push(u.render(n)):r.push(void 0);return r},n}(),e3d=e3d||{},e3d.Scene=function(){function n(){this.objects=[],this.camera=null}return n.prototype.render=function(){var u,t,i,n,f,r;if(i=e3d.program.mesh,this.camera!=null){for(i.begin(),u=this.camera.createMatrix(),r=this.objects,n=0,f=r.length;n<f;n++)t=r[n],t!=null&&t.render(u);return i.end()}},n}(),e3d=e3d||{},e3d.program={mesh:{vertexSource:"uniform mat4 uMatrix;\nattribute vec3 aPosition;\nattribute vec2 aTexCoord;\nattribute vec3 aColor;\nvarying vec2 vTexCoord;\nvarying vec3 vColor;\n\nvoid main() {\n\n gl_Position = uMatrix * vec4(aPosition,1);\n vTexCoord = aTexCoord;\n vColor = aColor;\n\n}",fragmentSource:"precision mediump float;\n\nuniform sampler2D uTexture;\nvarying vec2 vTexCoord;\nvarying vec3 vColor;\n\nvoid main() {\n\n gl_FragColor = texture2D(uTexture, vTexCoord) * vec4(vColor,1);\n\n}",init:function(){var n,t,i,r,u;return n=e3d.gl,t=e3d.program.mesh,i=e3d.compileProgram(t.vertexSource,t.fragmentSource),r=n.getUniformLocation(i,"uMatrix"),u=n.getUniformLocation(i,"uTexture"),t.aPositionLoc=n.getAttribLocation(i,"aPosition"),t.aTexCoordLoc=n.getAttribLocation(i,"aTexCoord"),t.aColorLoc=n.getAttribLocation(i,"aColor"),n.useProgram(i),n.uniform1i(u,0),n.useProgram(null),t.setMatrix=function(t){return n.uniformMatrix4fv(r,!1,t)},t.begin=function(){return n.useProgram(i),n.enableVertexAttribArray(t.aPositionLoc),n.enableVertexAttribArray(t.aTexCoordLoc),n.enableVertexAttribArray(t.aColorLoc)},t.end=function(){return n.disableVertexAttribArray(t.aPositionLoc),n.disableVertexAttribArray(t.aTexCoordLoc),n.disableVertexAttribArray(t.aColorLoc),n.useProgram(null)}}}},e3d.compileProgram=function(n,t){var u,i,r;if(i=e3d.gl,u=function(n,t){var r;if(r=i.createShader(n),i.shaderSource(r,t),i.compileShader(r),!i.getShaderParameter(r,i.COMPILE_STATUS)){console.log(i.getShaderInfoLog(r));throw"compileShader fail!";}return r},r=i.createProgram(),i.attachShader(r,u(i.VERTEX_SHADER,n)),i.attachShader(r,u(i.FRAGMENT_SHADER,t)),i.linkProgram(r),!i.getProgramParameter(r,i.LINK_STATUS)){console.log(i.getProgramInfoLog(r));throw"linkProgram fail!";}return r},e3d=e3d||{},e3d.Texture=function(){function n(n){var t,i;t=e3d.gl,this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),n!=null?(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,n),this.width=n.width,this.height=n.height):(i=new Uint8Array([255,255,255,255]),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,i),this.width=0,this.height=0)}return n.prototype.use=function(){var n;return n=e3d.gl,n.bindTexture(n.TEXTURE_2D,this.texture)},n.prototype.free=function(){var n;return n=e3d.gl,this.texture!=null?(n.deleteTexture(this.texture),this.texture=null):void 0},n}(),vec={equal:function(n,t){return n===t||n[0]===t[0]&&n[1]===t[1]&&n[2]===t[2]},add:function(n,t){return[n[0]+t[0],n[1]+t[1],n[2]+t[2]]},sub:function(n,t){return[n[0]-t[0],n[1]-t[1],n[2]-t[2]]},mul:function(n,t){return[n[0]*t,n[1]*t,n[2]*t]},div:function(n,t){return[n[0]/t,n[1]/t,n[2]/t]},neg:function(n){return[-n[0],-n[1],-n[2]]},dot:function(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]},dot4:function(n,t){return n[0]*t[0]+n[1]*t[1]+n[2]*t[2]+n[3]*t[3]},cross:function(n,t){return[n[1]*t[2]-n[2]*t[1],n[2]*t[0]-n[0]*t[2],n[0]*t[1]-n[1]*t[0]]},len:function(n){return Math.sqrt(vec.dot(n,n))},unit:function(n){return vec.div(n,vec.len(n))}},BoxObject=function(n){function t(n){this.box=n,t.__super__.constructor.call(this),i.length===0&&(i=[new e3d.Mesh(makeBox())]),this.meshes=i,this.textures=r,this.prevPosition=this.box.position,this.position=this.box.position}var i,r;return __extends(t,n),i=[],r=[],t.setTextures=function(n){var t,f,i,e,u;for(u=[],t=i=0,e=n.length;i<e;t=++i)f=n[t],u.push(r[t]=f);return u},t.prototype.animate=function(n){var i,r,t,u;return t=this.box.position,n!==LevelView.ANIMATION_FRAMES_PER_STEP?(i=vec.sub(t,this.prevPosition),u=n/LevelView.ANIMATION_FRAMES_PER_STEP,r=vec.mul(i,u),this.position=vec.add(this.prevPosition,r)):(this.position=t,this.prevPosition=t)},t.prototype.render=function(n){return t.__super__.render.call(this,n)},t}(e3d.Object),Camera=function(n){function t(){return t.__super__.constructor.apply(this,arguments)}var i,r;return __extends(t,n),i=1.3,r=.1,t.prototype.rotate=function(n,t){var u;return u=vec.add(this.rotation,[t,0,n]),u[0]=Math.min(u[0],i),u[0]=Math.max(u[0],r),this.rotation=u},t}(e3d.Camera),LevelView=function(){function t(){var n,t;this.camera=new Camera,this.camera.distance=12,this.scene=new e3d.Scene,this.scene.camera=this.camera,n={sky:["/textures/sky.png"],level:["/textures/wall.png","/textures/floor.png","/textures/platform.png"],box:["/textures/box.png"],lift:["/textures/lift.png","/textures/lifttop.png"],player:["/textures/player.png"]},t=this,loadImageFiles(n,function(n){return SkyObject.setTextures(createTextures(n.sky)),StaticLevelObject.setTextures(createTextures(n.level)),BoxObject.setTextures(createTextures(n.box)),LiftObject.setTextures(createTextures(n.lift)),PlayerObject.setTextures(createTextures(n.player)),e3d.scene=t.scene}),this.currState=null,this.onAnimationFinished=null,this.animationFramesLeft=0}var n;return n=6,t.ANIMATION_FRAMES_PER_STEP=n,t.prototype.build=function(n){var t,r,i;return t=[n.width/2,n.depth/2,n.height/2],this.camera.position=t,this.camera.rotation=[.5,0,0],i=new SkyObject,i.position=t,r=new StaticLevelObject(n),this.boxGroup=new e3d.Object,this.boxGroup.children=n.forEach("box",function(n){return new BoxObject(n)}),this.liftGroup=new e3d.Object,this.liftGroup.children=n.forEach("lift",function(n){return new LiftObject(n)}),this.player=new PlayerObject(n.player),this.scene.objects=[i,r,this.boxGroup,this.liftGroup,this.player]},t.prototype.update=function(t,i){var r;return t!==this.currState&&(this.currState=t,this.build(t),r=this,e3d.onrender=function(){var e,l,o,s,t,a,i,v,h,c,y,u,f,p,w;if(c=r.player,o=r.boxGroup.children,h=r.liftGroup.children,e=r.animationFramesLeft,e>0){for(i=n-e+1,c.animate(i),u=0,p=o.length;u<p;u++)l=o[u],l.animate(i);for(f=0,w=h.length;f<w;f++)v=h[f],v.animate(i);r.animationFramesLeft--}else s=r.onAnimationFinished,s!=null&&(r.onAnimationFinished=null,s());return t=r.camera,a=vec.sub(vec.add(c.position,[0,0,0]),t.position),y=vec.mul(a,.05),t.position=vec.add(t.position,y)}),i[0]!=null?(this.onAnimationFinished=i[0],this.animationFramesLeft=n):void 0},t}(),LiftObject=function(n){function t(n){this.lift=n,t.__super__.constructor.call(this),i.length===0&&(i=[new e3d.Mesh(makeLidlessBox()),new e3d.Mesh(makeTopFace())]),this.meshes=i,this.textures=r,this.prevPosition=this.lift.position,this.position=this.lift.position}var i,r;return __extends(t,n),i=[],r=[],t.setTextures=function(n){var t,f,i,e,u;for(u=[],t=i=0,e=n.length;i<e;t=++i)f=n[t],u.push(r[t]=f);return u},t.prototype.animate=function(n){var i,r,t,u;return t=this.lift.position,n!==LevelView.ANIMATION_FRAMES_PER_STEP?(i=vec.sub(t,this.prevPosition),u=n/LevelView.ANIMATION_FRAMES_PER_STEP,r=vec.mul(i,u),this.position=vec.add(this.prevPosition,r)):(this.position=t,this.prevPosition=t)},t.prototype.render=function(n){return t.__super__.render.call(this,n)},t}(e3d.Object),PlayerObject=function(n){function t(n){var u;this.player=n,t.__super__.constructor.call(this),i.length===0&&(i[0]=null,loadJsonFile("models/player.json",function(n){return i[0]=new e3d.Mesh(n)})),this.meshes=i,this.textures=r,u=vec.add(this.player.position,[.5,.5,.5]),this.prevPosition=u,this.position=u,this.scale=[.5,.5,.5]}var i,r;return __extends(t,n),i=[],r=[],t.setTextures=function(n){var t,f,i,e,u;for(u=[],t=i=0,e=n.length;i<e;t=++i)f=n[t],u.push(r[t]=f);return u},t.prototype.animate=function(n){var i,r,t,u;return t=vec.add(this.player.position,[.5,.5,.5]),n!==LevelView.ANIMATION_FRAMES_PER_STEP?(i=vec.sub(t,this.prevPosition),u=n/LevelView.ANIMATION_FRAMES_PER_STEP,r=vec.mul(i,u),this.position=vec.add(this.prevPosition,r)):(this.position=t,this.prevPosition=t)},t.prototype.render=function(n){var i,r;return i=this.player.direction,r=Math.PI/2,vec.equal(i,[0,1,0])&&(this.rotation=[0,0,0*r]),vec.equal(i,[-1,0,0])&&(this.rotation=[0,0,1*r]),vec.equal(i,[0,-1,0])&&(this.rotation=[0,0,2*r]),vec.equal(i,[1,0,0])&&(this.rotation=[0,0,3*r]),t.__super__.render.call(this,n)},t}(e3d.Object),SkyObject=function(n){function i(){i.__super__.constructor.call(this),t.length===0&&(t[0]=null,loadJsonFile("models/sky.json",function(n){return t[0]=new e3d.Mesh(n)})),this.meshes=t,this.textures=r,this.scale=[75,75,75]}var t,r;return __extends(i,n),t=[],r=[],i.setTextures=function(n){var t,f,i,e,u;for(u=[],t=i=0,e=n.length;i<e;t=++i)f=n[t],u.push(r[t]=f);return u},i}(e3d.Object),StaticLevelObject=function(n){function t(n){var e,u,r,f,o;t.__super__.constructor.call(this),o=n.width,e=n.depth,r=[],f=[],u=[],n.forEachBlock(function(t,i){var e,o,s,h,c;if(t.static&&(s=n.blockAt(vec.add(i,[-1,0,0])),h=n.blockAt(vec.add(i,[1,0,0])),e=n.blockAt(vec.add(i,[0,-1,0])),o=n.blockAt(vec.add(i,[0,1,0])),c=n.blockAt(vec.add(i,[0,0,1])),s.static||(r=r.concat(makeLeftFace(i))),h.static||(r=r.concat(makeRightFace(i))),e.static||(r=r.concat(makeBackFace(i))),o.static||(r=r.concat(makeFrontFace(i))),!c.static&&(t.type==="solid"&&(f=f.concat(makeTopFace(i))),t.type==="platform")))return u=u.concat(makeTopFace(i))}),this.meshes=[new e3d.Mesh(r),new e3d.Mesh(f),new e3d.Mesh(u)],this.textures=i}var i;return __extends(t,n),i=[],t.setTextures=function(n){var t,f,r,e,u;for(u=[],t=r=0,e=n.length;r<e;t=++r)f=n[t],u.push(i[t]=f);return u},t}(e3d.Object),createTextures=function(n){var r,t,u,i;for(i=[],t=0,u=n.length;t<u;t++)r=n[t],i.push(new e3d.Texture(r));return i},makeQuad=function(n,t){var u,f,i,e,r;return i=n,e=t[0],f=t[1],u=t[2],r=[[i[0][0],i[0][1],i[0][2],0,0,e,f,u],[i[1][0],i[1][1],i[1][2],1,0,e,f,u],[i[2][0],i[2][1],i[2][2],0,1,e,f,u],[i[3][0],i[3][1],i[3][2],1,1,e,f,u]],[].concat(r[0],r[1],r[2],r[3],r[2],r[1])},makeLeftFace=function(n){var u,f,t,i,r;return n==null&&(n=[0,0,0]),t=n[0],i=n[1],r=n[2],f=[[t,i,r+1],[t,i+1,r+1],[t,i,r],[t,i+1,r]],u=[.7,.7,.7],makeQuad(f,u)},makeRightFace=function(n){var u,f,t,i,r;return n==null&&(n=[0,0,0]),t=n[0],i=n[1],r=n[2],f=[[t+1,i+1,r+1],[t+1,i,r+1],[t+1,i+1,r],[t+1,i,r]],u=[.8,.8,.8],makeQuad(f,u)},makeBackFace=function(n){var u,f,t,i,r;return n==null&&(n=[0,0,0]),t=n[0],i=n[1],r=n[2],f=[[t+1,i,r+1],[t,i,r+1],[t+1,i,r],[t,i,r]],u=[.6,.6,.6],makeQuad(f,u)},makeFrontFace=function(n){var u,f,t,i,r;return n==null&&(n=[0,0,0]),t=n[0],i=n[1],r=n[2],f=[[t,i+1,r+1],[t+1,i+1,r+1],[t,i+1,r],[t+1,i+1,r]],u=[.9,.9,.9],makeQuad(f,u)},makeTopFace=function(n){var u,f,t,i,r;return n==null&&(n=[0,0,0]),t=n[0],i=n[1],r=n[2],f=[[t,i,r+1],[t+1,i,r+1],[t,i+1,r+1],[t+1,i+1,r+1]],u=[1,1,1],makeQuad(f,u)},makeLidlessBox=function(n){return[].concat(makeLeftFace(n),makeRightFace(n),makeBackFace(n),makeFrontFace(n))},makeBox=function(n){return[].concat(makeLidlessBox(n),makeTopFace(n))},Zoko=function(){if(!document.getElementById('zoko').getContext("experimental-webgl"))return nowebgl();function n(n){var r,u,i,t,f;r=n.find("canvas")[0],u=n.find("#overlay"),e3d.init(r),t=new LevelView,new PlayerController(t),new CameraController(t,u),i=new Game(t),f=new UI(i),i.observers=[f],e3d.run();}return n}();
| ver. 1.4 |
Github
|
.
| PHP 8.2.29 | Генераци� �траницы: 0 |
proxy
|
phpinfo
|
�а�тройка