35 lines
146 KiB
JavaScript
35 lines
146 KiB
JavaScript
|
/*
|
||
|
RequireJS text 0.26.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
|
||
|
Available via the MIT or new BSD license.
|
||
|
see: http://github.com/jrburke/requirejs for details
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
Copyright (c) 2010-2011 Ivo Wetzel.
|
||
|
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
of this software and associated documentation files (the "Software"), to deal
|
||
|
in the Software without restriction, including without limitation the rights
|
||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
|
copies of the Software, and to permit persons to whom the Software is
|
||
|
furnished to do so, subject to the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be included in
|
||
|
all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
|
THE SOFTWARE.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* A* (A-Star) algorithm for a path finder
|
||
|
* @author Andrea Giammarchi
|
||
|
* @license Mit Style License
|
||
|
*/
|
||
|
|
||
|
define("infomanager",[],function(){var e=Class.extend({init:function(e){this.game=e,this.infos={},this.destroyQueue=[]},addDamageInfo:function(e,t,r,i){var s=this.game.currentTime,o=s+""+Math.abs(e)+""+t+""+r,u=this,a=new n(o,e,t,r,n.DURATION,i);a.onDestroy(function(e){u.destroyQueue.push(e)}),this.infos[o]=a},forEachInfo:function(e){var t=this;_.each(this.infos,function(t,n){e(t)})},update:function(e){var t=this;this.forEachInfo(function(t){t.update(e)}),_.each(this.destroyQueue,function(e){delete t.infos[e]}),this.destroyQueue=[]}}),t={received:{fill:"rgb(255, 50, 50)",stroke:"rgb(255, 180, 180)"},inflicted:{fill:"white",stroke:"#373737"},healed:{fill:"rgb(80, 255, 80)",stroke:"rgb(50, 120, 50)"}},n=Class.extend({DURATION:1e3,init:function(e,n,r,i,s,o){this.id=e,this.value=n,this.duration=s,this.x=r,this.y=i,this.opacity=1,this.lastTime=0,this.speed=100,this.fillColor=t[o].fill,this.strokeColor=t[o].stroke},isTimeToAnimate:function(e){return e-this.lastTime>this.speed},update:function(e){this.isTimeToAnimate(e)&&(this.lastTime=e,this.tick())},tick:function(){this.y-=1,this.opacity-=.07,this.opacity<0&&this.destroy()},onDestroy:function(e){this.destroy_callback=e},destroy:function(){this.destroy_callback&&this.destroy_callback(this.id)}});return e}),define("timer",[],function(){var e=Class.extend({init:function(e,t){this.lastTime=t||0,this.duration=e},isOver:function(e){var t=!1;return e-this.lastTime>this.duration&&(t=!0,this.lastTime=e),t}});return e}),define("bubble",["jquery","timer"],function(e,t){var n=Class.extend({init:function(e,n,r){this.id=e,this.element=n,this.timer=new t(5e3,r)},isOver:function(e){return this.timer.isOver(e)?!0:!1},destroy:function(){e(this.element).remove()},reset:function(e){this.timer.lastTime=e}}),r=Class.extend({init:function(e){this.container=e,this.bubbles={}},getBubbleById:function(e){return e in this.bubbles?this.bubbles[e]:null},create:function(t,r,i){if(this.bubbles[t])this.bubbles[t].reset(i),e("#"+t+" p").html(r);else{var s=e('<div id="'+t+'" class="bubble"><p>'+r+'</p><div class="thingy"></div></div>');e(s).appendTo(this.container),this.bubbles[t]=new n(t,s,i)}},update:function(e){var t=this,n=[];_.each(this.bubbles,function(t){t.isOver(e)&&(t.destroy(),n.push(t.id))}),_.each(n,function(e){delete t.bubbles[e]})},clean:function(){var e=this,t=[];_.each(this.bubbles,function(e){e.destroy(),t.push(e.id)}),_.each(t,function(t){delete e.bubbles[t]}),this.bubbles={}},destroyBubble:function(e){var t=this.getBubbleById(e);t&&(t.destroy(),delete this.bubbles[e])},forEachBubble:function(e){_.each(this.bubbles,function(t){e(t)})}});return r}),define("camera",[],function(){var e=Class.extend({init:function(e){this.renderer=e,this.x=0,this.y=0,this.gridX=0,this.gridY=0,this.offset=.5,this.rescale()},rescale:function(){var e=this.renderer.mobile?1:2;this.gridW=15*e,this.gridH=7*e,log.debug("---------"),log.debug("Factor:"+e),log.debug("W:"+this.gridW+" H:"+this.gridH)},setPosition:function(e,t){this.x=e,this.y=t,this.gridX=Math.floor(e/16),this.gridY=Math.floor(t/16)},setGridPosition:function(e,t){this.gridX=e,this.gridY=t,this.x=this.gridX*16,this.y=this.gridY*16},lookAt:function(e){var t=this.renderer,n=Math.round(e.x-Math.floor(this.gridW/2)*t.tilesize),r=Math.round(e.y-Math.floor(this.gridH/2)*t.tilesize);this.setPosition(n,r)},forEachVisiblePosition:function(e,t){var t=t||0;for(var n=this.gridY-t,r=this.gridY+this.gridH+t*2;n<r;n+=1)for(var i=this.gridX-t,s=this.gridX+this.gridW+t*2;i<s;i+=1)e(i,n)},isVisible:function(e){return this.isVisiblePosition(e.gridX,e.gridY)},isVisiblePosition:function(e,t){return t>=this.gridY&&t<this.gridY+this.gridH&&e>=this.gridX&&e<this.gridX+this.gridW?!0:!1},focusEntity:function(e){var t=this.gridW-2,n=this.gridH-2,r=Math.floor((e.gridX-1)/t)*t,i=Math.floor((e.gridY-1)/n)*n;this.setGridPosition(r,i)}});return e}),define("entity",[],function(){var e=Class.extend({init:function(e,t){var n=this;this.id=e,this.kind=t,this.sprite=null,this.flipSpriteX=!1,this.flipSpriteY=!1,this.animations=null,this.currentAnimation=null,this.shadowOffsetY=0,this.setGridPos
|