Ajout BufferG #bourrin, Bug Fond Noir

This commit is contained in:
adri 2018-01-09 20:19:49 +01:00
parent 20543021ef
commit 4aaaeeefb7
11 changed files with 412 additions and 83 deletions

View File

@ -53,6 +53,22 @@ namespace Bonhomme02
Millieux.Cacher(handle); Millieux.Cacher(handle);
Bas.Cacher(handle); Bas.Cacher(handle);
} }
public new void Afficher(Graphics gr)
{
if(base.Visible)
{
Haut.Afficher(gr);
Millieux.Afficher(gr);
Bas.Afficher(gr);
}
}
public new void Cacher(Graphics gr)
{
Haut.Cacher(gr);
Millieux.Cacher(gr);
Bas.Cacher(gr);
}
public double TrouverAngleHaut(Point pt) public double TrouverAngleHaut(Point pt)
{ {
Point ptOrigine = parent.Coordonnee + parent.longueur; Point ptOrigine = parent.Coordonnee + parent.longueur;

View File

@ -14,6 +14,7 @@ namespace Bonhomme02
private bool _Visible = true; private bool _Visible = true;
private PictureBox _Hebergeur; private PictureBox _Hebergeur;
public Color backGround = Color.Gray;
private Color _Fond = Color.Blue; private Color _Fond = Color.Blue;
private Color _Crayon = Color.Black; private Color _Crayon = Color.Black;
private Boolean remplir = true; private Boolean remplir = true;

View File

@ -13,32 +13,36 @@ namespace Bonhomme02
public Tete tete; public Tete tete;
public Jambe jambe1, jambe2; public Jambe jambe1, jambe2;
public Bras bras; public Bras bras;
public PictureBox conteneur;
public Bonhomme() : base() public Bonhomme() : base()
{ {
} }
public Bonhomme(PictureBox hebergeur) : base( hebergeur) public Bonhomme(ref PictureBox hebergeur) : base( hebergeur)
{ {
this.conteneur = hebergeur;
} }
public Bonhomme(PictureBox hebergeur, double lg, double ep, double angle) : base( hebergeur, lg, ep, angle) public Bonhomme(ref PictureBox hebergeur, double lg, double ep, double angle) : base( hebergeur, lg, ep, angle)
{ {
this.conteneur = hebergeur;
} }
public Bonhomme(PictureBox hebergeur, int xy) : base( hebergeur, xy) public Bonhomme(ref PictureBox hebergeur, int xy) : base( hebergeur, xy)
{ {
this.conteneur = hebergeur;
} }
public Bonhomme(PictureBox hebergeur, int x, int y, double lg, double ep, double angle) : base( hebergeur, x, y, lg, ep, angle) public Bonhomme(ref PictureBox hebergeur, int x, int y, double lg, double ep, double angle) : base( hebergeur, x, y, lg, ep, angle)
{ {
this.conteneur = hebergeur;
Peau me = this; Peau me = this;
jambe1 = new Jambe(hebergeur, ref me, lg, ep/4, Math.PI / 2); jambe2 = new Jambe(hebergeur, ref me, lg, ep / 4, Math.PI / 2); tete = new Tete(hebergeur, ref me, (int)(ep*3.5/4)); jambe1 = new Jambe(hebergeur, ref me, lg, ep/4, Math.PI / 2); jambe2 = new Jambe(hebergeur, ref me, lg, ep / 4, Math.PI / 2); tete = new Tete(hebergeur, ref me, (int)(ep*3.5/4));
bras = new Bras(hebergeur, ref me, lg, ep/4, Math.PI / 2); bras = new Bras(hebergeur, ref me, lg, ep/4, Math.PI / 2);
} }
public Bonhomme(PictureBox hebergeur, ref Peau parent, double lg, double ep, double angle) : base( hebergeur, ref parent, lg, ep, angle) public Bonhomme(ref PictureBox hebergeur, ref Peau parent, double lg, double ep, double angle) : base( hebergeur, ref parent, lg, ep, angle)
{ {
this.conteneur = hebergeur;
} }
public new void Afficher(IntPtr handle) public new void Afficher(IntPtr handle)
{ {
@ -48,14 +52,29 @@ namespace Bonhomme02
jambe2.Afficher(handle); jambe2.Afficher(handle);
bras.Afficher(handle); bras.Afficher(handle);
} }
public new void Afficher(Graphics gr)
public new void Cacher(IntPtr handle)
{ {
base.Cacher(handle); base.Afficher(gr);
tete.Cacher(handle); tete.Afficher(gr);
jambe1.Cacher(handle); jambe1.Afficher(gr);
jambe2.Cacher(handle); jambe2.Afficher(gr);
bras.Cacher(handle); bras.Afficher(gr);
}
public void Afficher()
{
Afficher(conteneur.Handle);
}
public new void Cacher(Graphics gr)
{
base.Cacher(gr);
tete.Cacher(gr);
jambe1.Cacher(gr);
jambe2.Cacher(gr);
bras.Cacher(gr);
}
public void Cacher()
{
Cacher(conteneur.Handle);
} }
public void InterevrtirJambe() public void InterevrtirJambe()
{ {

View File

@ -102,5 +102,8 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\NyanCatoriginal.wav" /> <None Include="Resources\NyanCatoriginal.wav" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Resources\Super Mario Bros Win Stage Sound Effect.wav" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -36,12 +36,12 @@ namespace Bonhomme02
this.btnEffacer = new System.Windows.Forms.Button(); this.btnEffacer = new System.Windows.Forms.Button();
this.btnStopDeplacerCTick = new System.Windows.Forms.Button(); this.btnStopDeplacerCTick = new System.Windows.Forms.Button();
this.btnCreationCarrosse = new System.Windows.Forms.Button(); this.btnCreationCarrosse = new System.Windows.Forms.Button();
this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.NyanCatGif = new System.Windows.Forms.PictureBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.Obstacle = new System.Windows.Forms.PictureBox();
this.Sol = new System.Windows.Forms.PictureBox(); this.Sol = new System.Windows.Forms.PictureBox();
this.TV = new System.Windows.Forms.PictureBox(); this.TV = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NyanCatGif)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Obstacle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.Sol)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Sol)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.TV)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.TV)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -82,25 +82,25 @@ namespace Bonhomme02
this.btnCreationCarrosse.UseVisualStyleBackColor = true; this.btnCreationCarrosse.UseVisualStyleBackColor = true;
this.btnCreationCarrosse.Click += new System.EventHandler(this.btnCreationCarrosse_Click); this.btnCreationCarrosse.Click += new System.EventHandler(this.btnCreationCarrosse_Click);
// //
// pictureBox2 // NyanCatGif
// //
this.pictureBox2.BackColor = System.Drawing.Color.Gray; this.NyanCatGif.BackColor = System.Drawing.Color.Black;
this.pictureBox2.Location = new System.Drawing.Point(995, 13); this.NyanCatGif.Location = new System.Drawing.Point(995, 13);
this.pictureBox2.Name = "pictureBox2"; this.NyanCatGif.Name = "NyanCatGif";
this.pictureBox2.Size = new System.Drawing.Size(154, 105); this.NyanCatGif.Size = new System.Drawing.Size(154, 105);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.NyanCatGif.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 14; this.NyanCatGif.TabIndex = 14;
this.pictureBox2.TabStop = false; this.NyanCatGif.TabStop = false;
// //
// pictureBox1 // Obstacle
// //
this.pictureBox1.BackColor = System.Drawing.Color.Silver; this.Obstacle.BackColor = System.Drawing.Color.Silver;
this.pictureBox1.Location = new System.Drawing.Point(750, 224); this.Obstacle.Location = new System.Drawing.Point(750, 224);
this.pictureBox1.Name = "pictureBox1"; this.Obstacle.Name = "Obstacle";
this.pictureBox1.Size = new System.Drawing.Size(10, 192); this.Obstacle.Size = new System.Drawing.Size(10, 192);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.Obstacle.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 13; this.Obstacle.TabIndex = 13;
this.pictureBox1.TabStop = false; this.Obstacle.TabStop = false;
// //
// Sol // Sol
// //
@ -114,7 +114,7 @@ namespace Bonhomme02
// //
// TV // TV
// //
this.TV.BackColor = System.Drawing.Color.Gray; this.TV.BackColor = System.Drawing.Color.Black;
this.TV.Location = new System.Drawing.Point(12, 13); this.TV.Location = new System.Drawing.Point(12, 13);
this.TV.Name = "TV"; this.TV.Name = "TV";
this.TV.Size = new System.Drawing.Size(1137, 449); this.TV.Size = new System.Drawing.Size(1137, 449);
@ -126,19 +126,20 @@ namespace Bonhomme02
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1161, 538); this.ClientSize = new System.Drawing.Size(1161, 538);
this.Controls.Add(this.pictureBox2); this.Controls.Add(this.NyanCatGif);
this.Controls.Add(this.pictureBox1); this.Controls.Add(this.Obstacle);
this.Controls.Add(this.Sol); this.Controls.Add(this.Sol);
this.Controls.Add(this.btnCreationCarrosse); this.Controls.Add(this.btnCreationCarrosse);
this.Controls.Add(this.btnEffacer); this.Controls.Add(this.btnEffacer);
this.Controls.Add(this.btnStopDeplacerCTick); this.Controls.Add(this.btnStopDeplacerCTick);
this.Controls.Add(this.TV); this.Controls.Add(this.TV);
this.DoubleBuffered = true;
this.Name = "Form1"; this.Name = "Form1";
this.Text = "Dessins Animés"; this.Text = "Dessins Animés";
this.Load += new System.EventHandler(this.Form1_Load); this.Load += new System.EventHandler(this.Form1_Load);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NyanCatGif)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Obstacle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.Sol)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Sol)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.TV)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.TV)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -154,8 +155,8 @@ namespace Bonhomme02
private System.Windows.Forms.Button btnStopDeplacerCTick; private System.Windows.Forms.Button btnStopDeplacerCTick;
private System.Windows.Forms.Button btnCreationCarrosse; private System.Windows.Forms.Button btnCreationCarrosse;
private System.Windows.Forms.PictureBox Sol; private System.Windows.Forms.PictureBox Sol;
private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox Obstacle;
private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox NyanCatGif;
} }
} }

