コード例 #1
0
        public Entity BuildEntity(Entity e, params object[] args)
        {
            int tier = 1;
            if (spawned > 2)
                tier = 2;
            if (spawned > 5)
                tier = 3;

            #region Sprite

            string spriteKey = "";
            int type = spawned;

            spriteKey = bosses[type].SpriteKey;

            #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), 20, 1f, bitch);
            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, spriteKey != "bigredblobboss" ? 0.5f + (float)type / 10000f : 0.55f));
            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.BossCollision();
            ++bitch.Mass;

            Vector2 pos = new Vector2(0, -1);
            pos.Normalize();
            pos *= ScreenHelper.Viewport.Height / 1.5f;
            pos = ConvertUnits.ToSimUnits(pos);
            bitch.Position = pos;
            bitch.SleepingAllowed = false;

            #endregion Body

            #region Animation

            Animation a = null;
            if (s.Source.Count() > 1)
            {
                a = new Animation(AnimationType.None, 10);
                e.AddComponent<Animation>(a);
            }

            #endregion Animation

            #region AI/Health

            e.AddComponent<HealthRender>(new HealthRender());

            if (spriteKey == "flamer")
                e.AddComponent<AI>(new AI((args[0] as Body),
                    AI.CreateFlamer(e, 0.5f, bitch, s, _World), "Base"));

            else if (spriteKey == "bigredblobboss")
                e.AddComponent<AI>(new AI(null,
                    AI.CreateWarMachine(e, 0.5f, bitch, 10f, 0.7f, s, _World)));

            else if (spriteKey == "killerhead")
                e.AddComponent<AI>(new AI(null,
                    AI.CreateKiller(e, 0.5f, 20f, _World)));

            else if (spriteKey == "greenbossship")
                e.AddComponent<AI>(new AI(null,
                    AI.CreateBigGreen(e, 0.5f, 10f, 2f, 0.05f, 3.5f, s, _World)));

            else
                e.AddComponent<AI>(new AI((args[0] as Body),
                    AI.CreateFollow(e, 1, false), "Base", false));

            int points = 0;
            int health = 0;

            switch (tier)
            {
                case 1:
                    points = 300;
                    health = 150;
                    break;

                case 2:
                    points = 500;
                    health = 175;
                    break;

                case 3:
                    points = 1000;
                    health = 200;
                    break;
            }

            Health h = new Health(health);
            h.OnDeath += LambdaComplex.BossDeath(type, _World, e, s, tier, points, bosses[type].BossName);

            if (type == 1)
            {
                h.OnDeath +=
                    ex =>
                        {
                               Console.WriteLine("DEad");
                        };
            }

            if (a != null)
            {
                h.OnDamage +=
                    ent =>
                    {
                        if (h.IsAlive && a.Type == AnimationType.None)
                        {
                            e.RemoveComponent<Sprite>(s);

                            double healthFraction = (h.CurrentHealth / h.MaxHealth);

                            int frame = 0;
                            int frames = s.Source.Length;

                            frame = (int)(frames - (frames * healthFraction));

                            if (frame != s.FrameIndex)
                            {
                                int splodeSound = rbitch.Next(1, 5);
                                SoundManager.Play("Explosion" + splodeSound.ToString());
                                Vector2 poss = e.GetComponent<ITransform>().Position;
                                _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 15, e, e.GetComponent<IVelocity>().LinearVelocity);
                            }
                            s.FrameIndex = frame;

                            e.AddComponent<Sprite>(s);
                        }
                    };
            }

            if (spriteKey.Equals("flamer"))
            {
                h.OnDamage +=
                    ent =>
                    {
                        //Fire flame from random spot

                        int range = s.CurrentRectangle.Width / 2;
                        float posx = rbitch.Next(-range, range);
                        Vector2 pos1 = bitch.Position + ConvertUnits.ToSimUnits(new Vector2(posx, 0));

                        float x = posx / range;

                        float y = 1;

                        Vector2 velocity = new Vector2(x, y);
                        velocity.Normalize();
                        velocity *= 7;

                        _World.CreateEntity("Fire", pos1, velocity).Refresh();
                    };
            }

            e.AddComponent<Health>(h);

            #endregion AI/Health

            e.Tag = "Boss" + spawned.ToString();
            e.Group = "Enemies";

            ++spawned;

            #region Special Cases

            if (spriteKey == "smasher")
            {
                _World.CreateEntity("SmasherBall", e).Refresh();
            }

            if (spriteKey == "brain")
            {
                Vector2 offset = new Vector2(2, 0);
                Vector2 position = bitch.Position + offset;
                _World.CreateEntity("Cannon", position, e).Refresh();
                position = bitch.Position - offset;
                _World.CreateEntity("Cannon", position, e).Refresh();
            }

            if (spriteKey == "massivebluemissile")
            {
                _World.enemySpawnSystem.ThugSprite = "bluemissile";
                _World.enemySpawnSystem.SpawnRate = 0;
                _World.enemySpawnSystem.ThugSpawnRate = 3;
            }

            if (spriteKey == "killerhead")
            {
                List<Entity> children = new List<Entity>();
                Vector2 offset = new Vector2(2.85f, -0.6f);
                Vector2 position = bitch.Position + offset;
                Entity x;
                x = _World.CreateEntity("KillerGun", position, e, "killerrightgun", offset, e);
                x.Refresh();
                children.Add(x);
                offset.X = -3.15f;
                position = bitch.Position + offset;
                x = _World.CreateEntity("KillerGun", position, e, "killerleftgun", offset);
                x.Refresh();
                children.Add(x);
                e.AddComponent<Children>(new Children(children));
            }

            if (spriteKey == "eye")
            {
                _World.enemySpawnSystem.MookSprite = "eyeshot";
                _World.enemySpawnSystem.SpawnRate = 0;
                _World.enemySpawnSystem.MookSpawnRate = 2;
            }

            if (spriteKey == "clawbossthing")
            {
                _World.enemySpawnSystem.MookSprite = "8prongbrownthingwithfangs";
                _World.enemySpawnSystem.ThugSprite = "minibrownclawboss";
                _World.enemySpawnSystem.SpawnRate = 0;
                _World.enemySpawnSystem.MookSpawnRate = 2;
                _World.enemySpawnSystem.ThugSpawnRate = 2;
            }

            if (spriteKey == "flamer")
            {
                _World.enemySpawnSystem.SpawnRate = 0;
            }

            #endregion Special Cases

            return e;
        }
