97 lines
2.3 KiB
Plaintext
97 lines
2.3 KiB
Plaintext
import javafx.application.Application;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.layout.Pane;
|
|
import javafx.stage.Stage;
|
|
import javafx.scene.canvas.*;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.canvas.GraphicsContext;
|
|
import javafx.scene.paint.Color;
|
|
import java.lang.Thread;
|
|
import javafx.animation.AnimationTimer;
|
|
import javafx.scene.input.*;
|
|
import javafx.event.*;
|
|
import javafx.scene.input.KeyCodeCombination;
|
|
/**
|
|
*
|
|
* Beschreibung
|
|
*
|
|
* @version 1.0 vom 19.11.2024
|
|
* @author
|
|
*/
|
|
|
|
public class game extends Application {
|
|
// Anfang Attribute
|
|
public int gameWidth = 1000;
|
|
public int gameHeight = 720;
|
|
private AnimationTimer timer;
|
|
private int X = 0;
|
|
private Canvas main = new Canvas();
|
|
// Ende Attribute
|
|
|
|
public void start(Stage primaryStage) {
|
|
Pane root = new Pane();
|
|
Scene scene = new Scene(root, gameWidth, gameHeight);
|
|
// Anfang Komponenten
|
|
|
|
main.setLayoutX(0);
|
|
main.setLayoutY(0);
|
|
main.setWidth(gameWidth);
|
|
main.setHeight(gameHeight);
|
|
main.setOnKeyPressed(
|
|
(event) -> {main_KeyPressed(event);}
|
|
);
|
|
root.getChildren().add(main);
|
|
main.setOnMouseClicked(
|
|
(event) -> {main_MouseClicked(event);}
|
|
);
|
|
// Ende Komponenten
|
|
|
|
primaryStage.setOnCloseRequest(e -> System.exit(0));
|
|
primaryStage.setTitle("game");
|
|
primaryStage.setScene(scene);
|
|
primaryStage.show();
|
|
|
|
|
|
timer = new TimerMethod();
|
|
timer.start();
|
|
|
|
draw(main.getGraphicsContext2D());
|
|
|
|
} // end of public game
|
|
|
|
// Anfang Methoden
|
|
|
|
public static void main(String[] args){
|
|
launch(args);
|
|
// end of while
|
|
} // end of main
|
|
public void draw(GraphicsContext context) {
|
|
context.setFill(Color.BLUE);
|
|
context.fillRect(X,0,X+100,100);
|
|
context.clearRect(0,0,gameWidth,gameHeight);
|
|
|
|
}
|
|
public void main_MouseClicked(MouseEvent evt) {
|
|
X+=10;
|
|
|
|
} // end of main_MouseClicked
|
|
|
|
public void main_KeyPressed(KeyEvent evt) {
|
|
if(evt.getCode() == KeyCode.ENTER) {
|
|
timer.stop();
|
|
}
|
|
|
|
} // end of main_KeyPressed
|
|
|
|
// Ende Methoden
|
|
public class TimerMethod extends AnimationTimer {
|
|
@Override
|
|
public void handle(long now) {
|
|
mainLoop();
|
|
}
|
|
}
|
|
public void mainLoop() {
|
|
draw(main.getGraphicsContext2D());
|
|
}
|
|
} // end of class game
|