View File

@ -20,7 +20,7 @@ namespace Bonhomme02
private BufferedGraphics bufferG = null; private BufferedGraphics bufferG = null;
private Graphics g; private Graphics g;
SoundPlayer player = new SoundPlayer(); SoundPlayer player = new SoundPlayer();
Stream str = global::Bonhomme02.Properties.Resources.NyanCatoriginal; Stream str;
List<Task> tasks = new List<Task>(); List<Task> tasks = new List<Task>();
public Form1() public Form1()
{ {
@ -40,10 +40,10 @@ namespace Bonhomme02
} }
else else
{ {
bonhomme.Cacher(this.TV.Handle); bonhomme.Cacher(g);
bonhomme.coordonnee = new Point(bonhomme.coordonnee.X + 3, bonhomme.coordonnee.Y + 0); bonhomme.coordonnee = new Point(bonhomme.coordonnee.X + 3, bonhomme.coordonnee.Y + 0);
bonhomme.jambe1.BougerBas(+3, -3); bonhomme.jambe1.BougerBas(+3, -3);
bonhomme.Afficher(this.TV.Handle); bonhomme.Afficher(g);
} }
} }
@ -62,22 +62,23 @@ namespace Bonhomme02
private void btnCreationCarrosse_Click(object sender, EventArgs e) private void btnCreationCarrosse_Click(object sender, EventArgs e)
{ {
bonhomme = new Bonhomme(this.TV, 80, 80, 50, 20, Math.PI / 2); bonhomme = new Bonhomme(ref this.TV, 80, 80, 50, 20, Math.PI / 2);
bonhomme.jambe1.Bas.Fond = bonhomme.jambe1.Millieux.Fond = bonhomme.jambe1.Haut.Fond = Color.Pink; bonhomme.jambe1.Bas.Fond = bonhomme.jambe1.Millieux.Fond = bonhomme.jambe1.Haut.Fond = Color.Pink;
bonhomme.jambe2.Bas.Fond = bonhomme.jambe2.Millieux.Fond = bonhomme.jambe2.Haut.Fond = Color.DeepPink; bonhomme.jambe2.Bas.Fond = bonhomme.jambe2.Millieux.Fond = bonhomme.jambe2.Haut.Fond = Color.DeepPink;
bonhomme.tete.Fond = Color.Pink; bonhomme.tete.Fond = Color.Pink;
bonhomme.Afficher(this.TV.Handle); bonhomme.Afficher(g);
marche = new Marcher(ref bonhomme, this.TV.Handle, this.Sol.Location.Y-this.TV.Location.Y); marche = new Marcher(ref bonhomme, bufferG, this.Sol.Location.Y-this.TV.Location.Y);
Thread.Sleep(1000); Thread.Sleep(1000);
if (tasks.Count == 0) if (tasks.Count == 0)
{ {
str = global::Bonhomme02.Properties.Resources.NyanCatoriginal;
player.Stream = str; player.Stream = str;
this.pictureBox2.Image = global::Bonhomme02.Properties.Resources.tumblr_opsismTLqh1vghf22o1_400; this.NyanCatGif.Image = global::Bonhomme02.Properties.Resources.tumblr_opsismTLqh1vghf22o1_400;
player.Play(); player.Play();
} }
// https://msdn.microsoft.com/fr-be/Library/dd270696(v=vs.110).aspx // https://msdn.microsoft.com/fr-be/Library/dd270696(v=vs.110).aspx
tasks.Add(Task.Factory.StartNew(() => { tasks.Add(Task.Factory.StartNew(() => {
marche.Avancer(1, this.TV.Width); marche.Saut(ref this.Obstacle, 1);
})); }));
var continuation = Task.WhenAll(tasks); //https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/chaining-tasks-by-using-continuation-tasks var continuation = Task.WhenAll(tasks); //https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/chaining-tasks-by-using-continuation-tasks
Task continuationTask = continuation.ContinueWith((antecedent) => { Task continuationTask = continuation.ContinueWith((antecedent) => {
@ -85,7 +86,10 @@ namespace Bonhomme02
if (tasks.Count == 0) if (tasks.Count == 0)
{ {
player.Stop(); player.Stop();
this.pictureBox2.Image = null; str = str = global::Bonhomme02.Properties.Resources.Super_Mario_Bros_Win_Stage_Sound_Effect;
player.Stream = str;
player.Play();
this.NyanCatGif.Image = null;
} }
}); });
} }