コード例 #2
0
        public Entity BuildEntity(Entity e, params object[] args)
        {
            e.Group = "Base";
            e.Tag = "Base";

            #region Body

            Body Body = e.AddComponent<Body>(new Body(world, e));
            {
                FixtureFactory.AttachEllipse(//Add a basic bounding box (rectangle status)
                    ConvertUnits.ToSimUnits(spriteSheet.Animations["base"][0].Width / 2f),
                    ConvertUnits.ToSimUnits(spriteSheet.Animations["base"][0].Height / 2f),
                    15,
                    1,
                    Body);
                Body.Position = ConvertUnits.ToSimUnits(new Vector2(0, 0));
                Body.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Static;
                Body.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat16;
                Body.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat4 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat5 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat16;

                Body.SleepingAllowed = false;
            }

            #endregion Body

            #region Sprite

            Sprite Sprite = e.AddComponent<Sprite>(
                new Sprite(spriteSheet, "base",
                    Body, 1, Color.White, 0.1f));

            #endregion Sprite

            e.AddComponent<Score>(new Score());

            int health = 40;
            #if DEBUG
            health = 1000000;
            #endif
            Health h = new Health(health);
            h.OnDeath += LambdaComplex.BigEnemyDeath(e, world as SpaceWorld, 0);

            h.OnDamage +=
                ent =>
                {
                    SoundManager.SetVibration(0.25f, 0.15f);

                    e.RemoveComponent<Sprite>(Sprite);

                    double healthFraction = (h.CurrentHealth / h.MaxHealth);

                    if (healthFraction >= 0.33 && Sprite.FrameIndex == 2)
                    {
                        Sprite.FrameIndex = 1;
                    }
                    else if (healthFraction < 0.33 && Sprite.FrameIndex == 1)
                    {
                        Sprite.FrameIndex = 2;
                        SoundManager.SetVibration(0.3f, 0.3f);
                    }

                    else if (healthFraction >= 0.66 && Sprite.FrameIndex == 1)
                    {
                        Sprite.FrameIndex = 0;
                    }
                    else if (healthFraction < 0.66 && Sprite.FrameIndex == 0)
                    {
                        Sprite.FrameIndex = 1;
                        SoundManager.SetVibration(0.3f, 0.3f);
                    }

                    e.AddComponent<Sprite>(Sprite);
                };

            e.AddComponent<Health>(h);

            e.AddComponent<HealthRender>(new HealthRender());

            return e;
        }
