Example #1
0
        protected override void InitializeParticle(Particle p, Vector2 where)
        {
            base.InitializeParticle(p, where);

            // the base is mostly good, but we want to simulate a little bit of wind
            // heading to the right.
            p.Acceleration.X += MathHelp.RandomBetween(10, 50);
        }
Example #2
0
        public static void DrawText(string text, float x, float y, Color color, RenderContext context)
        {
            var    pos = new Vector2(x, y);
            Matrix mat = context.Camera.View;

            MathHelp.WorldToScreen(pos, context);

            // Matrix translation = Matrix.CreateTranslation(new Vector3(pos.X, pos.Y, 0));

            //Open and close the spritebach
            context.SpriteBatch.Begin();
            context.SpriteBatch.DrawString(m_Font, text, pos, color, 0, Vector2.Zero, 1, SpriteEffects.None, 1.0f);
            context.SpriteBatch.End();
        }
Example #3
0
        protected override Vector2 PickRandomDirection()
        {
            // Point the particles somewhere between 80 and 100 degrees.
            // tweak this to make the smoke have more or less spread.
            float radians = MathHelp.RandomBetween(
                MathHelper.ToRadians(80), MathHelper.ToRadians(100));

            Vector2 direction = Vector2.Zero;

            // from the unit circle, cosine is the x coordinate and sine is the
            // y coordinate. We're negating y because on the screen increasing y moves
            // down the monitor.
            // direction.X = (float)Math.Cos(radians);
            direction.Y = Direction;
            return(direction);
        }
Example #4
0
        protected virtual void InitializeParticle(Particle p, Vector2 where)
        {
            // first, call PickRandomDirection to figure out which way the particle
            // will be moving. velocity and acceleration's values will come from this.
            Vector2 direction = new Vector2(1, -1);

            // pick some random values for our particle
            float velocity =
                MathHelp.RandomBetween(minInitialSpeed, maxInitialSpeed);
            float acceleration =
                MathHelp.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                MathHelp.RandomBetween(minLifetime, maxLifetime);
            float scale =
                MathHelp.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                MathHelp.RandomBetween(minRotationSpeed, maxRotationSpeed);

            // then initialize it with those random values. initialize will save those,
            // and make sure it is marked as active.
            p.Initialize(
                where, velocity * direction, acceleration * direction,
                lifetime, scale, rotationSpeed);
        }
Example #5
0
        //Main update loop
        public override void Update(RenderContext context)
        {
            //Camera zooming
            CameraZoom(context);

            //Chains Pos
            m_ChainPositions.Add(Position);
            m_ChainRotations.Add(m_Rotation);
            m_ChainPositions.RemoveAt(0);
            m_ChainRotations.RemoveAt(0);



            m_DeltaTime = (float)context.GameTime.ElapsedGameTime.Milliseconds / 100;

            //So the player doesn;t lose all health on a hit, player is invincible in debug
            //#if(!DEBUG)
            if (m_bInvincible)
            {
                m_Time += m_DeltaTime;
                if (m_Time > 4.5f)
                {
                    m_bInvincible = false;
                    m_Time        = 0;
                }
            }
            if (m_GameIsReallyStarted == false)
            {
                m_bInvincible = true;
            }

            //Allow input
            if (AllowInput)
            {
                HandleInput(context);
            }

            HandlePickupTime();

            if (m_bMove)
            {
                Movement(m_DeltaTime);
            }

            //still working on the friction
            if (m_Velocity != Vector2.Zero)
            {
                Vector2 velocityNormalized = m_Velocity;
                velocityNormalized.Normalize();
                m_FrictionForce = m_FrictionMultiplier * (-velocityNormalized);
                m_Velocity     += m_FrictionForce;
            }

            RandomWind(m_DeltaTime);
            if (m_TwirlEffect == true && m_Twirl == true)
            {
                Twirl(m_DeltaTime, context);
            }
            else if (m_CameraCanRotate)
            {
                Vector3 up = Vector3.Up;
                up.X = MathHelper.Lerp(up.X, 0, 0.1f);
                context.Camera.SetUpVector(up);
            }

            Rotate(-m_Rotation, 90, 0);
            RotateBody(m_Rotation);

            //Clamp velocity to 60 by default
            if (!m_bPickedup)
            {
                m_CurrentVelo = m_Velocity.X;
            }
            MathHelp.Clamp(ref m_CurrentVelo, m_MaxXVelocity, -m_MaxXVelocity);
            m_Velocity = new Vector2(m_CurrentVelo, m_Velocity.Y);

            base.Update();

            UpdateChains();
        }
Example #6
0
        /// <summary>
        /// PickRandomDirection is used by InitializeParticles to decide which direction
        /// particles will move. The default implementation is a random vector in a
        /// circular pattern.
        /// </summary>
        protected virtual Vector2 PickRandomDirection()
        {
            float angle = MathHelp.RandomBetween(0, MathHelper.TwoPi);

            return(new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)));
        }