public Entity[] BuildEntityGroup(EntityWorld world, params object[] args)
        {
            Inventory inv = (args[0] as Entity).GetComponent<Inventory>();
            List<Entity> rets = new List<Entity>();

            //If the bullet type is not white
            if (inv.YELLOW > 0)
            {
                int shot = 1;
                SoundManager.Play("Shot" + shot.ToString(), .25f);

                //Shoot bullets out from base at an even division of the circle * a shot ratio

                double max = Math.PI * 2;
                double step = (Math.PI * 2 * ShotRatio) / (Math.Min(inv.YELLOW, MaxShot));
                for (double angle = 0;
                    angle < max;
                    angle += step)
                {
                    Transform fireAt = new Transform(Vector2.Zero, (float)angle);

                    Entity bullet = world.CreateEntity("WhiteBullet3", fireAt);

                    Bullet bb = bullet.GetComponent<Bullet>();
                    bb.Firer = null;
                    bullet.RemoveComponent<Bullet>(bullet.GetComponent<Bullet>());
                    bullet.AddComponent<Bullet>(bb);
                    bullet.Refresh();

                    rets.Add(bullet);
                }
                inv.YELLOW = 0;
            }
            return rets.ToArray();
        }
        /// <summary>
        /// Builds a bullet entity.
        /// </summary>
        /// <param name="e">The entity to build.</param>
        /// <param name="args">[0] = ITransform; [1] = IVelocity; [2] = Sprite; [3] = Bullet </param>
        /// <returns></returns>
        public Entity BuildEntity(Entity e, params object[] args)
        {
            e.Group = "Bullets";

            //Set up defaults
            IVelocity velocity = _DefaultVelocity;
            Sprite sprite = _DefaultSprite;
            ITransform transform = new Transform(Vector2.Zero, 0.0f);
            Bullet bullet = _DefaultBullet;

            //Check arguments.
            if (args != null)
            {
                if (args.Length > 0)
                    transform = (args[0] as ITransform);
                if (args.Length > 1)
                    velocity = (args[1] as IVelocity);
                if (args.Length > 2)
                    sprite = (Sprite)args[2];
                if (args.Length > 3)
                    bullet = (Bullet)args[3];
            }

            //Make the velocity proportional to the default velocity and the target rotation
            e.AddComponent<Particle>(new Particle(e, transform.Position, transform.Rotation,
                 velocity.LinearVelocity * new Vector2((float)Math.Cos(transform.Rotation),
                     (float)Math.Sin(transform.Rotation)),
                    velocity.AngularVelocity));
            e.AddComponent<Sprite>(sprite);
            e.AddComponent<Bullet>(bullet);

            return e;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            Entity ent = args[0] as Entity;
            Vector2 offset = (Vector2)args[1];
            Vector2 velocity = -ent.GetComponent<Body>().LinearVelocity;
            string spriteKey = "bluespark";

            Vector2 center = new Vector2(_SpriteSheet[spriteKey][0].Center.X, _SpriteSheet[spriteKey][0].Center.Y);

            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, 1));
            Animation a = e.AddComponent<Animation>(new Animation(AnimationType.Once, 5));
            ITransform i = new Transform(ent.GetComponent<Body>().Position + offset, 0f);
            IVelocity v = new Velocity(velocity, 0f);
            e.AddComponent<Particle>(new Particle(e, i.Position, i.Rotation, v.LinearVelocity, v.AngularVelocity));
            e.Group = "Explosions";

            return e;
        }
