From ef8564fb6de2d332aef9746eb1a676e5ffb4e3f1 Mon Sep 17 00:00:00 2001 From: obiot Date: Tue, 1 May 2012 11:47:59 +0800 Subject: [PATCH] Tutorial update --- .../tutorial_final/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step2/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step3/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step4/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step5/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step6/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step7/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- .../tutorial_step8/lib/melonJS-0.9.3-min.js | 218 +++++++++--------- tutorial/tutorial_template/gameObj.js | 0 tutorial/tutorial_template/index.html | 2 +- .../lib/melonJS-0.9.3-min.js | 218 +++++++++--------- 11 files changed, 991 insertions(+), 973 deletions(-) create mode 100644 tutorial/tutorial_template/gameObj.js diff --git a/tutorial/tutorial_final/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_final/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_final/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_final/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step2/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step2/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step2/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step2/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step3/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step3/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step3/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step3/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step4/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step4/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step4/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step4/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step5/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step5/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step5/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step5/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step6/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step6/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step6/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step6/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step7/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step7/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step7/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step7/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_step8/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_step8/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_step8/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_step8/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); diff --git a/tutorial/tutorial_template/gameObj.js b/tutorial/tutorial_template/gameObj.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tutorial/tutorial_template/index.html b/tutorial/tutorial_template/index.html index 6361870a6e..34dd8caa63 100644 --- a/tutorial/tutorial_template/index.html +++ b/tutorial/tutorial_template/index.html @@ -11,7 +11,7 @@
- +
diff --git a/tutorial/tutorial_template/lib/melonJS-0.9.3-min.js b/tutorial/tutorial_template/lib/melonJS-0.9.3-min.js index d4acf67281..1f56d78951 100644 --- a/tutorial/tutorial_template/lib/melonJS-0.9.3-min.js +++ b/tutorial/tutorial_template/lib/melonJS-0.9.3-min.js @@ -9,152 +9,154 @@ Tween JS https://github.com/sole/Tween.js */ -(function(a,c){function b(){if(!j){if(!d.body)return setTimeout(b,13);d.removeEventListener?d.removeEventListener("DOMContentLoaded",b,!1):a.removeEventListener("load",b,!1);j=!0;for(var f=0;fd?d:this};Number.prototype.random=function(a,d){return~~(Math.random()*(d-a+1))+a};Number.prototype.round=function(){var a=1==arguments.length?this:arguments[0],d=Math.pow(10,arguments[1]||arguments[0]);return Math.round(a*d)/d};Number.prototype.toHex=function(){return"0123456789ABCDEF".charAt(this-this%16>>4)+"0123456789ABCDEF".charAt(this%16)};Number.prototype.sign=function(){return 0>this?-1:0this.x)this.x=-this.x;if(0>this.y)this.y=-this.y},clamp:function(a,c){return new me.Vector2d(this.x.clamp(a,c),this.y.clamp(a, c))},minV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},floor:function(){return new me.Vector2d(~~this.x,~~this.y)},ceil:function(){return new me.Vector2d(Math.ceil(this.x),Math.ceil(this.y))},negate:function(){return new me.Vector2d(-this.x,-this.y)},negateSelf:function(){this.x=-this.x;this.y=-this.y},copy:function(a){this.x=a.x;this.y=a.y},length:function(){return Math.sqrt(this.x*this.x+this.y* this.y)},normalize:function(){var a=this.length();if(a=this.right&&a.top<=this.top&&a.bottom>=this.bottom},contains:function(a){return a.left>= -this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,e=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>e?-e:e);c.xb?-c.x:c.x):(c.x=0,c.y=0>e?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= +this.left&&a.right<=this.right&&a.top>=this.top&&a.bottom<=this.bottom},containsPoint:function(a){return a.x>=this.left&&a.x<=this.right&&a.y>=this.top&&a.y<=this.bottom},collideVsAABB:function(a){var c=new me.Vector2d(0,0);if(this.overlaps(a)){var b=this.left+this.hWidth-a.left-a.hWidth,g=this.top+this.hHeight-a.top-a.hHeight;c.x=a.hWidth+this.hWidth-(0>b?-b:b);c.y=a.hHeight+this.hHeight-(0>g?-g:g);c.xb?-c.x:c.x):(c.x=0,c.y=0>g?-c.y:c.y)}return c},draw:function(a,c){a.strokeStyle= c||"red";a.strokeRect(this.left-me.game.viewport.pos.x,this.top-me.game.viewport.pos.y,this.width,this.height)}})})(window); -(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,f,g,j){this.parent(new me.Vector2d(a,c),d-a,f-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(g||this.width,j||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, +(function(){var a=Math.min,c=Math.max;me.Viewport=me.Rect.extend({AXIS:{NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},limits:null,target:null,follow_axis:0,_shake:null,_fadeIn:null,_fadeOut:null,_deadwidth:0,_deadheight:0,_limitwidth:0,_limitheight:0,init:function(a,c,d,e,f,h){this.parent(new me.Vector2d(a,c),d-a,e-c);this.last=new me.Vector2d(-1,-1);this.limits=new me.Vector2d(f||this.width,h||this.height);this.target=null;this.follow_axis=this.AXIS.NONE;this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH, onComplete:null};this._fadeOut={color:0,alpha:0,duration:0,tween:null};this._fadeIn={color:0,alpha:1,duration:0,tween:null};this.setDeadzone(this.width/6,this.height/6)},_followH:function(b){if(b.x-this.pos.x>this._deadwidth)this.pos.x=~~a(b.x-this._deadwidth,this._limitwidth);else if(b.x-this.pos.xthis._deadheight)this.pos.y=~~a(b.y-this._deadheight,this._limitheight);else if(b.y-this.pos.ythis._shake.duration){if(this._shake.onComplete)this._shake.onComplete()}else{if(this._shake.axis==this.AXIS.BOTH||this._shake.axis==this.AXIS.HORIZONTAL)a=Math.random()*this._shake.intensity,this.pos.x=this.pos.x+ -this.width+athis.width)this.width=this.parallaxLayers[j].width; -if(this.parallaxLayers[j].height>this.height)this.height=this.parallaxLayers[j].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,e;e=this.parallaxLayers[c++];)e.baseOffset=(e.baseOffset+e.scrollspeed*me.timer.tick)%e.width,e.draw(a,~~e.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.width)this.width=this.parallaxLayers[h].width; +if(this.parallaxLayers[h].height>this.height)this.height=this.parallaxLayers[h].height},clearTile:function(){},update:function(){return this.updated},getRect:function(){return new me.Rect(this.vp.clone(),this.width,this.height)},draw:function(a){var b=this.vp.x;if(b>this.lastx)for(var c=0,h;h=this.parallaxLayers[c++];)h.baseOffset=(h.baseOffset+h.scrollspeed*me.timer.tick)%h.width,h.draw(a,~~h.baseOffset,0),this.lastx=b,this.updated=!0;else if(bthis.flickerTimer)this.flickering=!1,this.flickercb=null;else if(!this.flickering)this.flickercb=b,this.flickering=!0},flipX:function(a){if(a!=this.lastflipX)this.lastflipX=a,this.scale.x=-this.scale.x,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipX(this.width)},flipY:function(a){if(a!=this.lastflipY)this.lastflipY=a,this.scale.y=-this.scale.y,this.scaleFlag=1!=this.scale.x||1!=this.scale.y,this.collisionBox.flipY(this.height)},resize:function(a){if(0this.scale.x?-a:a,this.scale.y=0>this.scale.y?-a:a,this.scaleFlag=1!=this.scale.x||1!=this.scale.y},update:function(){return this.flickering?(this.flickerTimer-=me.timer.tick,0>this.flickerTimer&&(this.flickercb&&this.flickercb(),this.flicker(-1)),!0):!1},draw:function(a){if(this.flickering&&(this.flickerState=!this.flickerState,!this.flickerState))return;var b=~~(this.pos.x-this.vp.pos.x),c=~~(this.pos.y-this.vp.pos.y);this.scaleFlag&&(a.translate(b+this.hWidth,c+this.hHeight),a.scale(this.scale.x, -this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,e,h){this.anim= -[];this.current=this.resetAnim=null;this.parent(a,b,c,e,h);if(1==this.spritecount.x*this.spritecount.y)this.setCurrentSprite=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,e=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setCurrentSprite(++this.current.idx%this.current.length),this.fpscount=0,!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,g){this.parent(a,b,"string"==typeof g.image?me.loader.getImage(g.image):g.image,g.spritewidth,g.spriteheight);g.transparent_color&&this.setTransparency(g.transparent_color);this.GUID=me.utils.createGUID();this.name= -g.name?g.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=g.collidable||!1;this.type=g.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1; -this.onTileBreak=null},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a, -b){this.maxVel.x=a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()}, -distanceTo:function(a){var b=this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0 -a.y&&!a.yprop.isPlatform&&!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a, -b,c){this.parent(a,b,c);this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,e){this.collisionBox.adjustSize(a,b,c,e)},checkCollision:function(a){var b= -this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height), -this.collisionBox.draw(a)}});me.LevelEntity=me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, +this.scale.y),a.translate(-this.hWidth,-this.hHeight),b=c=0);a.drawImage(this.image,this.offset.x,this.offset.y,this.width,this.height,b,c,this.width,this.height);this.scaleFlag&&a.setTransform(1,0,0,1,0,0);me.debug.renderHitBox&&(this.parent(a,"blue"),this.collisionBox.draw(a,"red"))},destroy:function(){if(this.autodestroy)this.onDestroyEvent();return this.autodestroy},onDestroyEvent:function(){}});me.AnimationSheet=me.SpriteObject.extend({fpscount:0,animationspeed:0,init:function(a,b,c,h,g){this.anim= +[];this.current=this.resetAnim=null;this.parent(a,b,c,h,g);if(1==this.spritecount.x*this.spritecount.y)this.setAnimationFrame=function(){};this.animationspeed=me.sys.fps/10;this.addAnimation("default",null);this.setCurrentAnimation("default")},addAnimation:function(a,b){this.anim[a]={name:a,frame:[],idx:0,length:0};if(null==b)for(var b=[],c=0,h=this.spritecount.x*this.spritecount.y;cthis.animationspeed?(this.setAnimationFrame(++this.current.idx), +this.fpscount=0,0==this.current.idx&&this.resetAnim&&("string"==typeof this.resetAnim?this.setCurrentAnimation(this.resetAnim):"function"==typeof this.resetAnim&&this.resetAnim()),!0):!1}});me.ObjectEntity=me.AnimationSheet.extend({GUID:null,type:0,collidable:!1,init:function(a,b,f){this.parent(a,b,"string"==typeof f.image?me.loader.getImage(f.image):f.image,f.spritewidth,f.spriteheight);f.transparent_color&&this.setTransparency(f.transparent_color);this.GUID=me.utils.createGUID();this.name=f.name? +f.name.toLowerCase():"";this.pos.set(a,me.game.currentLevel?b+me.game.currentLevel.tileheight-this.height:b);this.vel=new me.Vector2d;this.accel=new me.Vector2d;this.friction=new me.Vector2d;this.maxVel=new me.Vector2d(1E3,1E3);this.gravity=me.sys.gravity!=c?me.sys.gravity:0.98;this.alive=this.isEntity=!0;this.falling=!1;this.jumping=!0;this.slopeY=0;this.onladder=this.onslope=!1;this.collidable=f.collidable||!1;this.type=f.type||0;this.collisionMap=me.game.collisionMap;this.canBreakTile=!1;this.onTileBreak= +null},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox);return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},setVelocity:function(a,b){this.accel.x=0!=a?a:this.accel.x;this.accel.y=0!=b?b:this.accel.y;this.setMaxVelocity(a,b)},setMaxVelocity:function(a,b){this.maxVel.x= +a;this.maxVel.y=b},setFriction:function(a,b){this.friction.x=a||0;this.friction.y=b||0},doWalk:function(a){this.flipX(a);this.vel.x+=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick},doClimb:function(a){return this.onladder?(this.vel.y=a?-this.accel.x*me.timer.tick:this.accel.x*me.timer.tick,!0):!1},doJump:function(){return!this.jumping&&!this.falling?(this.vel.y=-this.maxVel.y*me.timer.tick,this.jumping=!0):!1},forceJump:function(){this.jumping=this.falling=!1;this.doJump()},distanceTo:function(a){var b= +this.pos.x+this.hWidth-(a.pos.x+a.hWidth),a=this.pos.y+this.hHeight-(a.pos.y+a.hHeight);return Math.sqrt(b*b+a*a)},checkSlope:function(a,b){this.pos.y=a.pos.y-this.height;this.slopeY=b?a.height-(this.collisionBox.right+this.vel.x-a.pos.x):this.collisionBox.left+this.vel.x-a.pos.x;this.vel.y=0;this.pos.y+=this.slopeY.clamp(0,a.height)},computeVelocity:function(a){if(this.gravity)a.y+=!this.onladder?this.gravity*me.timer.tick:0,this.jumping=(this.falling=0a.y&&!a.yprop.isPlatform&& +!a.yprop.isLadder)this.falling=!0,this.vel.y=0;if(a.x)if(this.onladder=a.xprop.isLadder,a.xprop.isSlope&&!this.jumping)this.checkSlope(a.xtile,a.xprop.isLeftSlope),this.falling=!1;else if(!a.xprop.isPlatform&&!a.xprop.isLadder)if(a.xprop.isBreakable&&this.canBreakTile){if(me.game.currentLevel.clearTile(a.xtile.row,a.xtile.col),this.onTileBreak)this.onTileBreak()}else this.vel.x=0;this.pos.add(this.vel);return a}});me.CollectableEntity=me.ObjectEntity.extend({init:function(a,b,c){this.parent(a,b,c); +this.collidable=!0;this.type=me.game.COLLECTABLE_OBJECT}});me.InvisibleEntity=me.Rect.extend({GUID:null,z:0,collisionBox:null,init:function(a,b,c){this.parent(new me.Vector2d(a,b),c.width,c.height);this.collisionBox=new me.Rect(this.pos,c.width,c.height);this.GUID=me.utils.createGUID();this.name=c.name?c.name.toLowerCase():"";this.isEntity=this.collidable=this.visible=!0},updateColRect:function(a,b,c,h){this.collisionBox.adjustSize(a,b,c,h)},checkCollision:function(a){var b=this.collisionBox.collideVsAABB(a.collisionBox); +return 0!=b.x||0!=b.y?(this.onCollision(b,a),b.type=this.type,b.obj=this,b):null},onCollision:function(){this.collidable&&this.type==me.game.COLLECTABLE_OBJECT&&me.game.remove(this)},destroy:function(){this.onDestroyEvent();return!0},onDestroyEvent:function(){},update:function(){return!1},draw:function(a){if(me.debug.renderHitBox)a.strokeStyle="blue",a.strokeRect(this.pos.x-me.game.viewport.pos.x,this.pos.y-me.game.viewport.pos.y,this.width,this.height),this.collisionBox.draw(a)}});me.LevelEntity= +me.InvisibleEntity.extend({init:function(a,b,c){this.parent(a,b,c);this.nextlevel=c.to;this.fade=c.fade;this.duration=c.duration;this.fading=!1;this.gotolevel=c.to},onFadeComplete:function(){me.levelDirector.loadLevel(this.gotolevel);me.game.viewport.fadeOut(this.fade,this.duration)},goTo:function(a){this.gotolevel=a||this.nextlevel;if(this.fade&&this.duration){if(!this.fading)this.fading=!0,me.game.viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))}else me.levelDirector.loadLevel(this.gotolevel)}, onCollision:function(){this.goTo()}})})(window); -(function(){me.Font=Object.extend({ALIGN:{LEFT:"left",CENTER:"center",RIGHT:"right"},font:null,height:null,color:null,align:null,init:function(a,c,b,e){this.set(a,c,b,e)},bold:function(){this.font="bold "+this.font},italic:function(){this.font="italic "+this.font},set:function(a,c,b,e){this.font=""+c+"px "+a;this.height=c;this.color=b;this.align=e||"top"},getRect:function(){return new me.Rect(new Vector2d(0,0),0,0)},measureText:function(a,c){a.font=this.font;a.fillStyle=this.color;a.textBaseLine= -this.align;var b=a.measureText(c);b.height=this.height;return b},draw:function(a,c,b,e){a.font=this.font;a.fillStyle=this.color;a.textBaseLine=this.align;a.fillText(c,~~b,~~e)}});me.BitmapFont=me.Font.extend({size:null,sSize:null,firstChar:32,charCount:0,init:function(a,c,b,e){this.parent(a,null,null);this.size=new me.Vector2d;this.sSize=new me.Vector2d;this.firstChar=e||32;this.loadFontMetrics(a,c);this.align=this.ALIGN.RIGHT;b&&this.resize(b)},loadFontMetrics:function(a,c){this.font=me.loader.getImage(a); -this.size.x=c.x||c;this.size.y=c.y||this.font.height;this.sSize.copy(this.size);this.charCount=~~(this.font.width/this.size.x)},set:function(a,c){this.align=a;c&&this.resize(c)},resize:function(a){this.sSize.copy(this.size);this.sSize.x*=a;this.sSize.y*=a},measureText:function(a){return{width:a.length*this.sSize.x,height:this.sSize.y}},draw:function(a,c,b,e){c=new String(c);switch(this.align){case this.ALIGN.RIGHT:b-=this.measureText(c).width;break;case this.ALIGN.CENTER:b-=0.5*this.measureText(c).width}for(var d= -0,f=c.length;dk&&me.sys.interpolation?j/h:1};return a}();me.video=function(){var a={},c=null,b=null,e=null,d=null,f=null,g=!1,j=0,h=0;a.init=function(k,l,i,m,n){g=m||!1;me.sys.scale=!0===g?n||1:1;j=l*me.sys.scale;h=i*me.sys.scale;f=document.getElementById(k);c=document.createElement("canvas");c.setAttribute("width",j+"px");c.setAttribute("height",h+"px");c.setAttribute("border","0px solid black");f.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c),b=c.getContext("webgl-2d"), -me.sys.cacheImage=!0}catch(o){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}g?(d=a.createCanvasSurface(l,i),e=d.canvas):(d=b,e=b.canvas);return!0};a.getWrapper=function(){return f};a.getWidth=function(){return e.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return e.height};a.createCanvasSurface=function(a,b){var c=document.createElement("canvas"); -c.width=a||e.width;c.height=b||e.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(g)me.sys.scale=a?a:document.getElementById("screen size").value,j=e.width*me.sys.scale,h=e.height*me.sys.scale,c.width=j,c.height=h};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width*b-a.canvas.width>>1),-(a.canvas.height*b- -a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=g?function(){b.drawImage(e,0,0,e.width,e.height,0,0,j,h)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var f=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),g=b.data;switch(c){case "b&w":for(var c=0,e=g.length;c>>3,g[c]=d,g[c+1]=d,g[c+2]=d;break;case "brightness":d=Math.abs(d).clamp(0, -1);c=0;for(e=g.length;c>4,f=(f&15)<<4|j>>2,g=(j&3)<<6|h,c.push(String.fromCharCode(d)),64!=j&&c.push(String.fromCharCode(f)),64!=h&&c.push(String.fromCharCode(g));return c=c.join("")}}}();me.utils=function(){var a={},e={},d="",f=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),f=[],e,i,m;for(e=0,m=d.length/b;ea+b?a+b*me.timer.tick:0k&&me.sys.interpolation?h/j:1};return a}();me.video=function(){var a={},c=null,b=null,g=null,d=null,e=null,f=!1,h=0,j=0;a.init=function(k,m,l,i,n){f=i||!1;me.sys.scale=!0===f?n||1:1;h=m*me.sys.scale;j=l*me.sys.scale;c=document.createElement("canvas");c.setAttribute("width",h+"px");c.setAttribute("height",j+"px");c.setAttribute("border","0px solid black");e=k?document.getElementById(k):document.body;e.appendChild(c);if(me.sys.enableWebGL&&window.WebGLRenderingContext)try{WebGL2D.enable(c), +b=c.getContext("webgl-2d"),me.sys.cacheImage=!0}catch(q){b=null}if(null==b){me.sys.enableWebGL=!1;if(!c.getContext)return!1;b=c.getContext("2d")}f?(d=a.createCanvasSurface(m,l),g=d.canvas):(d=b,g=b.canvas);return!0};a.getWrapper=function(){return e};a.getWidth=function(){return g.width};a.getPos=function(a){for(var a=a||c,b=new me.Vector2d(a.offsetLeft,a.offsetTop);a=a.offsetParent;)b.x+=a.offsetLeft,b.y+=a.offsetTop;return b};a.getHeight=function(){return g.height};a.createCanvasSurface=function(a, +b){var c=document.createElement("canvas");c.width=a||g.width;c.height=b||g.height;return c.getContext("2d")};a.getScreenCanvas=function(){return c};a.getScreenFrameBuffer=function(){return d};a.updateDisplaySize=function(a){if(f)me.sys.scale=a?a:document.getElementById("screen size").value,h=g.width*me.sys.scale,j=g.height*me.sys.scale,c.width=h,c.height=j};a.clearSurface=function(a,b){a.fillStyle=b;a.fillRect(0,0,a.canvas.width,a.canvas.height)};a.scale=function(a,b){a.translate(-(a.canvas.width* +b-a.canvas.width>>1),-(a.canvas.height*b-a.canvas.height>>1));a.scale(b,b)};a.setAlpha=function(a,b){a.globalCompositeOperation=b?"source-over":"copy"};a.blitSurface=function(){a.blitSurface=f?function(){b.drawImage(g,0,0,g.width,g.height,0,0,h,j)}:function(){};a.blitSurface()};a.applyRGBFilter=function(b,c,d){var e=a.createCanvasSurface(b.width,b.height),b=me.utils.getPixels(b),f=b.data;switch(c){case "b&w":for(var c=0,h=f.length;c>>3,f[c]=d,f[c+1]=d,f[c+2]=d;break; +case "brightness":d=Math.abs(d).clamp(0,1);c=0;for(h=f.length;c>4,e=(e&15)<<4|h>>2,f=(h&3)<<6|j,c.push(String.fromCharCode(d)),64!=h&&c.push(String.fromCharCode(e)),64!=j&&c.push(String.fromCharCode(f));return c=c.join("")}}}();me.utils=function(){var a={},g={},d="",e=0;a.decodeBase64=function(a){return c.decode(a)};a.decodeBase64AsArray=function(a,b){var b=b||1,d=c.decode(a),e=[],g,l,i;for(g=0,i=d.length/b;ga+b?a+b*me.timer.tick:0b.x?a.left+b.x:a.right+b.x,e=0>b.y?a.top+b.y:a.bottom+b.y,h={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)h.x=b.x;if(0>=e||e>=this.realheight)h.y=b.y;return h}});me.TiledLayer=Object.extend({init:function(a,b,c,e,h,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=e;this.realwidth=this.width* -this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=h)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),j=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),h={x:0,xtile:c,xprop:{},y:0,ytile:c, -yprop:{}};if(0>=e||e>=this.realwidth)h.x=b.x;else if(0!=b.x)if(h.xtile=this.getTile(e,Math.ceil(a.bottom-1)),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);else if(h.xtile=this.getTile(e,~~a.top),h.xtile&&this.tileset.isTileCollidable(h.xtile.tileId))h.x=b.x,h.xprop=this.tileset.getTileProperties(h.xtile.tileId);if(0!=b.y)if(h.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y= -b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);else if(h.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,j),h.ytile&&this.tileset.isTileCollidable(h.ytile.tileId))h.y=b.y||1,h.yprop=this.tileset.getTileProperties(h.ytile.tileId);return h},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; +(this.tileYOffset[a]=this.margin+(this.spacing+this.tileheight)*~~(a/this.hTileCount));return this.tileYOffset[a]},drawTile:function(a,b,c,h,g,k,m){if(g||k||m){var l=1,i=0,n=0,q=1,s=b,r=c,b=c=0;m&&(l=0,n=i=1,q=0,r+=this.tileheight-this.tilewidth);g&&(l=-l,n=-n,s+=m?this.tileheight:this.tilewidth);k&&(i=-i,q=-q,r+=m?this.tilewidth:this.tileheight);a.setTransform(l,i,n,q,s,r)}a.drawImage(this.image,this.getTileOffsetX(h),this.getTileOffsetY(h),this.tilewidth,this.tileheight,b,c,this.tilewidth,this.tileheight); +(g||k||m)&&a.setTransform(1,0,0,1,0,0)}});CollisionTiledLayer=Object.extend({init:function(a,b){this.realwidth=a;this.realheight=b;this.isCollisionMap=!0},checkCollision:function(a,b){var c=0>b.x?a.left+b.x:a.right+b.x,h=0>b.y?a.top+b.y:a.bottom+b.y,g={x:0,y:0,xprop:{},yprop:{}};if(0>=c||c>=this.realwidth)g.x=b.x;if(0>=h||h>=this.realheight)g.y=b.y;return g}});me.TiledLayer=Object.extend({init:function(a,b,c,h,g,k){this.width=a;this.height=b;this.tilewidth=c;this.tileheight=h;this.realwidth=this.width* +this.tilewidth;this.realheight=this.height*this.tileheight;this.z=k;this.name=null;this.visible=!1;this.layerData=null;this.xLUT={};this.yLUT={};this.tileset=(this.tilesets=g)?this.tilesets.getTilesetByIndex(0):null},initArray:function(a){this.layerData=[];for(var b=0;bb.x?~~(a.left+b.x):Math.ceil(a.right-1+b.x),h=0>b.y?~~(a.top+b.y):Math.ceil(a.bottom-1+b.y),g={x:0,xtile:c,xprop:{},y:0,ytile:c, +yprop:{}};if(0>=f||f>=this.realwidth)g.x=b.x;else if(0!=b.x)if(g.xtile=this.getTile(f,Math.ceil(a.bottom-1)),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);else if(g.xtile=this.getTile(f,~~a.top),g.xtile&&this.tileset.isTileCollidable(g.xtile.tileId))g.x=b.x,g.xprop=this.tileset.getTileProperties(g.xtile.tileId);if(0!=b.y)if(g.ytile=this.getTile(0>b.x?~~a.left:Math.ceil(a.right-1),h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y= +b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);else if(g.ytile=this.getTile(0>b.x?Math.ceil(a.right-1):~~a.left,h),g.ytile&&this.tileset.isTileCollidable(g.ytile.tileId))g.y=b.y||1,g.yprop=this.tileset.getTileProperties(g.ytile.tileId);return g},update:function(){return!1}});me.TileMap=Object.extend({init:function(a,b){this.pos=new me.Vector2d(a,b);this.z=0;this.name=null;this.height=this.width=0;this.realheight=this.realwidth=-1;this.tileheight=this.tilewidth=0;this.tilesets=null; this.mapLayers=[];this.objectGroups=[];this.initialized=!1},reset:function(){this.tilesets=null;this.mapLayers.length=0;this.objectGroups.length=0;this.initialized=!1},getObjectGroupByName:function(a){return this.objectGroups[a]},getObjectGroups:function(){return this.objectGroups},getLayerByName:function(a){for(var b=null,a=a.trim().toLowerCase(),c=this.mapLayers.length;c--;)if(this.mapLayers[c].name.toLowerCase().contains(a)){b=this.mapLayers[c];break}a.toLowerCase().contains(me.LevelConstants.COLLISION_MAP)&& -null==b&&(b=new CollisionTiledLayer(me.game.currentLevel.realwidth,me.game.currentLevel.realheight));return b},clearTile:function(a,b){for(var c=this.mapLayers.length;c--;)(this.mapLayers[c].visible||this.mapLayers[c].isCollisionMap)&&this.mapLayers[c].clearTile(a,b)},addTo:function(a){this.visible&&a.add(this);for(var b=this.mapLayers.length;b--;)this.mapLayers[b].visible&&a.add(this.mapLayers[b])},update:function(){return!1}});me.levelDirector=function(){var a={},b={},e=[],j=0;a.reset=function(){}; -a.addLevel=function(){throw"melonJS: no level loader defined";};a.addTMXLevel=function(a,c){if(null==b[a])b[a]=new me.TMXTileMap(a,0,0),b[a].name=a,e[e.length]=a;c&&c()};a.loadLevel=function(a){a=a.toString().toLowerCase();if(b[a]===c)throw"melonJS: level "+a+" not found";if(b[a]instanceof me.TMXTileMap){var d=me.state.isRunning();d&&me.state.pause();me.game.reset();me.utils.resetGUID(a);b[a].reset();b[a].load();j=e.indexOf(a);me.game.loadTMXLevel(b[a]);d&&me.state.resume()}else throw"melonJS: no level loader defined"; -return!0};a.getCurrentLevelId=function(){return e[j]};a.reloadLevel=function(){return a.loadLevel(a.getCurrentLevelId())};a.nextLevel=function(){return j+1=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= +(function(){me.TMXTilesetGroup=Object.extend({init:function(){this.tilesets=[]},add:function(a){this.tilesets.push(a)},getTilesetByIndex:function(a){return this.tilesets[a]},getTilesetByGid:function(a){for(var c=-1,b=0,g=this.tilesets.length;b=this.tilesets[b].firstgid&&(c=b)}if(-1!=c)return this.tilesets[c];throw"no matching tileset found for gid "+a;}});me.TMXTileset=me.Tileset.extend({init:function(a){this.firstgid= me.XMLParser.getIntAttribute(a,me.TMX_TAG_FIRSTGID);this.parent(me.XMLParser.getStringAttribute(a,me.TMX_TAG_NAME),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEWIDTH),me.XMLParser.getIntAttribute(a,me.TMX_TAG_TILEHEIGHT),me.XMLParser.getIntAttribute(a,me.TMX_TAG_SPACING,0),me.XMLParser.getIntAttribute(a,me.TMX_TAG_MARGIN,0),a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_SOURCE));this.lastgid=this.firstgid+(this.hTileCount*this.vTileCount-1||0);this.trans=a.getElementsByTagName(me.TMX_TAG_IMAGE)[0].getAttribute(me.TMX_TAG_TRANS); if(null!==this.trans&&this.image)this.image=me.video.applyRGBFilter(this.image,"transparent",this.trans.toUpperCase()).canvas;this.tileoffset=new me.Vector2d(0,0);var c=a.getElementsByTagName(me.TMX_TAG_TILEOFFSET);if(0=this.firstgid&&a<=this.lastgid}})})(window); -(function(){TMXRenderer=Object.extend({init:function(a,c,b,e,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=e;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,e-d.firstgid,f,g,j)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,e,d,f,g,j){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> -1,-d.tilewidth+(c+b)*d.tileheight>>2,e-d.firstgid,f,g,j)}})})(window); -(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=this.tileMapCanvas=null},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),e=0;ethis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap),this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",e=0,d=a.childNodes.length;e(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn=function(a){return a* -a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return-(--a*a*a*a-1)};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return(a-=1)*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return-Math.cos(a*Math.PI/2)+1};me.Tween.Easing.Sinusoidal.EaseOut= -function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};me.Tween.Easing.Exponential.EaseIn=function(a){return 0==a?0:Math.pow(2,10*(a-1))};me.Tween.Easing.Exponential.EaseOut=function(a){return 1==a?1:-Math.pow(2,-10*a)+1};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0==a?0:1==a?1:1>(a*=2)?0.5*Math.pow(2,10*(a-1)):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return-(Math.sqrt(1-a*a)-1)}; -me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a/=0.5)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1; -e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1,e=0.4;if(0==a)return 0;if(1==a)return 1;e||(e=0.3);!b||1>b?(b=1,c=e/4):c=e/(2*Math.PI)*Math.asin(1/b);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/e):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/e)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut= -function(a){return(a-=1)*a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5> -a?0.5*Tween.Easing.Bounce.EaseIn(2*a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window); +(function(){TMXRenderer=Object.extend({init:function(a,c,b,g,d){this.predraw=a;this.width=c;this.height=b;this.tilewidth=g;this.tileheight=d},drawTile:function(){}});me.TMXOrthogonalRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,d.tileoffset.x+c*this.tilewidth,d.tileoffset.y+(b+1)*this.tileheight-d.tileheight,g-d.firstgid,e,f,h)}});me.TMXIsometricRenderer=TMXRenderer.extend({drawTile:function(a,c,b,g,d,e,f,h){d.drawTile(a,(this.width-1)*d.tilewidth+(c-b)*d.tilewidth>> +1,-d.tilewidth+(c+b)*d.tileheight>>2,g-d.firstgid,e,f,h)}})})(window); +(function(){me.TMXTileMap=me.TileMap.extend({init:function(a,c,b){this.parent(c,b);this.xmlMap=me.loader.getXML(a);if(!this.xmlMap)throw"melonJS:"+a+" TMX map not found";this.orientation=this.version="";this.tilesets=null},reset:function(){this.background_image=null;for(var a=this.mapLayers.length;a--;)this.mapLayers[a].layerSurface=null,this.mapLayers[a].layerCanvas=null,this.mapLayers[a].layerData=null,this.mapLayers[a].xLUT=this.yLUT=null,this.mapLayers[a].tilesets=this.tileset=null,this.mapLayers[a].objectGroups= +null,this.mapLayers[a]=null;this.initialized=!1;this.parent()},load:function(){if(!this.initialized){var a=0,c=1;me.XMLParser.parseFromString(this.xmlMap);for(var b=me.XMLParser.getAllTagElements(),g=0;gthis.opacity)this.layerSurface.globalAlpha=this.opacity}if(this.visible||this.isCollisionMap)this.initArray(this.isCollisionMap), +this.fillArray(a,c,b)},fillArray:function(a,c,b){switch(b){case null:switch(c){case null:a=a.getElementsByTagName(me.TMX_TAG_TILE);break;case me.TMX_TAG_CSV:case me.TMX_TAG_ATTR_BASE64:for(var b="",g=0,d=a.childNodes.length;g(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)};me.Tween.Easing.Cubic.EaseIn=function(a){return a*a*a};me.Tween.Easing.Cubic.EaseOut=function(a){return--a*a*a+1};me.Tween.Easing.Cubic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)};me.Tween.Easing.Quartic.EaseIn= +function(a){return a*a*a*a};me.Tween.Easing.Quartic.EaseOut=function(a){return 1- --a*a*a*a};me.Tween.Easing.Quartic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)};me.Tween.Easing.Quintic.EaseIn=function(a){return a*a*a*a*a};me.Tween.Easing.Quintic.EaseOut=function(a){return--a*a*a*a*a+1};me.Tween.Easing.Quintic.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)};me.Tween.Easing.Sinusoidal.EaseIn=function(a){return 1-Math.cos(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseOut= +function(a){return Math.sin(a*Math.PI/2)};me.Tween.Easing.Sinusoidal.EaseInOut=function(a){return 0.5*(1-Math.cos(Math.PI*a))};me.Tween.Easing.Exponential.EaseIn=function(a){return 0===a?0:Math.pow(1024,a-1)};me.Tween.Easing.Exponential.EaseOut=function(a){return 1===a?1:1-Math.pow(2,-10*a)};me.Tween.Easing.Exponential.EaseInOut=function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)};me.Tween.Easing.Circular.EaseIn=function(a){return 1-Math.sqrt(1-a*a)}; +me.Tween.Easing.Circular.EaseOut=function(a){return Math.sqrt(1- --a*a)};me.Tween.Easing.Circular.EaseInOut=function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};me.Tween.Easing.Elastic.EaseIn=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))};me.Tween.Easing.Elastic.EaseOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b? +(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Elastic.EaseInOut=function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1};me.Tween.Easing.Back.EaseIn=function(a){return a*a*(2.70158*a-1.70158)};me.Tween.Easing.Back.EaseOut=function(a){return--a* +a*(2.70158*a+1.70158)+1};me.Tween.Easing.Back.EaseInOut=function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)};me.Tween.Easing.Bounce.EaseIn=function(a){return 1-Tween.Easing.Bounce.EaseOut(1-a)};me.Tween.Easing.Bounce.EaseOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};me.Tween.Easing.Bounce.EaseInOut=function(a){return 0.5>a?0.5*Tween.Easing.Bounce.EaseIn(2* +a):0.5*Tween.Easing.Bounce.EaseOut(2*a-1)+0.5}})(window);