package mainPac;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Paint;
import javafx.scene.paint.Stop;
public class GameScene extends Scene {
private World world= new World();
public GameScene(Group root) {
super(root, 800, 600, true);
setFill(createFill());
setCamera(new PerspectiveCamera());
root.getChildren().addAll(world);
addListeners();
}
public static Paint createFill() {
LinearGradient gradient = new LinearGradient(0f, 0f, 0f, 1f, true, CycleMethod.NO_CYCLE, new Stop[]{
new Stop(0.0, Color.web("#64c2f8")),
new Stop(1, Color.web("#f8bd55")),});
return gradient;
}
private void addListeners() {
setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.UP) {
world.getPlane().getPhysicalObject().setPressingUp(true);
} else if (event.getCode() == KeyCode.DOWN) {
world.getPlane().getPhysicalObject().setPressingDown(true);
} else if (event.getCode() == KeyCode.RIGHT) {
world.getPlane().getPhysicalObject().setPressingRight(true);
} else if (event.getCode() == KeyCode.LEFT) {
world.getPlane().getPhysicalObject().setPressingLeft(true);
}
}
});
setOnKeyReleased(new EventHandler<KeyEvent>() {
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.UP) {
world.getPlane().getPhysicalObject().setPressingUp(false);
} else if (event.getCode() == KeyCode.DOWN) {
world.getPlane().getPhysicalObject().setPressingDown(false);
} else if (event.getCode() == KeyCode.RIGHT) {
world.getPlane().getPhysicalObject().setPressingRight(false);
} else if (event.getCode() == KeyCode.LEFT) {
world.getPlane().getPhysicalObject().setPressingLeft(false);
}
}
});
}
}