Esempio n. 4
0
        public override void Process(Entity e)
        {
            //Process guns
            Inventory inv = invMapper.Get(e);
            Gun gun = inv.CurrentGun;
            ITransform transform = transformMapper.Get(e);

            gun.Elapsed += elapsedMilli;

            //Update power
            if (gun.Power > 1)
            {
                gun.UpdatePower(elapsedMilli);
            }

            if (e.Group.Equals("Players"))
            {
                ITransform t = e.GetComponent<ITransform>();

                int index;
                try
                {
                    index = int.Parse(e.Tag.Replace("P", "")) - 1;
                }
                catch
                {
                    return;
                }

                if (!e.HasComponent<AI>())
                {
                    PlayerIndex playerIndex = (PlayerIndex)index;
                    GamePadState padState = GamePad.GetState(playerIndex);
                    KeyboardState keyState = Keyboard.GetState();

                    if (padState.IsConnected)
                    {
                        if (padState.IsButtonDown(Buttons.RightTrigger))
                            gun.BulletsToFire = true;
                    }

                    else if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                        gun.BulletsToFire = true;

                    if (!inv.BuildMode &&
                        (GamePad.GetState((PlayerIndex)index).IsButtonDown(Buttons.LeftTrigger) ||
                        (!GamePad.GetState((PlayerIndex)index).IsConnected && Mouse.GetState().RightButton == ButtonState.Pressed)))
                    {
                        world.CreateEntityGroup("BaseShot", "Bullets", e);
                        if (gun.Ammunition <= 0)
                            inv.ChangeGun(e, GunType.WHITE);
                    }
                }
            }

            //Fire bullets bro
            if (!inv.BuildMode && gun.Elapsed > gun.Interval / gun.Power && gun.BulletsToFire && gun.Ammunition > 0)
            {
                if (inv._type == InvType.Cannon)
                {
                    ITransform t = e.GetComponent<ITransform>();
                    world.CreateEntity("ExplosiveBullet", t.Position, new Vector2((float)Math.Cos(t.Rotation) * 8, (float)Math.Sin(t.Rotation) * 8), 1).Refresh();
                }
                else
                {
                    foreach (Vector2 offset in gun.GunOffsets)
                    {
                        float rotation = transform.Rotation;
                        float r_o = (float)Math.Atan2(offset.X, offset.Y);
                        float r_a = (float)Math.Atan2(offset.Y, offset.X);

                        Vector2 rotatedOffset = ConvertUnits.ToSimUnits(new Vector2((float)Math.Cos(r_a + rotation) * offset.Length(), (float)Math.Sin(r_a + rotation) * offset.Length()));
                        Transform fireAt = new Transform(transform.Position + rotatedOffset, rotation);

                        Entity bullet = world.CreateEntity(gun.BulletTemplateTag, fireAt);
                        gun.BulletVelocity = bullet.GetComponent<IVelocity>().LinearVelocity;
                        Bullet bb = bullet.GetComponent<Bullet>();
                        bb.Firer = e;
                        bullet.RemoveComponent<Bullet>(bullet.GetComponent<Bullet>());
                        bullet.AddComponent<Bullet>(bb);
                        bullet.Refresh();

                        int shot = r.Next(1, 3);
                        if (e.Group == "Structures" || e.Group == "Enemies")
                            SoundManager.Play("Shot" + shot.ToString(), .25f);
                        else
                            SoundManager.Play("Shot" + shot.ToString());
                    }

                    --gun.Ammunition;
                    if (gun.Ammunition == 0)
                    {
                        inv.CurrentGun = inv.WHITE;
                    }
                }

                gun.BulletsToFire = false;
                gun.Elapsed = 0;
            }
        }
Esempio n. 5
0
        public static Func<Body, bool> CreateBigGreen(Entity ent, float speed, float sideTime, float shootTime, float shotTime, float nonShoot, Sprite s, EntityWorld _World)
        {
            bool shot = false;
            float shotttt = 0f;
            float time = 0f;
            float ttttime = 0f;

            return
                (target) =>
                {
                    if (ttttime > sideTime)
                    {
                        ttttime = 0f;
                    }

                    Body b = ent.GetComponent<Body>();
                    float x = (float)(ConvertUnits.ToSimUnits(ScreenHelper.Viewport.Width / 2) * (Math.Cos(MathHelper.ToRadians(360 / sideTime) * ttttime)));

                    time += (float)_World.Delta / 1000;

                    if (shot)
                    {
                        if (shotttt > shotTime)
                        {
                            shotttt = 0f;

                            Vector2 offset = ConvertUnits.ToSimUnits(new Vector2(0, 25));

                            float rot = (float)Math.PI / 2;

                            Transform fireAt = new Transform(b.Position + offset, rot);

                            SoundManager.Play("Shot1");
                            _World.CreateEntity("BigGreenBullet", fireAt).Refresh();
                        }
                        if (time > shootTime)
                        {
                            time = 0f;
                            shot = false;
                        }
                    }
                    else
                    {
                        if (time > nonShoot)
                        {
                            time = 0f;
                            shot = true;
                        }
                    }

                    if (!ent.HasComponent<Slow>())
                    {
                        b.Position = new Vector2(x, b.Position.Y + speed * _World.Delta / 1000);
                        shotttt += (float)_World.Delta / 1000;
                        time += (float)_World.Delta / 1000;
                        ttttime += (float)_World.Delta / 1000;
                    }
                    else
                    {
                        handleSlow(ent, _World);
                    }
                    return false;
                };
        }
Esempio n. 6
0
        public static Func<Body, bool> CreateKillerGun(Entity ent, Entity origin, Vector2 offs, float shotTime, float shootTime, float nonShot, Sprite s, EntityWorld _World, bool shit)
        {
            bool shot = false;
            float shotttt = 0f;
            float time = 0f;

            return
                (target) =>
                {
                    Body b = ent.GetComponent<Body>();
                    Body b2 = origin.GetComponent<Body>();
                    b.RotateTo(Vector2.UnitX);
                    b.Position = b2.Position + offs;

                    if (shot)
                    {
                        if (shotttt > shotTime)
                        {
                            shotttt = 0f;

                            Vector2 offset = ConvertUnits.ToSimUnits(new Vector2(0, 50));

                            if (shit)
                                offset.X = ConvertUnits.ToSimUnits(6);
                            float rot = (float)Math.PI / 2;

                            Transform fireAt = new Transform(b.Position + offset, rot);

                            SoundManager.Play("Shot1");
                            _World.CreateEntity("KillerBullet", fireAt).Refresh();
                        }
                        if (time > shootTime)
                        {
                            time = 0f;
                            shot = false;
                        }
                    }
                    else
                    {
                        if (time > nonShot)
                        {
                            time = 0f;
                            shot = true;
                        }
                    }

                    if (!ent.HasComponent<Slow>())
                    {
                        shotttt += (float)_World.Delta / 1000;
                        time += (float)_World.Delta / 1000;
                    }

                    return false;
                };
        }