From a1b10db6705109e93352b7067304b90ceed645aa Mon Sep 17 00:00:00 2001 From: Villard PierreFrederic <pierre-frederic.villard@univ-lorraine.fr> Date: Fri, 3 Sep 2021 18:02:00 +0200 Subject: [PATCH] Gravity working --- .vscode/settings.json | 3 +++ src/controle/Controle.java | 7 ++++++- src/controle/ControleurClavier.java | 11 ++++++++++- src/physique/MoteurPhysique.java | 14 ++++++++++---- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a5eed8b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.dependency.packagePresentation": "hierarchical" +} \ No newline at end of file diff --git a/src/controle/Controle.java b/src/controle/Controle.java index 161a355..bd49a08 100644 --- a/src/controle/Controle.java +++ b/src/controle/Controle.java @@ -37,7 +37,12 @@ public class Controle { * */ static public boolean haut; - + + /** + * + */ + static public boolean bas; + /** * */ diff --git a/src/controle/ControleurClavier.java b/src/controle/ControleurClavier.java index e608e86..efc47c4 100644 --- a/src/controle/ControleurClavier.java +++ b/src/controle/ControleurClavier.java @@ -77,7 +77,11 @@ public class ControleurClavier implements KeyListener{ { c.haut=true; } - + //touche down + if (e.getKeyCode()==KeyEvent.VK_DOWN) + { + c.bas=true; + } //touche up if (e.getKeyCode()==KeyEvent.VK_Q) { @@ -104,6 +108,11 @@ public class ControleurClavier implements KeyListener{ { c.haut=false; } + //touche down + if (e.getKeyCode()==KeyEvent.VK_DOWN) + { + c.bas=false; + } if (affiche) afficheur.dessin(); } diff --git a/src/physique/MoteurPhysique.java b/src/physique/MoteurPhysique.java index 2cf4c4b..0b46d9d 100644 --- a/src/physique/MoteurPhysique.java +++ b/src/physique/MoteurPhysique.java @@ -111,10 +111,16 @@ public class MoteurPhysique { } else { + monde.balle.ay = 0; + monde.balle.vy = 0; if (monde.c.haut) { - monde.balle.ay = 0.1; + monde.balle.vy = 1; } + if (monde.c.bas) + { + monde.balle.vy = -1; + } } monde.balle.collision=false; @@ -128,7 +134,6 @@ public class MoteurPhysique { //m.balle.collision = true; //obj.collision=true; - //si collision vient de la gauche ou droite if (Collision.collisionGauche(monde.balle,obj) || (Collision.collisionDroite(monde.balle,obj))) @@ -154,12 +159,13 @@ public class MoteurPhysique { } } - + //si collision vient du Bas if (Collision.collisionBas(monde.balle,obj)) { + monde.balle.py = monde.balle.py - monde.balle.vy; - monde.balle.vy=-monde.balle.vy; + monde.balle.vy=-monde.balle.vy;; } } } -- GitLab