package com.loading;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import com.perpixelperfectcollision.IPixelPerfectShape;
import com.perpixelperfectcollision.PixelPerfectBitMask;
import com.perpixelperfectcollision.PixelPerfectTiledTextureRegion;

public class loading_progressbar extends AnimatedSprite implements IPixelPerfectShape {

	//****************************************************************
	//** Propiedades estandar de objeto de juego
	//****************************************************************
	
	public int oid;
    public int orotation_angle=0; 
	
	//****************************************************************
	//** Propiedades de Imagen i textura
	//****************************************************************
	
	// Tamaņo de Sprite Map especifico para este objeto
	public int oTilesWith;
	public int oTilesHeight;
	public int oTilesRow;
	public int oTilesColumn;
	
	// Textura especial que contiene los Tiles para el AnimatedSprite
	public TiledTextureRegion oTiledTextureRegion;
	
	//****************************************************************
	//** Pixel-Perfect Collisions stuff
	//****************************************************************
	
	PixelPerfectTiledTextureRegion ppTextureRegion;

	//****************************************************************
    //** Animacio
    //****************************************************************
    
    private boolean is_animated;  
    
	//****************************************************************
	//** Misc
	//****************************************************************
	
	// Variables de tiempo
    private long startTime = System.currentTimeMillis();
	
	public loading_progressbar(float pX, float pY, PixelPerfectTiledTextureRegion pTiledTextureRegion,BaseGameActivity act_temp,int tid,Engine tEngine,int tTilesWith,int tTilesHeight,int tTilesRow,int tTilesColumn,boolean t_is_animated) 
	{
		// Estamos llamando al constructor de la classe Padre. NO LOS CONSTRUCTORES NO SE HEREDAN
		super(pX, pY, pTiledTextureRegion);
        ppTextureRegion = pTiledTextureRegion;
		
		this.oid=tid;
		this.oTilesWith=tTilesWith;
		this.oTilesHeight=tTilesHeight;
		this.oTilesRow=tTilesRow;
		this.oTilesColumn=tTilesColumn;

		
		this.oTiledTextureRegion=pTiledTextureRegion;

		this.is_animated=t_is_animated;
	}

	// Evento que desencadema en el metodo constructor (movimiento del objeto sin tocar nada)
	// Iteracion en classe
	@Override
    protected void onManagedUpdate(final float pSecondsElapsed) 
	{

            if(this.is_animated)
            {
	            //Arrancamos la animacion
	            // Al fer la animacio es long per cada tile/imatge el seu temps , inici , fi ,true
	            if (!this.isAnimationRunning()){this.animate(new long[]{100,100,100,100,100},1,5,true);}
	            //this.stopAnimation(5);  -- > Para la animacion en la tile 5
	            //game_commons.fv=this.getCurrentTileIndex();
            }
            
            
            // OK rotacion en funcion del tiempo
            if (System.currentTimeMillis() - startTime >= 30) {
            	 // Vamos a hacer la rotacion
                if (orotation_angle>=360) orotation_angle=0;
                orotation_angle=orotation_angle+20;
                this.setRotation(orotation_angle);
                startTime = System.currentTimeMillis();
            }
            
            super.onManagedUpdate(pSecondsElapsed);
    }

	public PixelPerfectBitMask getMask() {
		// TODO Auto-generated method stub
		return null;
	}
	
}

