Code viewer for World: Cloned Super Mario Maze
function randomfloatAtoB(a,e){return a+Math.random()*(e-a)}function randomintAtoB(a,e){return Math.round(randomfloatAtoB(a,e))}function randomBoolean(){return!(Math.random()<.5)}function randomPick(a,e){return randomBoolean()?a:e}function World(){function a(){for(var a=0;a<gridsize;a++){sa[a]=new Array(gridsize);for(var e=0;e<gridsize;e++)sa[a][e]=GRID_BLANK}}function e(){for(var a=0;a<gridsize;a++){ua[a]=new Array(gridsize);for(var e=0;e<gridsize;e++)ua[a][e]=GRID_BLANK}}function o(a,e){return Q==a&&V==e||(ta==a&&ra==e||(aa==a&&ea==e||(sa[a][e]==GRID_WALL||sa[a][e]==GRID_MAZE)))}function n(a,e){return Q==a&&V==e||ta==a&&ra==e}function t(a,e){return oa==a&&na==e}function r(a){return a-1e3}function i(){var a=[new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/cathaln/mario-background.png"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/cathaln/mario-background.png"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/cathaln/mario-background.png"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/cathaln/mario-background.png"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/cathaln/mario-background.png"),side:THREE.BackSide}),new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("/uploads/cathaln/mario-background.png"),side:THREE.BackSide})],e=new THREE.CubeGeometry(skyboxConst,skyboxConst,skyboxConst),o=new THREE.MeshFaceMaterial(a),n=new THREE.Mesh(e,o);threeworld.scene.add(n)}function s(){var a=new THREE.MTLLoader;a.setTexturePath("/uploads/cathaln/"),a.setPath("/uploads/cathaln/"),a.load("mario.mtl",function(a){a.preload();var e=new THREE.OBJLoader;e.setMaterials(a),e.setPath("/uploads/cathaln/"),e.load("mario.obj",function(a){a.scale.multiplyScalar(20),Z=a,threeworld.scene.add(Z)})});var e=new THREE.MTLLoader;e.setTexturePath("/uploads/cathaln/"),e.setPath("/uploads/cathaln/"),e.load("goomba.mtl",function(a){a.preload();var e=new THREE.OBJLoader;e.setMaterials(a),e.setPath("/uploads/cathaln/"),e.load("goomba.obj",function(a){a.scale.multiplyScalar(1.3),Y=a,threeworld.scene.add(Y)})});var o=new THREE.MTLLoader;o.setTexturePath("/uploads/cathaln/"),o.setPath("/uploads/cathaln/"),o.load("goomba.mtl",function(a){a.preload();var e=new THREE.OBJLoader;e.setMaterials(a),e.setPath("/uploads/cathaln/"),e.load("goomba.obj",function(a){a.scale.multiplyScalar(1.3),theenemy2=a,threeworld.scene.add(theenemy2)})});var n=new THREE.MTLLoader;n.setTexturePath("/uploads/cathaln/"),n.setPath("/uploads/cathaln/"),n.load("princesspeach.mtl",function(a){a.preload();var e=new THREE.OBJLoader;e.setMaterials(a),e.setPath("/uploads/cathaln/"),e.load("princesspeach.obj",function(a){a.scale.multiplyScalar(4),X=a,threeworld.scene.add(X)})});var t=new THREE.TextureLoader;t.load("/uploads/cathaln/floor.jpg",function(a){a.minFilter=THREE.LinearFilter,l(new THREE.MeshBasicMaterial({map:a}))});var r=new THREE.TextureLoader;r.load("/uploads/cathaln/question.jpg",function(a){a.minFilter=THREE.LinearFilter,f(new THREE.MeshBasicMaterial({map:a}))});var i=new THREE.TextureLoader;i.load("/uploads/cathaln/grass2.jpg",function(a){a.minFilter=THREE.LinearFilter,E(new THREE.MeshBasicMaterial({map:a}))})}function u(){for(var a=0;a<gridsize;a++)for(var e=0;e<gridsize;e++)0!=a&&19!=a&&0!=e&&19!=e||(sa[a][e]=GRID_WALL)}function d(){for(var a=0,e=0;e<gridsize;e++)for(var o=0;o<gridsize;o++)if(sa[e][o]==GRID_WALL){var n=new THREE.BoxGeometry(squaresize,j,squaresize),t=new THREE.Mesh(n);t.material.color.setHex(BLANKCOLOR),t.position.x=r(e*squaresize),t.position.z=r(o*squaresize),t.position.y=0,threeworld.scene.add(t),da[a]=t,a++}}function l(a){for(var e=0;e<da.length;e++)da[e]&&(da[e].material=a)}function c(){for(var a=0;a<gridsize;a++)for(var e=0;e<gridsize;e++)ua[a][e]=GRID_WALL}function T(){for(var a=0,e=0;e<gridsize;e++)for(var o=0;o<gridsize;o++)if(ua[e][o]==GRID_WALL){var n=new THREE.BoxGeometry(squaresize,10,squaresize),t=new THREE.Mesh(n);t.material.color.setHex(BLANKCOLOR),t.position.x=r(e*squaresize),t.position.z=r(o*squaresize),t.position.y=-50,threeworld.scene.add(t),la[a]=t,a++}}function E(a){for(var e=0;e<la.length;e++)la[e]&&(la[e].material=a)}function m(){for(var a=2;a<19;a+=2){var e=randomintAtoB(4,16);sa[a-1][e]=GRID_MAZE;for(var o=2;o<18;o++)sa[a][o]=GRID_MAZE}for(var a=2;a<19;a+=4)sa[a][18]=GRID_MAZE;for(var a=4;a<19;a+=4)sa[a][1]=GRID_MAZE}function p(){for(var a=0,e=0;e<gridsize;e++)for(var o=0;o<gridsize;o++)if(sa[e][o]==GRID_MAZE){var n=new THREE.BoxGeometry(squaresize,j,squaresize),t=new THREE.Mesh(n);t.material.color.setHex(BLANKCOLOR),t.position.x=r(e*squaresize),t.position.z=r(o*squaresize),t.position.y=0,threeworld.scene.add(t),ca[a]=t,a++}}function f(a){for(var e=0;e<ca.length;e++)ca[e]&&(ca[e].material=a)}function h(){var a=r(Q*squaresize),e=r(V*squaresize),o=0;Y.position.x=a,Y.position.y=o,Y.position.z=e}function R(){var a,e;do a=randomintAtoB(1,18),e=randomintAtoB(1,18);while(o(a,e));Q=a,V=e}function A(a){var e=Q,n=V;a==ACTION_LEFT?e--:a==ACTION_RIGHT?e++:a==ACTION_UP?n++:a==ACTION_DOWN&&n--,o(e,n)||(true&&(a==ACTION_LEFT?I():a==ACTION_RIGHT?C():a==ACTION_UP?O():a==ACTION_DOWN&&_()),Q=e,V=n)}function I(){Y.rotation.set(0,4.71239,0)}function _(){Y.rotation.set(0,3.14159,0)}function O(){Y.rotation.set(0,0,0)}function C(){Y.rotation.set(0,1.5708,0)}function H(){var a=r(ta*squaresize),e=r(ra*squaresize),o=0;theenemy2.position.x=a,theenemy2.position.y=o,theenemy2.position.z=e}function v(){var a,e;do a=randomintAtoB(1,18),e=randomintAtoB(1,18);while(o(a,e));ta=a,ra=e}function N(a){var e=ta,n=ra;a==ACTION_LEFT?e--:a==ACTION_RIGHT?e++:a==ACTION_UP?n++:a==ACTION_DOWN&&n--,o(e,n)||(true&&(a==ACTION_LEFT?y():a==ACTION_RIGHT?L():a==ACTION_UP?w():a==ACTION_DOWN&&g()),ta=e,ra=n)}function y(){theenemy2.rotation.set(0,4.71239,0)}function g(){theenemy2.rotation.set(0,3.14159,0)}function w(){theenemy2.rotation.set(0,0,0)}function L(){theenemy2.rotation.set(0,1.5708,0)}function B(){if(Z){var a=r(aa*squaresize),e=r(ea*squaresize),o=Ta;Z.position.x=a,Z.position.y=o,Z.position.z=e,threeworld.follow.copy(Z.position)}}function z(){for(var a=18,e=1;o(a,e););aa=a,ea=e}function M(a){var e=aa,n=ea;a==ACTION_LEFT?e--:a==ACTION_RIGHT?e++:a==ACTION_UP?n++:a==ACTION_DOWN?n--:a==ACTION_JUMP&&(1==Ea?$("#user_span6").html(" &nbsp; <font color=red> <B> Already In Jump. </B> </font>   "):D(Z)?ea>5&&(Ea=!0):b(Z)&&ea<14&&(Ea=!0)),o(e,n)||(true&&(a==ACTION_LEFT?x():a==ACTION_RIGHT?U():a==ACTION_UP?G():a==ACTION_DOWN&&P()),aa=e,ea=n)}function x(){Z.rotation.y=4.71239}function P(){Z.rotation.y=3.14159}function G(){Z.rotation.y=0}function U(){Z.rotation.y=1.5708}function D(a){return 3.14159==a.rotation.y}function b(a){return 0==a.rotation.y}function k(){1==b(Z)?ea<14&&1==ma?1==ma&&(soundWooHoo(),Ta+=100,ma=!1,pa=!0):1==pa?(ea+=5,pa=!1,fa=!0):1==fa&&(Ta-=100,ma=!0,fa=!1,Ea=!1):1==D(Z)&&(ea>5&&1==ma?1==ma&&(soundWooHoo(),Ta+=100,ma=!1,pa=!0):1==pa?(ea-=5,pa=!1,fa=!0):1==fa&&(Ta-=100,ma=!0,fa=!1,Ea=!1))}function q(){var a=r(oa*squaresize),e=r(na*squaresize),o=0;X.position.x=a,X.position.y=o,X.position.z=e,X.rotation.y=3.14159}function W(){for(var a=1,e=18;o(a,e););oa=a,na=e}function S(a){37==a.keyCode&&M(ACTION_LEFT),38==a.keyCode&&M(ACTION_DOWN),39==a.keyCode&&M(ACTION_RIGHT),40==a.keyCode&&M(ACTION_UP),32==a.keyCode&&M(ACTION_JUMP)}function F(){return o(aa-1,ea)&&o(aa+1,ea)&&o(aa,ea+1)&&o(aa,ea-1)||n(aa-1,ea)||n(aa+1,ea)||n(aa,ea+1)||n(aa,ea-1)}function K(){return t(aa,ea)}function J(a){var e=(ha.getState()," Time(Ends at 400): <b> "+ia);$("#user_span3").html(e)}var j,Z,Y,X,Q,V,aa,ea,oa,na,ta,ra,ia,sa=new Array(gridsize),ua=new Array(gridsize),da=new Array(80),la=new Array(gridsize),ca=new Array(1),Ta=0,Ea=!1,ma=!0,pa=!1,fa=!1,ha=this;this.endCondition,this.newRun=function(){if(this.endCondition=!1,ia=0,a(),e(),c(),z(),W(),u(),m(),R(),v(),true){j=squaresize,threeworld.init3d(startRadiusConst,maxRadiusConst,SKYCOLOR);var o=new THREE.AmbientLight;threeworld.scene.add(o);var n=new THREE.DirectionalLight(LIGHTCOLOR,3);n.position.set(startRadiusConst,startRadiusConst,startRadiusConst),threeworld.scene.add(n),i(),initMusic(),d(),T(),p(),s(),document.onkeydown=S}},this.getState=function(){var a=[aa,ea,Q,V];return a},this.takeAction=function(a){if(ia++,true&&J(a),M(a),aa==Q&&ea==V){threeworld.scene.remove(Y),Q=-5,V=-5;var e="<audio    src=/uploads/cathaln/stomp.mp3   autoplay  > </audio>";$("#user_span2").html(e),$("#user_span6").html(" &nbsp; <font color=red> <B> Enemy Killed!  </B> </font>   ")}if(aa==ta&&ea==ra){threeworld.scene.remove(theenemy2),ta=-5,ra=-5;var e="<audio    src=/uploads/cathaln/stomp.mp3   autoplay  > </audio>";$("#user_span2").html(e),$("#user_span6").html(" &nbsp; <font color=red> <B> Enemy Killed!  </B> </font>   ")}var o,n;V<ea?o=ACTION_UP:V>ea&&(o=ACTION_DOWN),ra<ea?n=ACTION_UP:ra>ea&&(n=ACTION_DOWN),ia%6==0&&(A(o),N(n)),1==Ea&&k(),true&&(B(),q(),h(),H()),(F()||K())&&(this.endCondition=!0,goodsteps=0,true&&(musicPause(),F()?soundAlarm():K()&&soundFlagAlarm()))},this.endRun=function(){true&&(musicPause(),this.endCondition?$("#user_span6").html(" &nbsp; <font color=red> <B> Game Over. </B> </font>   "):$("#user_span6").html(" &nbsp; <font color=red> <B> Times Up! </B> </font>   "))}}function initMusic(){var a="<audio  id=theaudio  src=/uploads/cathaln/mariothemetune.mp3   autoplay loop> </audio>";$("#user_span1").html(a)}function musicPlay(){document.getElementById("theaudio").play()}function musicPause(){document.getElementById("theaudio").pause()}function soundAlarm(){var a="<audio    src=/uploads/cathaln/gameover.mp3   autoplay  > </audio>";$("#user_span2").html(a)}function soundFlagAlarm(){var a="<audio    src=/uploads/cathaln/levelcomplete.mp3   autoplay  > </audio>";$("#user_span2").html(a)}function soundWooHoo(){var a="<audio    src=/uploads/cathaln/woohoo.mp3   autoplay  > </audio>";$("#user_span2").html(a)}const CLOCKTICK=100,MAXSTEPS=400,gridsize=20,squaresize=100,MAXPOS=2e3,SKYCOLOR=14548957,BLANKCOLOR=SKYCOLOR,LIGHTCOLOR=16777215,show3d=!0,startRadiusConst=1600,skyboxConst=6e3,maxRadiusConst=2e4,ACTION_LEFT=0,ACTION_RIGHT=1,ACTION_UP=2,ACTION_DOWN=3,ACTION_JUMP=5,GRID_BLANK=0,GRID_WALL=1,GRID_MAZE=2;