1 line
1.2 KiB
JavaScript
1 line
1.2 KiB
JavaScript
define([],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}); |