コード例 #1
0
 public Asteroid(Asteroid copy) : base(copy)
 {
 }
コード例 #2
0
        public static void CreateDebris(GameResult gameResult, IControlable wrecked)
        {
            PhysicsState state;
            int          length    = wrecked.CollidableParts.Length;
            float        totalArea = 0;

            float[] areas = new float[length];
            for (int pos = 0; pos < length; ++pos)
            {
                totalArea += (areas[pos] = wrecked.CollidableParts[pos].BaseGeometry.Area);
            }
            float totalAreaInv = 1 / totalArea;

            if (wrecked is IShip)
            {
                float           smallest = float.MaxValue;
                ControlableWave wave;
                for (int pos = 0; pos < length; ++pos)
                {
                    state = new PhysicsState(wrecked.Current);
                    state.Position.Linear = wrecked.CollidableParts[pos].Position.Linear + new Vector2D((float)((rand.NextDouble() - .5f) * 2) * wrecked.CollidableParts[pos].BaseGeometry.InnerRadius, (float)((rand.NextDouble() - .5f) * 2) * wrecked.CollidableParts[pos].BaseGeometry.InnerRadius);
                    smallest = MathHelper.Min(smallest, wrecked.CollidableParts[pos].BaseGeometry.InnerRadius);


                    wave = new ControlableWave(
                        new LifeSpan(TimeForSecondaryExplosions),
                        wrecked.MassInfo.Mass * totalAreaInv * areas[pos] * .5f,
                        state,
                        wrecked.CollidableParts[pos].BaseGeometry.InnerRadius,
                        (wrecked.BoundingRadius - wrecked.CollidableParts[pos].BaseGeometry.InnerRadius) / TimeForSecondaryExplosions,
                        TimeWarp.DefaultExposionColors,
                        TimeWarp.DefaultExplosionPrimaryColor,
                        new ShipMovementInfo(DefaultShipMovementInfo),
                        new ShipState(DefaultShipState),
                        AsteroidFaction,
                        new ControlableSounds());

                    wave.OnCreation(gameResult, new FactionInfo(AsteroidFaction));
                }
                state = new PhysicsState(wrecked.Current);
                wave  = new ControlableWave(new LifeSpan(TimeForPrimaryExplosion),
                                            wrecked.MassInfo.Mass * .5f,
                                            state,
                                            smallest,
                                            (wrecked.BoundingRadius - smallest) / TimeForPrimaryExplosion,
                                            TimeWarp.DefaultExposionColors,
                                            TimeWarp.DefaultExplosionPrimaryColor,
                                            new ShipMovementInfo(DefaultShipMovementInfo),
                                            new ShipState(DefaultShipState),
                                            AsteroidFaction,
                                            new ControlableSounds());
                wave.OnCreation(gameResult, new FactionInfo(AsteroidFaction));
            }
            for (int pos = 0; pos < length; ++pos)
            {
                state          = new PhysicsState(wrecked.Current);
                state.Position = wrecked.CollidableParts[pos].Position;
                MassInertia massInfo;
                float       mass = wrecked.MassInfo.Mass * totalAreaInv * areas[pos];
                if (wrecked.CollidableParts[pos].UseCircleCollision)
                {
                    massInfo = MassInertia.FromSolidCylinder(mass, wrecked.CollidableParts[pos].BaseGeometry.BoundingRadius);
                }
                else
                {
                    wrecked.CollidableParts[pos].SetPosition(ALVector2D.Zero);
                    wrecked.CollidableParts[pos].CalcBoundingBox2D();
                    BoundingBox2D box = wrecked.CollidableParts[pos].BoundingBox2D;
                    massInfo = MassInertia.FromRectangle(mass, box.Upper.X - box.Lower.X, box.Upper.Y - box.Lower.Y);
                }
                //ColoredRigidBodyPart part = new ColoredRigidBodyPart(ALVector2D.Zero, state.Position, wrecked.CollidableParts[pos].BaseGeometry, DefaultCoefficients, DefaultColors, DefaultPrimaryColor);
                RigidBodyPart part = new RigidBodyPart(ALVector2D.Zero, state.Position, wrecked.CollidableParts[pos].BaseGeometry, DefaultCoefficients);
                Asteroid      roid = new Asteroid(part, massInfo, state);
                roid.OnCreation(gameResult, new FactionInfo(AsteroidFaction));
            }
        }