package com.menu;

import org.anddev.andengine.input.touch.TouchEvent;
import com.commons.objects.game_animated_object;
import com.perpixelperfectcollision.IPixelPerfectShape;
import com.perpixelperfectcollision.PixelPerfectBitMask;
import com.perpixelperfectcollision.PixelPerfectTiledTextureRegion;

public class menu_animated_part extends game_animated_object implements IPixelPerfectShape{

	//****************************************************************
	//** Pixel-Perfect Texture and Collisions stuff
	//****************************************************************
	
	public PixelPerfectTiledTextureRegion ppTextureRegion;
	private int oAction_when_ends_animation;
	public menu_animated_part(int tid,int tzindex,float pX, float pY,PixelPerfectTiledTextureRegion pTiledTextureRegion,float tScale,int tduration_ms,int tAction_when_ends_animation) 
	{
		// Estamos llamando al constructor de la classe Padre. NO LOS CONSTRUCTORES NO SE HEREDAN
		super(pX, pY, pTiledTextureRegion);
	
		this.oId=tid;
		
		this.setZIndex(tzindex);
		
		this.oBig_pos_X=pX;
		this.oBig_pos_Y=pY;
		
		this.oId=tid;
		this.oTiledTextureRegion=pTiledTextureRegion;
		
		// Temps en ms total duracio animacion
		this.duration_ms=tduration_ms;
		this.oRotation_angle=360;
		
		this.oScale=tScale;
	    
		this.oAction_when_ends_animation=tAction_when_ends_animation;
		
	    //**************** SCALE OBJECT *********************** 
        this.setScaleX(this.oScale);
        this.setScaleY(this.oScale); 
	    
	    //**************** ANIMATION STUFF ***********************
        this.ppTextureRegion = pTiledTextureRegion;
   	}

	// Evento que desencadema en el metodo constructor (movimiento del objeto sin tocar nada)
	// Iteracion en classe
	@Override
    protected void onManagedUpdate(final float pSecondsElapsed)
	{
			 
			    //Arrancamos la animacion
		        // Al fer la animacio es long per cada tile/imatge el seu temps , inici , fi ,true
				if (this.oThis_object_animate_now) 
				{
					if (!this.isVisible())
					{
						this.setVisible(true);
					}
					
					if (this.oDuration_time <= System.currentTimeMillis()) 
					{
						this.oThis_object_animate_now=false;
						this.setVisible(false);
						
						
						  // Evaluamos al finalizar 
			        	  switch (this.oAction_when_ends_animation) 
						  {
						  		case 0:
								
				                break;
				                
								case 1:
									System.exit(0);
				                break;
				                
				                default:
				                	
				                break;
						  }
					}
				}
		        
            super.onManagedUpdate(pSecondsElapsed);
    }
	
	
	
	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) 
	{
		
		return true;
	}
	public PixelPerfectBitMask getMask() {
		// TODO Auto-generated method stub
		return null;
	}

}
