public Entity BuildEntity(Entity e, params object[] args)
        {
            #region Body

            string spriteKey = "redgrayblobship";

            Body bitch = e.AddComponent<Body>(new Body(_World, e));
            FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 5, 1f, bitch);
            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.55f + (float)destroyers / 1000000f));
            bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2;
            bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3;
            bitch.OnCollision += LambdaComplex.BasicCollision();

            ++bitch.Mass;

            Vector2 pos = new Vector2((float)(rbitch.NextDouble() * 2) - 1, (float)(rbitch.NextDouble() * 2) - 1);
            pos.Normalize();
            pos *= MookTemplate.dist;
            pos = ConvertUnits.ToSimUnits(pos);
            bitch.Position = pos;

            #endregion Body

            #region Crystal

            Color crystalColor = DirectorSystem.CrystalColor();
            int amount = 10;
            e.AddComponent<Crystal>(new Crystal(crystalColor, amount));

            #endregion Crystal

            #region AI/Health

            AI a = new AI(null,
                AI.CreateShoot(e, 2, ConvertUnits.ToSimUnits(400), true), "Players");
            AI shootingAi = e.AddComponent<AI>(a);

            e.AddComponent<Health>(new Health(10)).OnDeath += LambdaComplex.BigEnemyDeath(e, _World, 50);

            #endregion AI/Health

            #region Inventory

            Inventory i = new Inventory(0, 0, 0, 0, InvType.Cannon, spriteKey);
            e.AddComponent<Inventory>(i);

            #endregion Inventory

            ++destroyers;
            e.Group = "Enemies";
            return e;
        }
