Advertisement
Guest User

Untitled

a guest
Jun 13th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.31 KB | None | 0 0
  1.         DateTime sSecondes, sSecondesAncien;
  2.         int i = 0;
  3.         public int NbrePxDeplacementPositif = 1;
  4.         public int NbrePxDeplacementNegatif = -1;
  5.         public int X = 1, Y = 1;
  6.         Point locationPic1 = Point.Empty;
  7.         Point locationPic2 = Point.Empty;
  8.         bool bControle = false;
  9.  
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void timer1_Tick(object sender, EventArgs e)
  16.         {
  17.             Point p = this.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y));
  18.             Point point = this.pictureBoxBarre.Location;
  19.             // Place la pictureBox sur le curseur
  20.             if ((p.X < 539 - 30) && (p.X > 0 + 45))
  21.             {
  22.                 point.X = p.X - 45;
  23.                 point.Y = 366;              
  24.                 this.pictureBoxBarre.Location = point;
  25.             }
  26.             // Permet de régler le rebond
  27.             if (pictureBoxBalle.Location.X > 538)
  28.             {
  29.                 X = NbrePxDeplacementNegatif;
  30.                 bControle = true;
  31.             }
  32.             if (pictureBoxBalle.Location.Y > 366)
  33.             {
  34.                 Y = NbrePxDeplacementNegatif;
  35.                 bControle = true;
  36.             }
  37.             if (pictureBoxBalle.Location.X < 0)
  38.             {
  39.                 X = NbrePxDeplacementPositif;
  40.                 bControle = true;
  41.             }
  42.             if (pictureBoxBalle.Location.Y < 0)
  43.             {
  44.                 Y = NbrePxDeplacementPositif;
  45.                 bControle = true;
  46.             }
  47.             // Déplace la balle
  48.             Point newlocationPic1 = this.pictureBoxBalle.Location;
  49.             newlocationPic1.X = newlocationPic1.X + X - locationPic1.X;
  50.             newlocationPic1.Y = newlocationPic1.Y + Y - locationPic1.Y;
  51.             this.pictureBoxBalle.Location = newlocationPic1;
  52.  
  53.         }
  54.  
  55.         private void pictureBoxBalle_LocationChanged(object sender, EventArgs e)
  56.         {
  57.                    /*  //   if (pictureBoxBalle.Location.Y == 366)
  58.             //    MessageBox.Show(Convert.ToString(pictureBoxBalle.Location.X + "," + pictureBoxBarre.Location.X +","+                (pictureBoxBarre.Location.X+88)+","+pictureBoxBalle.Location.Y));
  59.             sSecondes = DateTime.Now;
  60.             TimeSpan ts = sSecondes - sSecondesAncien;
  61.             if (ts.Seconds > 1)
  62.             {
  63.                 sSecondesAncien = sSecondes;
  64.                 if ((pictureBoxBalle.Location.X >= pictureBoxBarre.Location.X) && (pictureBoxBalle.Location.X <= pictureBoxBarre.Location.X + 88) && (pictureBoxBalle.Location.Y > 362)) // valeur normale = 366
  65.                     MessageBox.Show("oo");
  66.                     //i++;
  67.                 label1.Text = Convert.ToString(i);
  68.             }*/
  69.  
  70.               //   if (pictureBoxBalle.Location.Y == 366)
  71.      //    MessageBox.Show(Convert.ToString(pictureBoxBalle.Location.X + "," + pictureBoxBarre.Location.X +","+ (pictureBoxBarre.Location.X+88)+","+pictureBoxBalle.Location.Y));
  72.  
  73.            
  74.            
  75.      /*sSecondes = DateTime.Now;
  76.      TimeSpan ts = sSecondes - sSecondesAncien;
  77.      if (ts.Seconds > 2)
  78.      {
  79.          if ((pictureBoxBalle.Location.X >= pictureBoxBarre.Location.X) && (pictureBoxBalle.Location.X <= pictureBoxBarre.Location.X + 88) && (pictureBoxBalle.Location.Y > 364)) // valeur normale = 366
  80.              {
  81.                  i++;
  82.                  sSecondesAncien = sSecondes;
  83.              }
  84.          label1.Text = Convert.ToString(i);
  85.      }*/
  86.  
  87.  
  88.  
  89.  
  90.             sSecondes = DateTime.Now;
  91.             TimeSpan ts = sSecondes - sSecondesAncien;
  92.             if ((bControle == true) && (ts.Seconds > 2))
  93.             {
  94.                 if ((pictureBoxBalle.Location.X >= pictureBoxBarre.Location.X) && (pictureBoxBalle.Location.X <= pictureBoxBarre.Location.X + 88) && (pictureBoxBalle.Location.Y > 364)) // valeur normale = 366
  95.                 {
  96.                     i++;
  97.                     sSecondesAncien = sSecondes;
  98.                     bControle = false;
  99.                 }
  100.                 label1.Text = Convert.ToString(i);
  101.             }    
  102.         }
  103.  
  104.         // Permet de déplacer la barre du bas ainsi que la balle selon l'interval du timer
  105.         private void pictureBoxBarre_Click(object sender, EventArgs e)
  106.         {
  107.             timer1.Start();  
  108.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement