//--------------------------------------------- PBEntite[2] = new PictureBox { ImageLocation = (@"Image\Block.png"), Width =70 , Height =70 , Left =350 , Top =480 , = false//sauf que là y'a rien à quoi affecter false. };
int[] lesWidths = {280,700,70,70,70,70,70,560,70,70,350,280,70,70,70,350}; for (int i = 0; i < PBEntite.Length; i++) { PBEntite[i] = new PictureBox { ImageLocation = (@"Image\Block.png"), Width =lesWidths[i], Height = 140,//xn--crer-cpa le tableau des Heigts Left = 1700,//xn--crer-cpa le tableau des les lefts Top = 255,// créer le tableau des Top //xn--crer-cpa le tableau des trucs qui peuvent être false }; Controls.Add(PBEntite[0]); }
= falseIl faut quelquechose devant le égal....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LAsSautSix
{
public partial class Fond : Form
{
// variable public
PictureBox[] PBEntite = new PictureBox[16];
PictureBox[] pNPiege = new PictureBox[7];
int[] LesWidth = new int[] { 700, 70, 70, 70, 70, 70, 560, 70, 70, 350, 280, 70, 70, 70, 280, 350 };
int[] LesHeight = new int[] { 70, 70, 70, 280, 210, 210, 70, 280, 420, 70, 70, 70, 70, 70, 140,70 };
int[] LesLeft = new int[] { 130, 350, 500, 580, 580, 850, 850, 1340, 1340, 1060, 1700, 1840, 1630, 1490, 1700, 0 };
int[] LesTop = new int[] { 885, 480, 675, -70, 450, 185, 325, 325, 535, 885, 885, 745, 605, 465, 255, 1085 };
int[] LesWidthPieges = new int[] { 172, 70, 70, 210, 70, 210, 210 };
int[] lesHeightPiges = new int[] { 70, 207, 207, 70, 620, 70, 70 };
int[] LesLeftPieges = new int[] { 500, 510, 780, 1130, 1410, 1770, 1920 };
int[] LesTopPieges = new int[] { 815, 0, 186, 815, 326, 815, 255};
string[] LesString = new string[] { "N", "W", "W", "N", "E", "N", "N" };
bool ToucheGauche = false;
bool ToucheDroite = false;
bool ToucheSaut = false;
int Vitesse = 0;
const int Vitt = 10;
bool bInPossibleG = false;
bool bInPossibleD = false;
// variable public
public Fond()
{
InitializeComponent();
InitializeMap1();
}
private void InitializeMap1()
{
for (int i = 0; i <PBEntite.Length;i++)
{
PBEntite[i] = new PictureBox
{
Width = LesWidth[i],
Height = LesHeight[i],
Left = LesLeft[i],
Top = LesTop[i],
ImageLocation = (@"Image\Block.png"),
};
Controls.Add(PBEntite[i]);
}
for(int i = 0; i < pNPiege.Length; i++)
{
pNPiege[i] = new PictureBox
{
Width = LesWidthPieges[i],
Height = lesHeightPiges[i],
BackColor = Color.Transparent,
Top = LesTopPieges[i],
Left = LesLeftPieges[i],
ImageLocation = string.Format(@"Image\PIC_{0}.png", LesString[i]),
// mets en invisible les pieges
// Visible = false,
};
Controls.Add(pNPiege[i]);
};
}
// Touche pressé
private void Fond_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Space:
ToucheSaut = true;
break;
case Keys.Left:
ToucheGauche = true;
break;
case Keys.Right:
ToucheDroite = true;
break;
}
}
// Fin Touche pressé
// Touche relevé
private void Fond_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Space:
ToucheSaut = false;
break;
case Keys.Left:
ToucheGauche = false;
break;
case Keys.Right:
ToucheDroite = false;
break;
}
}
// Fin touche relevé
private void VraiTimer_Tick(object sender, EventArgs e)
{
Gravite();
Deplacement();
}
// Action des déplacement gauche et droite
public void Deplacement()
{
bInPossibleD = false;
bInPossibleG = false;
for(int i = 0; i < PBEntite.Length; i++)
{
if (ColisionDroite(PBEntite[i]))
{
bInPossibleD = true;
}
if (ColisionGauche(PBEntite[i]))
{
bInPossibleG = true;
}
}
}
// Fin de l'action des déplacement gauche et droite
//xn--dplacement-b7a de l'axe verticale
public void Gravite()
{
bool sautPossible = false;
if (Vitesse > 0)
{
for(int i = 0; i < PBEntite.Length; i++)
{
if (Descendant(PBEntite[i]))
{
pbPlayer.Top = PBEntite[i].Top - pbPlayer.Height;
Vitesse = 0;
sautPossible = true;
}
}
}
if (Vitesse < 0)
{
for (int i = 0; i < PBEntite.Length; i++)
{
if (Montant(PBEntite[i]))
{
pbPlayer.Top = PBEntite[i].Top + PBEntite[i].Height;
Vitesse = 0;
}
}
}
// Vérification si saut effectif
if (ToucheSaut == true && Vitesse == 0 && sautPossible == true)
{
Vitesse = -pbPlayer.Height / 6;
pbPlayer.Top -= 5;
}
// Fin de la vérification si saut effectif
pbPlayer.Top += Vitesse;
if (Vitesse + 1 <= 25)
{
Vitesse++;
}
//====================================================
if (bInPossibleD != true && ToucheDroite == true && ToucheGauche == false)
{
pbPlayer.Left += Vitt;
}
if (bInPossibleG != true && ToucheDroite == false && ToucheGauche == true)
{
pbPlayer.Left -= Vitt;
}
}
// Fin Déplacement de l'axe verticale
// Vérification des collisions avec Le déplacement droite
public bool ColisionDroite(PictureBox Brique)
{
if (pbPlayer.Top < Brique.Top + Brique.Height && pbPlayer.Top + pbPlayer.Height > Brique.Top && pbPlayer.Left + Vitt < Brique.Left + Brique.Width && pbPlayer.Left + pbPlayer.Width + Vitt > Brique.Left)
{
return true;
}
else
{
return false;
}
}
// Fin des vérification des collisions avec Le déplacement droite
// Vérification des collisions avec Le déplacement gauche
public bool ColisionGauche(PictureBox Brique)
{
if (pbPlayer.Top < Brique.Top + Brique.Height && pbPlayer.Top + pbPlayer.Height > Brique.Top && pbPlayer.Left - Vitt < Brique.Left + Brique.Width && pbPlayer.Left + pbPlayer.Width - Vitt > Brique.Left)
{
return true;
}
else
{
return false;
}
}
// Fin des vérification des collisions avec Le déplacement gauche
// Vérification des colision avec des block
public bool Descendant(PictureBox Block)
{
if (pbPlayer.Left < Block.Left + Block.Width && pbPlayer.Left + pbPlayer.Width > Block.Left)
{
if (pbPlayer.Top + pbPlayer.Height + Vitesse > Block.Top && pbPlayer.Top + Vitesse < Block.Top + Block.Height)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
// Fin des Vérifications des collisions avec des blocks
public bool Montant(PictureBox Block)
{
if (pbPlayer.Left < Block.Left + Block.Width && pbPlayer.Left + pbPlayer.Width > Block.Left)
{
if (pbPlayer.Top + Vitesse < Block.Top + Block.Height && pbPlayer.Top + pbPlayer.Height + Vitesse > Block.Top)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question