Exemplo n.º 1
0
            /// <summary>
            /// Creates a new particle with a random start location, and verticle velocity
            /// </summary>1
            /// <param name="newParticle"></param>
            protected override void NewParticle(XNACS1Particle newParticle)
            {
                newParticle.CenterX += XNACS1Base.RandomFloat(-(m_FireWidth / 2), (m_FireWidth / 2));
                newParticle.CenterY += XNACS1Base.RandomFloat(-1, 1);
                Vector2 velocity = m_FireDirection * XNACS1Base.RandomFloat(0, 1);


                velocity                *= m_Speed;
                newParticle.Velocity     = velocity;
                newParticle.ShouldTravel = true;
            }
Exemplo n.º 2
0
            /// <summary>
            /// Overloaded NewParticle Method, gives explosion particles initial velocity and sets
            /// ShouldTravel = true.
            /// </summary>
            /// <param name="newParticle"></param>
            protected override void NewParticle(XNACS1Particle newParticle)
            {
                newParticle.CenterX += XNACS1Base.RandomFloat(-m_Radius / 10, m_Radius / 10);
                newParticle.CenterY += XNACS1Base.RandomFloat(-m_Radius / 10, m_Radius / 10);
                Vector2 randomVelocity = new Vector2(XNACS1Base.RandomFloat(-1, 1), XNACS1Base.RandomFloat(-1, 1));

                randomVelocity.Normalize();
                randomVelocity          *= m_ExplodeSpeed * XNACS1Base.RandomFloat(.5f, 1);
                newParticle.Velocity     = randomVelocity;
                newParticle.ShouldTravel = true;
            }
        /// <summary>
        /// <b>Do not override this method!</b> This method is used by the XNACS1Lib to create
        /// and initialize the entire system.
        ///
        /// Override InitializeWorld() and perform all your intialization there!
        ///
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            bool fullScreen = false;

#if WINDOWS_PHONE
            // Phone
            m_GraphicsAccess.m_GraphicsManager.PreferredBackBufferWidth  = m_GraphicsAccess.GraphicsDevice.DisplayMode.Width;
            m_GraphicsAccess.m_GraphicsManager.PreferredBackBufferHeight = m_GraphicsAccess.GraphicsDevice.DisplayMode.Height;
            m_GraphicsAccess.m_GraphicsManager.SupportedOrientations     = DisplayOrientation.Portrait;
            m_GraphicsAccess.m_GraphicsManager.ApplyChanges();
            fullScreen = true;
#else
#if WINDOWS
            // Windows
            int w = (int)(m_GraphicsAccess.GraphicsDevice.DisplayMode.Width * kDefaultWidthCoverage);
            if (w < XNACS1_AppWindowWidth)
            {
                XNACS1_AppWindowWidth  = w;
                XNACS1_AppWindowHeight = (int)(XNACS1_AppWindowWidth / kHDTVAspecRatio);
            }
#else
            // XBOX
            fullScreen = true;
#endif
#endif

            m_WorldBound       = new XNACS1Rectangle(RequestedWorldMin, RequestedWorldWidth, RequestedWorldWidth);
            m_WorldBound.Color = Color.CornflowerBlue;

            m_GraphicsAccess.m_FontManager = new FontManager(m_GraphicsManager.GraphicsDevice, Content, XNACS1_AppWindowHeight);
            m_GraphicsAccess.CreateDrawHelper();

            // Call user's initialize method
            InitializeWorld();

            if (!mDeviceSizeSet)
            {
                XNACS1Base.SetAppWindowPixelDimension(fullScreen, XNACS1_AppWindowWidth, XNACS1_AppWindowHeight);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Overloaded TravelPrimitive for Particles.
        /// Moves the particle during each update cycle. This function is automacially called for all visible
        /// particle. Default behavior is to move the particle if:
        ///     . Primitive is visible (invivislble primitive is not updated)
        ///     . ShouldTravel is true
        ///     . HasNonZeroVelocity() is true
        /// This method moves the particle in the direction of its velocity and also displaces it according to the ParticleTravelMode chosen.
        /// </summary>
        public override void TravelPrimitive()
        {
            if (m_ParticleLife > 0)
            {
                m_ParticleLife--;
            }
            if (Visible && ShouldTravel)
            {
                m_TravelTime++;
                if (HasNonZeroVelocity())
                {
                    m_Center += Velocity;
                }

                if (m_TravelMode != ParticleTravelMode.Linear)
                {
                    Vector2 velocityNormal = Vector2.Zero;
                    Vector2 velocityFront;
                    if (m_LastCenter == m_Center)
                    {
                        velocityFront = VelocityDirection;
                    }
                    else
                    {
                        velocityFront = (m_Center - m_LastCenter);
                    }
                    velocityNormal.X = -(velocityFront).Y;
                    velocityNormal.Y = (velocityFront).X;
                    velocityNormal.Normalize();

                    //not dependent on velocity;
                    switch (m_TravelMode)
                    {
                    case ParticleTravelMode.RandomDisplace:
                        m_Displacement += new Vector2(XNACS1Base.RandomFloat(-1, 1), XNACS1Base.RandomFloat(-1, 1)) * m_DisplacementFrequency;
                        if (m_Displacement.Length() > m_DisplacementAmplitude)
                        {
                            m_Displacement.Normalize();
                        }
                        break;

                    case ParticleTravelMode.TransverseSine:
                        m_Displacement = velocityNormal * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;

                    case ParticleTravelMode.CompressionSine:
                        m_Displacement = Vector2.Normalize(m_Center - m_LastCenter) * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;

                    case ParticleTravelMode.VerticalSine:
                        m_Displacement = Vector2.UnitY * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;

                    case ParticleTravelMode.HorizontalSine:
                        m_Displacement = Vector2.UnitX * m_DisplacementAmplitude * (float)Math.Sin(m_DisplacementFrequency * m_TravelTime);
                        break;
                    }
                }
                m_LastCenter = m_Center;
            }
        }