From 5b6f0a99b13f0556f887bcfade3fe28d7130c437 Mon Sep 17 00:00:00 2001 From: Harsh Kumar Date: Thu, 3 Dec 2020 23:05:00 +0530 Subject: [PATCH] Added DoubleCircleVertical (#6) - doubleCircleVertical.fxml - DoubleCircleVerticalController.java - DoubleCircleVertical.java - Added class in Game.java Signed-off-by: Harsh Kumar --- src/Game.java | 4 +-- src/obstacles/DoubleCircleVertical.java | 20 +++++++++++ .../DoubleCircleVerticalController.java | 27 +++++++++++++++ .../controllers/SuperController.java | 18 ++++++---- src/obstacles/fxml/doubleCircleVertical.fxml | 34 +++++++++++++++++++ 5 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 src/obstacles/DoubleCircleVertical.java create mode 100644 src/obstacles/controllers/DoubleCircleVerticalController.java create mode 100644 src/obstacles/fxml/doubleCircleVertical.fxml diff --git a/src/Game.java b/src/Game.java index 70897ac..a8f0432 100644 --- a/src/Game.java +++ b/src/Game.java @@ -18,7 +18,7 @@ public class Game implements Serializable { private static final List map = Arrays.asList( - Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class + Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class ); private final Ball ball; private final long id; @@ -73,10 +73,10 @@ private void newObstacle() { if(map.size() == 1) break; } + Obstacle ob = (Obstacle) (obsType.getDeclaredConstructor().newInstance()); double pos = height; if(gameObjects.size() != 0) pos = gameObjects.get(gameObjects.size()-1).getPosY().getValue(); - Obstacle ob = (Obstacle) (obsType.getDeclaredConstructor().newInstance()); pos -= margin + ob.getHeight(); ob.attachToPane(obstaclesBox, (width-ob.getWidth())/2, pos); rememberGameObject(ob); diff --git a/src/obstacles/DoubleCircleVertical.java b/src/obstacles/DoubleCircleVertical.java new file mode 100644 index 0000000..bca0686 --- /dev/null +++ b/src/obstacles/DoubleCircleVertical.java @@ -0,0 +1,20 @@ +package obstacles; + +import elements.Ball; +import obstacles.controllers.DoubleCircleVerticalController; + +public class DoubleCircleVertical extends Obstacle { + private DoubleCircleVerticalController doubleCircleVerticalController; + + public DoubleCircleVertical() { + // Load the FXML and set 'pane' in Parent + loadObstaclePane("/obstacles/fxml/doubleCircleVertical.fxml"); + + doubleCircleVerticalController = (DoubleCircleVerticalController) controller; + } + + @Override + public int hasCollided(Ball b) { + return 0; + } +} diff --git a/src/obstacles/controllers/DoubleCircleVerticalController.java b/src/obstacles/controllers/DoubleCircleVerticalController.java new file mode 100644 index 0000000..eefeefd --- /dev/null +++ b/src/obstacles/controllers/DoubleCircleVerticalController.java @@ -0,0 +1,27 @@ +package obstacles.controllers; + +import javafx.fxml.FXML; +import javafx.scene.layout.Pane; + +import java.net.URL; +import java.util.ResourceBundle; + +public class DoubleCircleVerticalController extends SuperController { + @FXML + public Pane circle1, circle2; + public Pane star1, star2; + + public DoubleCircleVerticalController() { + super(); + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + // Add transitions + boolean clockwise = (Math.random()*2 >= 1) ? true : false; + addRotation(circle1, defaultRotatingDuration, clockwise); + addRotation(circle2, defaultRotatingDuration, clockwise); + loadStar(star1); + loadStar(star2); + } +} diff --git a/src/obstacles/controllers/SuperController.java b/src/obstacles/controllers/SuperController.java index c4e26e6..885af9c 100644 --- a/src/obstacles/controllers/SuperController.java +++ b/src/obstacles/controllers/SuperController.java @@ -19,27 +19,31 @@ public abstract class SuperController implements Initializable { // To store all transition objects private final List transitions; @FXML - public Pane star; + private Pane star; protected SuperController() { this.transitions = new ArrayList<>(); } - protected void loadStar() { - if(star != null) { + protected void loadStar(Pane customPane) { + if(customPane != null) { Pane temp; try { temp = FXMLLoader.load(getClass().getResource("/elements/fxml/star.fxml")); - List parentChildren = ((Pane) star.getParent()).getChildren(); - parentChildren.set(parentChildren.indexOf(star), temp); - star = temp; - addScaling(star); + List parentChildren = ((Pane) customPane.getParent()).getChildren(); + parentChildren.set(parentChildren.indexOf(customPane), temp); + customPane = temp; + addScaling(customPane); } catch (IOException e) { e.printStackTrace(); } } } + protected void loadStar() { + loadStar(star); + } + public void addRotation(Node node, int timeInMillis, boolean clockwise) { RotateTransition rt = new RotateTransition(); rt.setAxis(Rotate.Z_AXIS); diff --git a/src/obstacles/fxml/doubleCircleVertical.fxml b/src/obstacles/fxml/doubleCircleVertical.fxml new file mode 100644 index 0000000..b0f6a64 --- /dev/null +++ b/src/obstacles/fxml/doubleCircleVertical.fxml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +