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;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
using System.Windows.Forms;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
|
|
|
|
|
namespace Bonhomme02
|
|
|
|
|
{
|
|
|
|
|
class Marcher
|
|
|
|
|
{
|
|
|
|
|
Bonhomme bonhomme;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
IntPtr? handle;
|
|
|
|
|
Graphics gr;
|
|
|
|
|
BufferedGraphics buff;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
int ySol;
|
|
|
|
|
int resolution;
|
|
|
|
|
int deltaXYmax = 10;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
int step, cooXMax = 0;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
int vitesse;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
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-09 20:19:49 +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);
|
|
|
|
|
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);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
buff.Render();
|
|
|
|
|
}
|
|
|
|
|
else
|
2018-01-05 22:30:17 +01:00
|
|
|
|
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;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
buff.Render();
|
|
|
|
|
}
|
|
|
|
|
else
|
2018-01-05 22:30:17 +01:00
|
|
|
|
bonhomme.Afficher(handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
public Marcher(ref Bonhomme bonhomme, BufferedGraphics buff, int ySol)
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
handle = null;
|
2018-01-05 22:30:17 +01:00
|
|
|
|
step = 0;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
this.gr = buff.Graphics;
|
|
|
|
|
this.buff = buff;
|
|
|
|
|
this.bonhomme = bonhomme;
|
|
|
|
|
this.handle = null;
|
|
|
|
|
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.bras.Visible = false;
|
|
|
|
|
bonhomme.bras.Cacher(gr);
|
|
|
|
|
if(bonhomme.jambe1.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol
|
|
|
|
|
{
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
buff.Render();
|
|
|
|
|
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(gr);
|
|
|
|
|
buff.Render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Avancer()
|
|
|
|
|
{
|
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-09 20:19:49 +01:00
|
|
|
|
while(/*step<=110 || */bonhomme.X <= cooXMax)
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
2018-01-09 13:49:11 +01:00
|
|
|
|
old = 1; neww = 0;
|
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
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(0, -resolution);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
dejaDeplacer += resolution;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
2018-01-05 22:30:17 +01:00
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
|
2018-01-05 22:30:17 +01:00
|
|
|
|
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
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe2.BougerXHaut(resolution, ref bonhomme);
|
|
|
|
|
bonhomme.jambe1.BougerBas(resolution, 0);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
dejaDeplacer += resolution;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
2018-01-05 22:30:17 +01:00
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
2018-01-06 17:14:12 +01:00
|
|
|
|
CollerAuSol(ref bonhomme.jambe2); //Voir issues #24
|
2018-01-05 22:30:17 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2018-01-09 13:49:11 +01:00
|
|
|
|
while (bonhomme.jambe1.Bas.CSG.Y < ySol && old != neww) //Descendre jambe 1 sur sol
|
2018-01-06 16:56:46 +01:00
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(0, resolution);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
dejaDeplacer += resolution;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
2018-01-06 16:56:46 +01:00
|
|
|
|
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:
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if (bonhomme.jambe2.Bas.X > bonhomme.jambe1.Bas.X)
|
2018-01-05 22:30:17 +01:00
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
bonhomme.InterevrtirJambe();
|
|
|
|
|
}
|
|
|
|
|
while (dejaDeplacer < (deltaXYmax*2))//Monte&avance jambe 2,avance bonhome
|
|
|
|
|
{
|
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(-resolution, 0);
|
|
|
|
|
if(dejaDeplacer < deltaXYmax)
|
|
|
|
|
bonhomme.jambe2.BougerBas(resolution, -resolution);
|
2018-01-09 13:49:11 +01:00
|
|
|
|
else if(bonhomme.jambe2.Bas.CSG.Y < ySol && old != neww)
|
|
|
|
|
{
|
|
|
|
|
bonhomme.jambe2.BougerBas(resolution, resolution);
|
|
|
|
|
if (neww != bonhomme.jambe2.Bas.CSG.Y)
|
|
|
|
|
{
|
|
|
|
|
neww = bonhomme.jambe2.Bas.CSG.Y;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
old = bonhomme.jambe2.Bas.CSG.Y;
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
|
2018-01-06 16:56:46 +01:00
|
|
|
|
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);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
dejaDeplacer += resolution;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
2018-01-05 22:30:17 +01:00
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe2.BougerBas(0, resolution);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
2018-01-05 22:30:17 +01:00
|
|
|
|
dejaDeplacer += resolution;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
2018-01-05 22:30:17 +01:00
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 17:14:12 +01:00
|
|
|
|
bonhomme.InterevrtirJambe();// On inverse les deux jambe, jambe1=jambe2 et jambe2=jambe1
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
|
|
|
|
|
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
|
|
|
|
step +=3; // retour step 3
|
2018-01-05 22:30:17 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
step++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-09 13:49:11 +01:00
|
|
|
|
public void Avancer(int vitesse, int cooX)
|
|
|
|
|
{
|
|
|
|
|
this.cooXMax = cooX;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
this.vitesse = vitesse;
|
|
|
|
|
this.step = 0;
|
|
|
|
|
Avancer();
|
|
|
|
|
}
|
|
|
|
|
public void Avancer(int vitesse, int cooX, int startStep)
|
|
|
|
|
{
|
|
|
|
|
this.cooXMax = cooX;
|
|
|
|
|
this.vitesse = vitesse;
|
|
|
|
|
this.step = startStep;
|
|
|
|
|
Avancer();
|
2018-01-09 13:49:11 +01:00
|
|
|
|
}
|
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
|
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
//Graphics gr = Graphics.FromHwnd(handle.Value);
|
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
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;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
|
|
|
|
|
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
2018-01-06 16:56:46 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
public void Saut(ref PictureBox osbtacle, int vitesse)
|
|
|
|
|
{
|
|
|
|
|
int marcherJusqa = osbtacle.Location.X - bonhomme.conteneur.Location.X - osbtacle.Height - osbtacle.Width - 4*deltaXYmax;
|
|
|
|
|
Avancer(vitesse, marcherJusqa);
|
|
|
|
|
while (bonhomme.Coordonnee.X < osbtacle.Location.X - bonhomme.conteneur.Location.X)//Monter
|
|
|
|
|
{
|
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
|
|
|
|
bonhomme.X += 1;
|
|
|
|
|
bonhomme.Y -= 1;
|
|
|
|
|
if(bonhomme.jambe2.Bas.X < bonhomme.jambe1.Bas.X)
|
|
|
|
|
{
|
|
|
|
|
bonhomme.InterevrtirJambe();
|
|
|
|
|
}
|
|
|
|
|
if(bonhomme.jambe2.Bas.X> bonhomme.jambe1.Bas.X)
|
|
|
|
|
{
|
|
|
|
|
bonhomme.jambe2.BougerBas(-resolution, 0);
|
|
|
|
|
bonhomme.jambe1.BougerBas(resolution, 0);
|
|
|
|
|
}
|
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
while (bonhomme.jambe1.Bas.CSG.Y < ySol)//descendre
|
|
|
|
|
{
|
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Cacher(gr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Cacher(handle.Value);
|
|
|
|
|
bonhomme.X += 1;
|
|
|
|
|
bonhomme.Y += 1;
|
|
|
|
|
if (bonhomme.jambe2.Bas.X < bonhomme.jambe1.Bas.X)
|
|
|
|
|
{
|
|
|
|
|
bonhomme.InterevrtirJambe();
|
|
|
|
|
}
|
|
|
|
|
if (Math.Abs(bonhomme.jambe2.Bas.X - bonhomme.jambe1.Bas.X )< 2*deltaXYmax)
|
|
|
|
|
{
|
|
|
|
|
bonhomme.jambe2.BougerBas(resolution, 0);
|
|
|
|
|
bonhomme.jambe1.BougerBas(-resolution, 0);
|
|
|
|
|
}
|
|
|
|
|
if(handle == null){
|
|
|
|
|
bonhomme.Afficher(gr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonhomme.Afficher(handle.Value);
|
|
|
|
|
|
|
|
|
|
if (handle == null)
|
|
|
|
|
buff.Render();
|
|
|
|
|
Thread.Sleep(vitesse);
|
|
|
|
|
}
|
|
|
|
|
Avancer(vitesse, bonhomme.conteneur.Location.X + bonhomme.conteneur.Width, 3);
|
|
|
|
|
}
|
2018-01-05 22:30:17 +01:00
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
|
2018-01-05 22:30:17 +01:00
|
|
|
|
}
|