leendert/src/main/java/nl/minkema/leendert/Player.java

77 lines
2.4 KiB
Java

package nl.minkema.leendert;
import javafx.animation.TranslateTransition;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
import java.util.Arrays;
import java.util.Random;
/**
* @author J0QUE
* @version 1.0
*/
public class Player {
private final Image image;
private final ImageView view;
private int plaats = 0;
private int[] coords = Game.locations[plaats];
private final int[] add;
private static int who = 0;
public Player(Image image) {
Random r = new Random(System.currentTimeMillis());
this.image = image;
this.view = new ImageView(this.image);
this.add = new int[]{-image.widthProperty().intValue() / 2, -image.heightProperty().intValue() / 2};// new int[]{r.nextInt(10) - 5, r.nextInt(10) - 5};
coords = new int[]{coords[0] + add[0], coords[1] + add[1]};
System.out.println(Arrays.toString(coords));
getImageView().setTranslateX(coords[0]);
getImageView().setTranslateY(coords[1]);
}
public ImageView getImageView() {
return view;
}
public void move(int waar) {
System.out.println(waar);
if (waar + plaats > 100) return;
TranslateTransition tt = new TranslateTransition(Duration.millis(200), getImageView());
tt.setFromX(coords[0]);
tt.setFromY(coords[1]);
tt.setToX(coords[0] = Game.locations[plaats + 1][0] + add[0]);
tt.setToY(coords[1] = Game.locations[plaats + 1][1] + add[1]);
TranslateTransition last = tt;
for (int i = plaats + 2; i < waar + plaats + 1; i++) {
TranslateTransition tl = new TranslateTransition(Duration.millis(200), getImageView());
tl.setFromX(coords[0]);
tl.setFromY(coords[1]);
tl.setToX(coords[0] = Game.locations[i][0] + add[0]);
tl.setToY(coords[1] = Game.locations[i][1] + add[1]);
last.setOnFinished(e -> tl.play());
System.out.println(Arrays.toString(coords));
last = tl;
}
tt.play();
plaats += waar;
if (plaats==100){
System.out.println("Een speler heeft gewonnen!");
}
}
public static int getNextActive() {
System.out.println(who);
who++;
if (who >= Game.players.size()) {
return who = 0;
}
return who;
}
}