Esempio n. 1
0
        void queueTurnPoint() // adds a turn point to the queue so the snake body can turn at the right time
        {
            // make a new turn point for the snake
            TurnPoint newTP = new TurnPoint(snakeHead, mainForm);

            // add it to the queue of turn points
            turnPoints.Add(newTP);
        }
Esempio n. 2
0
        BodyPart bdPart;                                                                                  // body part to be used in testing
        void debugGarbage()                                                                               // this time we are testing the method of checking whether a part crossed a TurnPoint
        {
            bdPart = new BodyPart(0, 0, new Vector(10, 0), this);                                         // make a body part with velocity
            BodyPart marker = new BodyPart(BodyPart.SIZE * 3, BodyPart.SIZE * 3, new Vector(0, 0), this); // will mark the turnpoint

            tp = new TurnPoint(marker, this);
            // change the mouse movement handler to our own custom handler
            MouseMove  += new MouseEventHandler(mouseMoveEvent);
            MouseClick += new MouseEventHandler(runBdPart);               // move body part on mouse click
            marker.picBox.MouseClick += new MouseEventHandler(runBdPart);
            bdPart.picBox.MouseClick += new MouseEventHandler(runBdPart); // move body part on mouse click
        }
Esempio n. 3
0
        // ----- 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
                }
            }
        }