From 3aa5ca08cce574f8e8054b0b7e3d9db6985fc501 Mon Sep 17 00:00:00 2001 From: adri Date: Sat, 6 Jan 2018 16:56:46 +0100 Subject: [PATCH] =?UTF-8?q?Marcher=20OK,=20a=20am=C3=A9liorer=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bonhomme02/BaseBJ.cs | 31 +++++++++- Bonhomme02/Bonhomme.cs | 7 +++ Bonhomme02/Form1.cs | 4 +- Bonhomme02/Marcher.cs | 136 ++++++++++++++++++++++++++++++++++------- Bonhomme02/Vecteur.cs | 4 ++ 5 files changed, 155 insertions(+), 27 deletions(-) diff --git a/Bonhomme02/BaseBJ.cs b/Bonhomme02/BaseBJ.cs index 5891fd1..b0311d5 100644 --- a/Bonhomme02/BaseBJ.cs +++ b/Bonhomme02/BaseBJ.cs @@ -88,7 +88,12 @@ namespace Bonhomme02 cooMY += H.Y; int xx = (int)Math.Round(cooMX); int yy = (int)Math.Round(cooMY); - return new Point(xx, yy); + if(Double.IsNaN(a) || Double.IsNaN(b)) + { + return Millieux.Coordonnee; + } + else + return new Point(xx, yy); } catch(Exception e) { @@ -96,7 +101,7 @@ namespace Bonhomme02 return new Point(0, 0); } } - public void Bouger(int X, int Y) + public void BougerBas(int X, int Y) { Point nouveauPtBas = new Point(Bas.X + X, Bas.Y + Y); Point nouveauPtMillieux = TouverPointMillieux(nouveauPtBas); @@ -106,12 +111,32 @@ namespace Bonhomme02 Millieux.Angle = TrouverAngleMillieux(nouveauPtBas); } } + public void BougerXHaut(int x, ref Bonhomme bonhomme) + { + Point oldPtBas = Bas.Coordonnee; + Vecteur oldVecteurHautBas = new Vecteur(Bas.Coordonnee, Haut.Coordonnee); + Vecteur newVecteurHautBas; + Point newCooHaut = TrouverPointSurCerlceSelonX(Bas.Coordonnee, oldVecteurHautBas.ABS, Haut.Coordonnee.X + x); + bonhomme.Coordonnee = new Point(newCooHaut.X, (int)Math.Round(newCooHaut.Y - bonhomme.longueur.ABS)); + + Point nouveauPtMillieux = TouverPointMillieux(oldPtBas); + if (nouveauPtMillieux.X != 0 || nouveauPtMillieux.Y != 0) + { + Haut.Angle = TrouverAngleHaut(nouveauPtMillieux); + Millieux.Angle = TrouverAngleMillieux(oldPtBas); + } + } public void SetAngle(double h, double m, double b) { Haut.Angle = h; Millieux.Angle = m; Bas.Angle = b; } - + public Point TrouverPointSurCerlceSelonX(Point centre, double rayon, int nouveauX) + { + double racine = Math.Sqrt(rayon * rayon - nouveauX * nouveauX + 2 * centre.X * nouveauX - centre.X * centre.X); + double y = -(racine - centre.Y); + return new Point(nouveauX, (int)Math.Round(y)); + } } } diff --git a/Bonhomme02/Bonhomme.cs b/Bonhomme02/Bonhomme.cs index 53a2d69..3c947cb 100644 --- a/Bonhomme02/Bonhomme.cs +++ b/Bonhomme02/Bonhomme.cs @@ -57,5 +57,12 @@ namespace Bonhomme02 jambe2.Cacher(handle); bras.Cacher(handle); } + public void InterevrtirJambe() + { + Jambe tmp; + tmp = jambe1; + jambe1 = jambe2; + jambe2 = tmp; + } } } diff --git a/Bonhomme02/Form1.cs b/Bonhomme02/Form1.cs index 72a26c6..321d5cf 100644 --- a/Bonhomme02/Form1.cs +++ b/Bonhomme02/Form1.cs @@ -37,7 +37,7 @@ namespace Bonhomme02 { bonhomme.Cacher(this.TV.Handle); bonhomme.coordonnee = new Point(bonhomme.coordonnee.X + 3, bonhomme.coordonnee.Y + 0); - bonhomme.jambe1.Bouger(+3, -3); + bonhomme.jambe1.BougerBas(+3, -3); bonhomme.Afficher(this.TV.Handle); } } @@ -61,7 +61,7 @@ namespace Bonhomme02 bonhomme.Afficher(this.TV.Handle); marche = new Marcher(ref bonhomme, this.TV.Handle, this.Sol.Location.Y-this.TV.Location.Y); Thread.Sleep(1000); - Task.Factory.StartNew(() => marche.Avancer(5)); + Task.Factory.StartNew(() => marche.Avancer(10)); //this.btnStopDeplacerCTick.Enabled = true; // this.timerImage.Start(); diff --git a/Bonhomme02/Marcher.cs b/Bonhomme02/Marcher.cs index efac7aa..9147ec4 100644 --- a/Bonhomme02/Marcher.cs +++ b/Bonhomme02/Marcher.cs @@ -28,14 +28,15 @@ namespace Bonhomme02 this.ySol = ySol; resolution = 1; deltaXYmax = (int)Math.Round(3*bonhomme.jambe1.longueur.ABS/4); + //Reset de tous les angle au cas ou bonhomme.Angle = Math.PI / 2; bonhomme.jambe1.SetAngle(Math.PI / 2, Math.PI / 2, 0); - bonhomme.jambe2.Cacher(handle); - bonhomme.jambe2.Visible = false; // On va d'abord le faire marcher sur une jambe + //bonhomme.jambe2.Cacher(handle); + //bonhomme.jambe2.Visible = false; // On va d'abord le faire marcher sur une jambe bonhomme.bras.Visible = false; bonhomme.bras.Cacher(handle); - if(bonhomme.jambe1.Bas.CSG.Y != ySol) + if(bonhomme.jambe1.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol { Graphics gr = Graphics.FromHwnd(handle); bonhomme.Cacher(handle); @@ -49,18 +50,20 @@ namespace Bonhomme02 public void Avancer(int vitesse) { step = 0; + double old = 1, neww = 0; int dejaDeplacer = 0; - while(step<=32) + while(step<=128) { + Console.WriteLine(step + "::" + step % 5); dejaDeplacer = 0; switch (step%5) { case 0: - while (dejaDeplacer < deltaXYmax) //Descent corp + while (dejaDeplacer < deltaXYmax) //Monte jambe 1 { bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(0, -resolution); - bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X, bonhomme.Coordonnee.Y + resolution); + bonhomme.jambe1.BougerBas(0, -resolution); + //bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X, bonhomme.Coordonnee.Y + resolution); bonhomme.Afficher(handle); dejaDeplacer += resolution; Thread.Sleep(vitesse); @@ -68,62 +71,151 @@ namespace Bonhomme02 break; case 1: - while (dejaDeplacer < deltaXYmax)//avence corp pied fixe + while (dejaDeplacer < deltaXYmax)//avence corp + avancer jambe 1 jambe 2 fixe { bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(-resolution, 0); - bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); + bonhomme.jambe2.BougerXHaut(resolution, ref bonhomme); + bonhomme.jambe1.BougerBas(resolution, 0); bonhomme.Afficher(handle); dejaDeplacer += resolution; Thread.Sleep(vitesse); } + CollerAuSol(ref bonhomme.jambe2); break; case 2: - while (dejaDeplacer < deltaXYmax) + while (bonhomme.jambe1.Bas.CSG.Y < ySol-1 && old != neww) //Descendre jambe 1 sur sol { bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(-resolution, 0); + bonhomme.jambe1.BougerBas(0, resolution); + //bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); + bonhomme.Afficher(handle); + dejaDeplacer += resolution; + Thread.Sleep(vitesse); + if (neww != bonhomme.jambe1.Bas.CSG.Y) + { + neww = bonhomme.jambe1.Bas.CSG.Y; + } + else + old = bonhomme.jambe1.Bas.CSG.Y; + } + + break; + case 3: + while (dejaDeplacer < (deltaXYmax*2))//Monte&avance jambe 2,avance bonhome + { + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(-resolution, 0); + if(dejaDeplacer < deltaXYmax) + bonhomme.jambe2.BougerBas(resolution, -resolution); + else + bonhomme.jambe2.BougerBas(resolution, 0); bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); bonhomme.Afficher(handle); dejaDeplacer += resolution; Thread.Sleep(vitesse); } bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(0, -4); + //bonhomme.jambe1.BougerBas(0, 4); bonhomme.Afficher(handle); break; - case 3: - while (dejaDeplacer < (deltaXYmax*4)) + case 4: + while (bonhomme.jambe2.Bas.CSG.Y < ySol - 1 && old != neww)//Descend jambe 2 { bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(resolution, 0); + bonhomme.jambe2.BougerBas(0, resolution); //bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); bonhomme.Afficher(handle); dejaDeplacer += resolution; Thread.Sleep(vitesse); } bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(0, 4); + bonhomme.InterevrtirJambe(); bonhomme.Afficher(handle); + step+=2; break; - case 4: - while (dejaDeplacer < deltaXYmax*4) + /*---------------------------------------------T0 DO-----------------------------------------------*/ + case 5: + while (dejaDeplacer < deltaXYmax) //Monte pied 1 { bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(-resolution, 0); + bonhomme.jambe1.BougerBas(0, -resolution); + bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X, bonhomme.Coordonnee.Y + resolution); + bonhomme.Afficher(handle); + dejaDeplacer += resolution; + Thread.Sleep(vitesse); + } + + break; + case 6: + while (dejaDeplacer < deltaXYmax)//avence corp pied 2 fixe + { + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(-resolution, 0); + bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); + bonhomme.Afficher(handle); + dejaDeplacer += resolution; + Thread.Sleep(vitesse); + } + break; + case 7: + while (dejaDeplacer < deltaXYmax) + { + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(-resolution, 0); bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); bonhomme.Afficher(handle); dejaDeplacer += resolution; Thread.Sleep(vitesse); } bonhomme.Cacher(handle); - bonhomme.jambe1.Bouger(0, -4); + bonhomme.jambe1.BougerBas(0, -4); bonhomme.Afficher(handle); - step+=3; + break; + case 8: + while (dejaDeplacer < (deltaXYmax * 4)) + { + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(resolution, 0); + bonhomme.Afficher(handle); + dejaDeplacer += resolution; + Thread.Sleep(vitesse); + } + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(0, 4); + bonhomme.Afficher(handle); + break; + case 9: + while (dejaDeplacer < deltaXYmax * 4) + { + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(-resolution, 0); + bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); + bonhomme.Afficher(handle); + dejaDeplacer += resolution; + Thread.Sleep(vitesse); + } + bonhomme.Cacher(handle); + bonhomme.jambe1.BougerBas(0, -4); + bonhomme.Afficher(handle); + step += 3; break; } step++; } } + public void CollerAuSol(ref Jambe jambe) + { + if (jambe.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol + { + Graphics gr = Graphics.FromHwnd(handle); + bonhomme.Cacher(handle); + Point newCoo; + int longeurTTBonhome = jambe.Bas.CSG.Y - bonhomme.CIG.Y;// de pied.csg à bonhome.cig + newCoo = new Point(bonhomme.Coordonnee.X, ySol - longeurTTBonhome); + bonhomme.Coordonnee = newCoo; + bonhomme.Afficher(handle); + } + } } + } diff --git a/Bonhomme02/Vecteur.cs b/Bonhomme02/Vecteur.cs index d703bfd..6b82ba0 100644 --- a/Bonhomme02/Vecteur.cs +++ b/Bonhomme02/Vecteur.cs @@ -68,6 +68,10 @@ namespace Bonhomme02 { vecteur = Complex.FromPolarCoordinates(longueur, angle); } + public Vecteur(Point origine, Point bout) + { + vecteur = new Complex(bout.X-origine.X, bout.Y - origine.Y); + } public Vecteur(double longueur, ref Vecteur parent, bool flag) : this(longueur, parent.Angle - Math.PI / 2) { this.parent = parent;