Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DateTime sSecondes, sSecondesAncien;
- int i = 0;
- public int NbrePxDeplacementPositif = 1;
- public int NbrePxDeplacementNegatif = -1;
- public int X = 1, Y = 1;
- Point locationPic1 = Point.Empty;
- Point locationPic2 = Point.Empty;
- bool bControle = false;
- public Form1()
- {
- InitializeComponent();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Point p = this.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y));
- Point point = this.pictureBoxBarre.Location;
- // Place la pictureBox sur le curseur
- if ((p.X < 539 - 30) && (p.X > 0 + 45))
- {
- point.X = p.X - 45;
- point.Y = 366;
- this.pictureBoxBarre.Location = point;
- }
- // Permet de régler le rebond
- if (pictureBoxBalle.Location.X > 538)
- {
- X = NbrePxDeplacementNegatif;
- bControle = true;
- }
- if (pictureBoxBalle.Location.Y > 366)
- {
- Y = NbrePxDeplacementNegatif;
- bControle = true;
- }
- if (pictureBoxBalle.Location.X < 0)
- {
- X = NbrePxDeplacementPositif;
- bControle = true;
- }
- if (pictureBoxBalle.Location.Y < 0)
- {
- Y = NbrePxDeplacementPositif;
- bControle = true;
- }
- // Déplace la balle
- Point newlocationPic1 = this.pictureBoxBalle.Location;
- newlocationPic1.X = newlocationPic1.X + X - locationPic1.X;
- newlocationPic1.Y = newlocationPic1.Y + Y - locationPic1.Y;
- this.pictureBoxBalle.Location = newlocationPic1;
- }
- private void pictureBoxBalle_LocationChanged(object sender, EventArgs e)
- {
- /* // if (pictureBoxBalle.Location.Y == 366)
- // MessageBox.Show(Convert.ToString(pictureBoxBalle.Location.X + "," + pictureBoxBarre.Location.X +","+ (pictureBoxBarre.Location.X+88)+","+pictureBoxBalle.Location.Y));
- sSecondes = DateTime.Now;
- TimeSpan ts = sSecondes - sSecondesAncien;
- if (ts.Seconds > 1)
- {
- sSecondesAncien = sSecondes;
- if ((pictureBoxBalle.Location.X >= pictureBoxBarre.Location.X) && (pictureBoxBalle.Location.X <= pictureBoxBarre.Location.X + 88) && (pictureBoxBalle.Location.Y > 362)) // valeur normale = 366
- MessageBox.Show("oo");
- //i++;
- label1.Text = Convert.ToString(i);
- }*/
- // if (pictureBoxBalle.Location.Y == 366)
- // MessageBox.Show(Convert.ToString(pictureBoxBalle.Location.X + "," + pictureBoxBarre.Location.X +","+ (pictureBoxBarre.Location.X+88)+","+pictureBoxBalle.Location.Y));
- /*sSecondes = DateTime.Now;
- TimeSpan ts = sSecondes - sSecondesAncien;
- if (ts.Seconds > 2)
- {
- if ((pictureBoxBalle.Location.X >= pictureBoxBarre.Location.X) && (pictureBoxBalle.Location.X <= pictureBoxBarre.Location.X + 88) && (pictureBoxBalle.Location.Y > 364)) // valeur normale = 366
- {
- i++;
- sSecondesAncien = sSecondes;
- }
- label1.Text = Convert.ToString(i);
- }*/
- sSecondes = DateTime.Now;
- TimeSpan ts = sSecondes - sSecondesAncien;
- if ((bControle == true) && (ts.Seconds > 2))
- {
- if ((pictureBoxBalle.Location.X >= pictureBoxBarre.Location.X) && (pictureBoxBalle.Location.X <= pictureBoxBarre.Location.X + 88) && (pictureBoxBalle.Location.Y > 364)) // valeur normale = 366
- {
- i++;
- sSecondesAncien = sSecondes;
- bControle = false;
- }
- label1.Text = Convert.ToString(i);
- }
- }
- // Permet de déplacer la barre du bas ainsi que la balle selon l'interval du timer
- private void pictureBoxBarre_Click(object sender, EventArgs e)
- {
- timer1.Start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement