Esempio n. 1
0
        public virtual void Update(GameTime gameTime)
        {
            this.AnimationFrame = this.AnimationMode switch
            {
                AnimationMode.None => this.AnimationFrame,
                AnimationMode.Loop => ((int)Math.Floor(gameTime.TotalGameTime / this.AnimationFrameLength)) % this.textures.Length,
                AnimationMode.PingPong => PingPong(((int)Math.Floor(gameTime.TotalGameTime / this.AnimationFrameLength)) % (this.textures.Length + this.textures.Length - 2), this.textures.Length),
                _ => throw new NotImplementedException($"AnimationMode {this.AnimationMode}")
            };

            if (this.AttachedTo == null)
            {
                this.Position += this.Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (Velocity.Length() != 0.0f)
                {
                    this.Velocity *= 0.95f;
                    if (Velocity.Length() < 0.1f)
                    {
                        Velocity = new Vector2(0.0f);
                    }
                }
            }
            else
            {
                Vector2 offset = MyMathHelper.RotateBy(this.AttachOffset, this.AttachedTo.Rotation);

                this.Position = this.AttachedTo.Position + offset;
                this.Rotation = this.AttachedTo.Rotation;
            }
        }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            if (this.AttachedTo != null)
            {
                Vector2 offset = MyMathHelper.RotateBy(this.AttachOffset, this.AttachedTo.Rotation);

                this.Position = this.AttachedTo.Position + offset;
            }

            if (this.IsEnabled)
            {
                this.spawnBackpack += gameTime.ElapsedGameTime;
                while (this.spawnBackpack >= this.SpawnRate)
                {
                    this.spawnBackpack -= this.SpawnRate;
                    this.Spawn(gameTime);
                }
            }

            for (int i = 0; i < this.MaxParticles; i++)
            {
                this.positions[i] += this.velocetys[i];
                if (this.actives[i])
                {
                    var age = gameTime.TotalGameTime - this.createionTime[i];

                    var deathBegin = this.MaxAge - this.DeathDuration;



                    if (age >= this.MaxAge)
                    {
                        this.actives[i] = false;
                        this.active--;
                    }
                    else if (age > deathBegin)
                    {
                        var deathPosition = (age - deathBegin) / this.DeathDuration;

                        System.Diagnostics.Debug.Assert(deathPosition <= 1 && deathPosition >= 0);

                        if (this.Death.HasFlag(PatricleDeath.Fade))
                        {
                            this.fade[i] = 1f - (float)deathPosition;
                        }
                        if (this.Death.HasFlag(PatricleDeath.Shrink))
                        {
                            this.scale[i] = Vector2.One * (1f - (float)deathPosition);
                        }
                        else if (this.Death.HasFlag(PatricleDeath.Grow))
                        {
                            this.scale[i] = Vector2.One + Vector2.One * 2f * ((float)deathPosition);
                        }
                    }
                }
            }
        }