Skip to content

Commit

Permalink
Added Circle Obstacle (Solid) (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Kumar <harsh19043@iiitd.ac.in>
  • Loading branch information
hadron43 committed Nov 21, 2020
1 parent 1b06f61 commit 18649b7
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 34 deletions.
16 changes: 15 additions & 1 deletion src/Controller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import javafx.animation.Interpolator;
import javafx.animation.RotateTransition;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Scene;
Expand All @@ -11,11 +12,13 @@
import javafx.stage.Stage;
import javafx.util.Duration;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

public class Controller implements Initializable {
@FXML private Pane ring_1, ring_2, ring_3, icon_1, produced_btn;
@FXML private Pane ring_1, ring_2, ring_3, icon_1, produced_btn, box;
@FXML private ImageView ring_4, ring_5;

@FXML private ImageView backButton;
Expand Down Expand Up @@ -53,6 +56,17 @@ public void initialize(URL url, ResourceBundle rb) {

for(int i=0; i<items; ++i)
r[i].play();

// For loading sample obstacles for testing purposes
Pane newPane;
try {
newPane = FXMLLoader.load(getClass().getResource("/obstacles/circle.fxml"));
List<Node> parentChildren = ((Pane)box.getParent()).getChildren();
parentChildren.set(parentChildren.indexOf(box), newPane);
box = newPane;
} catch (IOException e) {
e.printStackTrace();
}
}

@FXML
Expand Down
34 changes: 9 additions & 25 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import javafx.animation.*;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.transform.*;
import javafx.stage.*;
import javafx.util.Duration;
import javafx.stage.Stage;

public class Main extends Application {

Expand All @@ -15,24 +12,8 @@ public static void main(String[] args) {
}

private Scene loadSampleObstacle() throws Exception {
Node obstacle = FXMLLoader.load(getClass().getResource("scenes/sample.fxml"));
BorderPane box = new BorderPane();
box.setCenter(obstacle);
Scene scene = new Scene(box, 500, 500);

scene.getStylesheets().add(getClass().getResource("style/style.css").toExternalForm());

RotateTransition rotateTransition = new RotateTransition();
rotateTransition.setAxis(Rotate.Z_AXIS);
rotateTransition.setByAngle(360);
rotateTransition.setCycleCount(1000);
rotateTransition.setDuration(Duration.millis(2000));
rotateTransition.setInterpolator(Interpolator.LINEAR);
rotateTransition.setNode(obstacle);
rotateTransition.play();

scene.setCursor(Cursor.DEFAULT);
return scene;
Parent root = FXMLLoader.load(getClass().getResource("scenes/sample.fxml"));
return new Scene(root, 500, 500);
}

protected static Scene loadSettings() throws Exception {
Expand All @@ -55,7 +36,10 @@ public void start(Stage primaryStage) throws Exception{
primaryStage.getIcons().add(new Image("/assets/color-switch-icon.png"));
primaryStage.setTitle("Color Switch");

Scene scene = getHome();
Scene scene = loadSampleObstacle();



primaryStage.setScene(scene);
primaryStage.setHeight(1024);
primaryStage.setWidth(768);
Expand Down
43 changes: 43 additions & 0 deletions src/obstacles/ObstaclesController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package obstacles;

import javafx.animation.Interpolator;
import javafx.animation.RotateTransition;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.layout.Pane;
import javafx.scene.transform.Rotate;
import javafx.util.Duration;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

public class ObstaclesController implements Initializable {
static int defaultRotatingDuration = 4000;

ArrayList<RotateTransition> rotatingElements;
@FXML
Pane circle;

private void addRotatingNode(Node node, int timeInMillis, boolean clockwise) {
RotateTransition rt = new RotateTransition();
rt.setAxis(Rotate.Z_AXIS);
rt.setByAngle((clockwise) ? 360 : -360);
rt.setCycleCount(1000);
rt.setInterpolator(Interpolator.LINEAR);
rt.setDuration(Duration.millis(timeInMillis));
rt.setNode(node);
rt.play();
}

private void addRotatingNode(Node node) {
addRotatingNode(node, defaultRotatingDuration, true);
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
rotatingElements = new ArrayList<>();
addRotatingNode(circle);
}
}
23 changes: 23 additions & 0 deletions src/obstacles/circle.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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" fx:id="circle" prefHeight="350" prefWidth="350"
xmlns="http://javafx.com/javafx/11.0.1" fx:controller="obstacles.ObstaclesController">

<stylesheets>
<URL value="@../style/style.css"/>
</stylesheets>
<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>
11 changes: 3 additions & 8 deletions src/scenes/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.shape.*?>
<?import java.net.URL?>

<GridPane xmlns:fx="http://javafx.com/fxml/1" alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/15.0.1" fx:controller="Controller">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<Pane mouseTransparent="true" opacity="0.71" prefHeight="340.0" prefWidth="340.0">
<Circle fill="WHITE" layoutX="170.0" layoutY="170.0" radius="169.0" stroke="BLACK" strokeType="INSIDE" />
<Arc focusTraversable="true" layoutX="169.0" layoutY="172.0" length="88.52" mouseTransparent="true" radiusX="169.0" radiusY="169.0" stroke="#e3e857" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="0.0" styleClass="fill-yellow" type="ROUND" />
<Arc focusTraversable="true" layoutX="171.0" layoutY="171.0" length="88.52" mouseTransparent="true" radiusX="169.0" radiusY="169.0" startAngle="90.0" stroke="#e3e857" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="0.0" styleClass="fill-blue" type="ROUND" />
<Arc focusTraversable="true" layoutX="171.0" layoutY="170.0" length="88.52" mouseTransparent="true" radiusX="169.0" radiusY="169.0" startAngle="180.0" stroke="#e3e857" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="0.0" styleClass="fill-pink" type="ROUND" />
<Arc focusTraversable="true" layoutX="169.0" layoutY="171.0" length="88.52" mouseTransparent="true" radiusX="169.0" radiusY="169.0" startAngle="270.0" stroke="#e3e857" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="0.0" styleClass="fill-purple" type="ROUND" />
<Circle fill="WHITE" layoutX="170.0" layoutY="169.0" radius="139.0" stroke="BLACK" strokeType="INSIDE" styleClass="fill-soft-black" />
<Pane fx:id="box" mouseTransparent="true" opacity="0.71" prefHeight="340.0" prefWidth="340.0">

</Pane>
<stylesheets>
<URL value="@../style/style.css" />
Expand Down

0 comments on commit 18649b7

Please sign in to comment.