package mainPac;
import bomb.Bomb;
import javafx.scene.DepthTest;
import javafx.scene.Group;
import clouds.Clouds;
import highscores.HighScoresPane;
import hud.HUD;
import java.util.ArrayList;
import java.util.List;
import plane.Plane;
import plane.PlaneState;
import highscores.SubmitScorePane;
public class World extends Group implements SimulationEntity{
private HUD hud;
private SubmitScorePane submitScorePane;
private HighScoresPane highScoresPane;
private GameTransition gameTransition;
private List<Bomb> bombList= new ArrayList<Bomb>();
private Plane plane;
private Clouds clouds;
private long startTime= System.currentTimeMillis();
public World() {
setDepthTest(DepthTest.ENABLE);
gameTransition = new GameTransition(this);
gameTransition.play();
hud= new HUD(this);
submitScorePane= new SubmitScorePane();
submitScorePane.setTranslateY(300);
highScoresPane= new HighScoresPane();
highScoresPane.setTranslateY(300);
clouds = new Clouds(this);
plane = new Plane(this);
init();
}
public void init(){
startTime= System.currentTimeMillis();
plane.init();
bombList= new ArrayList<Bomb>();
submitScorePane.setVisible(false);
highScoresPane.setVisible(false);
getChildren().clear();
getChildren().addAll(hud, clouds, plane, submitScorePane, highScoresPane);
setPlacements();
}
@Override
public void stepSimulation() {
if(plane.getState()==PlaneState.READY){
return;
}
plane.stepSimulation();
if(plane.getState()==PlaneState.DEAD){
return;
}
long delta= System.currentTimeMillis()-startTime;
if(delta/10000>bombList.size()){
Bomb newBomb= new Bomb(this);
bombList.add(newBomb);
getChildren().add(newBomb);
}
clouds.stepSimulation();
for(Bomb bomb : bombList){
bomb.stepSimulation();
}
if(plane.getState()==PlaneState.FLYING){
hud.setTime(""+delta/1000);
}
hud.setLives(""+plane.getLives());
setPlacements();
}
private void setPlacements(){
setTranslateX(-plane.getTranslateX()+400);
hud.setTranslateX(plane.getTranslateX()-350);
}
public Plane getPlane() {
return plane;
}
public Clouds getClouds() {
return clouds;
}
public HUD getHud(){
return hud;
}
public SubmitScorePane getSubmitScorePane(){
return submitScorePane;
}
public HighScoresPane getHighScoresPane(){
return highScoresPane;
}
}