ig.module(
    'game.entities.endanimation'
)
    .requires(
    'impact.entity'
)
    .defines(function (){
        Entityendanimation = ig.Entity.extend({
            collides:ig.Entity.COLLIDES.PASSIVE,
            type:ig.Entity.TYPE.NONE,
            pixcaltype:"ignore",
            size:{x:225,y:226},
            animSheet:new ig.AnimationSheet('media/Math_end.png',225,226),
            bounciness:1,
            temp:0,
			lastTile:48,
            init:function (x, y, settings) {
                    this.parent(x, y, settings);
            //      this.addAnim('idle',.1,[0]);
                    this.addAnim('endanim',.2,[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
                    this.addAnim('after_glow',.1,[17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48])
                    this.maxVel.x = 500;
                    this.maxVel.y = 500;
             },
            update:function (){
                     if(this.currentAnim.tile==16)
                    {
                        this.setScale(1,1);
                           this.pos.x=Math.floor((ig.system.width- this.size.x)/2);
                            this.pos.y=Math.floor((ig.system.height-this.size.y)/2);
                        this.currentAnim=this.anims.after_glow;
                        ig.game.killConsumedFoodEntity();
                        ig.game.cleanScreen();
                    }  
                   if(this.currentAnim.tile==this.lastTile){
                        this.kill();
                        var ll=new EntitytextBoxAnimation();
                        var nn= ig.game.spawnEntity(EntitytextBoxAnimation,(ig.system.width-ll.size.x)/2,(ig.system.height-ll.size.y)/2, {name:"textBox"});
                        nn.setScale(.1,.1);
                    }  
          if(this.currentAnim.tile<16){
               this.scaleCount++;
                     if(!this.isScaleTrigger)
                       {
                          this.scaleCountFadeIn=this.scaleCountFadeIn+1;
                           this.setScale(this.scaleCountFadeIn/50,this.scaleCountFadeIn/50);
                            this.pos.x=Math.floor((ig.system.width- this.size.x)/2);
                            this.pos.y=Math.floor((ig.system.height-this.size.y)/2);
                                if( this.scaleCount==100){
                                     this.isScaleTrigger=true;
                        }
                    }
                    else if(this.isScaleTrigger && this.isCompletedScale){
                          this.scaleCountFadeIn=this.scaleCountFadeIn-1;
                          if((this.scaleCountFadeIn/50)>=1){
                               this.setScale(this.scaleCountFadeIn/50,this.scaleCountFadeIn/50);
                          this.pos.x=Math.floor((ig.system.width- this.size.x)/2);
                          this.pos.y=Math.floor((ig.system.height-this.size.y)/2);
                      }
                 if(this.scaleCount==200){
                    this.isCompletedScale=false;
            }
              }
        }
          this.parent();
            },
            isCompletedScale:true,
            scaleCountFadeIn:0,
            scaleCount:0,
            isScaleTrigger:false
        });
    });