Ejemplo n.º 1
0
 public void Add(ChangeMessage msg)
 {
     Messages.Add(msg);
 }
Ejemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            MessageBuffer.Clear();

            for (int i = 0; i < ParticleDataObjects.Count; i++)
            {
                ParticleData gameData = ParticleDataObjects[i];
                float        Rot;

                #region Handle particle rotation
                if (gameData.RotateVelocity == true)
                {
                    Rot = (float)Math.Atan2(gameData.Velocity.Y, gameData.Velocity.X);
                }
                else
                {
                    Rot = gameData.Rotation + MathHelper.ToRadians(gameData.RotationIncrement) * ((float)gameTime.ElapsedGameTime.TotalSeconds * 60.0f);
                }
                #endregion

                gameData.Update(gameTime);

                #region Update position

                Vector2 newPos = gameData.Position + gameData.Velocity;
                #endregion

                float percTime = gameData.CurrentTime / gameData.MaxTime;

                #region Fade transparency
                float transparency = gameData.StartingTransparency;
                if (gameData.Fade == true)
                {
                    transparency = MathHelper.Lerp(gameData.StartingTransparency, 0, percTime);
                    //transparency = gameData.StartingTransparency * (1.0f - ((1 / (gameData.MaxTime + gameData.FadeDelay)) * (gameData.CurrentTime + gameData.CurrentFadeDelay)));
                }
                #endregion

                #region Scale particles
                float newScale = gameData.CurrentScale;

                if (gameData.Shrink == true && gameData.Grow == false)
                {
                    newScale = gameData.MaxScale * (1.0f - ((1 / gameData.MaxTime) * (gameData.CurrentTime)));
                }

                if (gameData.Grow == true && gameData.Shrink == false)
                {
                    newScale = gameData.MaxScale * ((1 / gameData.MaxTime) * (gameData.CurrentTime));
                }

                if (gameData.Shrink == true && gameData.Grow == true)
                {
                    newScale = gameData.MaxScale * (float)Math.Sin(Math.PI * percTime);
                }
                #endregion

                #region Fade Colours
                Color newCol = Color.Lerp(gameData.StartColor, gameData.EndColor, percTime);
                #endregion

                //transparency = MathHelper.Lerp(gameData.StartingTransparency, 0, percTime);

                ChangeMessage msg = new ChangeMessage()
                {
                    ID = i
                };

                if (gameData.Active == false)
                {
                    msg.MessageType = ChangeMessageType.DeleteRenderData;
                    ParticleDataObjects.Remove(gameData);
                    MessageBuffer.Add(msg);
                    i--;
                }

                if (gameData.CurrentTime <= gameData.MaxTime)
                {
                    msg.MessageType  = ChangeMessageType.UpdateParticle;
                    msg.Position     = newPos;
                    msg.Rotation     = Rot;
                    msg.Color        = newCol;
                    msg.Scale        = newScale;
                    msg.Transparency = transparency;
                    MessageBuffer.Add(msg);

                    gameData.Position = newPos;
                    gameData.Rotation = Rot;
                }
            }
        }