Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            explosionExpandTimer += deltaTime;
            explosionEndTimer -= deltaTime;
            if (explosionEndTimer <= 0)
            {
                explosionEffects.Clear();
                GameContentManager.Sprites.Remove(this);
            }
            if (explosionExpandTimer >= ExplosionExpandingInterval && explosionRadius > 0) // explosion has to expand
            {
                // explosion hasn't started expanding yet
                if (explosionTopEffects.Count == 0)
                {
                    ExplosionSprite center = explosionEffects.ElementAt(0);
                    Vector2 offsetPos = Vector2.Zero;
                    ExplosionSprite e;

                    // top expand
                    if (topExpansionAllowed)
                    {
                        offsetPos = new Vector2(0, center.SpriteTexture.Height * center.Scale);
                        e = new ExplosionSprite(center.Position - offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionTopEffects.Add(e);
                        explosionEffects.Add(e);
                    }

                    // bottom expand
                    if (bottomExpansionAllowed)
                    {
                        offsetPos = new Vector2(0, center.SpriteTexture.Height * center.Scale);
                        e = new ExplosionSprite(center.Position + offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionBottomEffects.Add(e);
                        explosionEffects.Add(e);
                    }

                    // right expand
                    if (rightExpansionAllowed)
                    {
                        offsetPos = new Vector2(center.SpriteTexture.Width * center.Scale, 0);
                        e = new ExplosionSprite(center.Position + offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionRightEffects.Add(e);
                        explosionEffects.Add(e);
                    }

                    // left expand
                    if (leftExpansionAllowed)
                    {
                        offsetPos = new Vector2(center.SpriteTexture.Width * center.Scale, 0);
                        e = new ExplosionSprite(center.Position - offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionLeftEffects.Add(e);
                        explosionEffects.Add(e);
                    }
                }
                else if (explosionRadius > 0) //in case this isn't the first expanding
                {
                    ExplosionSprite lastEffect;
                    Vector2 offsetPos = Vector2.Zero;
                    ExplosionSprite e;
                    
                    // top expand
                    if (topExpansionAllowed)
                    {
                        lastEffect = explosionTopEffects.ElementAt(explosionTopEffects.Count - 1);
                        offsetPos = new Vector2(0, lastEffect.SpriteTexture.Height * lastEffect.Scale);
                        e = new ExplosionSprite(lastEffect.Position - offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionTopEffects.Add(e);
                        explosionEffects.Add(e);
                    }

                    // bottom expand
                    if (bottomExpansionAllowed)
                    {
                        lastEffect = explosionBottomEffects.ElementAt(explosionBottomEffects.Count - 1);
                        offsetPos = new Vector2(0, lastEffect.SpriteTexture.Height * lastEffect.Scale);
                        e = new ExplosionSprite(lastEffect.Position + offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionBottomEffects.Add(e);
                        explosionEffects.Add(e);
                    }

                    // right expand
                    if (rightExpansionAllowed)
                    {
                        lastEffect = explosionRightEffects.ElementAt(explosionRightEffects.Count - 1);
                        offsetPos = new Vector2(lastEffect.SpriteTexture.Width * lastEffect.Scale, 0);
                        e = new ExplosionSprite(lastEffect.Position + offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionRightEffects.Add(e);
                        explosionEffects.Add(e);
                    }

                    // left expand
                    if (leftExpansionAllowed)
                    {
                        lastEffect = explosionLeftEffects.ElementAt(explosionLeftEffects.Count - 1);
                        offsetPos = new Vector2(lastEffect.SpriteTexture.Width * lastEffect.Scale, 0);
                        e = new ExplosionSprite(lastEffect.Position - offsetPos, 0);
                        e.LoadContent(GameContentManager.Game.Content);
                        e.GameContentManager = GameContentManager;
                        explosionLeftEffects.Add(e);
                        explosionEffects.Add(e);
                    }
                }
                explosionExpandTimer = 0;
                explosionRadius--;
            }
            handleCollisions();
        }
Exemplo n.º 2
0
 private void Explode()
 {
     var e = new ExplosionSprite(Position, 3);
     e.GameContentManager = GameContentManager;
     e.LoadContent(GameContentManager.Game.Content);
     GameContentManager.Sprites.Add(e);
     GameContentManager.Sprites.Remove(this);
     SoundEffect explosion = GameContentManager.Game.Content.Load<SoundEffect>("explo");
     explosion.Play();
 }