package Core.com;

import java.util.Vector;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class FondosDos {

	int width;
	int height;
	
	Bitmap[] fondosa;
	
	Bitmap spring;
	
	Vector<Spring> jumpers;
	
	
	int no_fondoa=0;
	
	double fay=0;
	
	float fax=0;
	float ifax=(float)1; //incremento x de fondo a -> original 1
	
	int[] fdrawA={R.drawable.fondodosa000,R.drawable.fondodosa000,R.drawable.fondodosa000,R.drawable.fondodosa000,R.drawable.fondodosa000};
	
	GView view;
	Mapas mapas;
	
	
	public FondosDos(GView View){
		
		view=View;
		width=view.width;
		
		fondosa=new Bitmap[2];
		fondosa[0]=Util.Cargar_bitmap(100,R.drawable.fondodosa000,view);
		fondosa[1]=Util.Cargar_bitmap(100,R.drawable.fondodosa000,view);
		
		jumpers=new Vector<Spring>();
	
		mapas=new Mapas();
		
		Bitmap b=Util.Cargar_bitmap(100, R.drawable.spring, view);
		spring=b;
		
		for(int i=0;i<mapas.sx.length;i++){
			
			Spring s=new Spring(b, mapas.sx[i],mapas.sy[i]);
			jumpers.add(s);
			
		}
		
		
	}
	
	
	public void Paint(Canvas c, Paint p){
		
		c.drawBitmap(fondosa[0], fax,  (float) fay, p);
		c.drawBitmap(fondosa[1],fax+width, (float) fay,p);
		
		for(int i=0;i<jumpers.size();i++){
			Spring j=jumpers.elementAt(i);	
			j.OnDraw(c, p);
		}
		
	}
	
	public void OnMove(double velx, double vely){
		
		fax-=velx;		
		if(fax<-width){		
			
			
			// 5 siguientes para reiniciar springs
			for(int i=0;i<mapas.sx.length;i++){
				jumpers.removeElementAt(0);		
				Spring s=new Spring(spring, mapas.sx[i],mapas.sy[i]);
				jumpers.add(s);	
			}
			
			// siguientes para empezar en el fondo 0
			fax=0;
			fondosa[0]=fondosa[1];	
			no_fondoa++;
			if(no_fondoa>3){				
				no_fondoa=-1;
			}
			fondosa[1]=Util.Cargar_bitmap(100, fdrawA[no_fondoa+1], view);
		}
		
		
		// para cambiar cuando haya fondos definitivos o casi
		fay+=vely;
		if(fay<-height){
			fay=0;			
			for(int i=0;i<jumpers.size();i++){
				Spring j=jumpers.elementAt(i);
				j.y=j.y_inicial;				
			}
		}
		
		
		for(int i=0;i<jumpers.size();i++){
			Spring j=jumpers.elementAt(i);
			j.x-=velx;		
			j.y+=vely;			
		}
		
		
	}


	
	
}
