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();
            }
        }
Beispiel #3
0
        public Controlable(
            LifeSpan lifeTime,
            MassInertia massInfo,
            PhysicsState physicsState,
            BodyFlags flags,
            ICollidableBodyPart[] collidableParts,
            ShipMovementInfo movementInfo,
            ShipState shipState,
            ControlableSounds controlableSounds,
            IWeaponsLogic weaponInfo)
            : this(
                lifeTime,
                massInfo,
                physicsState,
                flags, collidableParts,
                movementInfo,
                shipState,
                controlableSounds)
        {
            this.CollisionState.GenerateCollisionEvents = true;
            this.CollisionState.GenerateContactEvents   = true;
            this.weaponInfo = weaponInfo;

            this.controlableType = ControlableType.Weapon;
        }
Beispiel #4
0
 public Ship(
     LifeSpan lifeTime,
     MassInertia massInfo,
     PhysicsState physicsState,
     BodyFlags flags,
     ICollidableBodyPart[] collidableParts,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     ControlableSounds controlableSounds,
     ShipSounds shipSounds,
     ActionList actions,
     IShip[] subShips)
     : base(
         lifeTime,
         massInfo,
         physicsState,
         flags,
         collidableParts,
         movementInfo,
         shipState,
         controlableSounds)
 {
     this.UQMFlags       |= ContFlags.CanDoGravityWhip;
     this.shipSounds      = shipSounds;
     this.subShips        = subShips;
     this.actions         = actions;
     this.controlableType = ControlableType.Ship;
 }
Beispiel #5
0
        static void InitShape()
        {
            Coefficients coe  = TimeWarp.Coefficients;
            IGeometry2D  hull = new Polygon2D(ALVector2D.Zero, Polygon2D.FromSquare(10));

            DefaultShape = new RigidBodyTemplate(MassInertia.FromSquare(.01f, 10), new IGeometry2D[] { hull }, new Coefficients[] { coe });
            DefaultShape.BalanceBody();
        }
        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 #8
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);
        }
Beispiel #11
0
        static void InitShape()
        {
            Coefficients coe = TimeWarp.Coefficients;

            Vector2D[] hullverticies = new Vector2D[]
            {
                new Vector2D(5, 5),
                new Vector2D(-5, 5),
                new Vector2D(-5, -5),
                new Vector2D(5, -5)
            };
            IGeometry2D hull = new Polygon2D(ALVector2D.Zero, hullverticies);

            DefaultShape = new RigidBodyTemplate(MassInertia.FromRectangle(.1f, 10, 10), new IGeometry2D[] { hull }, new Coefficients[] { coe });
            DefaultShape.BalanceBody();
        }
        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))));
        }
        RigidBodyTemplate GetPrimaryWeaponShape()
        {
            Coefficients coe = TimeWarp.Coefficients;

            Vector2D[] bulletverticies = new Vector2D[]
            {
                new Vector2D(30, 5),
                new Vector2D(-30, 5),
                new Vector2D(-30, -5),
                new Vector2D(30, -5)
            };
            IGeometry2D       enginecone   = new Polygon2D(ALVector2D.Zero, bulletverticies);
            RigidBodyTemplate DefaultShape = new RigidBodyTemplate(MassInertia.FromRectangle(1, 10, 2), new IGeometry2D[] { enginecone }, new Coefficients[] { coe });

            DefaultShape.BalanceBody();
            return(DefaultShape);
        }
 protected Asteroid(ICollidableBodyPart part, MassInertia massInfo, PhysicsState physicsState)
     : base(
         (LifeSpan)DefaultLifeTime.Clone(),
         massInfo,
         physicsState,
         BodyFlags.None,
         new ICollidableBodyPart[] { part },
         new ShipMovementInfo(DefaultShipMovementInfo),
         new ShipState(rand.Next(1, 6)),
         new ControlableSounds(),
         new WeaponsLogic(TargetingInfo.None,
                          new EffectCollection(DefaultEffectCollection)))
 {
     this.factionInfo     = new FactionInfo(AsteroidFaction);
     this.controlableType = ControlableType.Debris | ControlableType.Weapon;
     this.weaponInfo.EffectCollection.AttachmentFlags = EffectAttachmentFlags.ClonedAttachment;
     this.shipState.Health = new Bounded <float>(4);
 }
Beispiel #15
0
 public Controlable(
     LifeSpan lifeTime,
     MassInertia massInfo,
     PhysicsState physicsState,
     BodyFlags flags,
     ICollidableBodyPart[] collidableParts,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     ControlableSounds controlableSounds)
     : base(lifeTime,
            massInfo,
            physicsState,
            flags,
            collidableParts)
 {
     this.shipState                        = shipState;
     this.movementInfo                     = movementInfo;
     this.controlableSounds                = controlableSounds;
     this.attachedEffectCollection         = new EffectCollection();
     this.CollisionState.GenerateRayEvents = true;
 }
        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 SpawningSolidWeapon(
     LifeSpan lifeTime,
     MassInertia massInfo,
     PhysicsState physicsState,
     BodyFlags flags, ICollidableBodyPart[] collidableParts,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     ControlableSounds controlableSounds,
     IWeaponsLogic weaponInfo,
     ISolidWeapon spawn,
     bool diesOnSpawn)
     : base(
         lifeTime,
         massInfo,
         physicsState,
         flags, collidableParts,
         movementInfo,
         shipState,
         controlableSounds,
         weaponInfo)
 {
     this.spawn       = spawn;
     this.diesOnSpawn = diesOnSpawn;
 }
        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));
            }
        }
 static void InitShape()
 {
     DefaultShape = new RigidBodyTemplate(MassInertia.FromRectangle(.01f, 5, 10), new IGeometry2D[] { new Polygon2D(ALVector2D.Zero, Polygon2D.FromRectangle(5, 10)) }, new Coefficients[] { TimeWarp.Coefficients });
 }