示例#1
0
文件: Gun.cs 项目: ASOIU/BlockWars
        public Gun(World world, Vector2 position, Player player)
        {
            ObjectType = EObjectType.Gun;
            mPosition = position;
            mWorld = world;
            mPlayer = player;
            CurrentMagazine = new List<int>();

            Vector2 size = new Vector2(10, 8);
            mBaseBox = new Box(world, position, size, "gun", true, player);

            size = new Vector2(10, 2);
            mBarrelBox = new Box(world, position, size, "barrel", true, player);

            Filter filter = new Filter();
            filter.maskBits = 0;
            Fixture fixture = mBarrelBox.mBody.GetFixtureList();
            fixture.SetFilterData(ref filter);
            fixture = mBaseBox.mBody.GetFixtureList();
            fixture.SetFilterData(ref filter);

            mIsActive = false;

            mFilter = new Filter();
            if (mPlayer.PlayerType == EntityCategory.Player2)
                mFilter.maskBits = (ushort)(EntityCategory.Player1);
            else
                mFilter.maskBits = (ushort)(EntityCategory.Player2);
            mFilter.categoryBits = (ushort)mPlayer.PlayerType;
        }
示例#2
0
文件: Bullet.cs 项目: ASOIU/BlockWars
 public Bullet(World world, Vector2 position, float maxDamageValue, Player player,int bulletType)
 {
     mPlayer = player;
     ObjectType = EObjectType.Bullet;
     switch (bulletType)
     {
         case 1:
             mDamageRadius = 10;
             break;
         case 2:
             mDamageRadius = 20;
             break;
     }
     mMaxDamageValue = maxDamageValue;
     Vector2 size = new Vector2(5, 5);
     mBox = new Box(world, position, size, "bullet", true, player);
     MassData massData = new MassData();
     massData.mass = 1000;
     mBox.mBody.SetMassData(ref massData);
     mIsActive = false;
     mIsDestoyed = false;
     Body.SetUserData(this);
 }
示例#3
0
        public static List<Box> Destroy(Box box, World world, float explosionDistance, Player player)
        {
            List<Box> boxes = new List<Box>();

            Vector2 pos = box.mBody.GetPosition();
            Vector2 size = box.mSize;
            Vector2 partBoxSize = size / 2;

            if (size.X < 1f || size.Y < 1)
            {
                return boxes;
            }

            Vector2 force = new Vector2(1.1f / explosionDistance);

            Vector2 partBoxPos = pos - partBoxSize / 2;
            Box partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player);
            partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero);
            boxes.Add(partBox);

            partBoxPos = pos + partBoxSize / 2;
            partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player);
            partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero);
            boxes.Add(partBox);

            partBoxPos = new Vector2(pos.X + partBoxSize.X / 2, pos.Y - partBoxSize.Y / 2);
            partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player);
            partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero);
            boxes.Add(partBox);

            partBoxPos = new Vector2(pos.X - partBoxSize.X / 2, pos.Y + partBoxSize.Y / 2);
            partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player);
            partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero);
            boxes.Add(partBox);
            return boxes;
        }