diff --git a/Main.java b/Main.java index 5564f4cbe641c97c29b39bf13249bed3c8561f13..d71c7cc49a4780e154a3f27c8e23013bcf63c3fd 100644 --- a/Main.java +++ b/Main.java @@ -1,57 +1,57 @@ -import javafx.animation.KeyFrame; -import javafx.animation.Timeline; -import javafx.application.Application; -import javafx.scene.Scene; -import javafx.stage.Stage; -import javafx.util.Duration; -import java.util.HashSet; - -public class Main extends Application { - public static final double WIDTH = 1600; - public static final double HEIGHT = 800; - public static final int FRAMES_PER_SECOND = 60; - private static final int MILLISECOND_DELAY = 1000 / FRAMES_PER_SECOND; - private static final double SECOND_DELAY = 1.0 / FRAMES_PER_SECOND; - private HashSet<String> currentlyActiveKeys = new HashSet<>(); - - private App app; - - @Override - public void start(Stage primaryStage) throws Exception { - primaryStage.setTitle("JavaFX canvas"); - - app = new App(primaryStage); - - // timeline and fps - KeyFrame frame = new KeyFrame(Duration.millis(MILLISECOND_DELAY), e -> { - app.update(SECOND_DELAY); - }); - Timeline animation = new Timeline(); - animation.setCycleCount(Timeline.INDEFINITE); - animation.getKeyFrames().add(frame); - animation.play(); - - // Listeners - keyListener(app.getScene()); - } - - public void keyListener(Scene scene) { - scene.setOnKeyPressed(event -> { - String codeString = event.getCode().toString(); - if (!currentlyActiveKeys.contains(codeString)) { - currentlyActiveKeys.add(codeString); - System.out.println(currentlyActiveKeys); - app.update(currentlyActiveKeys); - } - }); - scene.setOnKeyReleased(event -> { - currentlyActiveKeys.remove(event.getCode().toString()); - app.update(currentlyActiveKeys); - }); - } - - public static void main(String[] args) { - launch(args); - } - -} +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.util.Duration; +import java.util.HashSet; + +public class Main extends Application { + public static final double WIDTH = 1600; + public static final double HEIGHT = 800; + public static final int FRAMES_PER_SECOND = 60; + private static final int MILLISECOND_DELAY = 1000 / FRAMES_PER_SECOND; + private static final double SECOND_DELAY = 1.0 / FRAMES_PER_SECOND; + private HashSet<String> currentlyActiveKeys = new HashSet<>(); + + private App app; + + @Override + public void start(Stage primaryStage) throws Exception { + primaryStage.setTitle("JavaFX canvas"); + + app = new App(primaryStage); + + // timeline and fps + KeyFrame frame = new KeyFrame(Duration.millis(MILLISECOND_DELAY), e -> { + app.update(SECOND_DELAY); + }); + Timeline animation = new Timeline(); + animation.setCycleCount(Timeline.INDEFINITE); + animation.getKeyFrames().add(frame); + animation.play(); + + // Listeners + keyListener(app.getScene()); + } + + public void keyListener(Scene scene) { + scene.setOnKeyPressed(event -> { + String codeString = event.getCode().toString(); + if (!currentlyActiveKeys.contains(codeString)) { + currentlyActiveKeys.add(codeString); + System.out.println(currentlyActiveKeys); + app.update(currentlyActiveKeys); + } + }); + scene.setOnKeyReleased(event -> { + currentlyActiveKeys.remove(event.getCode().toString()); + app.update(currentlyActiveKeys); + }); + } + + public static void main(String[] args) { + launch(args); + } + +}