Exemple #1
0
        private void removeFixtureOnSeparation(Fixture f1, Fixture f2)
        {
            AdditionalFixtureData f1data = (AdditionalFixtureData)f1.UserData;
            AdditionalFixtureData f2data = (AdditionalFixtureData)f2.UserData;
            Fixture fixToRemove          = null;

            if (f1data == null || f2data == null)
            {
                return;
            }

            foreach (Fixture fixSearched in f1data.fixInContactList)
            {
                if (fixSearched == f2)
                {
                    fixToRemove = fixSearched;
                    break;
                }
            }

            f1data.fixInContactList.Remove(fixToRemove);
            if (f1data.fixInContactList.Count == 0)
            {
                f1data.isTouching = false;
            }
        }
Exemple #2
0
        private void checkSensorInteractions()
        {
            if (!Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                return;
            }
            AdditionalFixtureData fixInContactData;
            AdditionalFixtureData sensorData = (AdditionalFixtureData)playerHitSensorFix.UserData;

            if (sensorData.isTouching == true)
            {
                foreach (Fixture fixInContact in sensorData.fixInContactList)
                {
                    if (fixInContact.UserData == null)
                    {
                        continue;
                    }
                    fixInContactData = (AdditionalFixtureData)fixInContact.UserData;
                }
            }
        }
Exemple #3
0
        public Fixture createOctogoneFixture(float width, float height, Vector2 translationVector, AdditionalFixtureData userData = null)
        {
            float dh = height / 3f;
            float dw = width / 3f;

            /* Création des vertices correspondant à un octogone inscrit dans le rectangle passé en param */
            Vertices octogonVertices = new Vertices();

            octogonVertices.Add(new Vector2(0, dh) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(0, dh * 2f) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(dw, 0) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(dw * 2, 0) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(dw, height) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(dw * 2, height) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(width, dh) * KingOfThePit.pixelToMeter);
            octogonVertices.Add(new Vector2(width, dh * 2) * KingOfThePit.pixelToMeter);

            /* création de la shape et transaltion pour prendre en compte la position définie par le centre du body */
            octogonVertices.Translate(new Vector2(-width / 2f, -height / 2f) * KingOfThePit.pixelToMeter);
            octogonVertices.Translate(translationVector);
            PolygonShape octogonShape = new PolygonShape(octogonVertices, 20);

            Fixture octogonFix = body.CreateFixture(octogonShape, userData);

            return(octogonFix);
        }
Exemple #4
0
        public Fixture createRectangleFixture(float width, float height, Vector2 transalationVector, AdditionalFixtureData userData = null)
        {
            //Create rectangles shapes
            Vertices     rectangleVertices = PolygonTools.CreateRectangle((width / 2) * KingOfThePit.pixelToMeter, (height / 2) * KingOfThePit.pixelToMeter);
            PolygonShape rectangleShape    = new PolygonShape(rectangleVertices, 1);

            //Transalte rectangles shapes to set there positions
            rectangleShape.Vertices.Translate(transalationVector * KingOfThePit.pixelToMeter);
            //Bind body to shpes (create a compound body) and return
            return(body.CreateFixture(rectangleShape, userData));
        }