void redIfCrossed() // make red if crossed { if (tp.Crossed(bdPart)) // testing if this method correct checks if crossed turn point { // --- SETTING PICBOX TO RED CODE----- bdPart.picBox.Image = null; bdPart.picBox.BackColor = Color.Red; // ---- END OF RED SET CODE } else if (bdPart.picBox.Image == null) // reset image appearance if not crossed { bdPart.picBox.Image = Properties.Resources.green_box_hi; } }
// ----- END OF SIZE CHANGING CODE public void run(double time) // time is interval between each trigger of this function { // if (fireworks != null) // if firework is not null, the snake was destroyed in glorified fashion { fireworks.run(); // check if particles are done if (!(fireworks.particles.Count > 0)) { // delete it now the particles have finished fireworks = null; } } // loop throuhg all the snakes and trigger their run functions foreach (BodyPart bdPart in bodyParts) { bdPart.run(); // each bodypart moves } // check each turn point's current to-be-checked body part is ready to be influenced int i = 0; while (i < turnPoints.Count()) // loop through all turn points { TurnPoint tp = turnPoints[i]; // retrieve the current body part to-be-checked BodyPart bdPart; try { bdPart = bodyParts[tp.PartsCount]; } catch (ArgumentOutOfRangeException e) // for when the clipping occurs randomly { // delete the turn point tp.finalizer(); // call ending function in the turnpoint turnPoints.Remove(tp); // don't increment i so we dont skip an item as we just removed one continue; } // put bdPart the coords in an array for checking int[] picCoords = new int[] { bdPart.picBox.Location.X, bdPart.picBox.Location.Y }; // if the part occupies the turning point, change its velocity //if (picCoords.SequenceEqual(tp.Coords)) // check if coords are same HERE if (tp.Crossed(bdPart)) { // change the direction of the body part's velocity bdPart.velocity.Degrees = tp.Angle; // add to the count tp.PartsCount += 1; fixPos(bdPart); Console.WriteLine("Turning point collision!"); } // delete the turn point if all the parts have been influenced if (tp.PartsCount >= bodyParts.Count()) { // call ending function in the turnpoint tp.finalizer(); turnPoints.Remove(tp); // don't increment i so we dont skip an item as we just removed one } else { i++; // incrememnt i because there is no risk of skipping a turn point here } } }