コード例 #3
0
        /// <summary>
        /// Builds a player based on the specific index
        /// </summary>
        /// <param name="e"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public Entity BuildEntity(Entity e, params object[] args)
        {
            PlayerIndex index = (PlayerIndex)args[0];
            e.Group = "Players";
            string tag = "Player" + ((int)index + 1);
            e.Tag = "P" + ((int)index + 1);

            try
            {
                int playerIndex = int.Parse(e.Tag.Replace("P", "")) - 1;
            }
            catch
            {
                throw new FormatException("Yeah f**k you" + e.Tag);
            }

            #region Body

            //Set up initial body
            Body Body = e.AddComponent<Body>(new Body(world, e));
            FixtureFactory.AttachEllipse( //Add a basic bounding box (rectangle status)
                ConvertUnits.ToSimUnits(spriteSheet.Animations[tag][0].Width / 2f),
                ConvertUnits.ToSimUnits(spriteSheet.Animations[tag][0].Height / 2f),
                6,
                1,

                Body);

            if (locations.Values.Count == 0)
                SetStartingLocations();

            //Set the position
            Body.Position = locations[index];
            Body.BodyType = BodyType.Dynamic;
            Body.SleepingAllowed = false;
            Body.FixedRotation = true;
            Body.RotateTo(Body.Position);
            Body.Mass = 2;

            Body.CollisionCategories = Category.Cat1 | Category.Cat12;

            #endregion Body

            #region Sprite

            Sprite Sprite = e.AddComponent<Sprite>(
                new Sprite(spriteSheet, tag,
                    Body, 1, Color.White, 0.5f));

            #endregion Sprite

            #region Animation

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

            #endregion Animation

            #region Health

            Health h = new Health(1);

            h.OnDeath += LambdaComplex.SmallEnemyDeath(e, world as SpaceWorld, 0);
            h.OnDeath +=
                ent =>
                {
                    SoundManager.SetVibration(index, 0.4f, 0.5f);
                };
            e.AddComponent<Health>(h);

            #endregion Health

            #region Inventory

            uint yellow = 0;
            #if DEBUG
            yellow = 1000;
            #endif
            Inventory inventory = e.AddComponent<Inventory>(new Inventory(50, 50, 50, yellow, InvType.Player, ""));
            inventory.CurrentGun = inventory.WHITE;

            #endregion Inventory

            #region AI
            //Create AI if it's an artificial player.
            if (args.Length >= 2 && (bool)args[1])
            {
                AI ai = e.AddComponent<AI>(new AI(null,
                    (target) =>
                    {

                        bool returnCode = false;
                        AI eai = e.GetComponent<AI>();
                        if (target == null)
                        {
                            #region Movement
                            //When there is no target focus on building structures around the base on random sides and possibly preparing mines.
                            //If AI cannot afford to build, then commence swarm code (move around base randomly awaiting a target.
                            Body.LinearVelocity = Vector2.Zero;

                            Vector2 Omega = Vector2.Zero - Body.Position;

                            Body.ApplyLinearImpulse(new Vector2(Omega.Y, -Omega.X) * 2);

                            Body.RotateTo(Vector2.Zero - Body.Position);
                            Body.Rotation += (float)Math.PI;

                            if (Vector2.Distance(Vector2.Zero, Body.Position) > ConvertUnits.ToSimUnits(200))
                                Body.ApplyLinearImpulse((Vector2.Zero - Body.Position)*0.5f);
                            else
                                if (inventory.YELLOW >= 25 && r.Next(100) > 95)
                                {
                                    world.CreateEntity("Turret", ConvertUnits.ToDisplayUnits(Body.Position), e).Refresh();
                                    inventory.YELLOW -= 25;
                                    SoundManager.Play("Construction");
                                }

                            #endregion

                            returnCode = true;
                        }
                        else
                        {
                            #region Movement

                            Body.LinearVelocity = Vector2.Zero;

                            if (Vector2.Distance(Body.Position, target.Position) > 3)
                                Body.ApplyLinearImpulse(new Vector2((float)Math.Cos(Body.Rotation), (float)Math.Sin(Body.Rotation)) * 10);
                            else
                            {
                                //V = OMEGA x R
                                Vector2 R = Body.Position - target.Position;
                                Vector2 Omega = target.Position - Body.Position;

                                Body.ApplyLinearImpulse(new Vector2(Omega.Y, -Omega.X) * 3);
                            }

                            #endregion

                            #region Shooting
                            //TRUE AI CODE OCCURS HERE
                            //Begin to seek an attack
                            Gun g = inventory.CurrentGun;
                            g.BulletsToFire = true;

                            /* Aiming *\
                                * X = v*t + x_o therefore
                                *  let X_aim = v_tar*t + x_tar
                                *            = v_bul*t + x_bul
                                *  therefore
                                *      0 = v_tar*t + x_tar - (v_bul*t + x_bul) =>
                                *  therefore
                                *      x_bul - x_tar = t(v_tar - v_bul)
                                *  so that
                                *      t = (x_bul - x_tar)/(v_tar - v_bul)
                                *  therefore X = (v_tar)*(x_bul - x_tar)/(v_tar - v_bul) + x_tar
                                */

                            //Vector2 zero = target.LinearVelocity*time - inv.CurrentGun.BulletVelocity*time + target.Position - Body.Position;
                            Vector2 time = (Body.Position - target.Position) /
                                (target.LinearVelocity - inventory.CurrentGun.BulletVelocity);

                            Vector2 XFinal = (target.LinearVelocity) * time + target.Position;
                            Body.RotateTo(XFinal - Body.Position);
                            #endregion
                        }

                        return returnCode;
                    }, "Enemies", ConvertUnits.ToSimUnits(450f)));
            }
            #endregion

            return e;
        }