示例#2
0
        /// <summary>
        /// Finds a new target for AI component
        /// </summary>
        /// <param name="ai"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private Body _FindNewTarget(AI ai, Body location)
        {
            //find all fixtures in world around the location.
            AABB aabb = new AABB(location.Position, ai.SearchRadius, ai.SearchRadius);
            #if WINDOWS
            HashSet<PhysicsBody> bodies = new HashSet<PhysicsBody>();
            #else
            List<PhysicsBody> bodies = new List<PhysicsBody>();
            #endif

            world.QueryAABB(x =>
            {
                if (x.Body.BodyId != location.BodyId)
                {
                    if ((string.IsNullOrEmpty(ai.TargetGroup) || ai.TargetGroup.Equals((x.Body.UserData as Entity).Group)) &&
                        !(world.GetEntity((x.Body.UserData as Entity).Id) == null || (
                                world.GetEntity((x.Body.UserData as Entity).Id) != null &&
                                world.GetEntity((x.Body.UserData as Entity).Id).GetComponent<Body>() != null &&
                                !world.GetEntity((x.Body.UserData as Entity).Id).GetComponent<Body>().Equals(x.Body))))
                    {
                        bodies.Add(x.Body);
                    }
                }
                return true;
            }, ref aabb);

            if (bodies.Count > 0) //IF BODIES IN SEARCH RADIUS.
            {
                PhysicsBody[] list = new PhysicsBody[bodies.Count];
                bodies.CopyTo(list);
                Entity ent = (location.UserData as Entity);

                //SORT BY TARGETING TYPE.
                switch (ai.Targeting)
                {
                    case Targeting.Closest:
                        return ClosestEntity(location.Position, list).GetComponent<Body>();

                    case Targeting.Strongest:
                        return StrongestEntity(list).GetComponent<Body>();

                    case Targeting.Weakest:
                        return WeakestEntity(list).GetComponent<Body>();

                    case Targeting.None:
                        return null;

                    default:
                        return null;
                }
            }
            else
                return null;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            #region Body

            string spriteKey = "blaster";
            bool rotateTo = true;
            if (args.Length > 2)
            {
                spriteKey = (string)args[2];
                rotateTo = false;
            }

            Body bitch = e.AddComponent<Body>(new Body(_World, e));
            FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 5, 1f, bitch);
            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.55f + (float)cannons / 1000000f));
            bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2;
            bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3;
            bitch.OnCollision += LambdaComplex.BasicCollision();
            ++bitch.Mass;

            bitch.Position = (Vector2)args[0];

            #endregion Body

            #region Crystal

            Color crystalColor = DirectorSystem.CrystalColor();
            int amount = 5;
            e.AddComponent<Crystal>(new Crystal(crystalColor, amount));

            #endregion Crystal

            #region AI/Health

            e.AddComponent<Origin>(new Origin(args[1] as Entity));

            AI a = new AI(null,
                AI.CreateCannon(e, rotateTo), "Players");
            AI shootingAi = e.AddComponent<AI>(a);

            e.AddComponent<Health>(new Health(50)).OnDeath += LambdaComplex.BigEnemyDeath(e, _World, 50);

            #endregion AI/Health

            #region Inventory

            Inventory i = new Inventory(0, 0, 0, 0, InvType.Cannon, spriteKey);
            if (spriteKey == "killerleftgun")
            {
                i.CurrentGun.GunOffsets.Add(new Vector2(54, -19));
            }
            e.AddComponent<Inventory>(i);

            #endregion Inventory

            ++cannons;
            e.Tag = "Cannon" + cannons.ToString();
            e.Group = "Enemies";
            return e;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            int type = (int)args[0];

            #region Sprite

            string spriteKey = "";
            switch (type)
            {
                case 0:
                    spriteKey = "bluemissile";
                    break;

                case 1:
                    spriteKey = "graymissile";
                    break;

                case 2:
                    spriteKey = "swastika";
                    break;

                case 3:
                    spriteKey = "swastika2";
                    break;

                case 4:
                    spriteKey = "graye";
                    break;

                case 5:
                    spriteKey = "satellite";
                    break;
            }

            if (args.Length > 2)
                spriteKey = (string)args[2];

            #endregion Sprite

            #region Body

            Body bitch = e.AddComponent<Body>(new Body(_World, e));
            FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 5, 1f, bitch);
            Sprite s = new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.5f + (float)thugs / 1000000f);
            if (spriteKey.Contains("swastika"))
                s.Origin = new Vector2(s.CurrentRectangle.Width / 2, s.CurrentRectangle.Height / 2);
            e.AddComponent<Sprite>(s);
            bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2;
            bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6;
            bitch.OnCollision += LambdaComplex.BasicCollision();
            ++bitch.Mass;

            Vector2 pos = new Vector2((float)(rbitch.NextDouble() * 2) - 1, (float)(rbitch.NextDouble() * 2) - 1);
            pos.Normalize();
            pos *= MookTemplate.dist;
            pos = ConvertUnits.ToSimUnits(pos);
            bitch.Position = pos;
            bool rotateTo = true;
            if (spriteKey.Contains("swastika"))
            {
                e.GetComponent<Body>().AngularVelocity = (float)Math.PI * 4;
                rotateTo = false;
            }

            #endregion Body

            #region Animation

            if (s.Source.Count() > 1 && spriteKey != "satellite")
                e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10));

            #endregion Animation

            #region Crystal

            Color crystalColor = DirectorSystem.CrystalColor();
            int amount = 10;
            if (crystalColor == Color.Gray)
                amount = 2;
            e.AddComponent<Crystal>(new Crystal(crystalColor, amount));

            #endregion Crystal

            #region AI/Health

            AI a = new AI(args[1] as Body, AI.CreateFollow(e, 3, rotateTo), "Base");
            a.Recalculate = false;
            e.AddComponent<AI>(a);

            e.AddComponent<Health>(new Health(5)).OnDeath += LambdaComplex.BigEnemyDeath(e, _World as SpaceWorld, 25);

            #endregion AI/Health

            e.Group = "Enemies";
            return e;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            int type = (int)args[0];

            #region Sprite

            string spriteKey = "";
            switch (type)
            {
                case 0:
                    spriteKey = "squidship";
                    break;

                case 1:
                    spriteKey = "brownfangship";
                    break;

                case 2:
                    spriteKey = "bluecrystalship";
                    break;

                case 3:
                    spriteKey = "brownthingwithbluelight";
                    break;

                case 4:
                    spriteKey = "grayshipwithtwoprongs";
                    break;

                case 5:
                    spriteKey = "greyshipbrownbulb";
                    break;

                case 6:
                    spriteKey = "blueshipgraybulb";
                    break;
            }

            if (args.Length > 2)
                spriteKey = (string)args[2];

            #endregion Sprite

            #region Body

            Body bitch = e.AddComponent<Body>(new Body(_World, e));
            FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 5, 1f, bitch);
            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.53f + (float)mooks / 1000000f));
            bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2;
            bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6;
            bitch.OnCollision += LambdaComplex.BasicCollision();
            ++bitch.Mass;

            Vector2 pos = new Vector2((float)(r.NextDouble() * 2) - 1, (float)(r.NextDouble() * 2) - 1);
            pos.Normalize();
            pos *= dist;
            pos = ConvertUnits.ToSimUnits(pos);
            bitch.Position = pos;

            #endregion Body

            #region Animation

            if (s.Source.Count() > 1)
                e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10));

            #endregion Animation

            #region Crystal

            int amount = 3;
            Color crystalColor = DirectorSystem.CrystalColor();
            if (crystalColor == Color.Gray)
                amount = 2;
            e.AddComponent<Crystal>(new Crystal(crystalColor, amount));

            #endregion Crystal

            #region AI/Health

            AI a = new AI(args[1] as Body, AI.CreateFollow(e, 5, true), "Base");
            a.Recalculate = false;
            e.AddComponent<AI>(a);

            e.AddComponent<Health>(new Health(1)).OnDeath += LambdaComplex.SmallEnemyDeath(e, _World as SpaceWorld, 5);

            #endregion AI/Health

            e.Tag = "Mook" + mooks.ToString();
            e.Group = "Enemies";
            ++mooks;
            return e;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            int type = (int)args[0];

            #region Body

            string spriteKey = "";

            switch (type)
            {
                case 0:
                    spriteKey = "purpleship";
                    break;

                case 1:
                    spriteKey = "brownarmship";
                    break;
            }

            if (args.Length > 1)
                spriteKey = (string)args[1];

            Body bitch = e.AddComponent<Body>(new Body(_World, e));
            FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 5, 1f, bitch);
            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.51f + (float)gunners / 1000000f));
            bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2;
            bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3;
            bitch.OnCollision += LambdaComplex.BasicCollision();
            ++bitch.Mass;

            Vector2 pos = new Vector2((float)(rbitch.NextDouble() * 2) - 1, (float)(rbitch.NextDouble() * 2) - 1);
            pos.Normalize();
            pos *= MookTemplate.dist;
            pos = ConvertUnits.ToSimUnits(pos);
            bitch.Position = pos;

            #endregion Body

            #region Animation

            if (s.Source.Count() > 1)
                e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10));

            #endregion Animation

            #region Crystal

            Color crystalColor = DirectorSystem.CrystalColor();
            int amount = 5;
            if (crystalColor == Color.Gray)
                amount = 2;
            e.AddComponent<Crystal>(new Crystal(crystalColor, amount));

            #endregion Crystal

            #region AI/Health

            AI a = new AI(null,
                AI.CreateShoot(e, ConvertUnits.ToSimUnits(4f), ConvertUnits.ToSimUnits(400), true), "Structures");
            AI shootingAi = e.AddComponent<AI>(a);

            e.AddComponent<Health>(new Health(1)).OnDeath += LambdaComplex.SmallEnemyDeath(e, _World as SpaceWorld, 30);

            #endregion AI/Health

            #region Inventory

            Inventory i = new Inventory(0, 0, 0, 0, InvType.Gunner, spriteKey);
            e.AddComponent<Inventory>(i);

            #endregion Inventory

            ++gunners;
            e.Group = "Enemies";
            return e;
        }