Example #1
0
        private void checkSensorInteractions()
        {
            //if (!Keyboard.GetState().IsKeyDown(Keys.Space))
            if (!Bloodbender.ptr.inputHelper.IsNewMouseButtonPress(MouseButtons.LeftButton) && !Bloodbender.ptr.inputHelper.IsNewButtonPress(Buttons.RightTrigger))
            {
                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;
                    if (fixInContactData.physicParent is Totem)
                    {
                        ((Totem)fixInContactData.physicParent).generateProjectile(angleWithMouse());
                    }
                    else if (fixInContactData.physicParent is Enemy)
                    {
                        ((Enemy)fixInContactData.physicParent).takeHit(angleWithMouse());
                    }
                }
            }
        }
Example #2
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;
            }
        }
Example #3
0
        private bool CollisionCheck(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            AdditionalFixtureData additionalFixtureData = (AdditionalFixtureData)fixtureB.UserData;

            if (additionalFixtureData != null)
            {
                if (additionalFixtureData.physicParent is LanceGobelin)
                {
                    takeHit();
                }
            }
            return(true);
        }
Example #4
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) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(0, dh * 2f) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(dw, 0) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(dw * 2, 0) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(dw, height) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(dw * 2, height) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(width, dh) * Bloodbender.pixelToMeter);
            octogonVertices.Add(new Vector2(width, dh * 2) * Bloodbender.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) * Bloodbender.pixelToMeter);
            octogonVertices.Translate(translationVector);
            PolygonShape octogonShape = new PolygonShape(octogonVertices, 20);
            //octogonShape.Vertices.Translate(new Vector2(-width / 2f, -height / 2f) * Bloodbender.pixelToMeter);
            //octogonShape.Vertices.Translate(translationVector);

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

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

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