Example #1
0
        private BulletData mBulletData;                                          // The bullet data of this bullet. Needed for path, onHit, and damage.

        public Bullet(Vector2 position, GunData gunData, bool up, bool mirrored) :
            base(
                new List <Sprite> {
            new ManualSprite(ResourceManager.LoadSpriteData("Actor/Ally/Player/Guns/Projectiles/Projectiles", 5, 2),
                             (int)gunData.GunType,
                             up ? 1 : 0)
        },
                new List <Rectangle> {
            new Rectangle(0, 1, 6, 3)
        },
                position + CalculateOffset(gunData, up, mirrored),
                0)
        {
            CollisionListener += _OnCollision;
            Body.CollisionType = CollisionType.SOFT;

            mBulletData = gunData.BulletData;

            if (up)
            {
                Body.Velocity = new Vector2((mirrored ? -1 : 1) * mBulletData.AngledSpeed, -mBulletData.AngledSpeed);
            }
            else
            {
                Body.Velocity = new Vector2((mirrored ? -1 : 1) * mBulletData.Speed, 0);
            }

            Mirrored = mirrored;
        }
Example #2
0
        // Calculates the position at which the bullet should spawn based on gun data.
        private static Vector2 CalculateOffset(GunData gunData, bool up, bool mirrored)
        {
            Vector2 offset = armOffset + (up ? (gunData.BarrelAngledPos + angledBulletOffset) : (gunData.BarrelPos + bulletOffset));

            if (mirrored)
            {
                offset.X = offset.X * -1;
            }
            return(offset);
        }