Ajout son + gif nyan cat

This commit is contained in:
adri 2018-01-09 13:49:11 +01:00
parent 99ade4831c
commit 20543021ef
14 changed files with 142 additions and 31 deletions

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonhomme02", "Bonhomme02\Bonhomme02.csproj", "{B3C7D374-80DA-45F0-B97F-6320169C1BE7}"
EndProject

View File

@ -10,7 +10,7 @@ namespace Bonhomme02
{
class Bonhomme : Peau
{
Tete tete;
public Tete tete;
public Jambe jambe1, jambe2;
public Bras bras;

View File

@ -93,5 +93,14 @@
<ItemGroup>
<None Include="Resources\moon.jpg" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\tumblr_opsismTLqh1vghf22o1_400.gif" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\nyanCatSound.bmp" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\NyanCatoriginal.wav" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,4 +1,7 @@
namespace Bonhomme02
using System.Drawing;
using System.Windows.Forms;
namespace Bonhomme02
{
partial class Form1
{
@ -29,24 +32,20 @@
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.TV = new System.Windows.Forms.PictureBox();
this.timerImage = new System.Windows.Forms.Timer(this.components);
this.btnEffacer = new System.Windows.Forms.Button();
this.btnStopDeplacerCTick = new System.Windows.Forms.Button();
this.btnCreationCarrosse = new System.Windows.Forms.Button();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.Sol = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.TV)).BeginInit();
this.TV = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.Sol)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.TV)).BeginInit();
this.SuspendLayout();
//
// TV
//
this.TV.Location = new System.Drawing.Point(12, 13);
this.TV.Name = "TV";
this.TV.Size = new System.Drawing.Size(782, 449);
this.TV.TabIndex = 0;
this.TV.TabStop = false;
//
// timerImage
//
this.timerImage.Interval = 500;
@ -56,7 +55,7 @@
//
this.btnEffacer.Location = new System.Drawing.Point(13, 497);
this.btnEffacer.Name = "btnEffacer";
this.btnEffacer.Size = new System.Drawing.Size(389, 23);
this.btnEffacer.Size = new System.Drawing.Size(567, 23);
this.btnEffacer.TabIndex = 10;
this.btnEffacer.Text = "Effacer Tout";
this.btnEffacer.UseVisualStyleBackColor = true;
@ -65,9 +64,9 @@
// btnStopDeplacerCTick
//
this.btnStopDeplacerCTick.Enabled = false;
this.btnStopDeplacerCTick.Location = new System.Drawing.Point(408, 497);
this.btnStopDeplacerCTick.Location = new System.Drawing.Point(584, 497);
this.btnStopDeplacerCTick.Name = "btnStopDeplacerCTick";
this.btnStopDeplacerCTick.Size = new System.Drawing.Size(387, 23);
this.btnStopDeplacerCTick.Size = new System.Drawing.Size(565, 23);
this.btnStopDeplacerCTick.TabIndex = 9;
this.btnStopDeplacerCTick.Text = "Stop Tick";
this.btnStopDeplacerCTick.UseVisualStyleBackColor = true;
@ -77,27 +76,58 @@
//
this.btnCreationCarrosse.Location = new System.Drawing.Point(13, 468);
this.btnCreationCarrosse.Name = "btnCreationCarrosse";
this.btnCreationCarrosse.Size = new System.Drawing.Size(782, 23);
this.btnCreationCarrosse.Size = new System.Drawing.Size(1136, 23);
this.btnCreationCarrosse.TabIndex = 11;
this.btnCreationCarrosse.Text = "Creer Carrosse";
this.btnCreationCarrosse.UseVisualStyleBackColor = true;
this.btnCreationCarrosse.Click += new System.EventHandler(this.btnCreationCarrosse_Click);
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.Color.Gray;
this.pictureBox2.Location = new System.Drawing.Point(995, 13);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(154, 105);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 14;
this.pictureBox2.TabStop = false;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.Silver;
this.pictureBox1.Location = new System.Drawing.Point(750, 224);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(10, 192);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 13;
this.pictureBox1.TabStop = false;
//
// Sol
//
this.Sol.BackgroundImage = global::Bonhomme02.Properties.Resources.moon;
this.Sol.InitialImage = global::Bonhomme02.Properties.Resources.moon;
this.Sol.Location = new System.Drawing.Point(12, 415);
this.Sol.Name = "Sol";
this.Sol.Size = new System.Drawing.Size(782, 47);
this.Sol.Size = new System.Drawing.Size(1137, 47);
this.Sol.TabIndex = 12;
this.Sol.TabStop = false;
//
// TV
//
this.TV.BackColor = System.Drawing.Color.Gray;
this.TV.Location = new System.Drawing.Point(12, 13);
this.TV.Name = "TV";
this.TV.Size = new System.Drawing.Size(1137, 449);
this.TV.TabIndex = 0;
this.TV.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(807, 538);
this.ClientSize = new System.Drawing.Size(1161, 538);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.Sol);
this.Controls.Add(this.btnCreationCarrosse);
this.Controls.Add(this.btnEffacer);
@ -107,9 +137,12 @@
this.Text = "Dessins Animés";
this.Load += new System.EventHandler(this.Form1_Load);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
((System.ComponentModel.ISupportInitialize)(this.TV)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.Sol)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.TV)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
@ -121,6 +154,8 @@
private System.Windows.Forms.Button btnStopDeplacerCTick;
private System.Windows.Forms.Button btnCreationCarrosse;
private System.Windows.Forms.PictureBox Sol;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
}
}

