コード例 #1
0
 /// <summary>
 /// creates the enemy graphic by fetching the 4 points of the enemy
 /// </summary>
 /// <param name="tank">pass in the position of the enemy tank</param>
 /// <returns>return the array of enemytank points</returns>
 private PointF[] CreateEnemiesGraphic(AITanks tank)
 {
     //create an array of enemy tank points
     PointF[] tankPoints = new PointF[4];
     //se the points of the enemy tank
     tankPoints[0] = new PointF(tank.Location.X, tank.Location.Y);
     tankPoints[1] = new PointF(tank.Location.X + tank.Size.Width, tank.Location.Y);
     tankPoints[2] = new PointF(tank.Location.X + tank.Size.Width, tank.Location.Y + tank.Size.Height);
     tankPoints[3] = new PointF(tank.Location.X, tank.Location.Y + tank.Size.Height);
     return(tankPoints);
 }
コード例 #2
0
        /// <summary>
        /// create the graphic for the enemy barrel by fetching the 4 points
        /// </summary>
        /// <param name="tank"> pass in the location of the enemy tank </param>
        /// <returns></returns>
        private PointF[] CreateEnemyBarrelGraphic(AITanks tank)
        {
            //make array for the barrel points
            Point[] basePoints = new Point[4];

            // if the player is on the right side of the enemy
            // add one to see if it fixes graphic glitch
            if (player.Location.X > tank.Location.X + 1)
            {
                // top left corner
                basePoints[0] = new Point(-5, -2);

                //top right corner
                basePoints[1] = new Point(25, -2);

                //bottom right corner
                basePoints[2] = new Point(25, 2);

                //bottom left corner
                basePoints[3] = new Point(-5, 2);
            }

            //if the player is on the right side of the enemy
            //add one to see if it fixes graphics glitch
            else if (player.Location.X < tank.Location.X + 1)
            {
                // top left corner
                basePoints[0] = new Point(-25, -2);

                //top right corner
                basePoints[1] = new Point(5, -2);

                //bottom right corner
                basePoints[2] = new Point(5, 2);

                //bottom left corner
                basePoints[3] = new Point(-25, 2);
            }

            // when the player is directly above or below the enemy
            else if (player.Location.X == tank.Location.X)
            {
                //when the player is below the enemy
                if (player.Location.Y > tank.Location.Y)
                {
                    // top left corner
                    basePoints[0] = new Point(-25, -2);

                    //top right corner
                    basePoints[1] = new Point(5, -2);

                    //bottom right corner
                    basePoints[2] = new Point(5, 2);

                    //bottom left corner
                    basePoints[3] = new Point(-25, 2);
                }

                // when the player is above the eenemy
                else
                {
                    // top left corner
                    basePoints[0] = new Point(-5, -2);

                    //top right corner
                    basePoints[1] = new Point(25, -2);

                    //bottom right corner
                    basePoints[2] = new Point(25, 2);

                    //bottom left corner
                    basePoints[3] = new Point(-5, 2);
                }
            }

            //calculate the theta angle for the barrel calcualtions
            float angle = -(float)Math.Atan((tank.Location.Y - player.Location.Y + (tank.Size.Height / 2)) / (player.Location.X - tank.Location.X - (tank.Size.Width / 2)));

            //Barrel Points Array for the modified points
            PointF[] barrelPoints = new PointF[4];

            // put the cos and sin theta calculations in their own variables to make equation less messy
            float cos = (float)Math.Cos(angle);
            float sin = (float)Math.Sin(angle);

            // put the base points into the barrel point
            for (int i = 0; i < 4; i++)
            {
                //calculate where the points need to go and move the barrel to where the enemy is
                barrelPoints[i] = new PointF(basePoints[i].X * cos + basePoints[i].Y * sin + tank.Location.X + 10, basePoints[i].X * sin - basePoints[i].Y * cos + tank.Location.Y + 10);
            }

            return(barrelPoints);
        }