Skip to content

Commit

Permalink
Added Triangle (#6)
Browse files Browse the repository at this point in the history
- triangle.fxml
- TriangleController.java
- Triangle.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 5b6f0a9 commit 2933b52
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

public class Game implements Serializable {
private static final List<Class> map = Arrays.asList(
Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class
Circle.class, CircleFlow.class, DoubleCircle.class, Plus.class, Square.class, DoubleCircleVertical.class,
Triangle.class
);
private final Ball ball;
private final long id;
Expand Down
2 changes: 1 addition & 1 deletion src/obstacles/TestObstacle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class TestObstacle extends Application {
private Scene loadSampleObstacle() {
GridPane pane = new GridPane();
Obstacle obstacle = new CircleFlow();
Obstacle obstacle = new Triangle();
obstacle.attachToGrid(pane, 0, 0);
return new Scene(pane, 500, 500);
}
Expand Down
20 changes: 20 additions & 0 deletions src/obstacles/Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package obstacles;

import elements.Ball;
import obstacles.controllers.TriangleController;

public class Triangle extends Obstacle {
private TriangleController triangleController;

public Triangle() {
// Load the FXML and set 'pane' in Parent
loadObstaclePane("/obstacles/fxml/triangle.fxml");

triangleController = (TriangleController) controller;
}

@Override
public int hasCollided(Ball b) {
return 0;
}
}
2 changes: 2 additions & 0 deletions src/obstacles/controllers/SuperController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ protected void addScaling(Node node, int timeInMillis, double scaleFactor) {
public void addRotation(Node node) {
addRotation(node, defaultRotatingDuration, ((int) (Math.random()*2))==1?true:false);
}

protected Pane getStar() {return star;}
}
23 changes: 23 additions & 0 deletions src/obstacles/controllers/TriangleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package obstacles.controllers;

import javafx.fxml.FXML;
import javafx.scene.layout.Pane;

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

public class TriangleController extends SuperController {
@FXML
public Pane triangle;

public TriangleController() {
super();
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
// Add transitions
addRotation(triangle);
loadStar();
}
}
27 changes: 27 additions & 0 deletions src/obstacles/fxml/triangle.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

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

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

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

<Pane>
<Pane fx:id="triangle" layoutX="-4.0" layoutY="16.0" prefHeight="350" prefWidth="350.0" scaleX="0.9" scaleY="0.9">
<Rectangle arcHeight="5.0" arcWidth="5.0" height="350.0" layoutX="252.0" layoutY="-47.0" rotate="150.0" styleClass="fill-purple" width="28.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" height="28.0" layoutX="5.0" layoutY="258.0" styleClass="fill-pink" width="350.0" />
<Rectangle arcHeight="5.0" arcWidth="5.0" height="350.0" layoutX="81.0" layoutY="-45.0" rotate="30.0" styleClass="fill-yellow" width="28.0" />
<padding>
<Insets bottom="25.0" />
</padding>
</Pane>
<Pane layoutX="137.0" layoutY="149.0" prefHeight="75" prefWidth="75">
<Pane fx:id="star" />
</Pane>
</Pane>
</Pane>

0 comments on commit 2933b52

Please sign in to comment.