Advertisement
Sosowski

jAllegro's exgame.js compiled with Closure

Aug 9th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var e,f,k,l,m=200,n=200,p=100,q=100,t=0;
  2. window.addEventListener("load",function(){(u=document.getElementById("debug"))&&(v=!0);w();e=x("data/man.png");f=x("data/apple.png");k=x("data/grass.jpg");l=y();z(function(){A(function(){B[C]&&(q-=4);B[D]&&(q+=4);B[E]&&(p-=4);B[F]&&(p+=4);var a=p,b=q,d=m,g=n;if(20>Math.sqrt((d-a)*(d-a)+(g-b)*(g-b))){var c,h,r,a=l;c||0==c||(c=1);h||0==h||(h=1);r||(r=!1);a.volume=c;a.element.volume=a.volume*G;a.element.loop=r;a.element.playbackRate=h;a.element.currentTime=0;a.element.play();m=Math.floor(65536*Math.random())%
  3. (H-32);n=Math.floor(65536*Math.random())%(I-32);t++;J("Apple eaten!")}K.context.drawImage(k.canvas,0,0);K.context.drawImage(e.canvas,p,q);K.context.drawImage(f.canvas,m,n);c=K;h="Score: "+t;r=L(255,255,255);c.context.font=(24).toFixed()+"px "+M.name;c.context.textAlign="left";N(c,r);c.context.fillText(h,10,20)})});return 0});function w(){J("Allegro installed!");var a=document.getElementById("canvas_id");if(a){a.width=640;a.height=480;var b=a.getContext("2d");H=640;I=480;K={b:640,a:480,canvas:a,context:b,ready:!0};M={element:null,file:"",name:"monospace",type:"fnt"}}else J("[ERROR] Can't find canvas with id canvas_id"),alert("Can't find canvas with id canvas_id");K?O?_allog("Mouse already installed"):(K.canvas.addEventListener("mouseup",P),K.canvas.addEventListener("mousedown",Q),K.canvas.addEventListener("mousemove",
  4. aa),K.canvas.addEventListener("wheel",ba),K.canvas.addEventListener("contextmenu",ca),_menu_supress=!1,O=!0,J("Mouse installed!")):(J("[ERROR] You must call set_gfx_mode before install_mouse"),alert("You must call set_gfx_mode before install_mouse"));if(R)_allog("Keyboard already installed");else{S=da;for(a=0;128>a;a++)B[a]=!1;window.addEventListener("keyup",ea);window.addEventListener("keydown",fa);R=!0;J("Keybaord installed!")}}var O=!1;function ca(a){a.preventDefault()}
  5. function P(a){a.preventDefault()}function Q(a){a.preventDefault()}function aa(a){a.preventDefault()}function ba(a){a.preventDefault()}var T=[],U;function ga(){U();if(R)for(var a=0;128>a;a++);O&&(mosue_my=0)}function A(a){U=a;window.setInterval(ga,1E3/60);J("Game loop initialised!")}var V,W,X;
  6. function Y(){for(var a=0,b=0,d=0;d<T.length;d++)a++,"snd"==T[d].type&&T[d].element.readyState>=T[d].element.HAVE_FUTURE_DATA&&(T[d].ready=!0),T[d].ready&&b++;X&&X(a/b);b<a?window.setTimeout(Y,100):(J("Loading complete! Took "+(((new Date).getTime()-V)/1E3).toFixed(1)+" seconds!"),W())}function ha(a){Z(5,I-55,H-10,50,L(0,0,0));Z(10,I-50,H-20,40,L(255,255,255));Z(15,I-45,H-30,30,L(0,0,0));var b;b=H-40;a=0+(a-0)/1*(b-0);0<b?(a=a<b?a:b,b=0<a?a:0):(a=0>a?a:0,b=a>b?a:b);Z(20,I-40,b,20,L(255,255,255))}
  7. function z(a){V=(new Date).getTime();W=a;J("Loader initialised!");X=ha;window.setTimeout(Y,100)}var E=37,F=39,C=38,D=40,B=[],R=!1,da=[112,113,114,115,116,117,118,119,120,121,122,123],S=[];function fa(a){B[a.keyCode]=!0;-1==S.indexOf(a.keyCode)&&a.preventDefault()}function ea(a){B[a.keyCode]=!1;-1==S.indexOf(a.keyCode)&&a.preventDefault()}
  8. function x(a){J("Loading bitmap "+a+"...");var b=new Image;b.src=a;var d=document.createElement("canvas"),g=d.getContext("2d"),c={canvas:d,context:g,b:-1,a:-1,ready:!1,type:"bmp"};T.push(c);b.onload=function(){J("Bitmap "+a+" loaded, size: "+b.width+" x "+b.height+"!");c.canvas.width=b.width;c.canvas.height=b.height;c.context.drawImage(b,0,0);c.b=b.width;c.a=b.height;c.ready=!0};return c}var K,H=0,I=0,M;
  9. function N(a,b){a.context.fillStyle="rgba("+(b>>16&255)+","+(b>>8&255)+","+(b&255)+","+(b>>>24)/255+")"}function L(a,b,d){var g;g||(g=255);return g<<24|(a&255)<<16|(b&255)<<8|d&255}function Z(a,b,d,g,c){var h=K;N(h,c);h.context.fillRect(a,b,d,g)}var G=1,ia=[];
  10. function y(){var a=document.createElement("audio");a.src="data/munch.mp3";var b={element:a,file:"data/munch.mp3",volume:1,ready:!1,type:"snd"};T.push(b);ia.push(b);J("Loading sample data/munch.mp3...");a.onloadeddata=function(){b.ready||(b.ready=!0,J("Sample data/munch.mp3 loaded!"))};return b}var v=!1,u,ja=!1;function J(a){ja&&console&&console.log(a);v&&(u.innerHTML=u.innerHTML+a+"<br/>")};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement