Skip to content

Commit

Permalink
Added DoubleCircleVertical (#6)
Browse files Browse the repository at this point in the history
- doubleCircleVertical.fxml
- DoubleCircleVerticalController.java
- DoubleCircleVertical.java
- Added class in Game.java

Signed-off-by: Harsh Kumar <harsh19043@iiitd.ac.in>
  • Loading branch information
hadron43 committed Dec 3, 2020
1 parent dfb656d commit 5b6f0a9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class Game implements Serializable {
private static final List<Class> 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;
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/obstacles/DoubleCircleVertical.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
27 changes: 27 additions & 0 deletions src/obstacles/controllers/DoubleCircleVerticalController.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 11 additions & 7 deletions src/obstacles/controllers/SuperController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,31 @@ public abstract class SuperController implements Initializable {
// To store all transition objects
private final List<Transition> 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<Node> parentChildren = ((Pane) star.getParent()).getChildren();
parentChildren.set(parentChildren.indexOf(star), temp);
star = temp;
addScaling(star);
List<Node> 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);
Expand Down
34 changes: 34 additions & 0 deletions src/obstacles/fxml/doubleCircleVertical.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.net.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>

<Pane xmlns:fx="http://javafx.com/fxml/1" maxHeight="500" maxWidth="250" minHeight="500" minWidth="250" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="obstacles.controllers.DoubleCircleVerticalController">

<stylesheets>
<URL value="@../../style/style.css" />
</stylesheets>
<Pane fx:id="circle2" layoutX="-50.0" layoutY="-51.0" rotate="45.0" scaleX="0.71" scaleY="0.71">
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="0.0" styleClass="fill-yellow" type="ROUND" />
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="90.0" styleClass="fill-blue" type="ROUND" />
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="180.0" styleClass="fill-pink" type="ROUND" />
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="270.0" styleClass="fill-purple" type="ROUND" />
<Circle fill="WHITE" layoutX="175.0" layoutY="175.0" radius="147.0" stroke="BLACK" strokeType="INSIDE" styleClass="fill-soft-black" />
</Pane>
<Pane layoutX="88.0" layoutY="87.0" prefHeight="75" prefWidth="75">
<Pane fx:id="star2" />
</Pane>

<Pane fx:id="circle1" layoutX="-50.0" layoutY="199.0" rotate="-135.0" scaleX="0.71" scaleY="0.71">
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="0.0" styleClass="fill-yellow" type="ROUND" />
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="90.0" styleClass="fill-blue" type="ROUND" />
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="180.0" styleClass="fill-pink" type="ROUND" />
<Arc focusTraversable="true" layoutX="175.0" layoutY="175.0" length="90.0" radiusX="175.0" radiusY="175.0" startAngle="270.0" styleClass="fill-purple" type="ROUND" />
<Circle fill="WHITE" layoutX="175.0" layoutY="175.0" radius="147.0" stroke="BLACK" strokeType="INSIDE" styleClass="fill-soft-black" />
</Pane>

<Pane layoutX="87.0" layoutY="340.0" prefHeight="75" prefWidth="75">
<Pane fx:id="star1" />
</Pane>
</Pane>

0 comments on commit 5b6f0a9

Please sign in to comment.