Esempio n. 1
0
 PCharge ResolveCollisions(PCharge chargeA, PCharge[] charges, Vector previousSpeed)
 {
     for (int i = 0; i < charges.Length; i++)
     {
         if (chargeA != charges[i] && chargeA.Bounds.IntersectsWith(charges[i].Bounds) && charges[i].Active == true)
         {
             chargeA.Speed  = new Vector(0, 0);
             chargeA.Bounds = new System.Drawing.RectangleF((float)(chargeA.Bounds.Location.X - previousSpeed.X), (float)(chargeA.Bounds.Location.Y - previousSpeed.Y), chargeA.Bounds.Width, chargeA.Bounds.Height);
             break;
         }
     }
     return(chargeA);
 }
 void RemoveCharges()
 {
     for (int i = 0; i < charges.Length; i++)
     {
         if (ClientRectangle.Contains(Point.Round(charges[i].Bounds.Location)) == false && charges[i].Active == true)
         {
             PCharge[] tempCharges = new PCharge[numOfCharges];
             tempCharges = charges;
             numOfCharges--;
             charges = new PCharge[numOfCharges];
             for (int j = 0; j < i; j++)
             {
                 charges[j] = tempCharges[j];
             }
             for (int j = i; j < charges.Length; j++)
             {
                 charges[j] = tempCharges[j + 1];
             }
             gui.RemoveChargeInfoWidget(i);
         }
     }
 }
        private void BtnCharge_Click(object sender, EventArgs e)
        {
            if (placement.Active == false)
            {
                float charge      = 0;
                float mass        = 0;
                bool  fixedCharge = false;
                float.TryParse(txtCharge.Text, out charge);
                float.TryParse(txtMass.Text, out mass);

                if (chkFixed.CheckState == CheckState.Checked)
                {
                    fixedCharge = true;
                }

                if (mass > 0 && charge != 0)
                {
                    PCharge[] tempCharges = new PCharge[numOfCharges];
                    tempCharges = charges;
                    numOfCharges++;
                    charges = new PCharge[numOfCharges];

                    for (int i = 0; i < tempCharges.Length; i++)
                    {
                        charges[i] = tempCharges[i];
                    }

                    charges[numOfCharges - 1] = new PCharge(false, fixedCharge, charge, mass, 0, 0, 50, 50);
                    placement = new Placement(true, charges[numOfCharges - 1]);
                    gui.AddChargeInfoWidget();
                    lblStatus.Text = "";
                }
                else
                {
                    lblStatus.Text = "Invalid Charge/Mass. Retry.";
                }
            }
        }