Compare commits
2 Commits
06a3809148
...
f9cfd84239
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9cfd84239 | ||
|
|
9e18b47a66 |
@@ -3,7 +3,6 @@ package linea;
|
|||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Stroke;
|
|
||||||
import java.awt.geom.Arc2D;
|
import java.awt.geom.Arc2D;
|
||||||
|
|
||||||
public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercle
|
public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercle
|
||||||
@@ -124,17 +123,29 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl
|
|||||||
}
|
}
|
||||||
y+=depY;
|
y+=depY;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean EnCollision(Segment segCourant){
|
|
||||||
double t = (x - segCourant.x) / (x - segCourant.x + segCourant.xLong);
|
|
||||||
double yLigne = segCourant.y + segCourant.yLong * t;
|
|
||||||
|
|
||||||
|
public void ResterDansLigne(Ligne li){
|
||||||
double collisionHautPos = y + rayon;
|
double collisionHautPos = y + rayon;
|
||||||
double collisionBasPos = y - rayon;
|
double collisionBasPos = y - rayon;
|
||||||
|
|
||||||
return yLigne < collisionBasPos || yLigne > collisionHautPos;
|
double yLigne = li.GetHauteurPointCercle();
|
||||||
|
|
||||||
|
if (yLigne < collisionBasPos){
|
||||||
|
y = yLigne + rayon;
|
||||||
|
if (vitesse > 0) vitesse = 0;
|
||||||
|
}
|
||||||
|
if (yLigne > collisionHautPos){
|
||||||
|
y = yLigne - rayon;
|
||||||
|
if (vitesse < 0) vitesse = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public boolean VerifierCollision(Ligne li){
|
||||||
|
double collisionHautPos = y + rayon;
|
||||||
|
double collisionBasPos = y - rayon;
|
||||||
|
|
||||||
|
double yLigne = li.GetHauteurPointCercle();
|
||||||
|
|
||||||
|
return yLigne <= collisionBasPos || yLigne >= collisionHautPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,11 @@ public class Jeu implements KeyListener, ActionListener{
|
|||||||
ecran.traiterBoucleAnimation();
|
ecran.traiterBoucleAnimation();
|
||||||
score = score + 0.4;
|
score = score + 0.4;
|
||||||
labScore.setText("<html><h3>score : " + (int)score + "</h3></html>");
|
labScore.setText("<html><h3>score : " + (int)score + "</h3></html>");
|
||||||
if (demiCercleArriere.EnCollision(lili.SegCourant))
|
|
||||||
|
demiCercleArriere.ResterDansLigne(lili);
|
||||||
|
demiCercleAvant.ResterDansLigne(lili);
|
||||||
|
|
||||||
|
if (demiCercleArriere.VerifierCollision(lili))
|
||||||
RecommencerPartie();
|
RecommencerPartie();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ public class Ligne extends ObjetGraphique {
|
|||||||
for (Segment s : listeSegments) {
|
for (Segment s : listeSegments) {
|
||||||
s.Afficher(g);
|
s.Afficher(g);
|
||||||
if (SegCourant == null) {
|
if (SegCourant == null) {
|
||||||
if (xCercle < s.x + s.xLong && xCercle > s.x) {
|
if (xCercle <= s.x + s.xLong && xCercle >= s.x) {
|
||||||
SegCourant = s;
|
SegCourant = s;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((SegCourant.x + SegCourant.xLong) < xCercle) {
|
if ((SegCourant.x + SegCourant.xLong) < xCercle) {
|
||||||
if (s.x <= xCercle && (s.xLong) >= xCercle) {
|
if (s.x <= xCercle && (s.x + s.xLong) >= xCercle) {
|
||||||
SegCourant = s;
|
SegCourant = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,4 +72,10 @@ public class Ligne extends ObjetGraphique {
|
|||||||
s.x -= 10;
|
s.x -= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double GetHauteurPointCercle(){
|
||||||
|
double t = (400 - SegCourant.x) / SegCourant.xLong;
|
||||||
|
|
||||||
|
return SegCourant.y + SegCourant.yLong * t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user