Created
October 30, 2016 13:37
-
-
Save KristerV/05ba6e4fd38d0c693e6b92767da50632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.animation.AnimationTimer; | |
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.TextField; | |
import javafx.scene.input.KeyCode; | |
import javafx.scene.layout.Pane; | |
import javafx.scene.layout.VBox; | |
import javafx.scene.shape.Circle; | |
import javafx.stage.Stage; | |
import java.lang.reflect.Array; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
/** | |
* Created by kviirsaa on 30.10.2016. | |
*/ | |
public class Main extends Application { | |
double grav = 0; | |
double suund = 0; | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
System.out.println("algus"); | |
primaryStage.show(); | |
Pane pane = new Pane(); | |
Scene scene = new Scene(pane, 600, 600); | |
primaryStage.setScene(scene); | |
Circle ring = new Circle(50); | |
pane.getChildren().add(ring); | |
new AnimationTimer() { | |
@Override | |
public void handle(long now) { | |
grav += 0.3; | |
double ringPraeguY = ring.getCenterY(); | |
double uusRingiY = Math.min(ringPraeguY + grav, 550); | |
ring.setCenterY(uusRingiY); | |
ring.setCenterX(ring.getCenterX() + suund); | |
} | |
}.start(); | |
scene.setOnKeyPressed(event -> { | |
KeyCode code = event.getCode(); | |
if (code == KeyCode.RIGHT) { | |
suund++; | |
} else if (code == KeyCode.LEFT) { | |
suund--; | |
} else if (code == KeyCode.UP) { | |
grav = -10; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment