package space;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.jln.ld.GameEntity;
import com.jln.ld.Shared;

import menus.GameMenu;

public class Star{

	private float x; 
	private float y;
	private float speed;
	private TextureRegion region;
	private boolean onBack;
	
	public Star(boolean onBack){
		this.onBack = onBack;
		this.initStar();
	}
	
	private void initStar(){
		this.y = (float)(Math.random()*Shared.GAME_HEIGHT);
		this.x = (float)(Math.random()*500)+Shared.GAME_WIDTH;
		if(onBack){
			this.region = Shared.STARS_BACK[(int)(Math.random()*8)][(int)(Math.random()*4)];
		}else{
			this.region = Shared.STARS_FRONT[(int)(Math.random()*2)][(int)(Math.random()*4)];
		}
		this.speed = (float)(Math.random()*1)+((onBack?0:1));
	}
	
	public void update() {
		this.x -= speed;
		if(x < -50){
			this.initStar();
		}
		
	}

	public void render() {
		if(x < Shared.GAME_WIDTH+16){
			Shared.GAME_BATCH.draw(region, (int)((x-8)+Shared.DECAL_X), (int)((y-8)+Shared.DECAL_Y));
		}
		
	}

}