View File

@ -5,17 +5,21 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading; using System.Threading;
using System.Drawing; using System.Drawing;
using System.Windows.Forms;
namespace Bonhomme02 namespace Bonhomme02
{ {
class Marcher class Marcher
{ {
Bonhomme bonhomme; Bonhomme bonhomme;
IntPtr handle; IntPtr? handle;
Graphics gr;
BufferedGraphics buff;
int ySol; int ySol;
int resolution; int resolution;
int deltaXYmax = 10; int deltaXYmax = 10;
int step, cooXMax = 0; int step, cooXMax = 0;
int vitesse;
public Marcher() public Marcher()
{ {
@ -37,20 +41,58 @@ namespace Bonhomme02
if(bonhomme.jambe1.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol if(bonhomme.jambe1.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol
{ {
Graphics gr = Graphics.FromHwnd(handle); Graphics gr = Graphics.FromHwnd(handle);
if(handle == null){
bonhomme.Cacher(gr);
buff.Render();
}
else
bonhomme.Cacher(handle); bonhomme.Cacher(handle);
Point newCoo; Point newCoo;
int longeurTTBonhome = bonhomme.jambe1.Bas.CSG.Y - bonhomme.CIG.Y ;// de pied.csg à bonhome.cig int longeurTTBonhome = bonhomme.jambe1.Bas.CSG.Y - bonhomme.CIG.Y ;// de pied.csg à bonhome.cig
newCoo = new Point(bonhomme.CIG.X, ySol - longeurTTBonhome); newCoo = new Point(bonhomme.CIG.X, ySol - longeurTTBonhome);
bonhomme.Coordonnee = newCoo; bonhomme.Coordonnee = newCoo;
if(handle == null){
bonhomme.Afficher(gr);
buff.Render();
}
else
bonhomme.Afficher(handle); bonhomme.Afficher(handle);
} }
} }
public void Avancer(int vitesse) public Marcher(ref Bonhomme bonhomme, BufferedGraphics buff, int ySol)
{ {
handle = null;
step = 0; step = 0;
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()
{
double old = 1, neww = 0; double old = 1, neww = 0;
int dejaDeplacer = 0; int dejaDeplacer = 0;
while(step<=110 || bonhomme.X <= cooXMax) while(/*step<=110 || */bonhomme.X <= cooXMax)
{ {
old = 1; neww = 0; old = 1; neww = 0;
Console.WriteLine(step + "::" + step % 5); Console.WriteLine(step + "::" + step % 5);
@ -60,10 +102,20 @@ namespace Bonhomme02
case 0: case 0:
while (dejaDeplacer < deltaXYmax) //Monte jambe 1 while (dejaDeplacer < deltaXYmax) //Monte jambe 1
{ {
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
bonhomme.jambe1.BougerBas(0, -resolution); bonhomme.jambe1.BougerBas(0, -resolution);
bonhomme.Afficher(handle); if(handle == null){
bonhomme.Afficher(gr);
}
else
bonhomme.Afficher(handle.Value);
dejaDeplacer += resolution; dejaDeplacer += resolution;
if (handle == null)
buff.Render();
Thread.Sleep(vitesse); Thread.Sleep(vitesse);
} }
@ -71,11 +123,23 @@ namespace Bonhomme02
case 1: case 1:
while (dejaDeplacer < deltaXYmax)//avence corp + avancer jambe 1 jambe 2 fixe while (dejaDeplacer < deltaXYmax)//avence corp + avancer jambe 1 jambe 2 fixe
{ {
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
bonhomme.jambe2.BougerXHaut(resolution, ref bonhomme); bonhomme.jambe2.BougerXHaut(resolution, ref bonhomme);
bonhomme.jambe1.BougerBas(resolution, 0); bonhomme.jambe1.BougerBas(resolution, 0);
bonhomme.Afficher(handle); if(handle == null){
bonhomme.Afficher(gr);
}
else
bonhomme.Afficher(handle.Value);
dejaDeplacer += resolution; dejaDeplacer += resolution;
if (handle == null)
buff.Render();
Thread.Sleep(vitesse); Thread.Sleep(vitesse);
} }
CollerAuSol(ref bonhomme.jambe2); //Voir issues #24 CollerAuSol(ref bonhomme.jambe2); //Voir issues #24
@ -83,10 +147,22 @@ namespace Bonhomme02
case 2: case 2:
while (bonhomme.jambe1.Bas.CSG.Y < ySol && old != neww) //Descendre jambe 1 sur sol while (bonhomme.jambe1.Bas.CSG.Y < ySol && old != neww) //Descendre jambe 1 sur sol
{ {
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
bonhomme.jambe1.BougerBas(0, resolution); bonhomme.jambe1.BougerBas(0, resolution);
bonhomme.Afficher(handle); if(handle == null){
bonhomme.Afficher(gr);
}
else
bonhomme.Afficher(handle.Value);
dejaDeplacer += resolution; dejaDeplacer += resolution;
if (handle == null)
buff.Render();
Thread.Sleep(vitesse); Thread.Sleep(vitesse);
if (neww != bonhomme.jambe1.Bas.CSG.Y) if (neww != bonhomme.jambe1.Bas.CSG.Y)
{ {
@ -98,9 +174,18 @@ namespace Bonhomme02
break; break;
case 3: case 3:
if (bonhomme.jambe2.Bas.X > bonhomme.jambe1.Bas.X)
{
bonhomme.InterevrtirJambe();
}
while (dejaDeplacer < (deltaXYmax*2))//Monte&avance jambe 2,avance bonhome while (dejaDeplacer < (deltaXYmax*2))//Monte&avance jambe 2,avance bonhome
{ {
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
bonhomme.jambe1.BougerBas(-resolution, 0); bonhomme.jambe1.BougerBas(-resolution, 0);
if(dejaDeplacer < deltaXYmax) if(dejaDeplacer < deltaXYmax)
bonhomme.jambe2.BougerBas(resolution, -resolution); bonhomme.jambe2.BougerBas(resolution, -resolution);
@ -118,25 +203,56 @@ namespace Bonhomme02
else else
bonhomme.jambe2.BougerBas(resolution, 0); bonhomme.jambe2.BougerBas(resolution, 0);
bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y); bonhomme.Coordonnee = new Point(bonhomme.Coordonnee.X + resolution, bonhomme.Coordonnee.Y);
bonhomme.Afficher(handle); if(handle == null){
dejaDeplacer += resolution; bonhomme.Afficher(gr);
}
else
bonhomme.Afficher(handle.Value);
dejaDeplacer += resolution;
if (handle == null)
buff.Render();
Thread.Sleep(vitesse); Thread.Sleep(vitesse);
} }
break; break;
case 4: case 4:
while (bonhomme.jambe2.Bas.CSG.Y < ySol - 1 && old != neww)//Descend jambe 2 while (bonhomme.jambe2.Bas.CSG.Y < ySol - 1 && old != neww)//Descend jambe 2
{ {
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
bonhomme.jambe2.BougerBas(0, resolution); bonhomme.jambe2.BougerBas(0, resolution);
bonhomme.Afficher(handle); if(handle == null){
bonhomme.Afficher(gr);
}
else
bonhomme.Afficher(handle.Value);
dejaDeplacer += resolution; dejaDeplacer += resolution;
if (handle == null)
buff.Render();
Thread.Sleep(vitesse); Thread.Sleep(vitesse);
} }
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
bonhomme.InterevrtirJambe();// On inverse les deux jambe, jambe1=jambe2 et jambe2=jambe1 bonhomme.InterevrtirJambe();// On inverse les deux jambe, jambe1=jambe2 et jambe2=jambe1
bonhomme.Afficher(handle); if(handle == null){
step+=3; bonhomme.Afficher(gr);
}
else
bonhomme.Afficher(handle.Value);
if (handle == null)
buff.Render();
step +=3; // retour step 3
break; break;
} }
step++; step++;
@ -145,20 +261,104 @@ namespace Bonhomme02
public void Avancer(int vitesse, int cooX) public void Avancer(int vitesse, int cooX)
{ {
this.cooXMax = cooX; this.cooXMax = cooX;
Avancer(vitesse); 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();
} }
public void CollerAuSol(ref Jambe jambe) public void CollerAuSol(ref Jambe jambe)
{ {
if (jambe.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol if (jambe.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol
{ {
Graphics gr = Graphics.FromHwnd(handle); //Graphics gr = Graphics.FromHwnd(handle.Value);
bonhomme.Cacher(handle); if(handle == null){
bonhomme.Cacher(gr);
}
else
bonhomme.Cacher(handle.Value);
Point newCoo; Point newCoo;
int longeurTTBonhome = jambe.Bas.CSG.Y - bonhomme.CIG.Y;// de pied.csg à bonhome.cig int longeurTTBonhome = jambe.Bas.CSG.Y - bonhomme.CIG.Y;// de pied.csg à bonhome.cig
newCoo = new Point(bonhomme.Coordonnee.X, ySol - longeurTTBonhome); newCoo = new Point(bonhomme.Coordonnee.X, ySol - longeurTTBonhome);
bonhomme.Coordonnee = newCoo; bonhomme.Coordonnee = newCoo;
bonhomme.Afficher(handle); if(handle == null){
bonhomme.Afficher(gr);
} }
else
bonhomme.Afficher(handle.Value);
if (handle == null)
buff.Render();
}
}
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);
} }
} }

View File

@ -93,11 +93,19 @@ namespace Bonhomme02
public int X public int X
{ {
get { return Coordonnee.X; } get { return Coordonnee.X; }
set
{
Coordonnee = new Point(value, Coordonnee.Y);
}
} }
public int Y public int Y
{ {
get { return Coordonnee.Y; } get { return Coordonnee.Y; }
set
{
Coordonnee = new Point(Coordonnee.X, value);
}
} }
public double Angle public double Angle
{ {
@ -167,6 +175,45 @@ namespace Bonhomme02
} }
} }
public virtual void Afficher(Graphics gr)
{
if(base.Visible)
{
try
{
Point[] l = new Point[4] { CIG, CID, CSD, CSG };
if (base.Remplir )
{
gr.FillClosedCurve(new SolidBrush(base.Fond), l);
}
gr.DrawClosedCurve(new Pen(base.Crayon), l);
}
catch
{
}
}
}
public virtual void Cacher(Graphics gr)
{
try
{
if (base.Visible && 1 == 1)
{
Point[] l = new Point[4] { CIG, CID, CSD, CSG };
if (base.Remplir)
{
gr.FillClosedCurve(new SolidBrush(base.Hebergeur.BackColor), l);
}
gr.DrawClosedCurve(new Pen(base.Hebergeur.BackColor), l);
}
}
catch
{
}
}
#endregion #endregion
} }
} }

View File

@ -79,6 +79,15 @@ namespace Bonhomme02.Properties {
} }
} }
/// <summary>
/// Recherche une ressource localisée de type System.IO.UnmanagedMemoryStream semblable à System.IO.MemoryStream.
/// </summary>
internal static System.IO.UnmanagedMemoryStream Super_Mario_Bros_Win_Stage_Sound_Effect {
get {
return ResourceManager.GetStream("Super_Mario_Bros_Win_Stage_Sound_Effect", resourceCulture);
}
}
/// <summary> /// <summary>
/// Recherche une ressource localisée de type System.Drawing.Bitmap. /// Recherche une ressource localisée de type System.Drawing.Bitmap.
/// </summary> /// </summary>

View File

@ -124,6 +124,9 @@
<data name="NyanCatoriginal" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="NyanCatoriginal" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NyanCatoriginal.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>..\Resources\NyanCatoriginal.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="Super_Mario_Bros_Win_Stage_Sound_Effect" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Super Mario Bros Win Stage Sound Effect.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="tumblr_opsismTLqh1vghf22o1_400" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="tumblr_opsismTLqh1vghf22o1_400" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\tumblr_opsismTLqh1vghf22o1_400.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\tumblr_opsismTLqh1vghf22o1_400.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>

View File

@ -51,6 +51,32 @@ namespace Bonhomme02
gr.DrawEllipse(new Pen(Brushes.Black), posi.X, posi.Y, rayon * 2, rayon * 2); gr.DrawEllipse(new Pen(Brushes.Black), posi.X, posi.Y, rayon * 2, rayon * 2);
} }
} }
public void Cacher(Graphics gr)
{
Point posi = new Point(corp.coordonnee.X - rayon, corp.coordonnee.Y - rayon * 2);
if (base.Visible)
{
if (base.Remplir)
{
gr.FillEllipse(new SolidBrush(base.Hebergeur.BackColor), posi.X, posi.Y, rayon * 2, rayon * 2);
}
gr.DrawEllipse(new Pen(base.Hebergeur.BackColor), posi.X, posi.Y, rayon * 2, rayon * 2);
}
}
public void Afficher(Graphics gr)
{
if (base.Visible)
{
Point posi = new Point(corp.coordonnee.X - rayon, corp.coordonnee.Y - rayon * 2);
if (base.Remplir)
{
gr.FillEllipse(new SolidBrush(base.Fond), posi.X, posi.Y, rayon * 2, rayon * 2);
}
gr.DrawEllipse(new Pen(Brushes.Black), posi.X, posi.Y, rayon * 2, rayon * 2);
}
}
} }
} }