From 26e282e626be8d16eb40fe1ddf4454f96037a3e1 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sun, 5 Oct 2014 16:38:17 +0200 Subject: jaws: Remove tilemap support diff --git a/jaws/jaws-min.js b/jaws/jaws-min.js index dbe92de..180b648 100644 --- a/jaws/jaws-min.js +++ b/jaws/jaws-min.js @@ -1,2 +1,2 @@ -var jaws=function(t){function e(e){t.mouse_x=e.pageX||e.clientX,t.mouse_y=e.pageY||e.clientY;var i=t.canvas?t.canvas:t.dom;t.mouse_x-=i.offsetLeft,t.mouse_y-=i.offsetTop}var i,s;return t.SpriteList=function(){throw"To use SpriteList() you need to include src/extras/sprite_list.js"},t.Audio=function(){throw"To use jaws.Audio() you need to include src/extras/audio.js"},t.title=function(e){return t.isString(e)?e?i.innerHTML=e:i.innerHTML:void t.log.error("jaws.title: Passed in value is not a String.")},t.unpack=function(){var e=["Sprite","SpriteList","Animation","Viewport","SpriteSheet","Parallax","TileMap","pressed","QuadTree"];e.forEach(function(e){window[e]?t.log.warn("jaws.unpack: "+e+" already exists in global namespace."):window[e]=t[e]})},t.log=function(e,i){t.isString(e)||(e=JSON.stringify(e)),t.log.on&&(s&&t.log.use_log_element&&(i?s.innerHTML+=e+"
":s.innerHTML=e),console.log&&t.log.use_console&&console.log("JawsJS: ",e))},t.log.on=!0,t.log.use_console=!1,t.log.use_log_element=!0,t.log.warn=function(e){console.warn&&t.log.use_console&&t.log.on?console.warn(e):t.log("[WARNING]: "+JSON.stringify(e),!0)},t.log.error=function(e){console.error&&t.log.use_console&&t.log.on?console.error(e):t.log("[ERROR]: "+JSON.stringify(e),!0)},t.log.info=function(e){console.info&&t.log.use_console&&t.log.on?console.info(e):t.log("[INFO]: "+JSON.stringify(e),!0)},t.log.debug=function(e){console.debug&&t.log.use_console&&t.log.on?console.debug(e):t.log("[DEBUG]: "+JSON.stringify(e),!0)},t.log.clear=function(){s&&(s.innerHTML=""),console.clear&&console.clear()},t.init=function(o){i=document.getElementsByTagName("title")[0],t.url_parameters=t.getUrlParameters(),t.canvas=document.getElementsByTagName("canvas")[0],t.canvas||(t.dom=document.getElementById("canvas")),t.canvas?t.context=t.canvas.getContext("2d"):t.dom?t.dom.style.position="relative":(t.canvas=document.createElement("canvas"),t.canvas.width=o.width,t.canvas.height=o.height,t.context=t.canvas.getContext("2d"),document.body.appendChild(t.canvas)),s=document.getElementById("jaws-log"),t.url_parameters.debug&&(s||(s=document.createElement("div"),s.id="jaws-log",s.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(s))),t.url_parameters.bust_cache&&(t.log.info("Busting cache when loading assets"),t.assets.bust_cache=!0),t.context&&t.useCrispScaling(),t.width=t.canvas?t.canvas.width:t.dom.offsetWidth,t.height=t.canvas?t.canvas.height:t.dom.offsetHeight,t.mouse_x=0,t.mouse_y=0,window.addEventListener("mousemove",e)},t.useCrispScaling=function(){t.context.imageSmoothingEnabled=!1,t.context.webkitImageSmoothingEnabled=!1,t.context.mozImageSmoothingEnabled=!1},t.useSmoothScaling=function(){t.context.imageSmoothingEnabled=!0,t.context.webkitImageSmoothingEnabled=!0,t.context.mozImageSmoothingEnabled=!0},t.start=function(e,i,s){function o(e,s){t.log.info(s+"%: "+e,!0),i.loading_screen&&t.assets.displayProgress(s)}function n(e,i){t.log.info(i+"%: Error loading asset "+e,!0)}function r(){t.log.info("all assets loaded",!0),t.switchGameState(e||window,{fps:a},s)}i||(i={});var a=i.fps||60;return void 0===i.loading_screen&&(i.loading_screen=!0),i.width||(i.width=500),i.height||(i.height=300),t.init(i),t.isFunction(e)||t.isObject(e)?t.isObject(s)||void 0===s?(i.loading_screen&&t.assets.displayProgress(0),t.log.info("setupInput()",!0),t.setupInput(),t.log.info("assets.loadAll()",!0),void(t.assets.length()>0?t.assets.loadAll({onprogress:o,onerror:n,onload:r}):r())):void t.log.error("jaws.start: The setup options for the game state is not an object."):void t.log.error("jaws.start: Passed in GameState is niether function or object")},t.switchGameState=function(e,i,s){if(void 0===i&&(i={}),t.isFunction(e)&&(e=new e),!t.isObject(e))return void t.log.error("jaws.switchGameState: Passed in GameState should be a Function or an Object.");var o=i&&i.fps||t.game_loop&&t.game_loop.fps||60,n=i.setup;t.game_loop&&t.game_loop.stop(),t.clearKeyCallbacks(),t.previous_game_state=t.game_state,t.game_state=e,t.game_loop=new t.GameLoop(e,{fps:o,setup:n},s),t.game_loop.start()},t.imageToCanvas=function(e){if(t.isCanvas(e))return e;if(!t.isImage(e))return void t.log.error("jaws.imageToCanvas: Passed in object is not an Image.");var i=document.createElement("canvas");i.src=e.src,i.width=e.width,i.height=e.height;var s=i.getContext("2d");return s.drawImage(e,0,0,e.width,e.height),i},t.forceArray=function(t){return Array.isArray(t)?t:[t]},t.clear=function(){t.context.clearRect(0,0,t.width,t.height)},t.fill=function(e){t.context.fillStyle=e,t.context.fillRect(0,0,t.width,t.height)},t.draw=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;it.width||e.y>t.height:void 0},t.forceInsideCanvas=function(e){e.x&&e.y&&(e.x<0&&(e.x=0),e.x>t.width&&(e.x=t.width),e.y<0&&(e.y=0),e.y>t.height&&(e.y=t.height))},t.getUrlParameters=function(){for(var t,e=[],i=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),s=0;su;u+=1)for(var d=Math.floor(u/i),f=u*h.width,p=d*e.width,g=0;c>g;g+=1){var m=Math.floor(g/i),w=4*(f+g),y=4*(p+m);h.data[w]=n[y],h.data[w+1]=n[y+1],h.data[w+2]=n[y+2],h.data[w+3]=n[y+3]}return a.putImageData(h,0,0),r},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws);var jaws=function(t){function e(){h={}}function i(t){event=t?t:window.event;var e=l[event.keyCode];null!=e&&(e=e.split(" "),e.forEach(function(e){h[e]=!1,d[e]&&(d[e](e),t.preventDefault()),g[e]&&t.preventDefault()}))}function s(t){event=t?t:window.event;var e=l[event.keyCode];null!=e&&(e=e.split(" "),e.forEach(function(e){h[e]=!0,u[e]&&(u[e](e),t.preventDefault()),g[e]&&t.preventDefault()}))}function o(t){event=t?t:window.event;var e=f[event.button];"Microsoft Internet Explorer"==navigator.appName&&(e=p[event.button]),h[e]=!0,u[e]&&(u[e](e),t.preventDefault())}function n(t){event=t?t:window.event;var e=f[event.button];"Microsoft Internet Explorer"==navigator.appName&&(e=p[event.button]),h[e]=!1,d[e]&&(d[e](e),t.preventDefault())}function r(e){event=e?e:window.event,h.left_mouse_button=!0,t.mouse_x=e.touches[0].pageX-t.canvas.offsetLeft,t.mouse_y=e.touches[0].pageY-t.canvas.offsetTop}function a(e){event=e?e:window.event,h.left_mouse_button=!1,t.mouse_x=void 0,t.mouse_y=void 0}var h={},c={},l=[],u=[],d=[],f=[],p=[];t.setupInput=function(){var h=[];h[8]="backspace",h[9]="tab",h[13]="enter",h[16]="shift",h[17]="ctrl",h[18]="alt",h[19]="pause",h[20]="capslock",h[27]="esc",h[32]="space",h[33]="pageup",h[34]="pagedown",h[35]="end",h[36]="home",h[37]="left",h[38]="up",h[39]="right",h[40]="down",h[45]="insert",h[46]="delete",h[91]="left_window_key leftwindowkey",h[92]="right_window_key rightwindowkey",h[93]="select_key selectkey",h[106]="multiply *",h[107]="add plus +",h[109]="subtract minus -",h[110]="decimalpoint",h[111]="divide /",h[144]="numlock",h[145]="scrollock",h[186]="semicolon ;",h[187]="equalsign =",h[188]="comma ,",h[189]="dash -",h[190]="period .",h[191]="forwardslash /",h[192]="graveaccent `",h[219]="openbracket [",h[220]="backslash \\",h[221]="closebracket ]",h[222]="singlequote '";var c=[];c[0]="left_mouse_button",c[1]="center_mouse_button",c[2]="right_mouse_button";var u=[];u[1]="left_mouse_button",u[2]="right_mouse_button",u[4]="center_mouse_button",f=c,p=u;for(var d=["numpad0","numpad1","numpad2","numpad3","numpad4","numpad5","numpad6","numpad7","numpad8","numpad9"],g=["f1","f2","f3","f4","f5","f6","f7","f8","f9"],m=["0","1","2","3","4","5","6","7","8","9"],w=["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"],y=0;m[y];y++)h[48+y]=m[y];for(var y=0;w[y];y++)h[65+y]=w[y];for(var y=0;d[y];y++)h[96+y]=d[y];for(var y=0;g[y];y++)h[112+y]=g[y];l=h,window.addEventListener("keydown",s),window.addEventListener("keyup",i);var x=t.canvas||t.dom;x.addEventListener("mousedown",o,!1),x.addEventListener("mouseup",n,!1),x.addEventListener("touchstart",r,!1),x.addEventListener("touchend",a,!1),window.addEventListener("blur",e,!1),document.oncontextmenu=function(){return!1}};var g=[];return t.preventDefaultKeys=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;ithis.size){this.values.splice(0,1),this.value=0;for(var e=0;this.values[e];e++)this.value+=this.values[e];this.value=this.value/this.size}return this.values.push(t),this},this.get=function(){return parseInt(this.value)}}return window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,16.666)}}(),t.GameLoop=function(i,s,o){if(!(this instanceof arguments.callee))return new arguments.callee(i,s);this.tick_duration=0,this.fps=0,this.ticks=0;var n,r=!1,a=!1,h=this,c=new e(20);this.runtime=function(){return this.last_tick-this.first_tick},this.start=function(){t.log.info("Game loop start",!0),this.first_tick=(new Date).getTime(),this.current_tick=(new Date).getTime(),this.last_tick=(new Date).getTime(),s.setup!==!1&&i.setup&&i.setup(o),step_delay=1e3/s.fps,60==s.fps?requestAnimFrame(this.loop):n=setInterval(this.loop,step_delay)},this.loop=function(){h.current_tick=(new Date).getTime(),h.tick_duration=h.current_tick-h.last_tick,h.fps=c.add(1e3/h.tick_duration).get(),a||r||(i.update&&i.update(),i.draw&&i.draw(),h.ticks++),60!=s.fps||a||requestAnimFrame(h.loop),h.last_tick=h.current_tick},this.pause=function(){r=!0},this.unpause=function(){r=!1},this.stop=function(){n&&clearInterval(n),a=!0}},t}(jaws||{}),jaws=function(t){var e=0;return t.Rect=function(t,i,s,o){return this instanceof arguments.callee?(this.x=t,this.y=i,this.width=s,this.height=o,this.right=t+s-e,void(this.bottom=i+o-e)):new arguments.callee(t,i,s,o)},t.Rect.prototype.getPosition=function(){return[this.x,this.y]},t.Rect.prototype.move=function(t,e){return this.x+=t,this.y+=e,this.right+=t,this.bottom+=e,this},t.Rect.prototype.moveTo=function(t,i){return this.x=t,this.y=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.resize=function(t,i){return this.width+=t,this.height+=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.clone=function(){return new t.Rect(this.x,this.y,this.width,this.height)},t.Rect.prototype.shrink=function(t,i){return this.x+=t,this.y+=i,this.width-=t+t,this.height-=i+i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.resizeTo=function(t,i){return this.width=t,this.height=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.draw=function(){return t.context.strokeStyle="red",t.context.strokeRect(this.x-.5,this.y-.5,this.width,this.height),this},t.Rect.prototype.collidePoint=function(t,e){return t>=this.x&&t<=this.right&&e>=this.y&&e<=this.bottom},t.Rect.prototype.collideRect=function(t){return(this.x>=t.x&&this.x<=t.right||t.x>=this.x&&t.x<=this.right)&&(this.y>=t.y&&this.y<=t.bottom||t.y>=this.y&&t.y<=this.bottom)},t.Rect.prototype.toString=function(){return"[Rect "+this.x+", "+this.y+", "+this.width+", "+this.height+"]"},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.Rect);var jaws=function(jaws){return jaws.Sprite=function(t){return this instanceof arguments.callee?(this.set(t),void(this.context=t.context?t.context:jaws.context)):new arguments.callee(t)},jaws.Sprite.prototype.default_options={x:0,y:0,alpha:1,angle:0,flipped:!1,anchor_x:0,anchor_y:0,image:null,image_path:null,anchor:null,scale_image:null,damping:1,scale_x:1,scale_y:1,scale:1,color:"#ddd",width:16,height:16,_constructor:null,context:null,data:null},jaws.Sprite.prototype.set=function(t){if(jaws.isString(this.image)&&(this.image_path=this.image),jaws.parseOptions(this,t,this.default_options),this.scale&&(this.scale_x=this.scale_y=this.scale),this.image&&this.setImage(this.image),this.scale_image&&this.scaleImage(this.scale_image),this.anchor&&this.setAnchor(this.anchor),!this.image&&this.color&&this.width&&this.height){var e=document.createElement("canvas"),i=e.getContext("2d");e.width=this.width,e.height=this.height,i.fillStyle=this.color,i.fillRect(0,0,this.width,this.height),this.image=e}return this.cacheOffsets(),this},jaws.Sprite.prototype.clone=function(object){var constructor=this._constructor?eval(this._constructor):this.constructor,new_sprite=new constructor(this.attributes());return new_sprite._constructor=this._constructor||this.constructor.name,new_sprite},jaws.Sprite.prototype.setImage=function(t){var e=this;return jaws.isDrawable(t)?(this.image=t,this.cacheOffsets()):(jaws.assets.isLoaded(t)?(this.image=jaws.assets.get(t),this.cacheOffsets()):(jaws.log.warn("Image '"+t+"' not preloaded with jaws.assets.add(). Image and a working sprite.rect() will be delayed."),jaws.assets.load(t,{onload:function(){e.image=jaws.assets.get(t),e.cacheOffsets()}})),this)},jaws.Sprite.prototype.stepToWhile=function(t,e,i){var s=1,o=tthis.frame_duration&&(this.index+=this.frame_direction,this.sum_tick=0),(this.index>=this.frames.length||this.index<0)&&(this.bounce?(this.frame_direction=-this.frame_direction,this.index+=2*this.frame_direction):this.loop?this.index=this.frame_direction<0?this.frames.length-1:0:(this.index-=this.frame_direction,this.on_end&&(this.on_end(),this.on_end=null))),this},t.Animation.prototype.slice=function(e,i){var s={};return s.frame_duration=this.frame_duration,s.loop=this.loop,s.bounce=this.bounce,s.on_end=this.on_end,s.frame_direction=this.frame_direction,s.frames=this.frames.slice().slice(e,i),new t.Animation(s) -},t.Animation.prototype.next=function(){return this.update(),this.frames[this.index]},t.Animation.prototype.atLastFrame=function(){return this.index==this.frames.length-1},t.Animation.prototype.atFirstFrame=function(){return 0==this.index},t.Animation.prototype.currentFrame=function(){return this.frames[this.index]},t.Animation.prototype.toString=function(){return"[Animation, "+this.frames.length+" frames]"},t}(jaws||{}),jaws=function(t){return t.Viewport=function(e){if(!(this instanceof arguments.callee))return new arguments.callee(e);t.parseOptions(this,e,this.default_options),this.context||(this.context=t.context),this.width||(this.width=t.width),this.height||(this.height=t.height),this.max_x||(this.max_x=t.width),this.max_y||(this.max_y=t.height);var i=this;this.move=function(t,e){t&&(this.x+=t),e&&(this.y+=e),this.verifyPosition()},this.moveTo=function(t,e){void 0!=t&&(this.x=t),void 0!=e&&(this.y=e),this.verifyPosition()},this.isOutside=function(t){return!i.isInside(t)},this.isInside=function(t){return t.x>=i.x&&t.x<=i.x+i.width&&t.y>=i.y&&t.y<=i.y+i.height},this.isPartlyInside=function(t){var e=t.rect();return e.right>=i.x&&e.x<=i.x+i.width&&e.bottom>=i.y&&t.y<=i.y+i.height},this.isLeftOf=function(t){return t.xi.x+i.width},this.isAbove=function(t){return t.yi.y+i.height},this.centerAround=function(t){this.x=Math.floor(t.x-this.width/2),this.y=Math.floor(t.y-this.height/2),this.verifyPosition()},this.forceInsideVisibleArea=function(e,i){e.xthis.x+t.width-i&&(e.x=this.x+t.width-i),e.ythis.y+t.height-i&&(e.y=this.y+t.height-i)},this.forceInside=function(t,e){t.xthis.max_x-e&&(t.x=this.max_x-e),t.ythis.max_y-e&&(t.y=this.max_y-e)},this.apply=function(t){this.context.save(),this.context.translate(-this.x,-this.y),t(),this.context.restore()},this.draw=function(t){this.apply(function(){t.forEach?t.forEach(i.drawIfPartlyInside):t.draw&&i.drawIfPartlyInside(t)})},this.drawTileMap=function(t){var e=t.atRect({x:this.x,y:this.y,right:this.x+this.width,bottom:this.y+this.height});this.apply(function(){for(var t=0;tt&&(this.x=t);var t=this.max_y-this.height;this.y<0&&(this.y=0),this.y>t&&(this.y=t)},this.moveTo(e.x||0,e.y||0)},t.Viewport.prototype.default_options={context:null,width:null,height:null,max_x:null,max_y:null,x:0,y:0},t.Viewport.prototype.toString=function(){return"[Viewport "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"},t}(jaws||{});if("undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){function e(t,e){for(var i=function(e){return void 0!==t.isSpriteList?t.at(e):t[e]},s=[],o=new Array(e),n=0;e>n;n++)o[n]=n;for(var n=e-1,r=t.length;n>=0;r=t.length){for(s.push(o.map(i));n>=0&&o[n]===r-1;)n--,r--;if(n>=0){o[n]+=1;for(var a=n+1;e>a;a++)o[a]=o[a-1]+1;n=e-1}}return s}return t.collideOneWithOne=function(e,i){return e.radius&&i.radius&&e!==i&&t.collideCircles(e,i)?!0:e.rect&&i.rect&&e!==i&&t.collideRects(e.rect(),i.rect())?!0:!1},t.collideOneWithMany=function(e,i,s){var o=[];if(s){for(var n=0;n=e.x&&t.x<=e.right||e.x>=t.x&&e.x<=t.right)&&(t.y>=e.y&&t.y<=e.bottom||e.y>=t.y&&e.y<=t.bottom)},t.distanceBetween=function(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))},t.collide=function(e,i,s){if((e.rect||e.radius)&&i.forEach)return t.collideOneWithMany(e,i,s).length>0;if(e.forEach&&i.forEach)return t.collideManyWithMany(e,i,s).length>0;if(e.forEach&&(i.rect||i.radius))return t.collideOneWithMany(i,e,s).length>0;if(e.rect&&i.rect||e.radius&&i.radius){var o=t.collideOneWithOne(e,i);if(!s||!o)return o;s(e,i)}},t}(jaws||{});if("undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){return t.TileMap=function(e){if(!(this instanceof arguments.callee))return new arguments.callee(e);t.parseOptions(this,e,this.default_options),this.cells=new Array(this.size[0]);for(var i=0;i=o;o++)for(var n=parseInt(e.y/this.cell_size[1]),r=parseInt((e.bottom-1)/this.cell_size[1]),a=n;r>=a;a++)this.pushToCell(o,a,t);return t},t.TileMap.prototype.pushToCell=function(t,e,i){return this.cells[t][e].push(i),this.sortFunction&&this.cells[t][e].sort(this.sortFunction),this},t.TileMap.prototype.at=function(t,e){var i=parseInt(t/this.cell_size[0]),s=parseInt(e/this.cell_size[1]);return this.cells[i][s]},t.TileMap.prototype.atRect=function(t){var e=[];try{var i=parseInt(t.x/this.cell_size[0]);0>i&&(i=0);var s=parseInt(t.right/this.cell_size[0]);s>=this.size[0]&&(s=this.size[0]-1);var o=parseInt(t.y/this.cell_size[1]);0>o&&(o=0);var n=parseInt(t.bottom/this.cell_size[1]);n>=this.size[1]&&(n=this.size[1]-1);for(var r=i;s>=r;r++)for(var a=o;n>=a;a++)this.cells[r][a].forEach(function(t){-1==e.indexOf(t)&&e.push(t)})}catch(h){}return e},t.TileMap.prototype.all=function(){for(var t=[],e=0;et)&&(t=0),(void 0===e||0>e)&&(e=0),(void 0===i||i>this.width)&&(i=this.width),(void 0===s||s>this.height)&&(s=this.height),0==arguments.length)this.data=this.context.getImageData(t,e,i,s).data;else for(var o=this.context.getImageData(t,e,i,s).data,n=0,r=4*this.width,a=e*this.width*4+4*t,h=4*i,c=0;s>c;c++){for(var l=0;h>l;l++)this.data[a+l]=o[n++];a+=r}},t.PixelMap.prototype.draw=function(){t.context.drawImage(this.context.canvas,this.x,this.y,this.width,this.height)},t.PixelMap.prototype.namedColorAtRect=function(t,e){for(var i=t.x,s=t.y;it.x;i--)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);for(;s>t.y;s--)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);return!1},t.PixelMap.prototype.at=function(t,e){t=parseInt(t),e=parseInt(e),0>e&&(e=0);var i=e*this.width*4+4*t,s=this.data[i],o=this.data[i+1],n=this.data[i+2],r=this.data[i+3];return[s,o,n,r]},t.PixelMap.prototype.namedColorAt=function(t,e){for(var i=this.at(t,e),s=0;s=0&&t.y+t.height>=0&&t.draw(),t.x=t.x+t.width,this.repeat_x););if(t.y=t.y+t.height,t.x=e,!this.repeat_y)break}},t.Parallax.prototype.addLayer=function(e){var i=new t.ParallaxLayer(e);i.scaleAll(this.scale),this.layers.push(i)},t.Parallax.prototype.toString=function(){return"[Parallax "+this.x+", "+this.y+". "+this.layers.length+" layers]"},t.ParallaxLayer=function(e){return this instanceof arguments.callee?(this.damping=e.damping||0,void t.Sprite.call(this,e)):new arguments.callee(e)},t.ParallaxLayer.prototype=t.Sprite.prototype,t}(jaws||{}),jaws=function(jaws){return jaws.Text=function(t){return this instanceof arguments.callee?(this.set(t),t.context&&(this.context=t.context),void(t.context||jaws.context&&(this.context=jaws.context))):new arguments.callee(t)},jaws.Text.prototype.default_options={x:0,y:0,alpha:1,angle:0,anchor_x:0,anchor_y:0,anchor:"top_left",damping:1,style:"normal",fontFace:"serif",fontSize:12,color:"black",textAlign:"start",textBaseline:"alphabetic",text:"",wordWrap:!1,width:function(){return jaws.width},height:function(){return jaws.height},shadowColor:null,shadowBlur:null,shadowOffsetX:null,shadowOffsetY:null,_constructor:null},jaws.Text.prototype.set=function(t){return jaws.parseOptions(this,t,this.default_options),this.anchor&&this.setAnchor(this.anchor),this.cacheOffsets(),this},jaws.Text.prototype.clone=function(){var constructor=this._constructor?eval(this._constructor):this.constructor,new_sprite=new constructor(this.attributes());return new_sprite._constructor=this._constructor||this.constructor.name,new_sprite},jaws.Text.prototype.rotate=function(t){return this.angle+=t,this},jaws.Text.prototype.rotateTo=function(t){return this.angle=t,this},jaws.Text.prototype.moveTo=function(t,e){return this.x=t,this.y=e,this},jaws.Text.prototype.move=function(t,e){return t&&(this.x+=t),e&&(this.y+=e),this},jaws.Text.prototype.setX=function(t){return this.x=t,this},jaws.Text.prototype.setY=function(t){return this.y=t,this},jaws.Text.prototype.setTop=function(t){return this.y=t+this.top_offset,this},jaws.Text.prototype.setBottom=function(t){return this.y=t-this.bottom_offset,this},jaws.Text.prototype.setLeft=function(t){return this.x=t+this.left_offset,this},jaws.Text.prototype.setRight=function(t){return this.x=t-this.right_offset,this},jaws.Text.prototype.setWidth=function(t){return this.width=t,this.cacheOffsets(),this},jaws.Text.prototype.setHeight=function(t){return this.height=t,this.cacheOffsets(),this},jaws.Text.prototype.resize=function(t,e){return this.width+=t,this.height+=e,this.cacheOffsets(),this},jaws.Text.prototype.resizeTo=function(t,e){return this.width=t,this.height=e,this.cacheOffsets(),this},jaws.Text.prototype.setAnchor=function(t){var e={top_left:[0,0],left_top:[0,0],center_left:[0,.5],left_center:[0,.5],bottom_left:[0,1],left_bottom:[0,1],top_center:[.5,0],center_top:[.5,0],center_center:[.5,.5],center:[.5,.5],bottom_center:[.5,1],center_bottom:[.5,1],top_right:[1,0],right_top:[1,0],center_right:[1,.5],right_center:[1,.5],bottom_right:[1,1],right_bottom:[1,1]};return e.hasOwnProperty(t)&&(this.anchor_x=e[t][0],this.anchor_y=e[t][1],this.cacheOffsets()),this},jaws.Text.prototype.cacheOffsets=function(){return this.left_offset=this.width*this.anchor_x,this.top_offset=this.height*this.anchor_y,this.right_offset=this.width*(1-this.anchor_x),this.bottom_offset=this.height*(1-this.anchor_y),this.cached_rect&&this.cached_rect.resizeTo(this.width,this.height),this},jaws.Text.prototype.rect=function(){return!this.cached_rect&&this.width&&(this.cached_rect=new jaws.Rect(this.x,this.y,this.width,this.height)),this.cached_rect&&this.cached_rect.moveTo(this.x-this.left_offset,this.y-this.top_offset),this.cached_rect},jaws.Text.prototype.draw=function(){this.context.save(),0!==this.angle&&this.context.rotate(this.angle*Math.PI/180),this.context.globalAlpha=this.alpha,this.context.translate(-this.left_offset,-this.top_offset),this.context.fillStyle=this.color,this.context.font=this.style+" "+this.fontSize+"px "+this.fontFace,this.context.textBaseline=this.textBaseline,this.context.textAlign=this.textAlign,this.shadowColor&&(this.context.shadowColor=this.shadowColor),this.shadowBlur&&(this.context.shadowBlur=this.shadowBlur),this.shadowOffsetX&&(this.context.shadowOffsetX=this.shadowOffsetX),this.shadowOffsetY&&(this.context.shadowOffsetY=this.shadowOffsetY);var t=this.y,e=this.x;if(this.wordWrap)for(var i=this.text.split(" "),s="",o=0;othis.width?(this.context.fillText(s,this.x,this.y),s=i[o]+" ",this.y+=this.fontSize):s=n,this.context.fillText(s,this.x,this.y))}else if(this.context.measureText(this.text).widththis.width?(this.context.fillText(n,this.x,this.y),n=o[r]+" ",this.y+=this.fontSize):n=a,this.context.fillText(n,this.x,this.y))}else if(this.context.measureText(this.text).widththis.width?(e.fillText(n,this.x,this.y),n=o[r]+" ",this.y+=this.fontSize):n=a,e.fillText(n,this.x,this.y))}else if(e.measureText(this.text).widths;return t.xi&&(o?e=0:n&&(e=3)),e},t.QuadTree.prototype.insert=function(t){if(t.hasOwnProperty("x")||t.hasOwnProperty("y")||t.hasOwnProperty("width")||t.hasOwnProperty("height")){if("undefined"!=typeof this.nodes[0]){var e=this.getIndex(t);if(-1!==e)return void this.nodes[e].insert(t)}this.objects.push(t),"undefined"==typeof this.nodes[0]&&this.split();for(var i=0;i":s.innerHTML=e),console.log&&t.log.use_console&&console.log("JawsJS: ",e))},t.log.on=!0,t.log.use_console=!1,t.log.use_log_element=!0,t.log.warn=function(e){console.warn&&t.log.use_console&&t.log.on?console.warn(e):t.log("[WARNING]: "+JSON.stringify(e),!0)},t.log.error=function(e){console.error&&t.log.use_console&&t.log.on?console.error(e):t.log("[ERROR]: "+JSON.stringify(e),!0)},t.log.info=function(e){console.info&&t.log.use_console&&t.log.on?console.info(e):t.log("[INFO]: "+JSON.stringify(e),!0)},t.log.debug=function(e){console.debug&&t.log.use_console&&t.log.on?console.debug(e):t.log("[DEBUG]: "+JSON.stringify(e),!0)},t.log.clear=function(){s&&(s.innerHTML=""),console.clear&&console.clear()},t.init=function(o){i=document.getElementsByTagName("title")[0],t.url_parameters=t.getUrlParameters(),t.canvas=document.getElementsByTagName("canvas")[0],t.canvas||(t.dom=document.getElementById("canvas")),t.canvas?t.context=t.canvas.getContext("2d"):t.dom?t.dom.style.position="relative":(t.canvas=document.createElement("canvas"),t.canvas.width=o.width,t.canvas.height=o.height,t.context=t.canvas.getContext("2d"),document.body.appendChild(t.canvas)),s=document.getElementById("jaws-log"),t.url_parameters.debug&&(s||(s=document.createElement("div"),s.id="jaws-log",s.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(s))),t.url_parameters.bust_cache&&(t.log.info("Busting cache when loading assets"),t.assets.bust_cache=!0),t.context&&t.useCrispScaling(),t.width=t.canvas?t.canvas.width:t.dom.offsetWidth,t.height=t.canvas?t.canvas.height:t.dom.offsetHeight,t.mouse_x=0,t.mouse_y=0,window.addEventListener("mousemove",e)},t.useCrispScaling=function(){t.context.imageSmoothingEnabled=!1,t.context.webkitImageSmoothingEnabled=!1,t.context.mozImageSmoothingEnabled=!1},t.useSmoothScaling=function(){t.context.imageSmoothingEnabled=!0,t.context.webkitImageSmoothingEnabled=!0,t.context.mozImageSmoothingEnabled=!0},t.start=function(e,i,s){function o(e,s){t.log.info(s+"%: "+e,!0),i.loading_screen&&t.assets.displayProgress(s)}function n(e,i){t.log.info(i+"%: Error loading asset "+e,!0)}function a(){t.log.info("all assets loaded",!0),t.switchGameState(e||window,{fps:r},s)}i||(i={});var r=i.fps||60;return void 0===i.loading_screen&&(i.loading_screen=!0),i.width||(i.width=500),i.height||(i.height=300),t.init(i),t.isFunction(e)||t.isObject(e)?t.isObject(s)||void 0===s?(i.loading_screen&&t.assets.displayProgress(0),t.log.info("setupInput()",!0),t.setupInput(),t.log.info("assets.loadAll()",!0),void(t.assets.length()>0?t.assets.loadAll({onprogress:o,onerror:n,onload:a}):a())):void t.log.error("jaws.start: The setup options for the game state is not an object."):void t.log.error("jaws.start: Passed in GameState is niether function or object")},t.switchGameState=function(e,i,s){if(void 0===i&&(i={}),t.isFunction(e)&&(e=new e),!t.isObject(e))return void t.log.error("jaws.switchGameState: Passed in GameState should be a Function or an Object.");var o=i&&i.fps||t.game_loop&&t.game_loop.fps||60,n=i.setup;t.game_loop&&t.game_loop.stop(),t.clearKeyCallbacks(),t.previous_game_state=t.game_state,t.game_state=e,t.game_loop=new t.GameLoop(e,{fps:o,setup:n},s),t.game_loop.start()},t.imageToCanvas=function(e){if(t.isCanvas(e))return e;if(!t.isImage(e))return void t.log.error("jaws.imageToCanvas: Passed in object is not an Image.");var i=document.createElement("canvas");i.src=e.src,i.width=e.width,i.height=e.height;var s=i.getContext("2d");return s.drawImage(e,0,0,e.width,e.height),i},t.forceArray=function(t){return Array.isArray(t)?t:[t]},t.clear=function(){t.context.clearRect(0,0,t.width,t.height)},t.fill=function(e){t.context.fillStyle=e,t.context.fillRect(0,0,t.width,t.height)},t.draw=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;it.width||e.y>t.height:void 0},t.forceInsideCanvas=function(e){e.x&&e.y&&(e.x<0&&(e.x=0),e.x>t.width&&(e.x=t.width),e.y<0&&(e.y=0),e.y>t.height&&(e.y=t.height))},t.getUrlParameters=function(){for(var t,e=[],i=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),s=0;su;u+=1)for(var d=Math.floor(u/i),f=u*h.width,p=d*e.width,g=0;c>g;g+=1){var m=Math.floor(g/i),w=4*(f+g),x=4*(p+m);h.data[w]=n[x],h.data[w+1]=n[x+1],h.data[w+2]=n[x+2],h.data[w+3]=n[x+3]}return r.putImageData(h,0,0),a},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws);var jaws=function(t){function e(){h={}}function i(t){event=t?t:window.event;var e=l[event.keyCode];null!=e&&(e=e.split(" "),e.forEach(function(e){h[e]=!1,d[e]&&(d[e](e),t.preventDefault()),g[e]&&t.preventDefault()}))}function s(t){event=t?t:window.event;var e=l[event.keyCode];null!=e&&(e=e.split(" "),e.forEach(function(e){h[e]=!0,u[e]&&(u[e](e),t.preventDefault()),g[e]&&t.preventDefault()}))}function o(t){event=t?t:window.event;var e=f[event.button];"Microsoft Internet Explorer"==navigator.appName&&(e=p[event.button]),h[e]=!0,u[e]&&(u[e](e),t.preventDefault())}function n(t){event=t?t:window.event;var e=f[event.button];"Microsoft Internet Explorer"==navigator.appName&&(e=p[event.button]),h[e]=!1,d[e]&&(d[e](e),t.preventDefault())}function a(e){event=e?e:window.event,h.left_mouse_button=!0,t.mouse_x=e.touches[0].pageX-t.canvas.offsetLeft,t.mouse_y=e.touches[0].pageY-t.canvas.offsetTop}function r(e){event=e?e:window.event,h.left_mouse_button=!1,t.mouse_x=void 0,t.mouse_y=void 0}var h={},c={},l=[],u=[],d=[],f=[],p=[];t.setupInput=function(){var h=[];h[8]="backspace",h[9]="tab",h[13]="enter",h[16]="shift",h[17]="ctrl",h[18]="alt",h[19]="pause",h[20]="capslock",h[27]="esc",h[32]="space",h[33]="pageup",h[34]="pagedown",h[35]="end",h[36]="home",h[37]="left",h[38]="up",h[39]="right",h[40]="down",h[45]="insert",h[46]="delete",h[91]="left_window_key leftwindowkey",h[92]="right_window_key rightwindowkey",h[93]="select_key selectkey",h[106]="multiply *",h[107]="add plus +",h[109]="subtract minus -",h[110]="decimalpoint",h[111]="divide /",h[144]="numlock",h[145]="scrollock",h[186]="semicolon ;",h[187]="equalsign =",h[188]="comma ,",h[189]="dash -",h[190]="period .",h[191]="forwardslash /",h[192]="graveaccent `",h[219]="openbracket [",h[220]="backslash \\",h[221]="closebracket ]",h[222]="singlequote '";var c=[];c[0]="left_mouse_button",c[1]="center_mouse_button",c[2]="right_mouse_button";var u=[];u[1]="left_mouse_button",u[2]="right_mouse_button",u[4]="center_mouse_button",f=c,p=u;for(var d=["numpad0","numpad1","numpad2","numpad3","numpad4","numpad5","numpad6","numpad7","numpad8","numpad9"],g=["f1","f2","f3","f4","f5","f6","f7","f8","f9"],m=["0","1","2","3","4","5","6","7","8","9"],w=["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"],x=0;m[x];x++)h[48+x]=m[x];for(var x=0;w[x];x++)h[65+x]=w[x];for(var x=0;d[x];x++)h[96+x]=d[x];for(var x=0;g[x];x++)h[112+x]=g[x];l=h,window.addEventListener("keydown",s),window.addEventListener("keyup",i);var y=t.canvas||t.dom;y.addEventListener("mousedown",o,!1),y.addEventListener("mouseup",n,!1),y.addEventListener("touchstart",a,!1),y.addEventListener("touchend",r,!1),window.addEventListener("blur",e,!1),document.oncontextmenu=function(){return!1}};var g=[];return t.preventDefaultKeys=function(){var e=arguments;1==e.length&&t.isArray(e[0])&&(e=e[0]);for(var i=0;ithis.size){this.values.splice(0,1),this.value=0;for(var e=0;this.values[e];e++)this.value+=this.values[e];this.value=this.value/this.size}return this.values.push(t),this},this.get=function(){return parseInt(this.value)}}return window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,16.666)}}(),t.GameLoop=function(i,s,o){if(!(this instanceof arguments.callee))return new arguments.callee(i,s);this.tick_duration=0,this.fps=0,this.ticks=0;var n,a=!1,r=!1,h=this,c=new e(20);this.runtime=function(){return this.last_tick-this.first_tick},this.start=function(){t.log.info("Game loop start",!0),this.first_tick=(new Date).getTime(),this.current_tick=(new Date).getTime(),this.last_tick=(new Date).getTime(),s.setup!==!1&&i.setup&&i.setup(o),step_delay=1e3/s.fps,60==s.fps?requestAnimFrame(this.loop):n=setInterval(this.loop,step_delay)},this.loop=function(){h.current_tick=(new Date).getTime(),h.tick_duration=h.current_tick-h.last_tick,h.fps=c.add(1e3/h.tick_duration).get(),r||a||(i.update&&i.update(),i.draw&&i.draw(),h.ticks++),60!=s.fps||r||requestAnimFrame(h.loop),h.last_tick=h.current_tick},this.pause=function(){a=!0},this.unpause=function(){a=!1},this.stop=function(){n&&clearInterval(n),r=!0}},t}(jaws||{}),jaws=function(t){var e=0;return t.Rect=function(t,i,s,o){return this instanceof arguments.callee?(this.x=t,this.y=i,this.width=s,this.height=o,this.right=t+s-e,void(this.bottom=i+o-e)):new arguments.callee(t,i,s,o)},t.Rect.prototype.getPosition=function(){return[this.x,this.y]},t.Rect.prototype.move=function(t,e){return this.x+=t,this.y+=e,this.right+=t,this.bottom+=e,this},t.Rect.prototype.moveTo=function(t,i){return this.x=t,this.y=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.resize=function(t,i){return this.width+=t,this.height+=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.clone=function(){return new t.Rect(this.x,this.y,this.width,this.height)},t.Rect.prototype.shrink=function(t,i){return this.x+=t,this.y+=i,this.width-=t+t,this.height-=i+i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.resizeTo=function(t,i){return this.width=t,this.height=i,this.right=this.x+this.width-e,this.bottom=this.y+this.height-e,this},t.Rect.prototype.draw=function(){return t.context.strokeStyle="red",t.context.strokeRect(this.x-.5,this.y-.5,this.width,this.height),this},t.Rect.prototype.collidePoint=function(t,e){return t>=this.x&&t<=this.right&&e>=this.y&&e<=this.bottom},t.Rect.prototype.collideRect=function(t){return(this.x>=t.x&&this.x<=t.right||t.x>=this.x&&t.x<=this.right)&&(this.y>=t.y&&this.y<=t.bottom||t.y>=this.y&&t.y<=this.bottom)},t.Rect.prototype.toString=function(){return"[Rect "+this.x+", "+this.y+", "+this.width+", "+this.height+"]"},t}(jaws||{});"undefined"!=typeof module&&"exports"in module&&(module.exports=jaws.Rect);var jaws=function(jaws){return jaws.Sprite=function(t){return this instanceof arguments.callee?(this.set(t),void(this.context=t.context?t.context:jaws.context)):new arguments.callee(t)},jaws.Sprite.prototype.default_options={x:0,y:0,alpha:1,angle:0,flipped:!1,anchor_x:0,anchor_y:0,image:null,image_path:null,anchor:null,scale_image:null,damping:1,scale_x:1,scale_y:1,scale:1,color:"#ddd",width:16,height:16,_constructor:null,context:null,data:null},jaws.Sprite.prototype.set=function(t){if(jaws.isString(this.image)&&(this.image_path=this.image),jaws.parseOptions(this,t,this.default_options),this.scale&&(this.scale_x=this.scale_y=this.scale),this.image&&this.setImage(this.image),this.scale_image&&this.scaleImage(this.scale_image),this.anchor&&this.setAnchor(this.anchor),!this.image&&this.color&&this.width&&this.height){var e=document.createElement("canvas"),i=e.getContext("2d");e.width=this.width,e.height=this.height,i.fillStyle=this.color,i.fillRect(0,0,this.width,this.height),this.image=e}return this.cacheOffsets(),this},jaws.Sprite.prototype.clone=function(object){var constructor=this._constructor?eval(this._constructor):this.constructor,new_sprite=new constructor(this.attributes());return new_sprite._constructor=this._constructor||this.constructor.name,new_sprite},jaws.Sprite.prototype.setImage=function(t){var e=this;return jaws.isDrawable(t)?(this.image=t,this.cacheOffsets()):(jaws.assets.isLoaded(t)?(this.image=jaws.assets.get(t),this.cacheOffsets()):(jaws.log.warn("Image '"+t+"' not preloaded with jaws.assets.add(). Image and a working sprite.rect() will be delayed."),jaws.assets.load(t,{onload:function(){e.image=jaws.assets.get(t),e.cacheOffsets()}})),this)},jaws.Sprite.prototype.stepToWhile=function(t,e,i){var s=1,o=tthis.frame_duration&&(this.index+=this.frame_direction,this.sum_tick=0),(this.index>=this.frames.length||this.index<0)&&(this.bounce?(this.frame_direction=-this.frame_direction,this.index+=2*this.frame_direction):this.loop?this.index=this.frame_direction<0?this.frames.length-1:0:(this.index-=this.frame_direction,this.on_end&&(this.on_end(),this.on_end=null))),this},t.Animation.prototype.slice=function(e,i){var s={};return s.frame_duration=this.frame_duration,s.loop=this.loop,s.bounce=this.bounce,s.on_end=this.on_end,s.frame_direction=this.frame_direction,s.frames=this.frames.slice().slice(e,i),new t.Animation(s) +},t.Animation.prototype.next=function(){return this.update(),this.frames[this.index]},t.Animation.prototype.atLastFrame=function(){return this.index==this.frames.length-1},t.Animation.prototype.atFirstFrame=function(){return 0==this.index},t.Animation.prototype.currentFrame=function(){return this.frames[this.index]},t.Animation.prototype.toString=function(){return"[Animation, "+this.frames.length+" frames]"},t}(jaws||{}),jaws=function(t){return t.Viewport=function(e){if(!(this instanceof arguments.callee))return new arguments.callee(e);t.parseOptions(this,e,this.default_options),this.context||(this.context=t.context),this.width||(this.width=t.width),this.height||(this.height=t.height),this.max_x||(this.max_x=t.width),this.max_y||(this.max_y=t.height);var i=this;this.move=function(t,e){t&&(this.x+=t),e&&(this.y+=e),this.verifyPosition()},this.moveTo=function(t,e){void 0!=t&&(this.x=t),void 0!=e&&(this.y=e),this.verifyPosition()},this.isOutside=function(t){return!i.isInside(t)},this.isInside=function(t){return t.x>=i.x&&t.x<=i.x+i.width&&t.y>=i.y&&t.y<=i.y+i.height},this.isPartlyInside=function(t){var e=t.rect();return e.right>=i.x&&e.x<=i.x+i.width&&e.bottom>=i.y&&t.y<=i.y+i.height},this.isLeftOf=function(t){return t.xi.x+i.width},this.isAbove=function(t){return t.yi.y+i.height},this.centerAround=function(t){this.x=Math.floor(t.x-this.width/2),this.y=Math.floor(t.y-this.height/2),this.verifyPosition()},this.forceInsideVisibleArea=function(e,i){e.xthis.x+t.width-i&&(e.x=this.x+t.width-i),e.ythis.y+t.height-i&&(e.y=this.y+t.height-i)},this.forceInside=function(t,e){t.xthis.max_x-e&&(t.x=this.max_x-e),t.ythis.max_y-e&&(t.y=this.max_y-e)},this.apply=function(t){this.context.save(),this.context.translate(-this.x,-this.y),t(),this.context.restore()},this.draw=function(t){this.apply(function(){t.forEach?t.forEach(i.drawIfPartlyInside):t.draw&&i.drawIfPartlyInside(t)})},this.drawIfPartlyInside=function(t){i.isPartlyInside(t)&&t.draw()},this.verifyPosition=function(){var t=this.max_x-this.width;this.x<0&&(this.x=0),this.x>t&&(this.x=t);var t=this.max_y-this.height;this.y<0&&(this.y=0),this.y>t&&(this.y=t)},this.moveTo(e.x||0,e.y||0)},t.Viewport.prototype.default_options={context:null,width:null,height:null,max_x:null,max_y:null,x:0,y:0},t.Viewport.prototype.toString=function(){return"[Viewport "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"},t}(jaws||{});if("undefined"!=typeof require)var jaws=require("./core.js");var jaws=function(t){function e(t,e){for(var i=function(e){return void 0!==t.isSpriteList?t.at(e):t[e]},s=[],o=new Array(e),n=0;e>n;n++)o[n]=n;for(var n=e-1,a=t.length;n>=0;a=t.length){for(s.push(o.map(i));n>=0&&o[n]===a-1;)n--,a--;if(n>=0){o[n]+=1;for(var r=n+1;e>r;r++)o[r]=o[r-1]+1;n=e-1}}return s}return t.collideOneWithOne=function(e,i){return e.radius&&i.radius&&e!==i&&t.collideCircles(e,i)?!0:e.rect&&i.rect&&e!==i&&t.collideRects(e.rect(),i.rect())?!0:!1},t.collideOneWithMany=function(e,i,s){var o=[];if(s){for(var n=0;n=e.x&&t.x<=e.right||e.x>=t.x&&e.x<=t.right)&&(t.y>=e.y&&t.y<=e.bottom||e.y>=t.y&&e.y<=t.bottom)},t.distanceBetween=function(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))},t.collide=function(e,i,s){if((e.rect||e.radius)&&i.forEach)return t.collideOneWithMany(e,i,s).length>0;if(e.forEach&&i.forEach)return t.collideManyWithMany(e,i,s).length>0;if(e.forEach&&(i.rect||i.radius))return t.collideOneWithMany(i,e,s).length>0;if(e.rect&&i.rect||e.radius&&i.radius){var o=t.collideOneWithOne(e,i);if(!s||!o)return o;s(e,i)}},t}(jaws||{}),jaws=function(t){return t.PixelMap=function(e){return this instanceof arguments.callee?(this.options=e,this.scale=e.scale||1,this.x=e.x||0,this.y=e.y||0,e.image?(this.setContext(e.image),e.scale_image&&this.setContext(t.retroScaleImage(this.context.canvas,e.scale_image)),this.width=this.context.canvas.width*this.scale,this.height=this.context.canvas.height*this.scale):t.log.warn("PixelMap needs an image to work with"),this.named_colors=[],void this.update()):new arguments.callee(e)},t.PixelMap.prototype.setContext=function(e){var e=t.isDrawable(e)?e:t.assets.get(e);this.context=t.imageToCanvasContext(e)},t.PixelMap.prototype.update=function(t,e,i,s){if((void 0===t||0>t)&&(t=0),(void 0===e||0>e)&&(e=0),(void 0===i||i>this.width)&&(i=this.width),(void 0===s||s>this.height)&&(s=this.height),0==arguments.length)this.data=this.context.getImageData(t,e,i,s).data;else for(var o=this.context.getImageData(t,e,i,s).data,n=0,a=4*this.width,r=e*this.width*4+4*t,h=4*i,c=0;s>c;c++){for(var l=0;h>l;l++)this.data[r+l]=o[n++];r+=a}},t.PixelMap.prototype.draw=function(){t.context.drawImage(this.context.canvas,this.x,this.y,this.width,this.height)},t.PixelMap.prototype.namedColorAtRect=function(t,e){for(var i=t.x,s=t.y;it.x;i--)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);for(;s>t.y;s--)if(this.namedColorAt(i,s)==e||void 0===e)return this.namedColorAt(i,s);return!1},t.PixelMap.prototype.at=function(t,e){t=parseInt(t),e=parseInt(e),0>e&&(e=0);var i=e*this.width*4+4*t,s=this.data[i],o=this.data[i+1],n=this.data[i+2],a=this.data[i+3];return[s,o,n,a]},t.PixelMap.prototype.namedColorAt=function(t,e){for(var i=this.at(t,e),s=0;s=0&&t.y+t.height>=0&&t.draw(),t.x=t.x+t.width,this.repeat_x););if(t.y=t.y+t.height,t.x=e,!this.repeat_y)break}},t.Parallax.prototype.addLayer=function(e){var i=new t.ParallaxLayer(e);i.scaleAll(this.scale),this.layers.push(i)},t.Parallax.prototype.toString=function(){return"[Parallax "+this.x+", "+this.y+". "+this.layers.length+" layers]"},t.ParallaxLayer=function(e){return this instanceof arguments.callee?(this.damping=e.damping||0,void t.Sprite.call(this,e)):new arguments.callee(e)},t.ParallaxLayer.prototype=t.Sprite.prototype,t}(jaws||{}),jaws=function(jaws){return jaws.Text=function(t){return this instanceof arguments.callee?(this.set(t),t.context&&(this.context=t.context),void(t.context||jaws.context&&(this.context=jaws.context))):new arguments.callee(t)},jaws.Text.prototype.default_options={x:0,y:0,alpha:1,angle:0,anchor_x:0,anchor_y:0,anchor:"top_left",damping:1,style:"normal",fontFace:"serif",fontSize:12,color:"black",textAlign:"start",textBaseline:"alphabetic",text:"",wordWrap:!1,width:function(){return jaws.width},height:function(){return jaws.height},shadowColor:null,shadowBlur:null,shadowOffsetX:null,shadowOffsetY:null,_constructor:null},jaws.Text.prototype.set=function(t){return jaws.parseOptions(this,t,this.default_options),this.anchor&&this.setAnchor(this.anchor),this.cacheOffsets(),this},jaws.Text.prototype.clone=function(){var constructor=this._constructor?eval(this._constructor):this.constructor,new_sprite=new constructor(this.attributes());return new_sprite._constructor=this._constructor||this.constructor.name,new_sprite},jaws.Text.prototype.rotate=function(t){return this.angle+=t,this},jaws.Text.prototype.rotateTo=function(t){return this.angle=t,this},jaws.Text.prototype.moveTo=function(t,e){return this.x=t,this.y=e,this},jaws.Text.prototype.move=function(t,e){return t&&(this.x+=t),e&&(this.y+=e),this},jaws.Text.prototype.setX=function(t){return this.x=t,this},jaws.Text.prototype.setY=function(t){return this.y=t,this},jaws.Text.prototype.setTop=function(t){return this.y=t+this.top_offset,this},jaws.Text.prototype.setBottom=function(t){return this.y=t-this.bottom_offset,this},jaws.Text.prototype.setLeft=function(t){return this.x=t+this.left_offset,this},jaws.Text.prototype.setRight=function(t){return this.x=t-this.right_offset,this},jaws.Text.prototype.setWidth=function(t){return this.width=t,this.cacheOffsets(),this},jaws.Text.prototype.setHeight=function(t){return this.height=t,this.cacheOffsets(),this},jaws.Text.prototype.resize=function(t,e){return this.width+=t,this.height+=e,this.cacheOffsets(),this},jaws.Text.prototype.resizeTo=function(t,e){return this.width=t,this.height=e,this.cacheOffsets(),this},jaws.Text.prototype.setAnchor=function(t){var e={top_left:[0,0],left_top:[0,0],center_left:[0,.5],left_center:[0,.5],bottom_left:[0,1],left_bottom:[0,1],top_center:[.5,0],center_top:[.5,0],center_center:[.5,.5],center:[.5,.5],bottom_center:[.5,1],center_bottom:[.5,1],top_right:[1,0],right_top:[1,0],center_right:[1,.5],right_center:[1,.5],bottom_right:[1,1],right_bottom:[1,1]};return e.hasOwnProperty(t)&&(this.anchor_x=e[t][0],this.anchor_y=e[t][1],this.cacheOffsets()),this},jaws.Text.prototype.cacheOffsets=function(){return this.left_offset=this.width*this.anchor_x,this.top_offset=this.height*this.anchor_y,this.right_offset=this.width*(1-this.anchor_x),this.bottom_offset=this.height*(1-this.anchor_y),this.cached_rect&&this.cached_rect.resizeTo(this.width,this.height),this},jaws.Text.prototype.rect=function(){return!this.cached_rect&&this.width&&(this.cached_rect=new jaws.Rect(this.x,this.y,this.width,this.height)),this.cached_rect&&this.cached_rect.moveTo(this.x-this.left_offset,this.y-this.top_offset),this.cached_rect},jaws.Text.prototype.draw=function(){this.context.save(),0!==this.angle&&this.context.rotate(this.angle*Math.PI/180),this.context.globalAlpha=this.alpha,this.context.translate(-this.left_offset,-this.top_offset),this.context.fillStyle=this.color,this.context.font=this.style+" "+this.fontSize+"px "+this.fontFace,this.context.textBaseline=this.textBaseline,this.context.textAlign=this.textAlign,this.shadowColor&&(this.context.shadowColor=this.shadowColor),this.shadowBlur&&(this.context.shadowBlur=this.shadowBlur),this.shadowOffsetX&&(this.context.shadowOffsetX=this.shadowOffsetX),this.shadowOffsetY&&(this.context.shadowOffsetY=this.shadowOffsetY);var t=this.y,e=this.x;if(this.wordWrap)for(var i=this.text.split(" "),s="",o=0;othis.width?(this.context.fillText(s,this.x,this.y),s=i[o]+" ",this.y+=this.fontSize):s=n,this.context.fillText(s,this.x,this.y))}else if(this.context.measureText(this.text).widththis.width?(this.context.fillText(n,this.x,this.y),n=o[a]+" ",this.y+=this.fontSize):n=r,this.context.fillText(n,this.x,this.y))}else if(this.context.measureText(this.text).widththis.width?(e.fillText(n,this.x,this.y),n=o[a]+" ",this.y+=this.fontSize):n=r,e.fillText(n,this.x,this.y))}else if(e.measureText(this.text).widths;return t.xi&&(o?e=0:n&&(e=3)),e},t.QuadTree.prototype.insert=function(t){if(t.hasOwnProperty("x")||t.hasOwnProperty("y")||t.hasOwnProperty("width")||t.hasOwnProperty("height")){if("undefined"!=typeof this.nodes[0]){var e=this.getIndex(t);if(-1!==e)return void this.nodes[e].insert(t)}this.objects.push(t),"undefined"==typeof this.nodes[0]&&this.split();for(var i=0;i= this.size[0]) { - to_col = this.size[0] - 1; - } - var from_row = parseInt(rect.y / this.cell_size[1]); - if (from_row < 0) { - from_row = 0; - } - var to_row = parseInt(rect.bottom / this.cell_size[1]); - if (to_row >= this.size[1]) { - to_row = this.size[1] - 1; - } - - for(var col = from_col; col <= to_col; col++) { - for(var row = from_row; row <= to_row; row++) { - this.cells[col][row].forEach( function(item, total) { - if(objects.indexOf(item) == -1) { objects.push(item) } - }) - } - } - } - catch(e) { - // ... problems - } - return objects - } - - /** Returns all objects in tile map */ - jaws.TileMap.prototype.all = function() { - var all = []; - for(var col=0; col < this.size[0]; col++) { - for(var row=0; row < this.size[1]; row++) { - this.cells[col][row].forEach( function(element, total) { - all.push(element) - }); - } - } - return all - } - - /** Get objects in cell at col / row */ - jaws.TileMap.prototype.cell = function(col, row) { - return this.cells[col][row] - } - - /** Debugstring for TileMap() */ - jaws.TileMap.prototype.toString = function() { return "[TileMap " + this.size[0] + " cols, " + this.size[1] + " rows]" } - - return jaws; -})(jaws || {}); - -// Support CommonJS require() -if(typeof module !== "undefined" && ('exports' in module)) { module.exports = jaws.TileMap } - var jaws = (function(jaws) { /** * @class jaws.PixelMap diff --git a/jaws/src/core.js b/jaws/src/core.js index ac28595..48509bd 100755 --- a/jaws/src/core.js +++ b/jaws/src/core.js @@ -38,7 +38,6 @@ var jaws = (function(jaws) { //jaws.Parallax = function() { throw("To use jaws.Parallax() you need to include src/extras/parallax.js") } //jaws.QuadTree = function() { throw("To use QuadTree() you need to include src/extras/quadtree.js") } //jaws.PixelMap = function() { throw("To use PixelMap() you need to include src/extras/pixel_map.js") } - //jaws.TileMap = function() { throw("To use TileMap() you need to include src/extras/tile_map.js") } jaws.SpriteList = function() { throw("To use SpriteList() you need to include src/extras/sprite_list.js") } jaws.Audio = function() { throw("To use jaws.Audio() you need to include src/extras/audio.js") } @@ -66,7 +65,7 @@ var jaws = (function(jaws) { * If a global property is already taken, a warning will be written to jaws log. */ jaws.unpack = function() { - var make_global = ["Sprite", "SpriteList", "Animation", "Viewport", "SpriteSheet", "Parallax", "TileMap", "pressed", "QuadTree"]; + var make_global = ["Sprite", "SpriteList", "Animation", "Viewport", "SpriteSheet", "Parallax", "pressed", "QuadTree"]; make_global.forEach(function(item) { if (window[item]) { diff --git a/jaws/src/extras/tile_map_pathfinding.js b/jaws/src/extras/tile_map_pathfinding.js deleted file mode 100755 index cd89433..0000000 --- a/jaws/src/extras/tile_map_pathfinding.js +++ /dev/null @@ -1,180 +0,0 @@ -var jaws = (function(jaws) { - -/** - * A-Star pathfinding - * - * Takes starting and ending x,y co-ordinates (from a mouse-click for example), - * which are then translated onto the TileMap grid. - * - * Does not allow for Diagonal movements - * - * Uses a very simple Heuristic [see crowFlies()] for calculating node scores. - * - * Very lightly optimised for speed over memory usage. - * - * Returns a list of [col, row] pairs that define a valid path. Due to the simple Heuristic - * the path is not guaranteed to be the best path. - */ -jaws.TileMap.prototype.findPath = function(start_position, end_position, inverted) { - - if (typeof inverted == 'undefined') { inverted = false } - - var start_col = parseInt(start_position[0] / this.cell_size[0]) - var start_row = parseInt(start_position[1] / this.cell_size[1]) - - var end_col = parseInt(end_position[0] / this.cell_size[0]) - var end_row = parseInt(end_position[1] / this.cell_size[1]) - - if (start_col === end_col && start_row === end_row) { - return [{x: start_position[0], y:start_position[1]}] - } - - var col = start_col - var row = start_row - var step = 0 - var score = 0 - //travel corner-to-corner, through every square, plus one, just to make sure - var max_distance = (this.size[0]*this.size[1] * 2)+1 - - var open_nodes = new Array(this.size[0]) - for(var i=0; i < this.size[0]; i++) { - open_nodes[i] = new Array(this.size[1]) - for(var j=0; j < this.size[1]; j++) { - open_nodes[i][j] = false - } - } - open_nodes[col][row] = {parent: [], G: 0, score: max_distance} - - var closed_nodes = new Array(this.size[0]) - for(var i=0; i < this.size[0]; i++) { - closed_nodes[i] = new Array(this.size[1]) - for(var j=0; j < this.size[1]; j++) { - closed_nodes[i][j] = false - } - } - - var crowFlies = function(from_node, to_node) { - return Math.abs(to_node[0]-from_node[0]) + Math.abs(to_node[1]-from_node[1]); - } - - var findInClosed = function(col, row) { - if (closed_nodes[col][row]) - { - return true - } - else {return false} - } - - while ( !(col === end_col && row === end_row) ) { - /** - * add the nodes above, below, to the left and right of the current node - * if it doesn't have a sprite in it, and it hasn't already been added - * to the closed list, recalculate its score from the current node and - * update it if it's already in the open list. - */ - var left_right_up_down = [] - if (col > 0) { left_right_up_down.push([col-1, row]) } - if (col < this.size[0]-1) { left_right_up_down.push([col+1, row]) } - if (row > 0) {left_right_up_down.push([col, row-1])} - if (row < this.size[1]-1) { left_right_up_down.push([col, row+1]) } - - for (var i=0 ; i 0 && inverted) ) && - !findInClosed(c, r) ) - { - score = step+1+crowFlies([c, r] , [end_col, end_row]) - if (!open_nodes[c][r] || (open_nodes[c][r] && open_nodes[c][r].score > score)) { - open_nodes[c][r] = {parent: [col, row], G: step+1, score: score} - } - } - } - - /** - * find the lowest scoring open node - */ - var best_node = {node: [], parent: [], score: max_distance, G: 0} - for (var i=0 ; i 0) {return false} } - e2 = 2 * err - if (e2 > -dy) - { - err = err - dy - x0 = x0 + sx - } - if (e2 < dx) - { - err = err + dx - y0 = y0 + sy - } - } - - return true -} - -return jaws; -})(jaws || {}); - diff --git a/jaws/src/tile_map.js b/jaws/src/tile_map.js deleted file mode 100755 index b3dec0b..0000000 --- a/jaws/src/tile_map.js +++ /dev/null @@ -1,200 +0,0 @@ -if(typeof require !== "undefined") { var jaws = require("./core.js"); } - -var jaws = (function(jaws) { - /** - * @class Create and access tilebased 2D maps with very fast access of invidual tiles. "Field Summary" contains options for the TileMap()-constructor. - * - * @property {array} cell_size Size of each cell in tilemap, defaults to [32,32] - * @property {array} size Size of tilemap, defaults to [100,100] - * @property {function} sortFunction Function used by sortCells() to sort cells, defaults to no sorting - * - * @example - * var tile_map = new TileMap({size: [10, 10], cell_size: [16,16]}) - * var sprite = new jaws.Sprite({x: 40, y: 40}) - * var sprite2 = new jaws.Sprite({x: 41, y: 41}) - * tile_map.push(sprite) - * - * tile_map.at(10,10) // [] - * tile_map.at(40,40) // [sprite] - * tile_map.cell(0,0) // [] - * tile_map.cell(1,1) // [sprite] - * - */ - jaws.TileMap = function TileMap(options) { - if( !(this instanceof arguments.callee) ) return new arguments.callee( options ); - - jaws.parseOptions(this, options, this.default_options); - this.cells = new Array(this.size[0]); - - for(var col=0; col < this.size[0]; col++) { - this.cells[col] = new Array(this.size[1]); - for(var row=0; row < this.size[1]; row++) { - this.cells[col][row] = [] // populate each cell with an empty array - } - } - } - - jaws.TileMap.prototype.default_options = { - cell_size: [32,32], - size: [100,100], - sortFunction: null - } - - /** Clear all cells in tile map */ - jaws.TileMap.prototype.clear = function() { - for(var col=0; col < this.size[0]; col++) { - for(var row=0; row < this.size[1]; row++) { - this.cells[col][row] = []; - } - } - } - - /** Sort arrays in each cell in tile map according to sorter-function (see Array.sort) */ - jaws.TileMap.prototype.sortCells = function(sortFunction) { - for(var col=0; col < this.size[0]; col++) { - for(var row=0; row < this.size[1]; row++) { - this.cells[col][row].sort( sortFunction ) - } - } - } - - /** - * Push obj (or array of objs) into our cell-grid. - * - * Tries to read obj.x and obj.y to calculate what cell to occopy - */ - jaws.TileMap.prototype.push = function(obj) { - var that = this; - if(obj.forEach) { - obj.forEach( function(item) { that.push(item) } ); - return obj; - } - if(obj.rect) { - return this.pushAsRect(obj, obj.rect()); - } - else { - var col = parseInt(obj.x / this.cell_size[0]); - var row = parseInt(obj.y / this.cell_size[1]); - return this.pushToCell(col, row, obj); - } - } - /** - * Push objects into tilemap. - * Disregard height and width and only use x/y when calculating cell-position - */ - jaws.TileMap.prototype.pushAsPoint = function(obj) { - if(Array.isArray(obj)) { - for(var i=0; i < obj.length; i++) { this.pushAsPoint(obj[i]) } - return obj; - } - else { - var col = parseInt(obj.x / this.cell_size[0]); - var row = parseInt(obj.y / this.cell_size[1]); - return this.pushToCell(col, row, obj); - } - } - - /** push obj into cells touched by rect */ - jaws.TileMap.prototype.pushAsRect = function(obj, rect) { - var from_col = parseInt(rect.x / this.cell_size[0]); - var to_col = parseInt((rect.right-1) / this.cell_size[0]); // -1 - //jaws.log("rect.right: " + rect.right + " from/to col: " + from_col + " " + to_col, true) - - for(var col = from_col; col <= to_col; col++) { - var from_row = parseInt(rect.y / this.cell_size[1]); - var to_row = parseInt((rect.bottom-1) / this.cell_size[1]); // -1 - - //jaws.log("rect.bottom " + rect.bottom + " from/to row: " + from_row + " " + to_row, true) - for(var row = from_row; row <= to_row; row++) { - // console.log("pushAtRect() col/row: " + col + "/" + row + " - " + this.cells[col][row]) - this.pushToCell(col, row, obj); - } - } - return obj - } - - /** - * Push obj to a specific cell specified by col and row - * If cell is already occupied we create an array and push to that - */ - jaws.TileMap.prototype.pushToCell = function(col, row, obj) { - this.cells[col][row].push(obj); - if(this.sortFunction) this.cells[col][row].sort(this.sortFunction); - return this - } - - // - // READERS - // - - /** Get objects in cell that exists at coordinates x / y */ - jaws.TileMap.prototype.at = function(x, y) { - var col = parseInt(x / this.cell_size[0]); - var row = parseInt(y / this.cell_size[1]); - // console.log("at() col/row: " + col + "/" + row) - return this.cells[col][row]; - } - - /** Returns occupants of all cells touched by 'rect' */ - jaws.TileMap.prototype.atRect = function(rect) { - var objects = []; - var items; - - try { - var from_col = parseInt(rect.x / this.cell_size[0]); - if (from_col < 0) { - from_col = 0; - } - var to_col = parseInt(rect.right / this.cell_size[0]); - if (to_col >= this.size[0]) { - to_col = this.size[0] - 1; - } - var from_row = parseInt(rect.y / this.cell_size[1]); - if (from_row < 0) { - from_row = 0; - } - var to_row = parseInt(rect.bottom / this.cell_size[1]); - if (to_row >= this.size[1]) { - to_row = this.size[1] - 1; - } - - for(var col = from_col; col <= to_col; col++) { - for(var row = from_row; row <= to_row; row++) { - this.cells[col][row].forEach( function(item, total) { - if(objects.indexOf(item) == -1) { objects.push(item) } - }) - } - } - } - catch(e) { - // ... problems - } - return objects - } - - /** Returns all objects in tile map */ - jaws.TileMap.prototype.all = function() { - var all = []; - for(var col=0; col < this.size[0]; col++) { - for(var row=0; row < this.size[1]; row++) { - this.cells[col][row].forEach( function(element, total) { - all.push(element) - }); - } - } - return all - } - - /** Get objects in cell at col / row */ - jaws.TileMap.prototype.cell = function(col, row) { - return this.cells[col][row] - } - - /** Debugstring for TileMap() */ - jaws.TileMap.prototype.toString = function() { return "[TileMap " + this.size[0] + " cols, " + this.size[1] + " rows]" } - - return jaws; -})(jaws || {}); - -// Support CommonJS require() -if(typeof module !== "undefined" && ('exports' in module)) { module.exports = jaws.TileMap } diff --git a/jaws/src/viewport.js b/jaws/src/viewport.js index 992ccff..c273f47 100755 --- a/jaws/src/viewport.js +++ b/jaws/src/viewport.js @@ -167,17 +167,6 @@ jaws.Viewport = function ViewPort(options) { }); } - /** - * draws all items of 'tile_map' that's lies inside the viewport - * this is simular to viewport.draw( tile_map.all() ) but optmized for Huge game worlds (tile maps) - */ - this.drawTileMap = function( tile_map ) { - var sprites = tile_map.atRect({ x: this.x, y: this.y, right: this.x + this.width, bottom: this.y + this.height }) - this.apply( function() { - for(var i=0; i < sprites.length; i++) sprites[i].draw(); - }); - } - /** draws 'item' if it's partly inside the viewport */ this.drawIfPartlyInside = function(item) { if(that.isPartlyInside(item)) item.draw(); -- cgit v0.10.2