View File

@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -17,13 +19,16 @@ namespace Bonhomme02
private Marcher marche;
private BufferedGraphics bufferG = null;
private Graphics g;
SoundPlayer player = new SoundPlayer();
Stream str = global::Bonhomme02.Properties.Resources.NyanCatoriginal;
List<Task> tasks = new List<Task>();
public Form1()
{
InitializeComponent();
// Modification contre le scintillement - Creation d'une mémoire tampon graphique
bufferG = BufferedGraphicsManager.Current.Allocate(TV.CreateGraphics(), TV.DisplayRectangle);
g = bufferG.Graphics;
}
private void timerImage_Tick(object sender, EventArgs e)
@ -58,13 +63,31 @@ namespace Bonhomme02
{
bonhomme = new Bonhomme(this.TV, 80, 80, 50, 20, Math.PI / 2);
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.tete.Fond = Color.Pink;
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(10));
//this.btnStopDeplacerCTick.Enabled = true;
// this.timerImage.Start();
if (tasks.Count == 0)
{
player.Stream = str;
this.pictureBox2.Image = global::Bonhomme02.Properties.Resources.tumblr_opsismTLqh1vghf22o1_400;
player.Play();
}
// https://msdn.microsoft.com/fr-be/Library/dd270696(v=vs.110).aspx
tasks.Add(Task.Factory.StartNew(() => {
marche.Avancer(1, this.TV.Width);
}));
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) => {
tasks.RemoveAt(0);
if (tasks.Count == 0)
{
player.Stop();
this.pictureBox2.Image = null;
}
});
}
private void Form1_Load(object sender, EventArgs e)

View File

@ -15,7 +15,7 @@ namespace Bonhomme02
int ySol;
int resolution;
int deltaXYmax = 10;
int step;
int step, cooXMax = 0;
public Marcher()
{
@ -50,8 +50,9 @@ namespace Bonhomme02
step = 0;
double old = 1, neww = 0;
int dejaDeplacer = 0;
while(step<=128)
while(step<=110 || bonhomme.X <= cooXMax)
{
old = 1; neww = 0;
Console.WriteLine(step + "::" + step % 5);
dejaDeplacer = 0;
switch (step%5)
@ -80,7 +81,7 @@ namespace Bonhomme02
CollerAuSol(ref bonhomme.jambe2); //Voir issues #24
break;
case 2:
while (bonhomme.jambe1.Bas.CSG.Y < ySol-1 && old != neww) //Descendre jambe 1 sur sol
while (bonhomme.jambe1.Bas.CSG.Y < ySol && old != neww) //Descendre jambe 1 sur sol
{
bonhomme.Cacher(handle);
bonhomme.jambe1.BougerBas(0, resolution);
@ -103,11 +104,23 @@ namespace Bonhomme02
bonhomme.jambe1.BougerBas(-resolution, 0);
if(dejaDeplacer < deltaXYmax)
bonhomme.jambe2.BougerBas(resolution, -resolution);
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;
}
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);
}
break;
@ -123,12 +136,17 @@ namespace Bonhomme02
bonhomme.Cacher(handle);
bonhomme.InterevrtirJambe();// On inverse les deux jambe, jambe1=jambe2 et jambe2=jambe1
bonhomme.Afficher(handle);
step+=2;
step+=3;
break;
}
step++;
}
}
public void Avancer(int vitesse, int cooX)
{
this.cooXMax = cooX;
Avancer(vitesse);
}
public void CollerAuSol(ref Jambe jambe)
{
if (jambe.Bas.CSG.Y != ySol) // On positionne le bonhomme sur le sol

View File

@ -137,6 +137,7 @@ namespace Bonhomme02
if (base.Remplir )
{
gr.FillClosedCurve(new SolidBrush(base.Fond), l);
}
gr.DrawClosedCurve(new Pen(base.Crayon), l);
}

View File

@ -69,5 +69,24 @@ namespace Bonhomme02.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Recherche une ressource localisée de type System.IO.UnmanagedMemoryStream semblable à System.IO.MemoryStream.
/// </summary>
internal static System.IO.UnmanagedMemoryStream NyanCatoriginal {
get {
return ResourceManager.GetStream("NyanCatoriginal", resourceCulture);
}
}
/// <summary>
/// Recherche une ressource localisée de type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap tumblr_opsismTLqh1vghf22o1_400 {
get {
object obj = ResourceManager.GetObject("tumblr_opsismTLqh1vghf22o1_400", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -121,4 +121,10 @@
<data name="moon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\moon.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<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>
</data>
<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>
</data>
</root>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -46,7 +46,7 @@ namespace Bonhomme02
Point posi = new Point(corp.coordonnee.X - rayon , corp.coordonnee.Y - rayon * 2);
if (base.Remplir)
{
gr.FillEllipse(new SolidBrush(Color.Blue), posi.X, posi.Y, rayon * 2, rayon * 2);
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);
}

BIN
NyanCatSound.rct Normal file

Binary file not shown.