示例#1
0
        private void RacingBehaviour()//Vector maths for piranha swimming towards chicken leg
        {
            //Standard tokenposition converstion to a vector
            Vector3 tokenPosition = this.PossessedToken.Position;

            //Passes through the position of the chicken leg to the Piranha
            mFeedingPosition = tokenPosition - mAquarium.ChickenLeg.Position;
            //Vector normalisation to prevent piranha swimming off of the stage in one game tick
            mFeedingPosition.Normalize();
            //Movement towards the chicken leg
            tokenPosition = tokenPosition - mFeedingPosition * mSpeedX;
            //Reassigns values after calculations have been completed
            this.PossessedToken.Position = tokenPosition;

            //Two bools check for the X and Y axis to check piranha position relative to the ChickenLeg
            //X bool positional check
            if (tokenPosition.X - mAquarium.ChickenLeg.Position.X <= 3 && tokenPosition.X - mAquarium.ChickenLeg.Position.X >= -3)
            {
                checkLegX = true;
            }

            //Y bool positional check
            if (tokenPosition.Y - mAquarium.ChickenLeg.Position.Y <= 3 && tokenPosition.Y - mAquarium.ChickenLeg.Position.Y >= -3)
            {
                checkLegY = true;
            }

            //If both bools return true - then leg is set to null, and bools are reset
            if (checkLegX && checkLegY == true)
            {
                //Adds score to the winning team of that round
                if (teamNumber == 1)
                {
                    //Adds one to team ones score
                    team_1_Score += 1;
                }
                else if (teamNumber == 2)
                {
                    //Adds one to team twos score
                    team_2_Score += 1;
                }

                //Reset code
                //Removes Chicken Leg from scene
                mAquarium.RemoveChickenLeg();
                //Resets bool checks for position of pirahna in relation to chicken leg
                checkLegX = false;
                checkLegY = false;
                // Sets the fish to inactive
                active = false;
                //Selects the next Piranha that plays
                PiranhaPlayer();

                //Prints out the score of each team
                Console.WriteLine("Team 1 score = {0}", team_1_Score);
                Console.WriteLine("Team 2 score = {0}", team_2_Score);
            }
        }
示例#2
0
        /// <summary>
        /// AI Update method.
        /// </summary>
        /// <param name="pGameTime">Game time</param>


        public override void Update(ref GameTime pGameTime)
        {
            if (firstUpdate)
            {
                // Randomise the point the fish will start on along the sin/cos circle
                currentSin += rand.Next(0, 101);
                currentSin /= 100;

                // Face the fish towards the center of the screen
                if ((PossessedToken as PiranhaToken).TeamNum == 1)
                {
                    facingDirectionX = -1;
                }
                else
                {
                    facingDirectionX = 1;

                    // Invert the direction the fish swims along the sin/cos circle
                    sinIncrement *= -1;
                }

                PossessedToken.Orientation = new Vector3(facingDirectionX, PossessedToken.Orientation.Y, PossessedToken.Orientation.Z);

                firstUpdate = false;
            }

            tokenPosition = PossessedToken.Position; // Store the current position of the bubble

            // The game has ended and this fish is on the winning team
            if (swimming)
            {
                // Continue swimming off the edge of the screen
                tokenPosition.X += speed;

                speed += speedIncrease;
            }
            // If the chicken leg is in the aquarium
            else if (seeking)
            {
                // Get direction from the token to the chicken leg
                Vector2 direction = new Vector2(chickenLegPosition.X - tokenPosition.X, chickenLegPosition.Y - tokenPosition.Y);

                if (direction.Length() <= radius) // If token has reached the chicken leg
                {
                    if (aquarium.ChickenLeg != null)
                    {
                        aquarium.RemoveChickenLeg();

                        full = true;
                    }
                }
                else
                {
                    // Normalise direction, calculating how far to move this frame
                    direction  = Vector2.Normalize(direction);
                    direction *= speed;

                    // Move towards the chicken leg
                    tokenPosition += new Vector3(direction.X, direction.Y, 0);
                }
            }
            else if (returning)
            {
                // Get direction from the token to its original position
                Vector2 direction = new Vector2(originalPosition.X - tokenPosition.X, originalPosition.Y - tokenPosition.Y);

                if (direction.Length() <= speed) // If token would step over its original position on this update
                {
                    // Set the token back to its default pattern

                    // Reset the token's position
                    tokenPosition = originalPosition;

                    facingDirectionX          *= -1;
                    PossessedToken.Orientation = new Vector3(facingDirectionX, PossessedToken.Orientation.Y, PossessedToken.Orientation.Z);

                    returning = false;
                }
                else
                {
                    // Normalise direction, calculating how far to move this frame
                    direction  = Vector2.Normalize(direction);
                    direction *= speed;

                    // Move towards the token's original position
                    tokenPosition += new Vector3(direction.X, direction.Y, 0);
                }
            }
            else
            {
                tokenPosition.X += ((float)Math.Sin(currentSin) * sinIntensity); // Move the bubble in a sine pattern along the X axis
                tokenPosition.Y += ((float)Math.Cos(currentSin) * sinIntensity); // Move the bubble in a cosine pattern along the y axis

                currentSin += sinIncrement;                                      // Increase the evolution of the sin/cos pattern
            }

            PossessedToken.Position = tokenPosition; // Set the token's current position to the new one, after all movements
        }