Compare commits

..

2 Commits

Author SHA1 Message Date
MOISOIU Stefan-Mihai
f9cfd84239 Merge branch 'main' of https://titi.koxi.nl/blodat/projet-dev 2026-02-23 10:11:16 +01:00
MOISOIU Stefan-Mihai
9e18b47a66 collisions, cercle reste dans ligne 2026-02-23 10:07:29 +01:00
3 changed files with 32 additions and 11 deletions

View File

@@ -3,7 +3,6 @@ package linea;
import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Arc2D;
public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercle
@@ -125,16 +124,28 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl
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 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;
}
}

View File

@@ -151,7 +151,11 @@ public class Jeu implements KeyListener, ActionListener{
ecran.traiterBoucleAnimation();
score = score + 0.4;
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();
}

View File

@@ -52,12 +52,12 @@ public class Ligne extends ObjetGraphique {
for (Segment s : listeSegments) {
s.Afficher(g);
if (SegCourant == null) {
if (xCercle < s.x + s.xLong && xCercle > s.x) {
if (xCercle <= s.x + s.xLong && xCercle >= s.x) {
SegCourant = s;
}
} else {
if ((SegCourant.x + SegCourant.xLong) < xCercle) {
if (s.x <= xCercle && (s.xLong) >= xCercle) {
if (s.x <= xCercle && (s.x + s.xLong) >= xCercle) {
SegCourant = s;
}
}
@@ -72,4 +72,10 @@ public class Ligne extends ObjetGraphique {
s.x -= 10;
}
}
public double GetHauteurPointCercle(){
double t = (400 - SegCourant.x) / SegCourant.xLong;
return SegCourant.y + SegCourant.yLong * t;
}
}