static void InitShape()
        {
            Coefficients coe = TimeWarp.Coefficients;

            List <IGeometry2D>  goes = new List <IGeometry2D>();
            List <Coefficients> coes = new List <Coefficients>();

            goes.Add(new Polygon2D(ALVector2D.Zero, Polygon2D.FromNumberofSidesAndRadius(6, 15)));
            coes.Add(coe);

            DefaultShape = new RigidBodyTemplate(MassInertia.FromSolidCylinder(.4f, 15), goes.ToArray(), coes.ToArray());
            //DefaultShape.BalanceBody();
            ////DefaultShape.CalcInertiaMultiplier(.1f);

            goes.Clear();
            coes.Clear();


            goes.Add(new Polygon2D(ALVector2D.Zero, Polygon2D.FromNumberofSidesAndRadius(6, 9)));
            coes.Add(coe);


            SubDefaultShape = new RigidBodyTemplate(MassInertia.FromSolidCylinder(.01f, 9), goes.ToArray(), coes.ToArray());
            //SubDefaultShape.BalanceBody();
            //Sub//DefaultShape.CalcInertiaMultiplier(.1f);
        }
        static void InitShapes()
        {
            DefaultCoefficients = new Coefficients(1.1f, .2f, .2f);
            int length = 6;

            Templates = new RigidBodyTemplate[length];
            List <Vector2D> vertexes = new List <Vector2D>();

            for (int pos = 0; pos < length; ++pos)
            {
                int        numberofSides = rand.Next(5, 10);
                float      radius        = 20 + (float)rand.NextDouble() * 20;
                Vector2D[] poly          = Polygon2D.FromNumberofSidesAndRadius(numberofSides, radius);
                vertexes.AddRange(poly);
                for (int numbertoRemove = rand.Next(0, numberofSides - 4); numbertoRemove > 0; --numbertoRemove)
                {
                    vertexes.RemoveAt(rand.Next(0, vertexes.Count));
                }
                Polygon2D polly = new Polygon2D(ALVector2D.Zero, poly);
                poly = Polygon2D.MakeCentroidOrigin(vertexes.ToArray());
                MassInertia mi = MassInertia.FromSolidCylinder(1 + (float)rand.NextDouble() * 2, polly.BoundingRadius);
                Templates[pos] = new RigidBodyTemplate(mi, new IGeometry2D[] { polly }, new Coefficients[] { DefaultCoefficients });
                vertexes.Clear();
            }
        }
        static void InitShape()
        {
            Coefficients DefaultCoefficients = TimeWarp.Coefficients;

            DefaultShape = new RigidBodyTemplate(MassInertia.FromSolidCylinder(.01f, 90), new IGeometry2D[] { new Polygon2D(ALVector2D.Zero, Polygon2D.FromNumberofSidesAndRadius(10, 20)) }, new Coefficients[] { DefaultCoefficients });
            //DefaultShape.BalanceBody();
            //////DefaultShape.CalcInertiaMultiplier(.1f);
        }
        static void InitShape()
        {
            Coefficients coe = TimeWarp.Coefficients;

            DefaultShape = new RigidBodyTemplate(MassInertia.FromSolidCylinder(.01f, 7),
                                                 new IGeometry2D[] { new Polygon2D(Polygon2D.FromNumberofSidesAndRadius(10, 7)) },
                                                 new Coefficients[] { coe });
            DefaultShape.BalanceBody();
        }
Beispiel #5
0
            static void InitShape()
            {
                Coefficients coe = TimeWarp.Coefficients;

                IGeometry2D enginecone = new Polygon2D(new ALVector2D(0, new Vector2D(0, 0)), Polygon2D.FromNumberofSidesAndRadius(8, 8));

                DefaultShape = new RigidBodyTemplate(MassInertia.FromSolidCylinder(.1f, 8), new IGeometry2D[] { enginecone }, new Coefficients[] { coe });
                DefaultShape.BalanceBody();
            }
        static void InitShape()
        {
            Coefficients coe = TimeWarp.Coefficients;

            List <IGeometry2D>  goes = new List <IGeometry2D>();
            List <Coefficients> coes = new List <Coefficients>();

            goes.Add(new Polygon2D(ALVector2D.Zero, Polygon2D.FromNumberofSidesAndRadius(6, 20)));
            coes.Add(coe);

            DefaultShape = new RigidBodyTemplate(MassInertia.FromSolidCylinder(1, 20), goes.ToArray(), coes.ToArray());
        }
        /// <summary>
        /// Initializes the ships shape.
        /// </summary>
        static void InitShape()
        {
            //This method is complicated and i dont fell like commenting it.
            // this one is actaully very simple compared to the rest but still anoying.

            Coefficients DefaultCoefficients = TimeWarp.Coefficients;

            DefaultShape = new RigidBodyTemplate(
                MassInertia.FromSolidCylinder(4, 20),
                new IGeometry2D[] { new Polygon2D(ALVector2D.Zero, Polygon2D.FromNumberofSidesAndRadius(10, 20)) },
                new Coefficients[] { DefaultCoefficients });
            //DefaultShape.BalanceBody();
            //////DefaultShape.CalcInertiaMultiplier(.1f);
        }
        static ISolidWeapon CreateWeapon()
        {
            Coefficients coe    = TimeWarp.Coefficients;
            float        radius = 20;

            return(new Controlable(
                       DefaultLifeTime,
                       MassInertia.FromSolidCylinder(1, radius),
                       new PhysicsState(),
                       DefaultBodyFlags,
                       new ICollidableBodyPart[] { new RigidBodyPart(ALVector2D.Zero, (Polygon2D)Polygon2D.FromNumberofSidesAndRadius(8, radius), coe) },
                       new ShipMovementInfo(DefaultMovementInfo),
                       new ShipState(DefaultState),
                       new ControlableSounds(),
                       new WeaponsLogic(TargetingInfo.All,
                                        new EffectCollection(DefaultEffectCollection))));
        }
        static ISolidWeapon[] CreateWeapons()
        {
            Coefficients coe   = TimeWarp.Coefficients;
            int          count = 4;

            ISolidWeapon[] weapons = new ISolidWeapon[count];
            for (int pos = 0; pos < count; ++pos)
            {
                float radius = 5 + 5 * pos;
                weapons[pos] = new Controlable(
                    DefaultLifeTimes[pos],
                    MassInertia.FromSolidCylinder(.1f, radius),
                    new PhysicsState(),
                    DefaultBodyFlags,
                    new ICollidableBodyPart[] { new RigidBodyPart(ALVector2D.Zero, (Polygon2D)Polygon2D.FromNumberofSidesAndRadius(8, radius), coe) },
                    new ShipMovementInfo(DefaultMovementInfo),
                    new ShipState(DefaultState[pos]),
                    new ControlableSounds("EnergyChargeUp", null),
                    new WeaponsLogic(TargetingInfo.All,
                                     new EffectCollection(DefaultEffectCollections[pos])));
            }
            return(weapons);
        }
        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));
            }
        }