예제 #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
파일: Box.cs 프로젝트: ASOIU/BlockWars
        public Box(World world, Vector2 position, Vector2 size, string texture, bool isStatic, Player player, float health = 100)
        {
            ObjectType = EObjectType.Box;
            mHealth = health;
            mStartHealth = health;
            mIsDestroyed = false;
            mSize = size;
            mWorld = world;
            mTexture = texture;
            mPlayer = player;
            DestroyTime = null;
            PolygonShape polygonShape = new PolygonShape();
            polygonShape.SetAsBox(size.X / 2f, size.Y / 2f);

            BodyDef bodyDef = new BodyDef();
            bodyDef.position = position;
            bodyDef.bullet = true;
            if (isStatic)
            {
                bodyDef.type = BodyType.Static;
            }
            else
            {
                bodyDef.type = BodyType.Dynamic;
            }
            mBody = world.CreateBody(bodyDef);

            FixtureDef fixtureDef = new FixtureDef();
            fixtureDef.shape = polygonShape;//Форма
            fixtureDef.density = 0.1f;//Плотность
            fixtureDef.friction = 0.3f;//Сила трения
            fixtureDef.restitution = 0f;//Отскок

            Filter filter = new Filter();
            filter.maskBits = (ushort)(EntityCategory.Player1 | EntityCategory.Player2);
            filter.categoryBits = (ushort)player.PlayerType;

            var fixture = mBody.CreateFixture(fixtureDef);
            fixture.SetFilterData(ref filter);
            MassData data = new MassData();
            data.mass = 0.01f;
            mBody.SetUserData(this);
        }
        public Equipment(EquipmentName equipName, GameContent gameContent, World world)
        {
            this.gameContent = gameContent;
            this.world = world;

            this.equipName = equipName;
            BodyDef bd = new BodyDef();
            bd.type = BodyType.Dynamic;
            body = world.CreateBody(bd);

            equipmentData = gameContent.content.Load<EquipmentData>("Graphics/" + equipName.ToString());

            topLeftVertex = equipmentData.TopLeftVertex;
            origin = equipmentData.Origin;
            rotationButtonPos = equipmentData.RotationButtonPosition;

            rightClampPositionX = equipmentData.ClampData.RightClampPositionX;
            clampRotation = equipmentData.ClampData.RotationInDeg / 180f * (float)Math.PI;
            clampEnabled = equipmentData.ClampData.ClampEnabled;

            SetFixtures();

            // Collide only with Ground but not with itself and bonded Filter
            mouseFilter = new Filter();
            mouseFilter.categoryBits = 0x0002; mouseFilter.maskBits = 0x0001; mouseFilter.groupIndex = -2;

            // Collide with every thing
            groundFilter = new Filter();
            groundFilter.categoryBits = 0x0001; groundFilter.maskBits = 65535; groundFilter.groupIndex = 0;

            equipFilter = new Filter();
            equipFilter.categoryBits = 0x0002; equipFilter.maskBits = 0x0001; equipFilter.groupIndex = 2;

            //SetMode(false, false);

            body.SetUserData((EquipmentName)equipName);
        }
        public Atom(Symbol symbol, Vector2 position, GameContent gameContent, World world)
        {
            this.gameContent = gameContent;
            this.world = world;

            if (symbol == Symbol.Ra) eye = EyeState.Angry;

            this.symbol = symbol;
            this.symbolStr = symbol.ToString();
            symbolCenter = gameContent.symbolFont.MeasureString(this.symbolStr);
            symbolCenter.X *= 0.5f;
            symbolCenter.Y *= 0.92f;

            bondsLeft = (int)symbol;

            BodyDef bd = new BodyDef();
            bd.type = BodyType.Dynamic;
            bd.position = this.position = position / gameContent.b2Scale;
            bd.bullet = true;
            body = world.CreateBody(bd);
            body.SetUserData(this);

            CircleShape cs = new CircleShape();
            cs._radius = gameContent.atomRadius / gameContent.b2Scale;

            FixtureDef fd = new FixtureDef();
            fd.shape = cs;
            fd.restitution = 0.2f;
            fd.friction = 0.5f;

            fixture = body.CreateFixture(fd);

            electroShockAnimation = new Animation(gameContent.electroShock, 3, 0.1f, true, new Vector2(0.5f, 0.5f));

            radiationSmoke = new RadiationSmoke(gameContent, this);

            // Collide only with Ground but not with itself and bonded Filter
            mouseFilter = new Filter();
            mouseFilter.categoryBits = 0x0002; mouseFilter.maskBits = 0x0001; mouseFilter.groupIndex = -2;

            // Collide with every thing
            atomFilter = new Filter();
            atomFilter.categoryBits = 0x0001; atomFilter.maskBits = 0x0001; atomFilter.groupIndex = 1;

            fixture.SetFilterData(ref atomFilter);

            SetMode(false, false);
        }
예제 #5
0
	    /// Get the contact filtering data.
	    public void GetFilterData(out Filter filter)
        {
            filter = _filter;
        }
예제 #6
0
        /// Set the contact filtering data. This will not update contacts until the next time
        /// step when either parent body is active and awake.
	    public void SetFilterData(ref Filter filter)
        {
            _filter = filter;

	        if (_body == null)
	        {
		        return;
	        }

	        // Flag associated contacts for filtering.
	        ContactEdge edge = _body.GetContactList();
	        while (edge != null)
	        {
		        Contact contact = edge.Contact;
		        Fixture fixtureA = contact.GetFixtureA();
		        Fixture fixtureB = contact.GetFixtureB();
		        if (fixtureA == this || fixtureB == this)
		        {
			        contact.FlagForFiltering();
		        }

                edge = edge.Next;
	        }
        }
        // We need separation create/destroy functions from the constructor/destructor because
        // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++).
        internal void Create(Body body, FixtureDef def)
        {
            _userData = def.userData;
            _friction = def.friction;
            _restitution = def.restitution;

            _body = body;
            _next = null;

            _filter = def.filter;

            _isSensor = def.isSensor;

            _shape = def.shape.Clone();

            _density = def.density;
        }