Esempio n. 1
0
        /// <summary>
        /// Constructor for platform
        /// </summary>
        /// <param name="a_world"></param>World in which the platform is created and drawn
        /// <param name="a_leftPoint"></param>Left end point of the platform
        /// <param name="a_rightPoint"></param>Right end point of the platform
        /// <param name="a_texture"></param>Platform texture
        public Platform(World a_world, Vector2 a_leftPoint, Vector2 a_rightPoint, Texture2D a_texture)
        {
            m_world = a_world;

            m_leftPoint  = a_leftPoint;
            m_rightPoint = a_rightPoint;

            // Initializing platform position and dimensions
            float   width    = MathX.LineLength(a_leftPoint, a_rightPoint);
            Vector2 midPoint = MathX.Midpoint(a_leftPoint, a_rightPoint);

            m_sprite   = new Sprite(a_world, a_texture, new Vector2(width, 10), 0.0f, midPoint);
            m_rotation = MathX.GetAngleBetween(a_leftPoint, a_rightPoint) * (float)(Math.PI / 180);
            m_sprite.m_body.Rotation = m_rotation;
            m_sprite.m_body.BodyType = BodyType.Static;
            m_sprite.m_body.UserData = "platform";
            m_currentState           = PlatformState.ROOF;

            // Initializing normal vector
            Vector2 difference = a_leftPoint - a_rightPoint;

            m_normalVector = new Vector2(-difference.Y, difference.X);
            m_normalVector.Normalize();

            m_connection = new Sprite(a_world, ContentLibrary.circleTexture, 5, 0.0f, a_leftPoint);
            m_connection.m_body.BodyType = BodyType.Static;
            m_connection2 = new Sprite(a_world, ContentLibrary.circleTexture, 5, 0.0f, a_rightPoint);
            m_connection2.m_body.BodyType = BodyType.Static;
            //m_connection.m_body.UserData = "platform";
        }