2018-01-05 22:30:17 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
|
|
namespace Bonhomme02
|
|
|
|
|
{
|
|
|
|
|
class Marcher
|
|
|
|
|
{
|
|
|
|
|
Bonhomme bonhomme;
|
|
|
|
|
IntPtr handle;
|
|
|
|
|
int ySol;
|
|
|
|
|
int resolution;
|
|
|
|
|
int deltaXYmax = 10;
|
|
|
|
|
int step;
|
|
|
|
|
public Marcher()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public Marcher(ref Bonhomme bonhomme, IntPtr handle, int ySol)
|
|
|
|
|
{
|
|
|
|
|
step = 0;
|
|
|
|
|
this.bonhomme = bonhomme;
|
|
|
|
|
this.handle = handle;
|
|
|
|
|
this.ySol = ySol;
|
|
|
|
|
resolution = 1;
|
|
|
|
|
deltaXYmax = (int)Math.Round(3*bonhomme.jambe1.longueur.ABS/4);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
|
2018-01-05 22:30:17 +01:00
|
|
|
|
//Reset de tous les angle au cas ou
|
|
|
|
|
bonhomme.Angle = Math.PI / 2;
|
|
|
|
|
bonhomme.jambe1.SetAngle(Math.PI / 2, Math.PI / 2, 0);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
//bonhomme.jambe2.Cacher(handle);
|
|
|
|
|
//bonhomme.jambe2.Visible = false; // On va d'abord le faire marcher sur une jambe
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.bras.Visible = false;
|
|
|
|
|
bonhomme.bras.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
if(bonhomme.jambe1.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
|
|
|
|
Graphics gr = Graphics.FromHwnd(handle);
|
|
|
|
|
bonhomme.Cacher(handle);
|
|
|
|
|
Point newCoo;
|
|
|
|
|
int longeurTTBonhome = bonhomme.jambe1.Bas.CSG.Y - bonhomme.CIG.Y ;// de pied.csg à bonhome.cig
|
|
|
|
|
newCoo = new Point(bonhomme.CIG.X, ySol - longeurTTBonhome);
|
|
|
|
|
bonhomme.Coordonnee = newCoo;
|
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Avancer(int vitesse)
|
|
|
|
|
{
|
|
|
|
|
step = 0;
|
2018-01-06 16:56:46 +01:00
|
|
|
|
double old = 1, neww = 0;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
int dejaDeplacer = 0;
|
2018-01-06 16:56:46 +01:00
|
|
|
|
while(step<=128)
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
2018-01-06 16:56:46 +01:00
|
|
|
|
Console.WriteLine(step + "::" + step % 5);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
dejaDeplacer = 0;
|
|
|
|
|
switch (step%5)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2018-01-06 16:56:46 +01:00
|
|
|
|
while (dejaDeplacer < deltaXYmax) //Monte jambe 1
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(0, -resolution);
|
|
|
|
|
//bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X, bonhomme.Coordonnee.Y + resolution);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
dejaDeplacer += resolution;
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2018-01-06 16:56:46 +01:00
|
|
|
|
while (dejaDeplacer < deltaXYmax)//avence corp + avancer jambe 1 jambe 2 fixe
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe2.BougerXHaut(resolution, ref bonhomme);
|
|
|
|
|
bonhomme.jambe1.BougerBas(resolution, 0);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
dejaDeplacer += resolution;
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
2018-01-06 16:56:46 +01:00
|
|
|
|
CollerAuSol(ref bonhomme.jambe2);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2018-01-06 16:56:46 +01:00
|
|
|
|
while (bonhomme.jambe1.Bas.CSG.Y < ySol-1 && old != neww) //Descendre jambe 1 sur sol
|
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
|
|
|
|
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
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(-resolution, 0);
|
|
|
|
|
if(dejaDeplacer < deltaXYmax)
|
|
|
|
|
bonhomme.jambe2.BougerBas(resolution, -resolution);
|
|
|
|
|
else
|
|
|
|
|
bonhomme.jambe2.BougerBas(resolution, 0);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y);
|
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
dejaDeplacer += resolution;
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
//bonhomme.jambe1.BougerBas(0, 4);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
break;
|
2018-01-06 16:56:46 +01:00
|
|
|
|
case 4:
|
|
|
|
|
while (bonhomme.jambe2.Bas.CSG.Y < ySol - 1 && old != neww)//Descend jambe 2
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe2.BougerBas(0, resolution);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
//bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y);
|
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
dejaDeplacer += resolution;
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.InterevrtirJambe();
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Afficher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
step+=2;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
break;
|
2018-01-06 16:56:46 +01:00
|
|
|
|
/*---------------------------------------------T0 DO-----------------------------------------------*/
|
|
|
|
|
case 5:
|
|
|
|
|
while (dejaDeplacer < deltaXYmax) //Monte pied 1
|
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
|
|
|
|
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)
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(-resolution, 0);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y);
|
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
dejaDeplacer += resolution;
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
bonhomme.Cacher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(0, -4);
|
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
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);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Afficher(handle);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
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;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
step++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-06 16:56:46 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-05 22:30:17 +01:00
|
|
|
|
}
|
2018-01-06 16:56:46 +01:00
|
|
|
|
|
2018-01-05 22:30:17 +01:00
|
|
|
|
}
|