1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| //Création animation clavier pour pouvoir déplacer le cercle c :
HashSet<KeyCode> tab = new HashSet<KeyCode>();
AnimationTimer aT = new AnimationTimer() {
public void handle(long l) {
for(KeyCode t: tab) {
switch(t){
case ESCAPE:
r.setVisible(true);
exit.setVisible(true);
re.setVisible(true);
break;
case Z :
c.setLayoutY(c.getLayoutY()-7);
break;
case D :
c.setLayoutX(c.getLayoutX()+7);
break;
case Q :
c.setLayoutX(c.getLayoutX()-7);
break;
case S :
c.setLayoutY(c.getLayoutY()+7);
break;
}
//Collision mur de la fenetre :
if (c.getLayoutX() > 491){
c.setLayoutX(491);
}
if (c.getLayoutY() > 290){
c.setLayoutY(290);
}
if (c.getLayoutY() < -287){
c.setLayoutY(-287);
}
if (c.getLayoutX() < -488){
c.setLayoutX(- 488);
}
};
};
};
scene.setOnKeyPressed(e ->{
boolean wasEmpty = tab.isEmpty();
if(tab.add(e.getCode()) && wasEmpty)
aT.start();
});
scene.setOnKeyReleased(e ->{
if(tab.remove(e.getCode()) && tab.isEmpty())
aT.stop();
});
Shape s = Shape.intersect(r,r3);
boolean collision = s.getBoundsInLocal().isEmpty();
if(collision == true) {
aT.stop();
} |
Partager