Esempio n. 1
0
        public static void Explosion(Vector2 where, float scale = 1)
        {
            var explosion = new ParticleEntity(Particles.Animated("explosion", "explosion"));

            explosion.Position = where;
            Run.Level.Area.Add(explosion);
            explosion.Depth             = 32;
            explosion.Particle.Velocity = Vector2.Zero;
            explosion.Particle.Scale    = scale;
            explosion.AddShadow();

            Lights.Flash = 1f;
        }
Esempio n. 2
0
        public static void Make(Entity whoHurts, float hurtRadius = 32f, bool leave = true, Vec2 where = null, float damage = 16, float scale = 1, bool damageOwner = true)
        {
            Camera.Instance.Shake(10 * scale);
            Audio.SfxVolumeBuffer           = 0.5f;
            Audio.SfxVolumeBufferResetTimer = 1f;

            var w = where == null ? whoHurts.Center : new Vector2(where.X, where.Y);

            AnimationUtil.Explosion(w, scale);

            for (var i = 0; i < 4; i++)
            {
                var explosion = new ParticleEntity(Particles.Animated("explosion", "smoke"));
                explosion.Position = w;
                whoHurts.Area.Add(explosion);
                explosion.Depth                  = 31;
                explosion.Particle.Scale         = scale;
                explosion.Particle.AngleVelocity = 0;
                explosion.AddShadow();

                var a = explosion.Particle.Angle - Math.PI / 2;
                var d = 16;

                explosion.Particle.Position += new Vector2((float)Math.Cos(a) * d, (float)Math.Sin(a) * d);

                if (i == 0)
                {
                    explosion.AddComponent(new AudioEmitterComponent {
                        DestroySounds = false
                    });

                    explosion.GetComponent <AudioEmitterComponent>().EmitRandomizedPrefixed("level_explosion", 3);
                }
            }

            for (var i = 0; i < 6; i++)
            {
                var part = new ParticleEntity(Particles.Dust());

                part.Position = w + new Vector2(Rnd.Int(-4, 4), Rnd.Int(-4, 4));
                whoHurts.Area.Add(part);
                part.Depth             = 30;
                part.Particle.Velocity = MathUtils.CreateVector(Rnd.AnglePI(), 80);
            }

            Engine.Instance.Split  = 1f;
            Engine.Instance.Flash  = 1f;
            Engine.Instance.Freeze = 1f;

            var damager = whoHurts;

            if (whoHurts is Bomb b && b.Owner != null)
            {
                damager = b.Owner;
            }

            foreach (var e in whoHurts.Area.GetEntitesInRadius(w, hurtRadius, typeof(ExplodableComponent)))
            {
                if (e == whoHurts && !damageOwner)
                {
                    continue;
                }

                e.GetAnyComponent <BodyComponent>()?.KnockbackFrom(whoHurts, 4f);
                e.GetComponent <ExplodableComponent>().HandleExplosion(damager, whoHurts, damage);
            }

            if (Settings.Flashes)
            {
                Camera.Instance.TextureZoom -= 0.05f;
                Tween.To(1f, Camera.Instance.TextureZoom, x => Camera.Instance.TextureZoom = x, 0.2f);
            }

            if (leave)
            {
                whoHurts.Area.Add(new ExplosionLeftOver {
                    Center = w
                });
            }

            var xx    = (int)Math.Floor(w.X / 16f);
            var yy    = (int)Math.Floor(w.Y / 16f);
            var r     = (int)Math.Floor(hurtRadius / 16f);
            var level = Run.Level;
            var ice   = level.Biome is IceBiome;

            for (int x = -r; x <= r; x++)
            {
                for (int y = -r; y <= r; y++)
                {
                    var xm = x * 16;
                    var ym = y * 16;

                    if (Math.Sqrt(xm * xm + ym * ym) <= hurtRadius)
                    {
                        var index = level.ToIndex(x + xx, y + yy);
                        var l     = level.Get(index, true);
                        var ww    = new Dot((x + xx) * 16 + 8, (y + yy) * 16 + 8);

                        if (l.IsRock())
                        {
                            BreakRock(level, ww, x + xx, y + yy, l);
                            continue;
                        }

                        var tile = level.Get(index);

                        if (tile == Tile.Crack)
                        {
                            DiscoverCrack(whoHurts, level, x + xx, y + yy);
                        }
                        else if (tile == Tile.Planks || (ice && tile == Tile.WallA))
                        {
                            level.Break((x + xx) * 16, (y + yy) * 16);
                        }
                    }
                }
            }
        }