├── README.md ├── build ├── built.bat ├── compiler.jar └── tile-engine-min.js ├── gpl.txt ├── images ├── grid_tiles.png └── tiles.png ├── js ├── game.js ├── jquery.js ├── physics_engine │ ├── body.js │ └── physics_engine.js └── tile_engine │ ├── canvas_support.js │ ├── console.js │ ├── keyboard.js │ ├── mouse.js │ ├── source_image.js │ ├── sprite.js │ ├── tile.js │ ├── tile_engine.js │ ├── tile_source.js │ ├── util.js │ ├── view.js │ └── zone.js ├── main.html └── stylesheets └── style.css /README.md: -------------------------------------------------------------------------------- 1 | ATTENTION: This project is stale, I would recommend that you check out my tile_engine2 repo for a better more fully complete tile engine Lightweight Tile Engine For HTML5 Game Creation ============= This a a working version from what I learned from Johne Graham Additions include * dynamic viewport * gridded tile sets * kinetic mouse scrolling * timestep and minimal physics * plus more.... Please try this out in Chrome before any other browser. I believe it is because Chrome uses V8, but chrome will get around 233fps where all other browsers get only around 90fps. Status ------ This project is stale, I would recommend that you check out my grouter repo for a better more fully complete tile engine License ------- Lightweight Tile Engine For HTML5 Game Creation Copyright (C) 2010 John Graham Copyright (C) 2011 Tim Anema This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -------------------------------------------------------------------------------- /build/built.bat: -------------------------------------------------------------------------------- 1 | java -jar compiler.jar --js ../js/tile_engine/util.js --js ../js/tile_engine/canvas_support.js --js ../js/tile_engine/console.js --js ../js/tile_engine/mouse.js --js ../js/tile_engine/keyboard.js --js ../js/tile_engine/zone.js --js ../js/tile_engine/tile.js --js ../js/tile_engine/sprite.js --js ../js/tile_engine/tile_source.js --js ../js/tile_engine/source_image.js --js ../js/tile_engine/view.js --js ../js/physics_engine/body.js --js ../js/physics_engine/physics_engine.js --js ../js/tile_engine/tile_engine.js --compilation_level SIMPLE_OPTIMIZATIONS > tile-engine-min.js -------------------------------------------------------------------------------- /build/compiler.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanema/tile_engine/8e720146c75bc4dbf82a5184754f8d5eab3f9a90/build/compiler.jar -------------------------------------------------------------------------------- /build/tile-engine-min.js: -------------------------------------------------------------------------------- 1 | var setBytes=function(a,b){return a<<18|b};function getBytes(a){return[a&262143,a>>18&262143]}var makeMapTilesArray=function(a,b){for(var d=[],c=a.length;c--;)d[c]=setBytes(a[c],b[c]);return d};var CanvasSupport={canvas_compatible:false,check_canvas:function(){try{CanvasSupport.canvas_compatible=!!document.createElement("canvas").getContext("2d")}catch(a){CanvasSupport.canvas_compatible=!!document.createElement("canvas").getContext}return CanvasSupport.canvas_compatible}};var Console={console:0,hidden:true,init:function(){Console.console=$("
Loading...
").css("width",$("canvas").css("width")).insertAfter("canvas")},hide:function(){$(Console.console).hide("slow");Console.hidden=true},show:function(){$(Console.console).show("slow");Console.hidden=false},log:function(a){Console.console&&$(Console.console).append("> "+a+"
")},error:function(a){Console.console&&$(Console.console).append('> '+a+"
")}};function newMouse(){var a={down:false,offsetx:0,offsety:0,timer:0,accelx:0,accely:0,clickposx:0,clickposy:0,dx:0,dy:0,view:0,thrust:10,decay:0.97,maxSpeed:200,init:function(b){$(b).mousedown(a.mouseDown).mouseup(function(){a.down=false}).mouseout(function(){a.down=false}).mousemove(a.move);setInterval(a.update,100)},isDown:function(){return a.down},mouseDown:function(b){a.dx=0;a.dy=0;a.setClickPos(b)},setClickPos:function(b){a.clickposx=b.screenX;a.clickposy=b.screenY;a.down=true},move:function(b){a.isDown()? 2 | (a.timer++,a.offsetx=b.screenX-a.clickposx,a.offsety=b.screenY-a.clickposy,a.setClickPos(b),a.accelx=a.offsetx/a.timer,a.accely=a.offsety/a.timer):a.reset()},reset:function(){a.offsetx=0;a.offsety=0;a.accelx=0;a.accely=0;a.timer=0},update:function(){if(a.isDown()){a.dx-=a.accelx*a.thrust;a.dy+=a.accely*a.thrust;var b=Math.sqrt(a.dx*a.dx+a.dy*a.dy);b>a.maxSpeed&&(a.dx*=a.maxSpeed/b,a.dy*=a.maxSpeed/b)}a.dx*=a.decay;a.dy*=a.decay;a.reset()}};return a};function newKeyboard(){var a={orientation:{},LEFT:37,RIGHT:39,UP:38,DOWN:40,thrust:10,maxSpeed:100,key_down:false,_focus:false,ctx_click:false,doc_click:false,dx:0,dy:0,decay:0.97,init:function(b){$(document).keydown(function(b){a.keydown(b)}).keyup(function(b){a.keyup(b)});$(b).mouseup(function(){a.ctx_click=true});$(document).keydown(a.keydown).keyup(a.keyup).mousedown(function(){a.doc_click=true}).mouseup(function(){a._focus=a.ctx_click&&a.doc_click;a.doc_click=a.ctx_click=false});setInterval(a.update, 3 | 1)},keydown:function(b){a.orientation[b.keyCode]=a._focus;a.key_down=a._focus},keyup:function(b){a.orientation[b.keyCode]=false;a.key_down=false},update:function(){a.orientation[a.LEFT]&&(a.dx-=a.thrust);a.orientation[a.RIGHT]&&(a.dx+=a.thrust);a.orientation[a.UP]&&(a.dy+=a.thrust);a.orientation[a.DOWN]&&(a.dy-=a.thrust);var b=Math.sqrt(a.dx*a.dx+a.dy*a.dy);b>a.maxSpeed&&(a.dx*=a.maxSpeed/b,a.dy*=a.maxSpeed/b);a.dx*=a.decay;a.dy*=a.decay}};return a};function newZone(){var a={base_canvas:0,dec_canvas:0,tileEngine:0,base_ctx:0,dec_ctx:0,left:0,top:0,right:0,bottom:0,tileWidth:0,tileHeight:0,width:0,height:0,x:0,y:0,viewoffset:0,tiles:0,init:function(b,d,c,e,g,f,h){a.tileEngine=b;a.left=a.x=d;a.top=a.y=c;a.right=d+f;a.bottom=c+h;a.tileWidth=e;a.tileHeight=g;a.width=f;a.height=h;a.base_canvas=document.createElement("canvas");a.base_ctx=a.base_canvas.getContext("2d");a.dec_canvas=document.createElement("canvas");a.dec_ctx=a.dec_canvas.getContext("2d"); 4 | a.base_canvas.setAttribute("width",f);a.base_canvas.setAttribute("height",h);a.dec_canvas.setAttribute("width",f);a.dec_canvas.setAttribute("height",h);a.tiles=[]},addTile:function(b){a.tiles.push(b)},arrangeTiles:function(b){for(var d=a.width/a.tileWidth,c=a.height/a.tileHeight,e=0,g=0;g1)c.current_direction=c.sourceHash.right;if(c.dx<-1)c.current_direction=c.sourceHash.left;if(c.dy>1)c.current_direction=c.sourceHash.up;if(c.dy<-1)c.current_direction=c.sourceHash.down},current_frame:function(){return c.current_direction[c.current_index]}, 7 | update_index:function(){if(c.dx>1||c.dx<-1||c.dy>1||c.dy<-1)if(c.current_index++,c.current_index>=c.current_direction.length)c.current_index=0},draw:function(a,b){if(b)for(var f=b.length;f--;){var h=b[f];c.spriteSource&&h.isInView(c)&&d.drawImage(c.spriteSource[c.current_frame()].canvas,c.x+h.xoffset-a.x,c.y+h.yoffset-a.y)}else c.spriteSource&&a.isInView(c)&&d.drawImage(c.spriteSource[c.current_frame()].canvas,c.x-a.x,c.y-a.y)}};return c};function newTileSource(){var a={canvas:0,ctx:0,sourceImage:0,init:function(b,d,c,e,g){a.sourceImage=g;a.canvas=document.createElement("canvas");a.ctx=a.canvas.getContext("2d");a.canvas.setAttribute("width",b);a.canvas.setAttribute("height",d);a.ctx.drawImage(a.sourceImage.image,c,e,b,d,0,0,b,d)}};return a};function newSourceImage(){var a={imageFilename:0,image:0,init:function(b){a.imageFilename=b;a.image=new Image;a.image.src=b}};return a};function newView(a,b,d,c,e,g){var f={x:a||0,y:b||0,viewWidth:0,viewHeight:0,director:null,xoffset:0,yoffset:0,isControllingSprite:0,main_sprite:0,init:function(a,b,c){f.director=a;f.main_sprite=b;f.isControllingSprite=c;f.decay=0.97;f.update()},update:function(){f.isControllingSprite()&&(f.x+=(f.main_sprite.x-(f.x+d/2))*0.05,f.y+=(f.main_sprite.y-(f.y+c/2))*0.05);if(f.x+d>e)f.x=e-d;else if(f.x<0)f.x=0;if(f.y+c>g)f.y=g-c;else if(f.y<0)f.y=0;f.viewWidth=f.x+d;f.viewHeight=f.y+c},isInView:function(a){return a.x+ 8 | a.width>this.x&&a.x<=this.viewWidth&&a.y+a.height>this.y&&a.y<=this.viewHeight},up:function(){var a=$.extend({},this);if(a.y<0)a.y+=g,a.viewHeight=g,a.yoffset=-g;return a},down:function(){var a=$.extend({},this);if(a.viewHeight>g)a.y=0,a.viewHeight-=g,a.yoffset=g;return a},left:function(){var a=$.extend({},this);if(a.x<0)a.x+=e,a.viewWidth=e,a.xoffset=-e;return a},right:function(){var a=$.extend({},this);if(a.viewWidth>e)a.x=0,a.viewWidth-=e,a.xoffset=e;return a}};return f};function Body(a,b,d,c){return{x:a,y:b,px:a,py:b,dx:0,dy:0,width:d,height:c,decay:0.97,setX:function(a){this.x=this.px=a},setY:function(a){this.y=this.py=a},accelerate:function(a){if(this.director)this.dx=this.director.dx,this.dy=this.director.dy;this.x+=this.dx*a*a;this.y-=this.dy*a*a},inertia:function(){var a=this.x-this.px,b=this.y-this.py;this.px=this.x;this.py=this.y;this.x+=a*this.decay;this.y+=b*this.decay}}};function newPhysicsEngine(){var a={tiles:0,tile_width:0,tile_height:0,bodies:[],collidable_bodies:[],ingnore_collide:false,init:function(b,d,c,e,g){a.tiles=b;a.tile_width=d;a.tile_height=c;a.map_width=e;a.map_height=g},to_unit:function(a,d){return Math.floor(a/d)*d},collide:function(){for(var b=0,d=a.collidable_bodies_length;b0?a.to_unit(d+b.width,a.tile_width):d;do if(a.tiles[d][c].darker=0.4,a.tiles[d][c].physicsID!=0)return b.setX(b.dx>=0?d-a.tile_width:d+a.tile_width),true;while((c+=a.tile_height)=0?c+a.tile_height:c-a.tile_height),true;while((d+=a.tile_width)Math.abs(d.dy)?(a.barrier_collide_x(d,c,e),a.barrier_collide_y(d,c,e)):(a.barrier_collide_y(d,c,e),a.barrier_collide_x(d,c,e))}},border_collide:function(){for(var b=a.collidable_bodies_length;b--;){var d=a.collidable_bodies[b], 11 | c=d.width,e=d.height,g=d.x,f=d.y;if(g<0)d.x=0;else if(g+c>a.map_width)d.x=a.map_width-(c+0.01);if(f<0)d.y=0;else if(f+e>a.map_height)d.y=a.map_height-(e+0.01)}},gravity:function(){for(var b=a.bodies_length;b--;)a.bodies[b].dx*=a.bodies[b].decay,a.bodies[b].dy*=a.bodies[b].decay},accelerate:function(b){for(var d=a.bodies_length;d--;)a.bodies[d].accelerate(b)},inertia:function(b){for(var d=a.bodies_length;d--;)a.bodies[d].inertia(b)},update:function(){for(var b=a.bodies_length;b--;)a.bodies[b].update&& 12 | a.bodies[b].update()},integrate:function(b){a.gravity();a.accelerate(b);a.collide();a.border_collide();a.barrier_collide(b);a.inertia(b);a.update()},add_actor:function(b,d,c,e,g,f){d=Body(d,c,e,g);$.extend(b,d);a.bodies.push(b);f||a.collidable_bodies.push(b);a.bodies_length=a.bodies.length;a.collidable_bodies_length=a.collidable_bodies.length}};return a};function newTileEngine(){var a={canvas:0,ctx:0,tiles:0,zones:0,tileSource:0,tileSourcesHash:{},width:0,height:0,zoneTilesWide:0,zoneTilesHigh:0,tilesHigh:0,tilesWide:0,tileWidth:0,tileHeight:0,mapWidth:0,mapHeight:0,sprites:[],main_sprite:0,mouse:newMouse(),keyboard:newKeyboard(),physics_engine:newPhysicsEngine(),timeofDay:0.2,view:0,active_controller:0,t:0,dt:0.01,currentTime:(new Date).getTime(),accumulator:0,gameTimer:0,fps:250,fps_count:0,fps_timer:0,init:function(){a.view||alert("please set map attributes before initializing tile engine"); 13 | a.mouse.init(a.canvas);a.keyboard.init(a.canvas);a.physics_engine.init(a.tiles,a.tileWidth,a.tileHeight,a.mapWidth,a.mapHeight);a.view.init(a.mouse,a.main_sprite,a.isKeyBoardActive);$(a.canvas).mouseup(function(){a.ctx_click=true});$(document).keydown(function(){if(a._focus)a.active_controller=a.keyboard}).mousedown(function(){a.active_controller=a.mouse;a.doc_click=true}).mouseup(function(){a._focus=a.ctx_click&&a.doc_click;a.doc_click=a.ctx_click=false});Console.log("Tile Map Initialized")},start:function(){Console.log("FPS limit set to: "+ 14 | a.fps);a.gameTimer=setInterval(a.drawFrame,1E3/a.fps);a.fps_timer=setInterval(a.updateFPS,2E3)},updateFPS:function(){a.fps=a.fps_count/2;a.fps_count=0},isKeyBoardActive:function(){return a.active_controller==a.keyboard},isMouseActive:function(){return a.active_controller==a.mouse},setMapAttributes:function(b){a.canvas=b.canvas;a.ctx=b.ctx;a.width=a.canvas.width;a.height=a.canvas.height;a.tileWidth=b.tileWidth;a.tileHeight=b.tileHeight;a.zoneTilesWide=b.zoneTilesWide;a.zoneTilesHigh=b.zoneTilesHigh; 15 | a.tilesWide=b.tilesWide;a.tilesHigh=b.tilesHigh;a.mapWidth=a.tilesWide*a.tileWidth;a.mapHeight=a.tilesHigh*a.tileHeight;a.view=newView(b.init_x,b.init_y,a.width,a.height,a.mapWidth,a.mapHeight);a.physics_engine.add_actor(a.view,b.init_x,b.init_y,a.width,a.height,true);Console.log(b.sourceTileCounts+" Source Tiles to Load");Console.log(b.tilesArray.length+" Map Tiles to Load");var d=newSourceImage();d.init(b.sourceFile);d.image.onload=function(){a.tileSource=a.createTileSource(b.tileWidth,b.tileHeight, 16 | b.sourceTileCounts,b.sourceTileAccross,b.tile_offset_x||0,b.tile_offset_y||0,d)};a.createTiles(b.tilesArray,b.physicsArray)},setMainSpriteAttributes:function(b){a.main_sprite=a.addSprite(b,a.keyboard)},addSprite:function(b,d){var c=newSprite(a.mapWidth,a.mapHeight,a.ctx);c.init(b.init_x,b.init_y,b.width,b.height,b.movement_hash,d);a.physics_engine.add_actor(c,b.init_x,b.init_y,b.width,b.height);var e=newSourceImage();e.init(b.sourceFile);e.image.onload=function(){c.spriteSource=a.createTileSource(b.width, 17 | b.height,b.sourceTileCounts,b.sourceTileAccross,b.tile_offset_x||0,b.tile_offset_y||0,e)};a.sprites.push(c);return c},integrator:function(){var b=(new Date).getTime(),d=(b-a.currentTime)/100;d>0.25&&(d=0.25);a.currentTime=b;for(a.accumulator+=d;a.accumulator>=a.dt;)a.accumulator-=a.dt,a.physics_engine.integrate(a.dt),a.t+=a.dt;a.active_controller?a.active_controller.update():a.view.update()},drawFrame:function(){a.integrator();a.ctx.clearRect(0,0,a.width,a.height);a.render(a.view);a.fps_count++}, 18 | render:function(b){for(var d=a.zones.length,c=[];d--;){var e=a.zones[d];b.isInView(e)&&(c.push(e.forDecoration(b)),e.drawTiles(b),a.ctx.drawImage(e.base_canvas,Math.round(e.x-b.x),Math.round(e.y-b.y)))}for(d=a.sprites.length;d--;)a.sprites[d].draw(b);for(d=c.length;d--;)e=c[d],e.drawDecorations(b),a.ctx.drawImage(e.dec_canvas,e.x-b.x,e.y-b.y);a.ctx.fillStyle="rgba(0, 0, 0,"+a.timeofDay+")";a.ctx.fillRect(0,0,a.width,a.height)},createTileSource:function(b,d,c,e,g,f,h){if(a.tileSourcesHash[h.imageFilename])return a.tileSourcesHash[h.imageFilename]; 19 | for(var i=[],j=0,l=0,k=0,m=0,n=0,o=0;o=e&&(j=0,k+=d,l=0,n++,m=0)}a.tileSourcesHash[h.imageFilename]=i;return a.tileSourcesHash[h.imageFilename]},createTiles:function(b,d){a.createZones();for(var c=0,e=0,g=0,g=0,f=Math.ceil(a.tilesWide/a.zoneTilesWide),h=0,i=a.tilesHigh;h0&&(k=c,l=k*a.tileWidth);var k=a.zoneTilesHigh*a.tileHeight,m=a.zoneTilesHigh;g==d-1&&e>0&&(m=e,k=m*a.tileHeight);h.init(a,i,j,a.tileWidth,a.tileHeight,l,k);a.zones.push(h)}}};Console.init();return CanvasSupport.check_canvas()?a:(Console.log("Your Browser Does not support this app!"),false)}; 22 | -------------------------------------------------------------------------------- /gpl.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /images/grid_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanema/tile_engine/8e720146c75bc4dbf82a5184754f8d5eab3f9a90/images/grid_tiles.png -------------------------------------------------------------------------------- /images/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tanema/tile_engine/8e720146c75bc4dbf82a5184754f8d5eab3f9a90/images/tiles.png -------------------------------------------------------------------------------- /js/game.js: -------------------------------------------------------------------------------- 1 | /*All code copyright 2010 by John Graham unless otherwise attributed*/ 2 | 3 | //this array tells the tile engine which offset in the tiles.png image to use 4 | 5 | var maptilesArray1 = [ 6 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, 7 | 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, 8 | 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, 9 | 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, 10 | 256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319, 11 | 320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383, 12 | 384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447, 13 | 448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511, 14 | 512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575, 15 | 576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639, 16 | 640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703, 17 | 704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767, 18 | 768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831, 19 | 832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895, 20 | 896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959, 21 | 960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1023, 22 | 1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087, 23 | 1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151, 24 | 1152,1153,1154,1155,1156,1157,1158,1159,1160,1161,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1184,1185,1186,1187,1188,1189,1190,1191,1192,1193,1194,1195,1196,1197,1198,1199,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1213,1214,1215, 25 | 1216,1217,1218,1219,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229,1230,1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,1241,1242,1243,1244,1245,1246,1247,1248,1249,1250,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,1271,1272,1273,1274,1275,1276,1277,1278,1279, 26 | 1280,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,1298,1299,1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1310,1311,1312,1313,1314,1315,1316,1317,1318,1319,1320,1321,1322,1323,1324,1325,1326,1327,1328,1329,1330,1331,1332,1333,1334,1335,1336,1337,1338,1339,1340,1341,1342,1343, 27 | 1344,1345,1346,1347,1348,1349,1350,1351,1352,1353,1354,1355,1356,1357,1358,1359,1360,1361,1362,1363,1364,1365,1366,1367,1368,1369,1370,1371,1372,1373,1374,1375,1376,1377,1378,1379,1380,1381,1382,1383,1384,1385,1386,1387,1388,1389,1390,1391,1392,1393,1394,1395,1396,1397,1398,1399,1400,1401,1402,1403,1404,1405,1406,1407, 28 | 1408,1409,1410,1411,1412,1413,1414,1415,1416,1417,1418,1419,1420,1421,1422,1423,1424,1425,1426,1427,1428,1429,1430,1431,1432,1433,1434,1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452,1453,1454,1455,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471, 29 | 1472,1473,1474,1475,1476,1477,1478,1479,1480,1481,1482,1483,1484,1485,1486,1487,1488,1489,1490,1491,1492,1493,1494,1495,1496,1497,1498,1499,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510,1511,1512,1513,1514,1515,1516,1517,1518,1519,1520,1521,1522,1523,1524,1525,1526,1527,1528,1529,1530,1531,1532,1533,1534,1535, 30 | 1536,1537,1538,1539,1540,1541,1542,1543,1544,1545,1546,1547,1548,1549,1550,1551,1552,1553,1554,1555,1556,1557,1558,1559,1560,1561,1562,1563,1564,1565,1566,1567,1568,1569,1570,1571,1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586,1587,1588,1589,1590,1591,1592,1593,1594,1595,1596,1597,1598,1599, 31 | 1600,1601,1602,1603,1604,1605,1606,1607,1608,1609,1610,1611,1612,1613,1614,1615,1616,1617,1618,1619,1620,1621,1622,1623,1624,1625,1626,1627,1628,1629,1630,1631,1632,1633,1634,1635,1636,1637,1638,1639,1640,1641,1642,1643,1644,1645,1646,1647,1648,1649,1650,1651,1652,1653,1654,1655,1656,1657,1658,1659,1660,1661,1662,1663, 32 | 1664,1665,1666,1667,1668,1669,1670,1671,1672,1673,1674,1675,1676,1677,1678,1679,1680,1681,1682,1683,1684,1685,1686,1687,1688,1689,1690,1691,1692,1693,1694,1695,1696,1697,1698,1699,1700,1701,1702,1703,1704,1705,1706,1707,1708,1709,1710,1711,1712,1713,1714,1715,1716,1717,1718,1719,1720,1721,1722,1723,1724,1725,1726,1727, 33 | 1728,1729,1730,1731,1732,1733,1734,1735,1736,1737,1738,1739,1740,1741,1742,1743,1744,1745,1746,1747,1748,1749,1750,1751,1752,1753,1754,1755,1756,1757,1758,1759,1760,1761,1762,1763,1764,1765,1766,1767,1768,1769,1770,1771,1772,1773,1774,1775,1776,1777,1778,1779,1780,1781,1782,1783,1784,1785,1786,1787,1788,1789,1790,1791, 34 | 1792,1793,1794,1795,1796,1797,1798,1799,1800,1801,1802,1803,1804,1805,1806,1807,1808,1809,1810,1811,1812,1813,1814,1815,1816,1817,1818,1819,1820,1821,1822,1823,1824,1825,1826,1827,1828,1829,1830,1831,1832,1833,1834,1835,1836,1837,1838,1839,1840,1841,1842,1843,1844,1845,1846,1847,1848,1849,1850,1851,1852,1853,1854,1855, 35 | 1856,1857,1858,1859,1860,1861,1862,1863,1864,1865,1866,1867,1868,1869,1870,1871,1872,1873,1874,1875,1876,1877,1878,1879,1880,1881,1882,1883,1884,1885,1886,1887,1888,1889,1890,1891,1892,1893,1894,1895,1896,1897,1898,1899,1900,1901,1902,1903,1904,1905,1906,1907,1908,1909,1910,1911,1912,1913,1914,1915,1916,1917,1918,1919, 36 | 1920,1921,1922,1923,1924,1925,1926,1927,1928,1929,1930,1931,1932,1933,1934,1935,1936,1937,1938,1939,1940,1941,1942,1943,1944,1945,1946,1947,1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983, 37 | 1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047, 38 | 2048,2049,2050,2051,2052,2053,2054,2055,2056,2057,2058,2059,2060,2061,2062,2063,2064,2065,2066,2067,2068,2069,2070,2071,2072,2073,2074,2075,2076,2077,2078,2079,2080,2081,2082,2083,2084,2085,2086,2087,2088,2089,2090,2091,2092,2093,2094,2095,2096,2097,2098,2099,2100,2101,2102,2103,2104,2105,2106,2107,2108,2109,2110,2111, 39 | 2112,2113,2114,2115,2116,2117,2118,2119,2120,2121,2122,2123,2124,2125,2126,2127,2128,2129,2130,2131,2132,2133,2134,2135,2136,2137,2138,2139,2140,2141,2142,2143,2144,2145,2146,2147,2148,2149,2150,2151,2152,2153,2154,2155,2156,2157,2158,2159,2160,2161,2162,2163,2164,2165,2166,2167,2168,2169,2170,2171,2172,2173,2174,2175, 40 | 2176,2177,2178,2179,2180,2181,2182,2183,2184,2185,2186,2187,2188,2189,2190,2191,2192,2193,2194,2195,2196,2197,2198,2199,2200,2201,2202,2203,2204,2205,2206,2207,2208,2209,2210,2211,2212,2213,2214,2215,2216,2217,2218,2219,2220,2221,2222,2223,2224,2225,2226,2227,2228,2229,2230,2231,2232,2233,2234,2235,2236,2237,2238,2239, 41 | 2240,2241,2242,2243,2244,2245,2246,2247,2248,2249,2250,2251,2252,2253,2254,2255,2256,2257,2258,2259,2260,2261,2262,2263,2264,2265,2266,2267,2268,2269,2270,2271,2272,2273,2274,2275,2276,2277,2278,2279,2280,2281,2282,2283,2284,2285,2286,2287,2288,2289,2290,2291,2292,2293,2294,2295,2296,2297,2298,2299,2300,2301,2302,2303, 42 | 2304,2305,2306,2307,2308,2309,2310,2311,2312,2313,2314,2315,2316,2317,2318,2319,2320,2321,2322,2323,2324,2325,2326,2327,2328,2329,2330,2331,2332,2333,2334,2335,2336,2337,2338,2339,2340,2341,2342,2343,2344,2345,2346,2347,2348,2349,2350,2351,2352,2353,2354,2355,2356,2357,2358,2359,2360,2361,2362,2363,2364,2365,2366,2367, 43 | 2368,2369,2370,2371,2372,2373,2374,2375,2376,2377,2378,2379,2380,2381,2382,2383,2384,2385,2386,2387,2388,2389,2390,2391,2392,2393,2394,2395,2396,2397,2398,2399,2400,2401,2402,2403,2404,2405,2406,2407,2408,2409,2410,2411,2412,2413,2414,2415,2416,2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2430,2431, 44 | 2432,2433,2434,2435,2436,2437,2438,2439,2440,2441,2442,2443,2444,2445,2446,2447,2448,2449,2450,2451,2452,2453,2454,2455,2456,2457,2458,2459,2460,2461,2462,2463,2464,2465,2466,2467,2468,2469,2470,2471,2472,2473,2474,2475,2476,2477,2478,2479,2480,2481,2482,2483,2484,2485,2486,2487,2488,2489,2490,2491,2492,2493,2494,2495, 45 | 2496,2497,2498,2499,2500,2501,2502,2503,2504,2505,2506,2507,2508,2509,2510,2511,2512,2513,2514,2515,2516,2517,2518,2519,2520,2521,2522,2523,2524,2525,2526,2527,2528,2529,2530,2531,2532,2533,2534,2535,2536,2537,2538,2539,2540,2541,2542,2543,2544,2545,2546,2547,2548,2549,2550,2551,2552,2553,2554,2555,2556,2557,2558,2559, 46 | 2560,2561,2562,2563,2564,2565,2566,2567,2568,2569,2570,2571,2572,2573,2574,2575,2576,2577,2578,2579,2580,2581,2582,2583,2584,2585,2586,2587,2588,2589,2590,2591,2592,2593,2594,2595,2596,2597,2598,2599,2600,2601,2602,2603,2604,2605,2606,2607,2608,2609,2610,2611,2612,2613,2614,2615,2616,2617,2618,2619,2620,2621,2622,2623, 47 | 2624,2625,2626,2627,2628,2629,2630,2631,2632,2633,2634,2635,2636,2637,2638,2639,2640,2641,2642,2643,2644,2645,2646,2647,2648,2649,2650,2651,2652,2653,2654,2655,2656,2657,2658,2659,2660,2661,2662,2663,2664,2665,2666,2667,2668,2669,2670,2671,2672,2673,2674,2675,2676,2677,2678,2679,2680,2681,2682,2683,2684,2685,2686,2687, 48 | 2688,2689,2690,2691,2692,2693,2694,2695,2696,2697,2698,2699,2700,2701,2702,2703,2704,2705,2706,2707,2708,2709,2710,2711,2712,2713,2714,2715,2716,2717,2718,2719,2720,2721,2722,2723,2724,2725,2726,2727,2728,2729,2730,2731,2732,2733,2734,2735,2736,2737,2738,2739,2740,2741,2742,2743,2744,2745,2746,2747,2748,2749,2750,2751, 49 | 2752,2753,2754,2755,2756,2757,2758,2759,2760,2761,2762,2763,2764,2765,2766,2767,2768,2769,2770,2771,2772,2773,2774,2775,2776,2777,2778,2779,2780,2781,2782,2783,2784,2785,2786,2787,2788,2789,2790,2791,2792,2793,2794,2795,2796,2797,2798,2799,2800,2801,2802,2803,2804,2805,2806,2807,2808,2809,2810,2811,2812,2813,2814,2815, 50 | 2816,2817,2818,2819,2820,2821,2822,2823,2824,2825,2826,2827,2828,2829,2830,2831,2832,2833,2834,2835,2836,2837,2838,2839,2840,2841,2842,2843,2844,2845,2846,2847,2848,2849,2850,2851,2852,2853,2854,2855,2856,2857,2858,2859,2860,2861,2862,2863,2864,2865,2866,2867,2868,2869,2870,2871,2872,2873,2874,2875,2876,2877,2878,2879, 51 | 2880,2881,2882,2883,2884,2885,2886,2887,2888,2889,2890,2891,2892,2893,2894,2895,2896,2897,2898,2899,2900,2901,2902,2903,2904,2905,2906,2907,2908,2909,2910,2911,2912,2913,2914,2915,2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,2931,2932,2933,2934,2935,2936,2937,2938,2939,2940,2941,2942,2943, 52 | 2944,2945,2946,2947,2948,2949,2950,2951,2952,2953,2954,2955,2956,2957,2958,2959,2960,2961,2962,2963,2964,2965,2966,2967,2968,2969,2970,2971,2972,2973,2974,2975,2976,2977,2978,2979,2980,2981,2982,2983,2984,2985,2986,2987,2988,2989,2990,2991,2992,2993,2994,2995,2996,2997,2998,2999,3000,3001,3002,3003,3004,3005,3006,3007, 53 | 3008,3009,3010,3011,3012,3013,3014,3015,3016,3017,3018,3019,3020,3021,3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,3038,3039,3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,3050,3051,3052,3053,3054,3055,3056,3057,3058,3059,3060,3061,3062,3063,3064,3065,3066,3067,3068,3069,3070,3071, 54 | 3072,3073,3074,3075,3076,3077,3078,3079,3080,3081,3082,3083,3084,3085,3086,3087,3088,3089,3090,3091,3092,3093,3094,3095,3096,3097,3098,3099,3100,3101,3102,3103,3104,3105,3106,3107,3108,3109,3110,3111,3112,3113,3114,3115,3116,3117,3118,3119,3120,3121,3122,3123,3124,3125,3126,3127,3128,3129,3130,3131,3132,3133,3134,3135, 55 | 3136,3137,3138,3139,3140,3141,3142,3143,3144,3145,3146,3147,3148,3149,3150,3151,3152,3153,3154,3155,3156,3157,3158,3159,3160,3161,3162,3163,3164,3165,3166,3167,3168,3169,3170,3171,3172,3173,3174,3175,3176,3177,3178,3179,3180,3181,3182,3183,3184,3185,3186,3187,3188,3189,3190,3191,3192,3193,3194,3195,3196,3197,3198,3199, 56 | 3200,3201,3202,3203,3204,3205,3206,3207,3208,3209,3210,3211,3212,3213,3214,3215,3216,3217,3218,3219,3220,3221,3222,3223,3224,3225,3226,3227,3228,3229,3230,3231,3232,3233,3234,3235,3236,3237,3238,3239,3240,3241,3242,3243,3244,3245,3246,3247,3248,3249,3250,3251,3252,3253,3254,3255,3256,3257,3258,3259,3260,3261,3262,3263, 57 | 3264,3265,3266,3267,3268,3269,3270,3271,3272,3273,3274,3275,3276,3277,3278,3279,3280,3281,3282,3283,3284,3285,3286,3287,3288,3289,3290,3291,3292,3293,3294,3295,3296,3297,3298,3299,3300,3301,3302,3303,3304,3305,3306,3307,3308,3309,3310,3311,3312,3313,3314,3315,3316,3317,3318,3319,3320,3321,3322,3323,3324,3325,3326,3327, 58 | 3328,3329,3330,3331,3332,3333,3334,3335,3336,3337,3338,3339,3340,3341,3342,3343,3344,3345,3346,3347,3348,3349,3350,3351,3352,3353,3354,3355,3356,3357,3358,3359,3360,3361,3362,3363,3364,3365,3366,3367,3368,3369,3370,3371,3372,3373,3374,3375,3376,3377,3378,3379,3380,3381,3382,3383,3384,3385,3386,3387,3388,3389,3390,3391, 59 | 3392,3393,3394,3395,3396,3397,3398,3399,3400,3401,3402,3403,3404,3405,3406,3407,3408,3409,3410,3411,3412,3413,3414,3415,3416,3417,3418,3419,3420,3421,3422,3423,3424,3425,3426,3427,3428,3429,3430,3431,3432,3433,3434,3435,3436,3437,3438,3439,3440,3441,3442,3443,3444,3445,3446,3447,3448,3449,3450,3451,3452,3453,3454,3455, 60 | 3456,3457,3458,3459,3460,3461,3462,3463,3464,3465,3466,3467,3468,3469,3470,3471,3472,3473,3474,3475,3476,3477,3478,3479,3480,3481,3482,3483,3484,3485,3486,3487,3488,3489,3490,3491,3492,3493,3494,3495,3496,3497,3498,3499,3500,3501,3502,3503,3504,3505,3506,3507,3508,3509,3510,3511,3512,3513,3514,3515,3516,3517,3518,3519, 61 | 3520,3521,3522,3523,3524,3525,3526,3527,3528,3529,3530,3531,3532,3533,3534,3535,3536,3537,3538,3539,3540,3541,3542,3543,3544,3545,3546,3547,3548,3549,3550,3551,3552,3553,3554,3555,3556,3557,3558,3559,3560,3561,3562,3563,3564,3565,3566,3567,3568,3569,3570,3571,3572,3573,3574,3575,3576,3577,3578,3579,3580,3581,3582,3583, 62 | 3584,3585,3586,3587,3588,3589,3590,3591,3592,3593,3594,3595,3596,3597,3598,3599,3600,3601,3602,3603,3604,3605,3606,3607,3608,3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,3619,3620,3621,3622,3623,3624,3625,3626,3627,3628,3629,3630,3631,3632,3633,3634,3635,3636,3637,3638,3639,3640,3641,3642,3643,3644,3645,3646,3647, 63 | 3648,3649,3650,3651,3652,3653,3654,3655,3656,3657,3658,3659,3660,3661,3662,3663,3664,3665,3666,3667,3668,3669,3670,3671,3672,3673,3674,3675,3676,3677,3678,3679,3680,3681,3682,3683,3684,3685,3686,3687,3688,3689,3690,3691,3692,3693,3694,3695,3696,3697,3698,3699,3700,3701,3702,3703,3704,3705,3706,3707,3708,3709,3710,3711, 64 | 3712,3713,3714,3715,3716,3717,3718,3719,3720,3721,3722,3723,3724,3725,3726,3727,3728,3729,3730,3731,3732,3733,3734,3735,3736,3737,3738,3739,3740,3741,3742,3743,3744,3745,3746,3747,3748,3749,3750,3751,3752,3753,3754,3755,3756,3757,3758,3759,3760,3761,3762,3763,3764,3765,3766,3767,3768,3769,3770,3771,3772,3773,3774,3775, 65 | 3776,3777,3778,3779,3780,3781,3782,3783,3784,3785,3786,3787,3788,3789,3790,3791,3792,3793,3794,3795,3796,3797,3798,3799,3800,3801,3802,3803,3804,3805,3806,3807,3808,3809,3810,3811,3812,3813,3814,3815,3816,3817,3818,3819,3820,3821,3822,3823,3824,3825,3826,3827,3828,3829,3830,3831,3832,3833,3834,3835,3836,3837,3838,3839, 66 | 3840,3841,3842,3843,3844,3845,3846,3847,3848,3849,3850,3851,3852,3853,3854,3855,3856,3857,3858,3859,3860,3861,3862,3863,3864,3865,3866,3867,3868,3869,3870,3871,3872,3873,3874,3875,3876,3877,3878,3879,3880,3881,3882,3883,3884,3885,3886,3887,3888,3889,3890,3891,3892,3893,3894,3895,3896,3897,3898,3899,3900,3901,3902,3903, 67 | 3904,3905,3906,3907,3908,3909,3910,3911,3912,3913,3914,3915,3916,3917,3918,3919,3920,3921,3922,3923,3924,3925,3926,3927,3928,3929,3930,3931,3932,3933,3934,3935,3936,3937,3938,3939,3940,3941,3942,3943,3944,3945,3946,3947,3948,3949,3950,3951,3952,3953,3954,3955,3956,3957,3958,3959,3960,3961,3962,3963,3964,3965,3966,3967, 68 | 3968,3969,3970,3971,3972,3973,3974,3975,3976,3977,3978,3979,3980,3981,3982,3983,3984,3985,3986,3987,3988,3989,3990,3991,3992,3993,3994,3995,3996,3997,3998,3999,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,4010,4011,4012,4013,4014,4015,4016,4017,4018,4019,4020,4021,4022,4023,4024,4025,4026,4027,4028,4029,4030,4031, 69 | 4032,4033,4034,4035,4036,4037,4038,4039,4040,4041,4042,4043,4044,4045,4046,4047,4048,4049,4050,4051,4052,4053,4054,4055,4056,4057,4058,4059,4060,4061,4062,4063,4064,4065,4066,4067,4068,4069,4070,4071,4072,4073,4074,4075,4076,4077,4078,4079,4080,4081,4082,4083,4084,4085,4086,4087,4088,4089,4090,4091,4092,4093,4094,4095 70 | ]; 71 | 72 | var maptilesArray2 = [ 73 | 71,71,70,71,71,71,71,71,71, 74 | 135,135,92,135,135,135,135,135,135, 75 | 72,72,90,72,72,72,72,72,72, 76 | 134,134,91,134,134,134,134,134,134, 77 | 70,70,70,70,70,70,70,70,70, 78 | 71,71,70,71,71,71,71,71,71, 79 | 71,71,70,71,71,71,71,71,71, 80 | 71,71,70,71,71,71,71,71,71, 81 | 71,71,70,71,71,71,71,71,71, 82 | 71,71,70,71,71,71,71,71,71, 83 | 135,135,92,135,135,135,135,135,135, 84 | 72,72,90,72,72,72,72,72,72, 85 | 134,134,91,134,134,134,134,134,134, 86 | 70,70,70,70,70,70,70,70,70, 87 | 71,71,70,71,71,71,71,71,71, 88 | 71,27,70,71,71,49,50,71,71, 89 | 71,22,70,71,71,66,66,73,71, 90 | 71,71,70,71,71,71,71,71,71 91 | ]; 92 | var decorationtilesArray = [ 93 | 0,0,0,0,0,0,0,0,0, 94 | 0,0,0,0,0,0,0,0,0, 95 | 0,0,0,0,0,0,0,0,0, 96 | 0,0,44,0,0,0,0,0,0, 97 | 0,0,0,0,0,0,0,0,0, 98 | 0,0,0,0,0,0,0,0,0, 99 | 0,0,0,0,0,0,0,0,0, 100 | 0,0,0,0,0,0,0,0,0, 101 | 0,0,0,0,0,45,0,0,0, 102 | 0,0,0,0,0,0,0,0,0, 103 | 0,0,0,0,0,0,0,0,0, 104 | 0,0,9,0,0,0,0,0,0, 105 | 0,0,0,0,0,0,0,0,0, 106 | 0,0,0,0,0,0,0,0,0, 107 | 0,0,0,0,0,0,0,0,0, 108 | 0,0,0,0,0,0,0,0,0, 109 | 0,0,0,0,0,0,0,0,0, 110 | 0,0,0,0,0,0,0,0,0 111 | ]; 112 | var tilesPhysicsArray = [ 113 | 0,0,0,0,0,0,0,0,0, 114 | 0,0,0,0,0,0,0,0,0, 115 | 1,1,0,1,1,1,1,1,1, 116 | 0,0,1,0,0,0,0,0,0, 117 | 0,0,0,0,0,0,0,0,0, 118 | 0,0,0,0,0,0,0,0,0, 119 | 0,0,0,0,0,0,0,0,0, 120 | 0,0,0,0,0,0,0,0,0, 121 | 0,0,0,0,0,0,0,0,0, 122 | 0,0,0,0,0,0,0,0,0, 123 | 0,0,0,0,0,0,0,0,0, 124 | 1,1,0,0,1,1,1,1,1, 125 | 0,0,0,0,0,0,0,0,0, 126 | 0,0,0,0,0,0,0,0,0, 127 | 0,0,0,0,0,0,0,0,0, 128 | 0,0,0,0,0,0,0,0,0, 129 | 0,0,0,0,0,0,0,0,0, 130 | 0,0,0,0,0,0,0,0,0 131 | ]; 132 | 133 | 134 | var tilesArray1 = makeMapTilesArray(maptilesArray1, decorationtilesArray) 135 | var tilesArray2 = makeMapTilesArray(maptilesArray2, decorationtilesArray) 136 | 137 | var Game = { 138 | tileEngine: 0, //holds tile engine object 139 | fps_el: 0, //fps elemnt to put the fps in 140 | initGame: function() { //initialize game 141 | Game.initGameData(); 142 | Game.fps_el = document.getElementById('fps'); 143 | Game.fps_timer = setInterval(Game.updateFPS, 2000); 144 | Game.tileEngine.start(); //start game loop 145 | Console.log("Main Loop Started"); 146 | }, 147 | updateFPS: function(){ //add new message 148 | if(Game.fps_el) 149 | $(Game.fps_el).html(Game.tileEngine.fps.toFixed(0) + 'fps'); 150 | }, 151 | initGameData: function(){ //create and initialize tile engine 152 | //change map type for testing 153 | var large_map = false; 154 | 155 | Game.tileEngine = newTileEngine(); //create tile engine object 156 | var mapObj = new Object(); //create tile engine initializer mapObject 157 | mapObj.canvas = document.getElementById('main_canvas'); 158 | mapObj.ctx = mapObj.canvas.getContext('2d'); 159 | mapObj.init_x = 0; 160 | mapObj.init_y = 0; 161 | 162 | if(large_map){ 163 | mapObj.sourceFile = 'images/grid_tiles.png'; 164 | mapObj.tileWidth = 16; 165 | mapObj.tileHeight = 16; 166 | mapObj.tile_offset_x = 1; 167 | mapObj.tile_offset_y = 1; 168 | mapObj.sourceTileCounts = 4096; 169 | mapObj.sourceTileAccross = 64; 170 | mapObj.tilesWide = 64; 171 | mapObj.tilesHigh = 64; 172 | mapObj.tilesArray = tilesArray1; 173 | mapObj.physicsArray = tilesPhysicsArray; 174 | mapObj.zoneTilesWide = 9; 175 | mapObj.zoneTilesHigh = 9; 176 | }else{ 177 | mapObj.sourceFile = 'images/tiles.png'; 178 | mapObj.tileWidth = 32; 179 | mapObj.tileHeight = 32; 180 | mapObj.sourceTileCounts = 254; 181 | mapObj.sourceTileAccross = 22; 182 | mapObj.tilesWide = 9; 183 | mapObj.tilesHigh = 18; 184 | mapObj.tilesArray = tilesArray2; 185 | mapObj.physicsArray = tilesPhysicsArray; 186 | mapObj.zoneTilesWide = 3; 187 | mapObj.zoneTilesHigh = 3; 188 | } 189 | 190 | Game.tileEngine.setMapAttributes(mapObj); 191 | 192 | var spriteObj = new Object(); 193 | spriteObj.init_x = 64; 194 | spriteObj.init_y = 84; 195 | spriteObj.width = 32; 196 | spriteObj.height = 32; 197 | spriteObj.sourceFile = 'images/tiles.png'; 198 | spriteObj.sourceTileCounts = 254; 199 | spriteObj.sourceTileAccross = 22; 200 | spriteObj.movement_hash = { 201 | up: [15,16,17,18,19,20,21], 202 | down: [37,38,39,40,41,42,43], 203 | left: [60,82,104,126,148,170,192], 204 | right: [59,81,103,125,147,169,191] 205 | } 206 | Game.tileEngine.setMainSpriteAttributes(spriteObj) 207 | 208 | Game.tileEngine.init(); //initialize tile engine object 209 | } 210 | }; 211 | 212 | $(function(){Game.initGame();}) //initialize game object -------------------------------------------------------------------------------- /js/jquery.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v1.7.1 jquery.com | jquery.org/license */ 2 | (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"":"")+""),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!=="border")for(;g=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c
a",d=q.getElementsByTagName("*"),e=q.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=q.getElementsByTagName("input")[0],b={leadingWhitespace:q.firstChild.nodeType===3,tbody:!q.getElementsByTagName("tbody").length,htmlSerialize:!!q.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:q.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete q.test}catch(s){b.deleteExpando=!1}!q.addEventListener&&q.attachEvent&&q.fireEvent&&(q.attachEvent("onclick",function(){b.noCloneEvent=!1}),q.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),q.appendChild(i),k=c.createDocumentFragment(),k.appendChild(q.lastChild),b.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,k.removeChild(i),k.appendChild(q),q.innerHTML="",a.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",q.style.width="2px",q.appendChild(j),b.reliableMarginRight=(parseInt((a.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(q.attachEvent)for(o in{submit:1,change:1,focusin:1})n="on"+o,p=n in q,p||(q.setAttribute(n,"return;"),p=typeof q[n]=="function"),b[o+"Bubbles"]=p;k.removeChild(q),k=g=h=j=q=i=null,f(function(){var a,d,e,g,h,i,j,k,m,n,o,r=c.getElementsByTagName("body")[0];!r||(j=1,k="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",m="visibility:hidden;border:0;",n="style='"+k+"border:5px solid #000;padding:0;'",o="
"+""+"
",a=c.createElement("div"),a.style.cssText=m+"width:0;height:0;position:static;top:0;margin-top:"+j+"px",r.insertBefore(a,r.firstChild),q=c.createElement("div"),a.appendChild(q),q.innerHTML="
t
",l=q.getElementsByTagName("td"),p=l[0].offsetHeight===0,l[0].style.display="",l[1].style.display="none",b.reliableHiddenOffsets=p&&l[0].offsetHeight===0,q.innerHTML="",q.style.width=q.style.paddingLeft="1px",f.boxModel=b.boxModel=q.offsetWidth===2,typeof q.style.zoom!="undefined"&&(q.style.display="inline",q.style.zoom=1,b.inlineBlockNeedsLayout=q.offsetWidth===2,q.style.display="",q.innerHTML="
",b.shrinkWrapBlocks=q.offsetWidth!==2),q.style.cssText=k+m,q.innerHTML=o,d=q.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,i={doesNotAddBorder:e.offsetTop!==5,doesAddBorderForTableAndCells:h.offsetTop===5},e.style.position="fixed",e.style.top="20px",i.fixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",i.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,i.doesNotIncludeMarginInBodyOffset=r.offsetTop!==j,r.removeChild(a),q=a=null,f.extend(b,i))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;h=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/\bhover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")}; 3 | f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&i.push({elem:this,matches:d.slice(e)});for(j=0;j0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div
","
"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function() 4 | {for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1>");try{for(var c=0,d=this.length;c1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||!bc.test("<"+a.nodeName)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=bg[l]||bg._default,n=m[0],o=b.createElement("div");b===c?bh.appendChild(o):U(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]===""&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return br.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bq,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bq.test(g)?g.replace(bq,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bz(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bA=function(a,b){var c,d,e;b=b.replace(bs,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b)));return c}),c.documentElement.currentStyle&&(bB=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bt.test(f)&&bu.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bz=bA||bB,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bD=/%20/g,bE=/\[\]$/,bF=/\r?\n/g,bG=/#.*$/,bH=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bI=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bJ=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bK=/^(?:GET|HEAD)$/,bL=/^\/\//,bM=/\?/,bN=/)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("
").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window); -------------------------------------------------------------------------------- /js/physics_engine/body.js: -------------------------------------------------------------------------------- 1 | function Body(x, y, width, height){ 2 | var body = { 3 | x: x, y: y, px: x, py: y, dx: 0, dy: 0, 4 | width: width, height: height, 5 | decay: 0.97, 6 | setX: function(x){ 7 | this.px = x; 8 | this.x = x; 9 | }, 10 | setY: function(y){ 11 | this.py = y; 12 | this.y = y; 13 | }, 14 | accelerate: function(delta){ 15 | if(this.director){ 16 | this.dx = this.director.dx; 17 | this.dy = this.director.dy; 18 | } 19 | this.x += this.dx * delta * delta; 20 | this.y -= this.dy * delta * delta; 21 | }, 22 | inertia: function(delta){ 23 | var diffx = this.x - this.px; 24 | var diffy = this.y - this.py; 25 | this.px = this.x; 26 | this.py = this.y; 27 | this.x += diffx * this.decay; 28 | this.y += diffy * this.decay; 29 | } 30 | } 31 | return body; 32 | } -------------------------------------------------------------------------------- /js/physics_engine/physics_engine.js: -------------------------------------------------------------------------------- 1 | function newPhysicsEngine(){ 2 | var p_e = { 3 | tiles: 0, tile_width: 0, tile_height: 0, 4 | bodies: new Array(), collidable_bodies: new Array(), 5 | ingnore_collide: false, 6 | init: function(tiles, tileWidth, tileHeight, mapWidth, mapHeight){ 7 | p_e.tiles = tiles 8 | p_e.tile_width = tileWidth 9 | p_e.tile_height = tileHeight 10 | p_e.map_width = mapWidth 11 | p_e.map_height = mapHeight 12 | }, 13 | to_unit: function(i, unit){ 14 | return Math.floor(i/ unit) * unit 15 | }, 16 | collide: function(){ 17 | for(var i=0, l=p_e.collidable_bodies_length; i 0) ? p_e.to_unit(x+body.width, p_e.tile_width) : x 45 | do{ 46 | p_e.tiles[this_x][this_y].darker = 0.4; 47 | if(p_e.tiles[this_x][this_y].physicsID != 0){ 48 | body.setX(body.dx >= 0 ? this_x-p_e.tile_width:this_x+p_e.tile_width); 49 | return true; 50 | } 51 | }while((this_y += p_e.tile_height) < to_y) 52 | return false; 53 | }, 54 | barrier_collide_y: function (body, x, y){ 55 | var to_x = body.x+body.width, 56 | this_x = x, 57 | this_y = (body.dy < 0) ? p_e.to_unit(y+body.height,p_e.tile_height) : y; 58 | do{ 59 | p_e.tiles[this_x][this_y].darker = 0.4; 60 | if(p_e.tiles[this_x][this_y].physicsID != 0){ 61 | body.setY(body.dy >= 0 ? this_y+p_e.tile_height:this_y-p_e.tile_height); 62 | return true; 63 | } 64 | }while((this_x += p_e.tile_width) < to_x) 65 | return false; 66 | }, 67 | barrier_collide: function(delta){ 68 | var i = p_e.collidable_bodies_length 69 | while(i--){ 70 | var body = p_e.collidable_bodies[i], 71 | x = p_e.to_unit(body.x, p_e.tile_width), 72 | y = p_e.to_unit(body.y, p_e.tile_height); 73 | if(Math.abs(body.dx) > Math.abs(body.dy)){ 74 | p_e.barrier_collide_x(body,x,y); 75 | p_e.barrier_collide_y(body,x,y); 76 | }else{ 77 | p_e.barrier_collide_y(body,x,y); 78 | p_e.barrier_collide_x(body,x,y); 79 | } 80 | } 81 | }, 82 | border_collide: function(){ 83 | var i = p_e.collidable_bodies_length 84 | while(i--){ 85 | var body = p_e.collidable_bodies[i], 86 | width = body.width, 87 | height = body.height, 88 | x = body.x, 89 | y = body.y; 90 | 91 | if(x < 0){ 92 | body.x = 0; 93 | }else if(x + width > p_e.map_width){ 94 | body.x = p_e.map_width - (width+0.01); 95 | } 96 | if(y < 0){ 97 | body.y = 0; 98 | }else if(y + height > p_e.map_height){ 99 | body.y = p_e.map_height-(height+0.01); 100 | } 101 | } 102 | }, 103 | gravity: function(){ 104 | var i = p_e.bodies_length 105 | while(i--){ 106 | p_e.bodies[i].dx *= p_e.bodies[i].decay; 107 | p_e.bodies[i].dy *= p_e.bodies[i].decay; 108 | } 109 | }, 110 | accelerate: function(delta){ 111 | var i = p_e.bodies_length 112 | while(i--){ 113 | p_e.bodies[i].accelerate(delta); 114 | } 115 | }, 116 | inertia: function(delta){ 117 | var i = p_e.bodies_length 118 | while(i--){ 119 | p_e.bodies[i].inertia(delta); 120 | } 121 | }, 122 | update: function(){ 123 | var i = p_e.bodies_length 124 | while(i--){ 125 | if(p_e.bodies[i].update) 126 | p_e.bodies[i].update(); 127 | } 128 | }, 129 | integrate: function(delta){ 130 | p_e.gravity(); 131 | p_e.accelerate(delta); 132 | p_e.collide(); 133 | p_e.border_collide(); 134 | p_e.barrier_collide(delta); 135 | p_e.inertia(delta); 136 | p_e.update(); 137 | }, 138 | add_actor: function(actor, x, y, width, height, ingnore_collide){ 139 | var body = Body(x, y, width, height); 140 | $.extend(actor, body); 141 | p_e.bodies.push(actor) 142 | if(!ingnore_collide) 143 | p_e.collidable_bodies.push(actor) 144 | p_e.bodies_length = p_e.bodies.length 145 | p_e.collidable_bodies_length = p_e.collidable_bodies.length 146 | } 147 | } 148 | return p_e; 149 | } -------------------------------------------------------------------------------- /js/tile_engine/canvas_support.js: -------------------------------------------------------------------------------- 1 | //function to detect canvas support by alterebro (http://code.google.com/p/browser-canvas-support/) var CanvasSupport = { canvas_compatible : false, check_canvas : function() { try { CanvasSupport.canvas_compatible = !!(document.createElement('canvas').getContext('2d')); // S60 } catch(e) { CanvasSupport.canvas_compatible = !!(document.createElement('canvas').getContext); // IE } return CanvasSupport.canvas_compatible; } } -------------------------------------------------------------------------------- /js/tile_engine/console.js: -------------------------------------------------------------------------------- 1 | var Console = { //object to create messages (using alert in a game loop will crash your browser) console: 0, //hold element where messages will be added hidden: true, init: function(){ Console.console = $("
Loading...
") .css('width', $('canvas').css('width')) .insertAfter('canvas') }, hide: function(){$(Console.console).hide('slow'); Console.hidden=true;}, show: function(){$(Console.console).show('slow'); Console.hidden=false;}, log: function(msg){ //add new message if(Console.console) $(Console.console).append('> '+msg+'
'); }, error: function(msg){ //add new message if(Console.console) $(Console.console).append('> '+msg+'
'); } }; -------------------------------------------------------------------------------- /js/tile_engine/keyboard.js: -------------------------------------------------------------------------------- 1 | function newKeyboard(){ var keyboard = { LEFT: 37, RIGHT: 39, UP: 38, DOWN: 40, orientation: {}, thrust: 10, maxSpeed: 100, key_down: false,_focus:false, ctx_click:false, doc_click: false, dx: 0, dy: 0, decay: 0.97, init: function(context) { $(document).keydown(function(event){keyboard.keydown(event)}) .keyup(function(event){keyboard.keyup(event)}) $(context).mouseup(function(event){keyboard.ctx_click = true;}) $(document).keydown(keyboard.keydown) .keyup(keyboard.keyup) .mousedown(function(event){keyboard.doc_click = true;}) .mouseup(function(event){keyboard._focus = keyboard.ctx_click && keyboard.doc_click;keyboard.doc_click = keyboard.ctx_click = false;}) setInterval(keyboard.update,1) }, keydown: function (event){ keyboard.orientation[event.keyCode] = keyboard._focus; keyboard.key_down = keyboard._focus; }, keyup: function (event){ keyboard.orientation[event.keyCode] = false; keyboard.key_down = false; }, update: function(){ if (keyboard.orientation[keyboard.LEFT])keyboard.dx -= keyboard.thrust; if (keyboard.orientation[keyboard.RIGHT])keyboard.dx += keyboard.thrust; if (keyboard.orientation[keyboard.UP])keyboard.dy += keyboard.thrust; if (keyboard.orientation[keyboard.DOWN])keyboard.dy -= keyboard.thrust; //speed limit var currentSpeed = Math.sqrt((keyboard.dx * keyboard.dx) + (keyboard.dy * keyboard.dy)); if (currentSpeed > keyboard.maxSpeed){ keyboard.dx *= keyboard.maxSpeed/currentSpeed; keyboard.dy *= keyboard.maxSpeed/currentSpeed; } keyboard.dx *= keyboard.decay; keyboard.dy *= keyboard.decay; } } return keyboard; } -------------------------------------------------------------------------------- /js/tile_engine/mouse.js: -------------------------------------------------------------------------------- 1 | function newMouse(){ var Mouse = { down: false,offsetx: 0,offsety: 0,timer: 0,accelx: 0,accely: 0, clickposx: 0,clickposy: 0,dx: 0,dy:0,view: 0,thrust: 10, decay: 0.97, maxSpeed: 200, init: function(context) { $(context) .mousedown(Mouse.mouseDown) .mouseup(function() {Mouse.down = false;}) .mouseout(function() {Mouse.down = false;}) .mousemove(Mouse.move); setInterval(Mouse.update, 100); }, isDown: function() {return Mouse.down;}, mouseDown:function(event){ Mouse.dx = 0; Mouse.dy = 0; Mouse.setClickPos(event) }, setClickPos: function(event) { Mouse.clickposx = event.screenX; Mouse.clickposy = event.screenY; Mouse.down = true; }, move: function(event) { if (Mouse.isDown()) { Mouse.timer++; Mouse.offsetx = event.screenX - Mouse.clickposx; Mouse.offsety = event.screenY - Mouse.clickposy; Mouse.setClickPos(event); Mouse.accelx = Mouse.offsetx / Mouse.timer; Mouse.accely = Mouse.offsety / Mouse.timer; } else { Mouse.reset(); } }, reset: function() { Mouse.offsetx = 0; Mouse.offsety = 0; Mouse.accelx = 0; Mouse.accely = 0; Mouse.timer = 0; }, update: function(){ if (Mouse.isDown()) { Mouse.dx = Mouse.dx - (Mouse.accelx * Mouse.thrust); Mouse.dy = Mouse.dy + (Mouse.accely * Mouse.thrust); //speed limit var currentSpeed = Math.sqrt((Mouse.dx * Mouse.dx) + (Mouse.dy * Mouse.dy)); if (currentSpeed > Mouse.maxSpeed){ Mouse.dx *= Mouse.maxSpeed/currentSpeed; Mouse.dy *= Mouse.maxSpeed/currentSpeed; } } Mouse.dx *= Mouse.decay; Mouse.dy *= Mouse.decay; Mouse.reset(); } }; return Mouse; } -------------------------------------------------------------------------------- /js/tile_engine/source_image.js: -------------------------------------------------------------------------------- 1 | function newSourceImage(){ //image used to create tile 2 | var SourceImage = { 3 | imageFilename: 0, //filename for image 4 | image: 0, //dom image object 5 | init: function(file){ 6 | SourceImage.imageFilename = file; 7 | SourceImage.image = new Image(); //create new image object 8 | SourceImage.image.src = file; //load file into image object 9 | } 10 | }; 11 | return SourceImage; 12 | } -------------------------------------------------------------------------------- /js/tile_engine/sprite.js: -------------------------------------------------------------------------------- 1 | 2 | function newSprite(mapWidth, mapHeight, ctx){ 3 | var Sprite = { 4 | sourceHash: 0,current_index:0, current_direction: 0, director: null, 5 | init: function(x, y, width, height, sourceHash, director){ //initialize sprite 6 | Sprite.director = director; 7 | Sprite.sourceHash = sourceHash; 8 | Sprite.current_direction = Sprite.sourceHash.up 9 | setInterval(Sprite.update_index, 100) 10 | }, 11 | update: function(){ 12 | if(Sprite.dx > 1) 13 | Sprite.current_direction = Sprite.sourceHash.right 14 | if(Sprite.dx < -1) 15 | Sprite.current_direction = Sprite.sourceHash.left 16 | if(Sprite.dy > 1) 17 | Sprite.current_direction = Sprite.sourceHash.up 18 | if(Sprite.dy < -1) 19 | Sprite.current_direction = Sprite.sourceHash.down 20 | }, 21 | current_frame: function(){ 22 | return Sprite.current_direction[Sprite.current_index]; 23 | }, 24 | update_index: function(){ 25 | if(Sprite.dx > 1 || Sprite.dx < -1 || Sprite.dy > 1 || Sprite.dy < -1){ 26 | Sprite.current_index++; 27 | if(Sprite.current_index >= Sprite.current_direction.length) 28 | Sprite.current_index = 0 29 | } 30 | }, 31 | draw: function(view, views){ 32 | if(views){ 33 | var v = views.length; 34 | while(v--){ 35 | var currentView = views[v]; 36 | if(Sprite.spriteSource && currentView.isInView(Sprite)){ 37 | ctx.drawImage(Sprite.spriteSource[Sprite.current_frame()].canvas, (Sprite.x+currentView.xoffset)-view.x, (Sprite.y+currentView.yoffset)-view.y); 38 | } 39 | } 40 | }else if(Sprite.spriteSource && view.isInView(Sprite)) 41 | ctx.drawImage(Sprite.spriteSource[Sprite.current_frame()].canvas, Sprite.x-view.x, Sprite.y-view.y); 42 | 43 | } 44 | }; 45 | return Sprite; //returns newly created sprite object 46 | }; -------------------------------------------------------------------------------- /js/tile_engine/tile.js: -------------------------------------------------------------------------------- 1 | /*** function to create and then return a new Tile object */ 2 | function newTile(){ 3 | var Tile = { 4 | x: 0, // X and Y position of this tile 5 | y: 0, // 6 | local_x:0, //local x and y of thier position within thier zones 7 | local_y:0, 8 | width: 0, 9 | height: 0, 10 | baseSourceIndex: 0, //index of tile source in tile engine's source array 11 | decorationIndex: 0, //index of secondary layer 12 | physicsID: 0, //physics type 13 | darker: 0, // mostly for debug but also for cool effect later maybe! 14 | init: function(x, y, width, height, source_index, physics_id){ //initialize sprite 15 | Tile.x = x; 16 | Tile.y = y; 17 | Tile.width = width; 18 | Tile.height = height; 19 | var sourceNumbers = getBytes(source_index) 20 | Tile.baseSourceIndex = sourceNumbers[1]; // set index of tile source for this tile 21 | Tile.decorationIndex = sourceNumbers[0]; 22 | Tile.physicsID = physics_id || 0; 23 | } 24 | }; 25 | return Tile; //returns newly created sprite object 26 | }; -------------------------------------------------------------------------------- /js/tile_engine/tile_engine.js: -------------------------------------------------------------------------------- 1 | /* 2 | Lightweight Tile Engine For HTML5 Game Creation 3 | Copyright (C) 2010 John Graham 4 | Copyright (C) 2011 Tim Anema 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | function newTileEngine(){ 21 | var TileEngine = { //main canvas and demo container 22 | canvas: 0, //main canvas object 23 | ctx: 0, //main canvas drawing context 24 | tiles: new Array(), //double dimenal array by coordinates 25 | zones: new Array(), //array of tile zones 26 | tileSource: 0, //array of tile source objects, one for each unique tile 27 | tileSourcesHash: {}, 28 | width: 0, //width of tile map 29 | height: 0, //height of tile map 30 | zoneTilesWide: 0, //width in tiles of a zone 31 | zoneTilesHigh: 0, //height in tiles of a zone 32 | tilesHigh: 0, //height in tiles of entire map 33 | tilesWide: 0, //width in tiles of entire map 34 | tileWidth: 0, //width in pixels single tile 35 | tileHeight: 0, //height in pixels of single tile 36 | mapWidth: 0, 37 | mapHeight: 0, 38 | sprites: new Array(), 39 | main_sprite: 0, 40 | mouse: newMouse(), 41 | keyboard: newKeyboard(), 42 | physics_engine: newPhysicsEngine(), 43 | timeofDay: 0.2, 44 | view : 0, 45 | active_controller: 0, 46 | t: 0.0, 47 | dt: 0.01, 48 | currentTime: (new Date).getTime(), 49 | accumulator: 0.0, 50 | gameTimer: 0, //holds id of main game timer 51 | fps: 250, 52 | fps_count: 0, //hold frame count 53 | fps_timer: 0, //timer for FPS update (2 sec) 54 | 55 | init: function(){ //initialize experiment 56 | if(!TileEngine.view) 57 | alert("please set map attributes before initializing tile engine"); 58 | TileEngine.mouse.init(TileEngine.canvas) 59 | TileEngine.keyboard.init(TileEngine.canvas) 60 | TileEngine.physics_engine.init(TileEngine.tiles, TileEngine.tileWidth, TileEngine.tileHeight,TileEngine.mapWidth, TileEngine.mapHeight) 61 | TileEngine.view.init(TileEngine.mouse, TileEngine.main_sprite, TileEngine.isKeyBoardActive); 62 | 63 | //Active controller handling 64 | $(TileEngine.canvas).mouseup(function(event){TileEngine.ctx_click = true;}) 65 | $(document).keydown(function(event){if(TileEngine._focus)TileEngine.active_controller = TileEngine.keyboard}) 66 | .mousedown(function(event){TileEngine.active_controller = TileEngine.mouse;TileEngine.doc_click = true;}) 67 | .mouseup(function(event){TileEngine._focus = TileEngine.ctx_click && TileEngine.doc_click;TileEngine.doc_click = TileEngine.ctx_click = false;}) 68 | Console.log("Tile Map Initialized"); 69 | }, 70 | start: function(){ 71 | Console.log("FPS limit set to: " + TileEngine.fps) 72 | var interval = 1000 / TileEngine.fps; 73 | TileEngine.gameTimer = setInterval(TileEngine.drawFrame, interval); 74 | TileEngine.fps_timer = setInterval(TileEngine.updateFPS, 2000); 75 | }, 76 | updateFPS: function(){ 77 | TileEngine.fps = TileEngine.fps_count / 2; // every two seconds cut the fps by 2 78 | TileEngine.fps_count = 0; // every two seconds cut the fps by 2 79 | }, 80 | isKeyBoardActive: function(){return TileEngine.active_controller == TileEngine.keyboard}, 81 | isMouseActive: function(){return TileEngine.active_controller == TileEngine.mouse}, 82 | setMapAttributes: function(obj){ //this function must be called prior to initializing tile engine 83 | TileEngine.canvas = obj.canvas; //get canvas element from html 84 | TileEngine.ctx = obj.ctx; //create main drawing canvas 85 | TileEngine.width = TileEngine.canvas.width; 86 | TileEngine.height = TileEngine.canvas.height; 87 | TileEngine.tileWidth = obj.tileWidth; 88 | TileEngine.tileHeight = obj.tileHeight; 89 | TileEngine.zoneTilesWide = obj.zoneTilesWide; 90 | TileEngine.zoneTilesHigh = obj.zoneTilesHigh; 91 | TileEngine.tilesWide = obj.tilesWide; 92 | TileEngine.tilesHigh = obj.tilesHigh; 93 | TileEngine.mapWidth = TileEngine.tilesWide*TileEngine.tileWidth 94 | TileEngine.mapHeight = TileEngine.tilesHigh*TileEngine.tileHeight 95 | TileEngine.view = newView(obj.init_x,obj.init_y, TileEngine.width, TileEngine.height, TileEngine.mapWidth,TileEngine.mapHeight); 96 | TileEngine.physics_engine.add_actor(TileEngine.view, obj.init_x, obj.init_y, TileEngine.width, TileEngine.height, true); 97 | 98 | Console.log(obj.sourceTileCounts + ' Source Tiles to Load'); 99 | Console.log(obj.tilesArray.length + ' Map Tiles to Load'); 100 | 101 | var source = newSourceImage(); 102 | source.init(obj.sourceFile); 103 | source.image.onload = function(){ //event handler for image load 104 | TileEngine.tileSource = TileEngine.createTileSource(obj.tileWidth, obj.tileHeight, obj.sourceTileCounts, obj.sourceTileAccross, obj.tile_offset_x || 0, obj.tile_offset_y || 0, source); //create tile sources using image source 105 | } 106 | TileEngine.createZones(); //create zones 107 | TileEngine.createTiles(obj.tilesArray, obj.physicsArray); 108 | }, 109 | setMainSpriteAttributes: function(obj){TileEngine.main_sprite = TileEngine.addSprite(obj, TileEngine.keyboard)}, 110 | addSprite: function(obj, director){ 111 | var sprite = newSprite(TileEngine.mapWidth,TileEngine.mapHeight, TileEngine.ctx); 112 | sprite.init(obj.init_x, obj.init_y, obj.width, obj.height, obj.movement_hash, director) 113 | TileEngine.physics_engine.add_actor(sprite, obj.init_x, obj.init_y, obj.width, obj.height); 114 | var source = newSourceImage(); 115 | source.init(obj.sourceFile); 116 | source.image.onload = function(){ //event handler for image load 117 | sprite.spriteSource = TileEngine.createTileSource(obj.width, obj.height, obj.sourceTileCounts, obj.sourceTileAccross, obj.tile_offset_x || 0, obj.tile_offset_y || 0, source); //create tile sources using image source 118 | } 119 | TileEngine.sprites.push(sprite) 120 | return sprite; 121 | }, 122 | integrator: function(t,dt){ 123 | var newTime = (new Date).getTime(), 124 | deltaTime = (newTime - TileEngine.currentTime)/100 125 | if(deltaTime > 0.25) 126 | deltaTime = 0.25 127 | TileEngine.currentTime = newTime; 128 | TileEngine.accumulator += deltaTime; 129 | while(TileEngine.accumulator >= TileEngine.dt) { 130 | TileEngine.accumulator -= TileEngine.dt; 131 | TileEngine.physics_engine.integrate(TileEngine.dt) 132 | TileEngine.t += TileEngine.dt; 133 | } 134 | TileEngine.active_controller ? TileEngine.active_controller.update():TileEngine.view.update(); 135 | }, 136 | drawFrame: function(){ //main drawing function 137 | //physics 138 | TileEngine.integrator(); 139 | //clear main canvas 140 | TileEngine.ctx.clearRect(0, 0, TileEngine.width, TileEngine.height); 141 | //draw() 142 | TileEngine.render(TileEngine.view); 143 | TileEngine.fps_count++; //increments frame for fps display 144 | }, 145 | render: function(view){ 146 | var i = TileEngine.zones.length, 147 | validZones = new Array(); 148 | //base map 149 | while(i--){ 150 | var check_zone = TileEngine.zones[i]; 151 | if(view.isInView(check_zone)){ 152 | validZones.push(check_zone); 153 | check_zone.drawTiles(view); 154 | TileEngine.ctx.drawImage(check_zone.base_canvas, Math.round(check_zone.x-view.x), Math.round(check_zone.y-view.y)); 155 | } 156 | } 157 | 158 | //sprites 159 | i = TileEngine.sprites.length 160 | while(i--) 161 | TileEngine.sprites[i].draw(view) 162 | 163 | //decorations 164 | i = validZones.length; 165 | while(i--){ 166 | var check_zone = validZones[i]; 167 | check_zone.drawDecorations(view); 168 | TileEngine.ctx.drawImage(check_zone.dec_canvas, check_zone.x-view.x, check_zone.y-view.y); 169 | } 170 | 171 | //do brightness of the screen 172 | TileEngine.ctx.fillStyle = "rgba(0, 0, 0," + TileEngine.timeofDay + ")"; 173 | TileEngine.ctx.fillRect(0, 0, TileEngine.width, TileEngine.height); 174 | }, 175 | createTileSource: function(tileWidth, tileHeight, count, accross, offset_x, offset_y, source){ //create tiles sources 176 | if(TileEngine.tileSourcesHash[source.imageFilename]) 177 | return TileEngine.tileSourcesHash[source.imageFilename] 178 | 179 | var source_array = new Array(), 180 | accross_count = 0,x = 0,y = 0, 181 | offset_x_count = 0, offset_y_count = 0; 182 | 183 | for(var i = 0; i < count; i++){ 184 | var new_tileSource = newTileSource(); 185 | new_tileSource.init(tileWidth, tileHeight,x+(offset_x*offset_x_count), y+(offset_y*offset_y_count), source); 186 | source_array.push(new_tileSource); 187 | accross_count++; 188 | x += tileWidth; 189 | offset_x_count++; 190 | if(accross_count >= accross){ 191 | accross_count = 0; 192 | y += tileHeight; 193 | x = 0; 194 | offset_y_count++; 195 | offset_x_count = 0; 196 | } 197 | } 198 | //save in the hash that way two file are not needed 199 | TileEngine.tileSourcesHash[source.imageFilename] = source_array; 200 | return TileEngine.tileSourcesHash[source.imageFilename]; 201 | }, 202 | 203 | createTiles: function(tilesArray, physicsArray) { //load tile array 204 | var tile_index = 0; //track current position in tile array 205 | var y_zone = 0; //used to determine which zone to add tile to 206 | var x_zone = 0; //used to determine which zone to add tile to 207 | var zone_index = 0; //track current position in zone array 208 | var zone_wide = Math.ceil(TileEngine.tilesWide/TileEngine.zoneTilesWide); //how many zones are there horizontally 209 | 210 | function getX(index){return TileEngine.tileWidth * (index % TileEngine.tilesWide)} 211 | function getY(index){return TileEngine.tileHeight * parseInt(index / TileEngine.tilesWide)} 212 | 213 | for(var h = 0, hh = TileEngine.tilesHigh; h < hh; h++) 214 | { 215 | y_zone = Math.floor(h/TileEngine.zoneTilesHigh); //calculate which vertical zone we are in 216 | for(var i = 0, ii = TileEngine.tilesWide; i < ii; i++){ //cycle through each row 217 | if(!TileEngine.tiles[i*TileEngine.tileWidth])//if this x array is not initialized yet 218 | TileEngine.tiles[i*TileEngine.tileWidth] = new Array(); 219 | 220 | x_zone = Math.floor(i/TileEngine.zoneTilesWide);// calculate which horizontal zone we are in 221 | 222 | var new_tile = newTile(); //create new tile object 223 | 224 | new_tile.init(getX(tile_index), getY(tile_index), TileEngine.tileWidth, TileEngine.tileHeight, tilesArray[tile_index], physicsArray[tile_index]); //init tile 225 | zone_index = (y_zone * zone_wide) + x_zone;//find what zone to add to using vert and horizontal positions 226 | 227 | TileEngine.zones[zone_index].addTile(new_tile); //add tile to zone 228 | TileEngine.tiles[new_tile.x][new_tile.y] = new_tile; //add tile to tile engine 229 | 230 | tile_index++; 231 | } 232 | x_zone = 0; //reset horizontal position when we loop to new row 233 | } 234 | 235 | Console.log("Tiles Ready"); 236 | }, 237 | createZones: function(){//create array of zones for map 238 | //caluculate how many zones we need (width by height) 239 | var zone_wide = Math.ceil(TileEngine.tilesWide/TileEngine.zoneTilesWide), 240 | zone_high = Math.ceil(TileEngine.tilesHigh/TileEngine.zoneTilesHigh); 241 | 242 | /*these are used if tilemap is not evenly divisible by size of zones in tiles 243 | **they are used to define the size of zones on the right and bottom edges of the 244 | **map */ 245 | var x_remainder = TileEngine.tilesWide%TileEngine.zoneTilesWide, 246 | y_remainder = TileEngine.tilesHigh%TileEngine.zoneTilesHigh; 247 | 248 | for(var h = 0; h < zone_high; h++){ //loop through zone rows 249 | for(var i = 0; i < zone_wide; i++){ //loop through zone columns 250 | var new_zone = newZone(), //create new zone 251 | x = i * TileEngine.zoneTilesWide * TileEngine.tileWidth, //set x pos of new zone 252 | y = h * TileEngine.zoneTilesHigh * TileEngine.tileHeight, //set y pos of new zone 253 | width = TileEngine.zoneTilesWide * TileEngine.tileWidth, //set width of new zone 254 | height = TileEngine.zoneTilesHigh * TileEngine.tileHeight, //set height of new zone 255 | tiles_wide = TileEngine.zoneTilesWide, //set tiles wide for new zone 256 | tiles_high = TileEngine.zoneTilesHigh; //set tiles high for new zone 257 | 258 | if(i == (zone_wide - 1) && x_remainder > 0){ //if is last zone on horizontal row and tiles divide unevenly into zones 259 | tiles_wide = x_remainder; //change new zone tiles wide to be correct 260 | width = tiles_wide * TileEngine.tileWidth; //change new zone width to be correct 261 | } 262 | if(h == (zone_high - 1) && y_remainder > 0){ //if last zones on bottom and tiles divide unevenly into zones 263 | tiles_high = y_remainder; //adjust tiles high 264 | height = tiles_high * TileEngine.tileHeight; //adjust zone height 265 | } 266 | 267 | new_zone.init(TileEngine, x, y, TileEngine.tileWidth, TileEngine.tileHeight, width, height); //intitialize new zone 268 | TileEngine.zones.push(new_zone); //push zone to tile engine array 269 | } 270 | } 271 | } 272 | } 273 | 274 | Console.init(); 275 | if(CanvasSupport.check_canvas()){ //check canvas support before intializing 276 | return TileEngine; 277 | } 278 | else { 279 | Console.log('Your Browser Does not support this app!'); 280 | return false; 281 | } 282 | }; -------------------------------------------------------------------------------- /js/tile_engine/tile_source.js: -------------------------------------------------------------------------------- 1 | function newTileSource(){ //image used to create tile 2 | var TileSource = { 3 | canvas: 0, //main canvas object 4 | ctx: 0, //main canvas drawing context 5 | sourceImage: 0, //image source for this tile 6 | init: function(width, height, src_x, src_y, source){ 7 | TileSource.sourceImage = source; //set image source 8 | TileSource.canvas = document.createElement('canvas'); 9 | TileSource.ctx = TileSource.canvas.getContext('2d'); //create main drawing canvas 10 | TileSource.canvas.setAttribute('width', width); //set tile source canvas size 11 | TileSource.canvas.setAttribute('height', height); 12 | TileSource.ctx.drawImage(TileSource.sourceImage.image, src_x, src_y, width, height, 0, 0, width, height); //draw image to tile source canvas 13 | } 14 | }; 15 | return TileSource; 16 | }; -------------------------------------------------------------------------------- /js/tile_engine/util.js: -------------------------------------------------------------------------------- 1 | var setBytes = function(num1,num2,num3) { return (num1 << 18)| num2;//return (((num1 << 16) | (num2||0)) << 4) | (num3||0); }; function getBytes(num) { return [num & 0x3FFFF, (num >> 18) & 0x3FFFF];//return [num & 0xF, (num >> 4) & 0xFFFF, (num >> 20) & 0xFFFF]; }; var makeMapTilesArray = function(tiles_a, decor_a){ var tilesArray = new Array() var i = tiles_a.length while(i--){ tilesArray[i] = setBytes(tiles_a[i], decor_a[i]); } return tilesArray; } -------------------------------------------------------------------------------- /js/tile_engine/view.js: -------------------------------------------------------------------------------- 1 | 2 | function newView(x, y, width, height, mapWidth, mapHeight){ 3 | var view = { 4 | x:x || 0,y:y || 0,viewWidth: 0, viewHeight: 0, 5 | director: null, xoffset: 0, yoffset: 0, isControllingSprite: 0, 6 | main_sprite: 0, 7 | init: function(dir, main_sprite, isControllingSprite){ 8 | view.director = dir; 9 | view.main_sprite = main_sprite; 10 | view.isControllingSprite = isControllingSprite; 11 | view.decay = 0.97; //override decay 12 | view.update(); 13 | }, 14 | update : function(){ 15 | if(view.isControllingSprite()){ 16 | view.x = view.x+(view.main_sprite.x - (view.x + width/2)) * 0.05 17 | view.y = view.y+(view.main_sprite.y - (view.y + height/2)) * 0.05 18 | } 19 | 20 | if((view.x+width) > mapWidth){ 21 | view.x = mapWidth-width; 22 | }else if(view.x < 0){ 23 | view.x = 0; 24 | } 25 | if((view.y+height) > mapHeight){ 26 | view.y = mapHeight-height; 27 | }else if(view.y < 0){ 28 | view.y = 0 29 | } 30 | 31 | view.viewWidth = view.x + width; 32 | view.viewHeight = view.y + height; 33 | }, 34 | isInView: function(check){ 35 | return (check.x+check.width > this.x && check.x <= this.viewWidth)&&(check.y+check.height > this.y && check.y <= this.viewHeight) 36 | }, 37 | up: function(){ 38 | var v = $.extend({}, this); 39 | if(v.y < 0){ 40 | v.y += mapHeight; 41 | v.viewHeight = mapHeight;//no need to do the extra calc for the actual width 42 | v.yoffset = -mapHeight; 43 | } 44 | return v; 45 | }, 46 | down: function(){ 47 | var v = $.extend({}, this); 48 | if(v.viewHeight > mapHeight){ 49 | v.y = 0 50 | v.viewHeight -= mapHeight; 51 | v.yoffset = mapHeight; 52 | } 53 | return v; 54 | }, 55 | left: function(){ 56 | var v = $.extend({}, this); 57 | if(v.x < 0){ 58 | v.x += mapWidth; 59 | v.viewWidth = mapWidth;//no need to do the extra calc for the actual width 60 | v.xoffset = -mapWidth; 61 | } 62 | return v; 63 | }, 64 | right: function(){ 65 | var v = $.extend({}, this); 66 | if(v.viewWidth > mapWidth){ 67 | v.x = 0 68 | v.viewWidth -= mapWidth; 69 | v.xoffset = mapWidth; 70 | } 71 | return v; 72 | } 73 | } 74 | return view; 75 | } -------------------------------------------------------------------------------- /js/tile_engine/zone.js: -------------------------------------------------------------------------------- 1 | 2 | function newZone(){ 3 | var Zone = { 4 | base_canvas: 0, //zone canvas object 5 | dec_canvas: 0, //zone canvas object 6 | tileEngine: 0, //the main tile engine object (used to fetch tile sources) 7 | base_ctx: 0, //zone canvas drawing context 8 | dec_ctx: 0, //zone canvas drawing context 9 | left: 0, //x position of this zone in the tile map 10 | top: 0, //y position of this zone in the tile map 11 | right: 0, //x position of right edge 12 | bottom: 0, //y position of bottom edge 13 | tileWidth: 0, 14 | tileHeight: 0, 15 | width: 0, 16 | height: 0, 17 | x: 0, 18 | y: 0, 19 | viewoffset: 0, 20 | tiles: 0, //array of tiles in this zone 21 | init: function(engine, left, top, tileWidth, tileHeight, width, height){ 22 | Zone.tileEngine = engine; 23 | Zone.left = Zone.x = left; 24 | Zone.top = Zone.y = top; 25 | Zone.right = left + width; 26 | Zone.bottom = top + height; 27 | Zone.tileWidth = tileWidth; 28 | Zone.tileHeight = tileHeight; 29 | Zone.width = width; 30 | Zone.height = height; 31 | Zone.base_canvas = document.createElement('canvas'); 32 | Zone.base_ctx = Zone.base_canvas.getContext('2d'); //create main drawing canvas 33 | Zone.dec_canvas = document.createElement('canvas'); 34 | Zone.dec_ctx = Zone.dec_canvas.getContext('2d'); //create main drawing canvas 35 | Zone.base_canvas.setAttribute('width', width); //set tile source canvas size 36 | Zone.base_canvas.setAttribute('height', height); 37 | Zone.dec_canvas.setAttribute('width', width); //set tile source canvas size 38 | Zone.dec_canvas.setAttribute('height', height); 39 | Zone.tiles = new Array(); 40 | }, 41 | getX: function (index){return Zone.tileWidth * (index % (Zone.width / Zone.tileWidth))}, 42 | getY: function (index){return Zone.tileHeight * parseInt(index / (Zone.height / Zone.tileWidth))}, 43 | addTile: function(tile){ 44 | var index = Zone.tiles.push(tile) - 1; 45 | tile.local_x = Zone.getX(index); 46 | tile.local_y = Zone.getY(index); 47 | }, 48 | drawTiles: function(view){ 49 | Zone.base_ctx.clearRect(0,0,Zone.width, Zone.height); 50 | if(Zone.tiles){ 51 | var i = Zone.tiles.length; 52 | while(i--){ 53 | var check_tile = Zone.tiles[i]; 54 | if(view.isInView(check_tile) && Zone.tileEngine.tileSource[check_tile.baseSourceIndex]){ 55 | Zone.base_ctx.drawImage(Zone.tileEngine.tileSource[check_tile.baseSourceIndex].canvas, check_tile.local_x, check_tile.local_y); //draw tile based on its source index and position 56 | } 57 | if(check_tile.darker != 0){ 58 | Zone.base_ctx.fillStyle = "rgba(0,0,0," + check_tile.darker + ")"; 59 | Zone.base_ctx.fillRect(check_tile.local_x,check_tile.local_y,Zone.tileWidth, Zone.tileHeight); 60 | check_tile.darker = 0; 61 | } 62 | } 63 | } 64 | }, 65 | drawDecorations: function(view){ 66 | Zone.dec_ctx.clearRect(0,0,Zone.width, Zone.height); 67 | if(Zone.tiles){ 68 | var i = Zone.tiles.length; 69 | while(i--){ 70 | var check_tile = Zone.tiles[i]; 71 | //decoration cannot be at tile 0 72 | if(check_tile.decorationIndex != 0 && view.isInView(check_tile) && Zone.tileEngine.tileSource[check_tile.decorationIndex]){ 73 | Zone.dec_ctx.drawImage(Zone.tileEngine.tileSource[check_tile.decorationIndex].canvas, check_tile.local_x, check_tile.local_y); //draw tile based on its source index and position 74 | } 75 | } 76 | } 77 | } 78 | }; 79 | return Zone; 80 | } -------------------------------------------------------------------------------- /main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
-
19 | 20 |

21 | Unfortunately, your browser is currently unsupported by this web 22 | application. Sorry for the inconvenience. Please use one of the 23 | supported browsers listed below, or draw the image you want using an 24 | offline tool.
25 | Supported browsers: 26 |

33 |

34 |
35 | 36 | -------------------------------------------------------------------------------- /stylesheets/style.css: -------------------------------------------------------------------------------- 1 | canvas#main_canvas{ 2 | border: 1px solid black; 3 | } 4 | 5 | div#console{ 6 | position: fixed; 7 | height: 250px; 8 | overflow-x: hidden; 9 | overflow-y: auto; 10 | background-color: #000; 11 | color: #fff; 12 | } --------------------------------------------------------------------------------