Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 59 additions and 17 deletions.
  1. +1 −0  README.rdoc
  2. +15 −14 jaws-min.js
  3. +43 −3 jaws.js
View
1  README.rdoc
@@ -59,6 +59,7 @@ Check out the sourcecode for comments and explanations:
* {http://markbennett.ca/JAWS-on-a-plane/}[http://markbennett.ca/JAWS-on-a-plane/] - A minigame by https://github.com/MarkBennett
* {http://davidgomes.github.com/paxlure/}[http://davidgomes.github.com/paxlure/] - Zombie blasting minigame by https://github.com/davidgomes
* {http://crystalpart.com/hp/}[http://crystalpart.com/hp/] - A mini game by by Ashan Fernando (http://crystalpart.com/wp/)
+* {http://magigames.org/runestone_defense.html}[http://magigames.org/runestone_defense.html] - Runestone, a tower defense game by David Blood
... missing your game here? Msg me on github!
== Loading Jaws
View
29 jaws-min.js
@@ -1,24 +1,25 @@
-var jaws=function(c){function b(b){c.mouse_x=b.pageX||b.clientX;c.mouse_y=b.pageY||b.clientX;b=c.canvas?c.canvas:c.dom;c.mouse_x-=b.offsetLeft;c.mouse_y-=b.offsetTop}var d,e;c.title=function(b){return b?d.innerHTML=b:d.innerHTML};c.unpack=function(){"Sprite,SpriteList,Animation,Viewport,SpriteSheet,Parallax,TileMap,Rect,pressed".split(",").forEach(function(b){window[b]?c.log(b+"already exists in global namespace"):window[b]=c[b]})};c.log=function(b,c){e&&(b+="<br />",e.innerHTML=c?e.innerHTML.toString()+
+var jaws=function(c){function b(b){c.mouse_x=b.pageX||b.clientX;c.mouse_y=b.pageY||b.clientX;b=c.canvas?c.canvas:c.dom;c.mouse_x-=b.offsetLeft;c.mouse_y-=b.offsetTop}var d,e;c.title=function(b){return b?d.innerHTML=b:d.innerHTML};c.unpack=function(){"Sprite SpriteList Animation Viewport SpriteSheet Parallax TileMap Rect pressed".split(" ").forEach(function(b){window[b]?c.log(b+"already exists in global namespace"):window[b]=c[b]})};c.log=function(b,c){e&&(b+="<br />",e.innerHTML=c?e.innerHTML.toString()+
b:b)};c.init=function(f){d=document.getElementsByTagName("title")[0];c.url_parameters=c.getUrlParameters();e=document.getElementById("jaws-log");c.url_parameters.debug&&!e&&(e=document.createElement("div"),e.id="jaws-log",e.style.cssText="overflow: auto; color: #aaaaaa; width: 300px; height: 150px; margin: 40px auto 0px auto; padding: 5px; border: #444444 1px solid; clear: both; font: 10px verdana; text-align: left;",document.body.appendChild(e));c.canvas=document.getElementsByTagName("canvas")[0];
c.canvas||(c.dom=document.getElementById("canvas"));c.canvas?c.context=c.canvas.getContext("2d"):c.dom?c.dom.style.position="relative":(c.canvas=document.createElement("canvas"),c.canvas.width=f.width,c.canvas.height=f.height,c.context=c.canvas.getContext("2d"),document.body.appendChild(c.canvas));c.width=c.canvas?c.canvas.width:c.dom.offsetWidth;c.height=c.canvas?c.canvas.height:c.dom.offsetHeight;c.mouse_x=0;c.mouse_y=0;window.addEventListener("mousemove",b)};c.start=function(b,d,e){function h(b){c.context&&
-d.loading_screen&&(c.context.save(),c.context.fillStyle="black",c.context.fillRect(0,0,c.width,c.height),c.context.textAlign="center",c.context.fillStyle="white",c.context.font="15px terminal",c.context.fillText("Loading",c.width/2,c.height/2-30),c.context.font="bold 30px terminal",c.context.fillText(b+"%",c.width/2,c.height/2),c.context.restore())}function k(b,d){c.log(d+"%: "+b,!0);h(d)}function m(b){c.log("Error loading: "+b,!0)}function n(){c.log("all assets loaded",!0);c.switchGameState(b||window,
-{fps:r},e)}d||(d={});var r=d.fps||60;void 0===d.loading_screen&&(d.loading_screen=!0);d.width||(d.width=500);d.height||(d.height=300);c.init(d);h(0);c.log("setupInput()",!0);c.setupInput();c.log("assets.loadAll()",!0);0<c.assets.length()?c.assets.loadAll({onload:k,onerror:m,onfinish:n}):n()};c.switchGameState=function(b,d,e){d=d&&d.fps||c.game_loop&&c.game_loop.fps||60;c.game_loop&&c.game_loop.stop();c.clearKeyCallbacks();c.isFunction(b)&&(b=new b);c.previous_game_state=c.game_state;c.game_state=
+d.loading_screen&&(c.context.save(),c.context.fillStyle="black",c.context.fillRect(0,0,c.width,c.height),c.context.textAlign="center",c.context.fillStyle="white",c.context.font="15px terminal",c.context.fillText("Loading",c.width/2,c.height/2-30),c.context.font="bold 30px terminal",c.context.fillText(b+"%",c.width/2,c.height/2),c.context.restore())}function k(b,d){c.log(d+"%: "+b,!0);h(d)}function l(b){c.log("Error loading: "+b,!0)}function n(){c.log("all assets loaded",!0);c.switchGameState(b||window,
+{fps:q},e)}d||(d={});var q=d.fps||60;void 0===d.loading_screen&&(d.loading_screen=!0);d.width||(d.width=500);d.height||(d.height=300);c.init(d);h(0);c.log("setupInput()",!0);c.setupInput();c.log("assets.loadAll()",!0);0<c.assets.length()?c.assets.loadAll({onload:k,onerror:l,onfinish:n}):n()};c.switchGameState=function(b,d,e){d=d&&d.fps||c.game_loop&&c.game_loop.fps||60;c.game_loop&&c.game_loop.stop();c.clearKeyCallbacks();c.isFunction(b)&&(b=new b);c.previous_game_state=c.game_state;c.game_state=
b;c.game_loop=new c.GameLoop(b,{fps:d},e);c.game_loop.start()};c.imageToCanvas=function(b){var c=document.createElement("canvas");c.src=b.src;c.width=b.width;c.height=b.height;c.getContext("2d").drawImage(b,0,0,b.width,b.height);return c};c.forceArray=function(b){return Array.isArray(b)?b:[b]};c.clear=function(){c.context.clearRect(0,0,c.width,c.height)};c.isImage=function(b){return"[object HTMLImageElement]"===Object.prototype.toString.call(b)};c.isCanvas=function(b){return"[object HTMLCanvasElement]"===
Object.prototype.toString.call(b)};c.isDrawable=function(b){return c.isImage(b)||c.isCanvas(b)};c.isString=function(b){return"string"==typeof b};c.isArray=function(b){return void 0===b?!1:-1!=b.constructor.toString().indexOf("Array")};c.isFunction=function(b){return"[object Function]"===Object.prototype.toString.call(b)};c.isOutsideCanvas=function(b){return 0>b.x||0>b.y||b.x>c.width||b.y>c.height};c.forceInsideCanvas=function(b){0>b.x&&(b.x=0);b.x>c.width&&(b.x=c.width);0>b.y&&(b.y=0);b.y>c.height&&
-(b.y=c.height)};c.getUrlParameters=function(){for(var b=[],c,d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),e=0;e<d.length;e++)c=d[e].split("="),b.push(c[0]),b[c[0]]=c[1];return b};return c}(jaws||{}),jaws=function(c){function b(b){event=b?b:window.event;var c=j[event.keyCode];g[c]=!1;k[c]&&(k[c](c),b.preventDefault());n[c]&&b.preventDefault()}function d(b){event=b?b:window.event;var c=j[event.keyCode];g[c]=!0;h[c]&&(h[c](c),b.preventDefault());n[c]&&b.preventDefault()}
-function e(b){event=b?b:window.event;var c=m[event.button];g[c]=!0;h[c]&&(h[c](c),b.preventDefault())}function f(b){event=b?b:window.event;var c=m[event.button];g[c]=!1;k[c]&&(k[c](c),b.preventDefault())}var g={},j=[],h=[],k=[],m=[];c.setupInput=function(){var c=[];c[8]="backspace";c[9]="tab";c[13]="enter";c[16]="shift";c[17]="ctrl";c[18]="alt";c[19]="pause";c[20]="capslock";c[27]="esc";c[32]="space";c[33]="pageup";c[34]="pagedown";c[35]="end";c[36]="home";c[37]="left";c[38]="up";c[39]="right";c[40]=
-"down";c[45]="insert";c[46]="delete";c[91]="leftwindowkey";c[92]="rightwindowkey";c[93]="selectkey";c[106]="multiply";c[107]="add";c[109]="subtract";c[110]="decimalpoint";c[111]="divide";c[144]="numlock";c[145]="scrollock";c[186]="semicolon";c[187]="equalsign";c[188]="comma";c[189]="dash";c[190]="period";c[191]="forwardslash";c[192]="graveaccent";c[219]="openbracket";c[220]="backslash";c[221]="closebracket";c[222]="singlequote";m=["left_mouse_button","center_mouse_button","right_mouse_button"];for(var g=
-"numpad1,numpad2,numpad3,numpad4,numpad5,numpad6,numpad7,numpad8,numpad9".split(","),h="f1,f2,f3,f4,f5,f6,f7,f8,f9".split(","),k="0,1,2,3,4,5,6,7,8,9".split(","),n="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(","),l=0;k[l];l++)c[48+l]=k[l];for(l=0;n[l];l++)c[65+l]=n[l];for(l=0;g[l];l++)c[96+l]=g[l];for(l=0;h[l];l++)c[112+l]=h[l];j=c;window.addEventListener("keydown",d);window.addEventListener("keyup",b);window.addEventListener("mousedown",e,!1);window.addEventListener("mouseup",f,!1);
-document.oncontextmenu=function(){return!1}};var n=[];c.preventDefaultKeys=function(b){b.forEach(function(b){n[b]=!0})};c.pressed=function(b){return g[b]};c.on_keydown=function(b,d){if(c.isArray(b))for(var e=0;b[e];e++)h[b[e]]=d;else h[b]=d};c.on_keyup=function(b,d){if(c.isArray(b))for(var e=0;b[e];e++)k[b[e]]=d;else k[b]=d};c.clearKeyCallbacks=function(){k=[];h=[]};return c}(jaws||{}),jaws=function(c){c.Assets=function(){if(!(this instanceof arguments.callee))return new arguments.callee;this.loaded=
-[];this.loading=[];this.src_list=[];this.data=[];this.bust_cache=!1;this.fuchia_to_transparent=this.image_to_canvas=!0;this.root="";this.file_type={};this.file_type.json="json";this.file_type.wav="audio";this.file_type.mp3="audio";this.file_type.ogg="audio";this.file_type.png="image";this.file_type.jpg="image";this.file_type.jpeg="image";this.file_type.gif="image";this.file_type.bmp="image";this.file_type.tiff="image";var b=this;this.length=function(){return this.src_list.length};this.get=function(d){if(c.isArray(d))return d.map(function(c){return b.data[c]});
+(b.y=c.height)};c.getUrlParameters=function(){for(var b=[],c,d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),e=0;e<d.length;e++)c=d[e].split("="),b.push(c[0]),b[c[0]]=c[1];return b};return c}(jaws||{}),jaws=function(c){function b(b){event=b?b:window.event;var c=k[event.keyCode];h[c]=!1;n[c]&&(n[c](c),b.preventDefault());o[c]&&b.preventDefault()}function d(b){event=b?b:window.event;var c=k[event.keyCode];h[c]=!0;l[c]&&(l[c](c),b.preventDefault());o[c]&&b.preventDefault()}
+function e(b){event=b?b:window.event;var c=q[event.button];"Microsoft Internet Explorer"==navigator.appName&&(c=p[event.button]);h[c]=!0;l[c]&&(l[c](c),b.preventDefault())}function f(b){event=b?b:window.event;var c=q[event.button];"Microsoft Internet Explorer"==navigator.appName&&(c=p[event.button]);h[c]=!1;n[c]&&(n[c](c),b.preventDefault())}function g(b){event=b?b:window.event;h.left_mouse_button=!0;c.mouse_x=b.touches[0].pageX-c.canvas.offsetLeft;c.mouse_y=b.touches[0].pageY-c.canvas.offsetTop}
+function j(b){event=b?b:window.event;h.left_mouse_button=!1;c.mouse_x=void 0;c.mouse_y=void 0}var h={},k=[],l=[],n=[],q=[],p=[];c.setupInput=function(){var c=[];c[8]="backspace";c[9]="tab";c[13]="enter";c[16]="shift";c[17]="ctrl";c[18]="alt";c[19]="pause";c[20]="capslock";c[27]="esc";c[32]="space";c[33]="pageup";c[34]="pagedown";c[35]="end";c[36]="home";c[37]="left";c[38]="up";c[39]="right";c[40]="down";c[45]="insert";c[46]="delete";c[91]="leftwindowkey";c[92]="rightwindowkey";c[93]="selectkey";c[106]=
+"multiply";c[107]="add";c[109]="subtract";c[110]="decimalpoint";c[111]="divide";c[144]="numlock";c[145]="scrollock";c[186]="semicolon";c[187]="equalsign";c[188]="comma";c[189]="dash";c[190]="period";c[191]="forwardslash";c[192]="graveaccent";c[219]="openbracket";c[220]="backslash";c[221]="closebracket";c[222]="singlequote";q=["left_mouse_button","center_mouse_button","right_mouse_button"];p=[,"left_mouse_button","right_mouse_button",,"center_mouse_button"];for(var h="numpad1 numpad2 numpad3 numpad4 numpad5 numpad6 numpad7 numpad8 numpad9".split(" "),
+l="f1 f2 f3 f4 f5 f6 f7 f8 f9".split(" "),n="0123456789".split(""),o="abcdefghijklmnopqrstuvwxyz".split(""),m=0;n[m];m++)c[48+m]=n[m];for(m=0;o[m];m++)c[65+m]=o[m];for(m=0;h[m];m++)c[96+m]=h[m];for(m=0;l[m];m++)c[112+m]=l[m];k=c;window.addEventListener("keydown",d);window.addEventListener("keyup",b);window.addEventListener("mousedown",e,!1);window.addEventListener("mouseup",f,!1);window.addEventListener("touchstart",g,!1);window.addEventListener("touchend",j,!1);document.oncontextmenu=function(){return!1}};
+var o=[];c.preventDefaultKeys=function(b){b.forEach(function(b){o[b]=!0})};c.pressed=function(b){return h[b]};c.on_keydown=function(b,d){if(c.isArray(b))for(var e=0;b[e];e++)l[b[e]]=d;else l[b]=d};c.on_keyup=function(b,d){if(c.isArray(b))for(var e=0;b[e];e++)n[b[e]]=d;else n[b]=d};c.clearKeyCallbacks=function(){n=[];l=[]};return c}(jaws||{}),jaws=function(c){c.Assets=function(){if(!(this instanceof arguments.callee))return new arguments.callee;this.loaded=[];this.loading=[];this.src_list=[];this.data=
+[];this.bust_cache=!1;this.fuchia_to_transparent=this.image_to_canvas=!0;this.root="";this.file_type={};this.file_type.json="json";this.file_type.wav="audio";this.file_type.mp3="audio";this.file_type.ogg="audio";this.file_type.png="image";this.file_type.jpg="image";this.file_type.jpeg="image";this.file_type.gif="image";this.file_type.bmp="image";this.file_type.tiff="image";var b=this;this.length=function(){return this.src_list.length};this.get=function(d){if(c.isArray(d))return d.map(function(c){return b.data[c]});
if(this.loaded[d])return this.data[d];c.log("No such asset: "+d,!0)};this.isLoading=function(b){return this.loading[b]};this.isLoaded=function(b){return this.loaded[b]};this.getPostfix=function(b){postfix_regexp=/\.([a-zA-Z0-9]+)/;return postfix_regexp.exec(b)[1]};this.getType=function(b){b=this.getPostfix(b);return this.file_type[b]?this.file_type[b]:b};this.add=function(b){if(c.isArray(b))for(var e=0;b[e];e++)this.add(b[e]);else this.src_list.push(b);return this};this.loadAll=function(b){this.error_count=
this.load_count=0;this.onload=b.onload;this.onerror=b.onerror;this.onfinish=b.onfinish;for(i=0;this.src_list[i];i++)this.load(this.src_list[i])};this.getOrLoad=function(b,c,f){this.data[b]?c():this.load(b,c,f)};this.load=function(b,c,f){var g={};g.src=b;g.onload=c;g.onerror=f;this.loading[b]=!0;b=this.root+g.src;this.bust_cache&&(b+="?"+parseInt(1E7*Math.random()));switch(this.getType(g.src)){case "image":g.image=new Image;g.image.asset=g;g.image.onload=this.assetLoaded;g.image.onerror=this.assetError;
g.image.src=b;break;case "audio":g.audio=new Audio(b);g.audio.asset=g;this.data[g.src]=g.audio;g.audio.addEventListener("canplay",this.assetLoaded,!1);g.audio.addEventListener("error",this.assetError,!1);g.audio.load();break;default:c=new XMLHttpRequest,c.asset=g,c.onreadystatechange=this.assetLoaded,c.open("GET",b,!0),c.send(null)}};this.assetLoaded=function(){var d=this.asset,e=d.src,f=b.getType(d.src);b.loaded[e]=!0;b.loading[e]=!1;if("json"==f){if(4!=this.readyState)return;b.data[d.src]=JSON.parse(this.responseText)}else if("image"==
-f){e=b.image_to_canvas?c.imageToCanvas(d.image):d.image;if(b.fuchia_to_transparent&&"bmp"==b.getPostfix(d.src)){canvas=c.isImage(e)?c.imageToCanvas(e):e;for(var e=canvas.getContext("2d"),f=e.getImageData(0,0,canvas.width,canvas.height),g=f.data,j=0;j<g.length;j+=4)255==g[j]&&0==g[j+1]&&255==g[j+2]&&(g[j+3]=0);e.putImageData(f,0,0);e=canvas}b.data[d.src]=e}else"audio"==f&&(d.audio.removeEventListener("canplay",b.assetLoaded,!1),b.data[d.src]=d.audio);b.load_count++;b.processCallbacks(d,!0)};this.assetError=
+f){e=b.image_to_canvas?c.imageToCanvas(d.image):d.image;if(b.fuchia_to_transparent&&"bmp"==b.getPostfix(d.src)){canvas=c.isImage(e)?c.imageToCanvas(e):e;for(var e=canvas.getContext("2d"),f=e.getImageData(0,0,canvas.width,canvas.height),g=f.data,j=0;j<g.length;j+=4)255==g[j]&&(0==g[j+1]&&255==g[j+2])&&(g[j+3]=0);e.putImageData(f,0,0);e=canvas}b.data[d.src]=e}else"audio"==f&&(d.audio.removeEventListener("canplay",b.assetLoaded,!1),b.data[d.src]=d.audio);b.load_count++;b.processCallbacks(d,!0)};this.assetError=
function(){var c=this.asset;b.error_count++;b.processCallbacks(c,!1)};this.processCallbacks=function(c,e){var f=parseInt(100*((b.load_count+b.error_count)/b.src_list.length));if(e){if(b.onload)b.onload(c.src,f);if(c.onload)c.onload()}else{if(b.onerror)b.onerror(c.src,f);if(c.onerror)c.onerror(c)}if(100==f){if(b.onfinish)b.onfinish();b.onload=null;b.onerror=null;b.onfinish=null}}};c.assets=new c.Assets;return c}(jaws||{}),jaws=function(c){function b(b){this.size=b;this.values=Array(this.size);this.value;
this.add=function(b){if(this.values.length>this.size){this.values.splice(0,1);for(var c=this.value=0;this.values[c];c++)this.value+=this.values[c];this.value/=this.size}this.values.push(b);return this};this.get=function(){return parseInt(this.value)}}window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b){window.setTimeout(b,16.666)}}();c.GameLoop=
-function(d,e,f){if(!(this instanceof arguments.callee))return new arguments.callee(d,e);this.fps=this.tick_duration=this.ticks=0;var g,j=!1,h=!1,k=this,m=new b(20);this.runtime=function(){return this.last_tick-this.first_tick};this.start=function(){c.log("game loop start",!0);this.first_tick=(new Date).getTime();this.current_tick=(new Date).getTime();this.last_tick=(new Date).getTime();d.setup&&d.setup(f);step_delay=1E3/e.fps;60==e.fps?requestAnimFrame(this.loop):g=setInterval(this.loop,step_delay);
-c.log("game loop loop",!0)};this.loop=function(){k.current_tick=(new Date).getTime();k.tick_duration=k.current_tick-k.last_tick;k.fps=m.add(1E3/k.tick_duration).get();!h&&!j&&(d.update&&d.update(),d.draw&&d.draw(),k.ticks++);60==e.fps&&!h&&requestAnimFrame(k.loop);k.last_tick=k.current_tick};this.pause=function(){j=!0};this.unpause=function(){j=!1};this.stop=function(){g&&clearInterval(g);h=!0}};return c}(jaws||{}),jaws=function(c){c.Rect=function(b,c,e,f){if(!(this instanceof arguments.callee))return new arguments.callee(b,
+function(d,e,f){if(!(this instanceof arguments.callee))return new arguments.callee(d,e);this.fps=this.tick_duration=this.ticks=0;var g,j=!1,h=!1,k=this,l=new b(20);this.runtime=function(){return this.last_tick-this.first_tick};this.start=function(){c.log("game loop start",!0);this.first_tick=(new Date).getTime();this.current_tick=(new Date).getTime();this.last_tick=(new Date).getTime();d.setup&&d.setup(f);step_delay=1E3/e.fps;60==e.fps?requestAnimFrame(this.loop):g=setInterval(this.loop,step_delay);
+c.log("game loop loop",!0)};this.loop=function(){k.current_tick=(new Date).getTime();k.tick_duration=k.current_tick-k.last_tick;k.fps=l.add(1E3/k.tick_duration).get();!h&&!j&&(d.update&&d.update(),d.draw&&d.draw(),k.ticks++);60==e.fps&&!h&&requestAnimFrame(k.loop);k.last_tick=k.current_tick};this.pause=function(){j=!0};this.unpause=function(){j=!1};this.stop=function(){g&&clearInterval(g);h=!0}};return c}(jaws||{}),jaws=function(c){c.Rect=function(b,c,e,f){if(!(this instanceof arguments.callee))return new arguments.callee(b,
c,e,f);this.x=b;this.y=c;this.width=e;this.height=f;this.right=b+e;this.bottom=c+f};c.Rect.prototype.getPosition=function(){return[this.x,this.y]};c.Rect.prototype.move=function(b,c){this.x+=b;this.y+=c;this.right+=b;this.bottom+=c;return this};c.Rect.prototype.moveTo=function(b,c){this.x=b;this.y=c;this.right=this.x+this.width;this.bottom=this.y+this.height;return this};c.Rect.prototype.resize=function(b,c){this.width+=b;this.height+=c;this.right=this.x+this.width;this.bottom=this.y+this.height;
return this};c.Rect.prototype.resizeTo=function(b,c){this.width=b;this.height=c;this.right=this.x+this.width;this.bottom=this.y+this.height;return this};c.Rect.prototype.draw=function(){c.context.strokeStyle="red";c.context.strokeRect(this.x,this.y,this.width,this.height);return this};c.Rect.prototype.collidePoint=function(b,c){return b>=this.x&&b<=this.right&&c>=this.y&&c<=this.bottom};c.Rect.prototype.collideRect=function(b){return(this.x>=b.x&&this.x<=b.right||b.x>=this.x&&b.x<=this.right)&&(this.y>=
b.y&&this.y<=b.bottom||b.y>=this.y&&b.y<=this.bottom)};c.Rect.prototype.toString=function(){return"[Rect "+this.x+", "+this.y+", "+this.width+", "+this.height+"]"};return c}(jaws||{});"undefined"!==typeof module&&"exports"in module&&(module.exports=jaws.Rect);
@@ -67,5 +68,5 @@ c.TileMap.prototype.all=function(){for(var b=[],c=0;c<this.size[0];c++)for(var e
jaws=function(c){function b(b,c){for(var f=function(c){return b.isSpriteList!==void 0?b.at(c):b[c]},g=[],j=Array(c),h=0;h<c;h++)j[h]=h;for(var h=c-1,k=b.length;0<=h;k=b.length){for(g.push(j.map(f));0<=h&&j[h]==k-1;){h--;k--}if(0<=h){j[h]=j[h]+1;for(h=h+1;h<c;h++)j[h]=j[h-1]+1;h=c-1}}return g}c.collideOneWithOne=function(b,e){return b.radius&&e.radius&&b!==e&&c.collideCircles(b,e)||b.rect&&e.rect&&b!==e&&c.collideRects(b.rect(),e.rect())?true:false};c.collideOneWithMany=function(b,e){return e.filter(function(e){return c.collideOneWithOne(b,
e)})};c.collideManyWithMany=function(d,e){var f=[];d===e?b(d,2).forEach(function(b){c.collideOneWithOne(b[0],b[1])&&f.push([b[0],b[1]])}):d.forEach(function(b){e.forEach(function(d){c.collideOneWithOne(b,d)&&f.push([b,d])})});return f};c.collideCircles=function(b,e){return c.distanceBetween(b,e)<b.radius+e.radius};c.collideRects=function(b,c){return(b.x>=c.x&&b.x<=c.right||c.x>=b.x&&c.x<=b.right)&&(b.y>=c.y&&b.y<=c.bottom||c.y>=b.y&&c.y<=b.bottom)};c.distanceBetween=function(b,c){return Math.sqrt(Math.pow(b.x-
c.x,2)+Math.pow(b.y-c.y,2))};return c}(jaws||{});
-jaws=function(c){c.gfx={};c.gfx.retroScaleImage=function(b,d){var e=c.isImage(b)?c.imageToCanvas(b):b,e=e.getContext("2d").getImageData(0,0,e.width,e.height).data,f=document.createElement("canvas");f.width=b.width*d;f.height=b.height*d;for(var g=f.getContext("2d"),j=g.createImageData(f.width,f.height),h=j.width,k=j.height,m=0;m<k;m=m+1)for(var n=m*j.width,r=Math.floor(m/d)*b.width,o=0;o<h;o=o+1){var p=(n+o)*4,q=(r+Math.floor(o/d))*4;j.data[p]=e[q];j.data[p+1]=e[q+1];j.data[p+2]=e[q+2];j.data[p+3]=
-e[q+3]}g.putImageData(j,0,0);return f};return c}(jaws||{});window.addEventListener("load",function(){if(jaws.onload)jaws.onload()},!1);
+jaws=function(c){c.gfx={};c.gfx.retroScaleImage=function(b,d){var e=c.isImage(b)?c.imageToCanvas(b):b,e=e.getContext("2d").getImageData(0,0,e.width,e.height).data,f=document.createElement("canvas");f.width=b.width*d;f.height=b.height*d;for(var g=f.getContext("2d"),j=g.createImageData(f.width,f.height),h=j.width,k=j.height,l=0;l<k;l=l+1)for(var n=l*j.width,q=Math.floor(l/d)*b.width,p=0;p<h;p=p+1){var o=(n+p)*4,r=(q+Math.floor(p/d))*4;j.data[o]=e[r];j.data[o+1]=e[r+1];j.data[o+2]=e[r+2];j.data[o+3]=
+e[r+3]}g.putImageData(j,0,0);return f};return c}(jaws||{});window.addEventListener("load",function(){if(jaws.onload)jaws.onload()},!1);
View
46 jaws.js
@@ -360,6 +360,7 @@ var jaws = (function(jaws) {
var on_keydown_callbacks = []
var on_keyup_callbacks = []
var mousebuttoncode_to_string = []
+ var ie_mousebuttoncode_to_string = []
/** @private
* Map all javascript keycodes to easy-to-remember letters/words
@@ -416,8 +417,15 @@ jaws.setupInput = function() {
m[0] = "left_mouse_button"
m[1] = "center_mouse_button"
m[2] = "right_mouse_button"
+
+ var ie_m = [];
+ ie_m[1] = "left_mouse_button";
+ ie_m[2] = "right_mouse_button";
+ ie_m[4] = "center_mouse_button";
mousebuttoncode_to_string = m
+ ie_mousebuttoncode_to_string = ie_m;
+
var numpadkeys = ["numpad1","numpad2","numpad3","numpad4","numpad5","numpad6","numpad7","numpad8","numpad9"]
var fkeys = ["f1","f2","f3","f4","f5","f6","f7","f8","f9"]
@@ -434,6 +442,9 @@ jaws.setupInput = function() {
window.addEventListener("keyup", handleKeyUp)
window.addEventListener('mousedown', handleMouseDown, false);
window.addEventListener('mouseup', handleMouseUp, false);
+ window.addEventListener('touchstart', handleTouchStart, false);
+ window.addEventListener('touchend', handleTouchEnd, false);
+
// this turns off the right click context menu which screws up the mouseup event for button 2
document.oncontextmenu = function() {return false};
}
@@ -471,24 +482,54 @@ function handleKeyDown(e) {
function handleMouseDown(e) {
event = (e) ? e : window.event
var human_name = mousebuttoncode_to_string[event.button] // 0 1 2
+ if (navigator.appName == 'Microsoft Internet Explorer'){
+ human_name = ie_mousebuttoncode_to_string[event.button];
+ }
pressed_keys[human_name] = true
if(on_keydown_callbacks[human_name]) {
on_keydown_callbacks[human_name](human_name)
e.preventDefault()
}
}
+
+
/** @private
* handle event "onmouseup" by remembering what button was un-pressed
*/
function handleMouseUp(e) {
event = (e) ? e : window.event
- var human_name = mousebuttoncode_to_string[event.button]
+ var human_name = mousebuttoncode_to_string[event.button]
+
+ if (navigator.appName == 'Microsoft Internet Explorer'){
+ human_name = ie_mousebuttoncode_to_string[event.button];
+ }
pressed_keys[human_name] = false
if(on_keyup_callbacks[human_name]) {
on_keyup_callbacks[human_name](human_name)
e.preventDefault()
}
-// need to investigate prevent default for mouse actions instead of hard coding the oncontextmenu
+}
+
+/** @private
+ * handle event "touchstart" by remembering what button was pressed
+ */
+function handleTouchStart(e) {
+ event = (e) ? e : window.event
+ pressed_keys['left_mouse_button'] = true
+ jaws.mouse_x = e.touches[0].pageX - jaws.canvas.offsetLeft;
+ jaws.mouse_y = e.touches[0].pageY - jaws.canvas.offsetTop;
+ //e.preventDefault()
+}
+
+/** @private
+ * handle event "touchend" by remembering what button was pressed
+ */
+function handleTouchEnd(e) {
+ event = (e) ? e : window.event
+ pressed_keys['left_mouse_button'] = false
+ jaws.mouse_x = undefined;
+ jaws.mouse_y = undefined;
+
}
var prevent_default_keys = []
@@ -558,7 +599,6 @@ jaws.clearKeyCallbacks = function() {
return jaws;
})(jaws || {});
-
var jaws = (function(jaws) {
/**

No commit comments for this range

Something went wrong with that request. Please try again.