Ejemplo n.º 1
0
        // Implement contact listener.
        public override void BeginContact(b2Contact contact)
        {
            b2Fixture fixtureA = contact.GetFixtureA();
            b2Fixture fixtureB = contact.GetFixtureB();

            if (fixtureA == m_sensor)
            {
                object userData = fixtureB.Body.UserData;
                if (userData != null)
                {
                    m_touching[(int)userData] = true;
                }
            }

            if (fixtureB == m_sensor)
            {
                object userData = fixtureA.Body.UserData;
                if (userData != null)
                {
                    m_touching[(int)userData] = true;
                }
            }
        }
Ejemplo n.º 2
0
        public override void PreSolve(b2Contact contact, b2Manifold oldManifold)
        {
            base.PreSolve(contact, oldManifold);

            b2Fixture fixtureA = contact.GetFixtureA();
            b2Fixture fixtureB = contact.GetFixtureB();

            if (fixtureA != m_platform && fixtureA != m_character)
            {
                return;
            }

            if (fixtureB != m_platform && fixtureB != m_character)
            {
                return;
            }

            b2Vec2 position = m_character.Body.Position;

            if (position.y < m_top + m_radius - 3.0f * b2Settings.b2_linearSlop)
            {
                contact.SetEnabled(false);
            }
        }
Ejemplo n.º 3
0
        public override void PreSolve(b2Contact contact, b2Manifold oldManifold)
        {
            b2Manifold manifold = contact.GetManifold();

            if (manifold.pointCount == 0)
            {
                return;
            }

            b2Fixture fixtureA = contact.GetFixtureA();
            b2Fixture fixtureB = contact.GetFixtureB();

            b2Collision.b2GetPointStates(state1, state2, oldManifold, manifold);

            contact.GetWorldManifold(ref worldManifold);

            for (int i = 0; i < manifold.pointCount && m_pointCount < k_maxContactPoints; ++i)
            {
                ContactPoint cp = m_points[m_pointCount];
                if (cp == null)
                {
                    cp = new ContactPoint();
                    m_points[m_pointCount] = cp;
                }
                cp.fixtureA = fixtureA;
                cp.fixtureB = fixtureB;
                cp.position = worldManifold.points[i];
                cp.normal = worldManifold.normal;
                cp.state = state2[i];
                ++m_pointCount;
            }
        }
Ejemplo n.º 4
0
            // called by Box2D during the Step function when two fixtures finish touching
            public override void EndContact(b2Contact contact)
            {
                base.EndContact(contact);

                PlanetCuteRubeLayer layer = (PlanetCuteRubeLayer)m_layer;
                b2Fixture fA = contact.GetFixtureA();
                b2Fixture fB = contact.GetFixtureB();

                if (fA == layer.m_footSensorFixture || fB == layer.m_footSensorFixture)
                    layer.m_numFootContacts--;
                //CCLOG("Num foot contacts: %d", layer->m_numFootContacts);
            }
Ejemplo n.º 5
0
            public override void BeginContact(b2Contact contact)
            {
                base.BeginContact(contact);

                PlanetCuteRubeLayer layer = m_layer;
                b2Fixture fA = contact.GetFixtureA();
                b2Fixture fB = contact.GetFixtureB();

                if (fA == layer.m_footSensorFixture || fB == layer.m_footSensorFixture)
                    layer.m_numFootContacts++;
                //CCLOG("Num foot contacts: %d", layer->m_numFootContacts);

                PlanetCuteFixtureUserData fudA = (PlanetCuteFixtureUserData)fA.UserData;
                PlanetCuteFixtureUserData fudB = (PlanetCuteFixtureUserData)fB.UserData;

                if (fudA.fixtureType == _fixtureType.FT_PICKUP && fB.Body == layer.m_playerBody)
                    layer.m_pickupsToProcess.Add(fudA);
                if (fudB.fixtureType == _fixtureType.FT_PICKUP && fA.Body == layer.m_playerBody)
                    layer.m_pickupsToProcess.Add(fudB);
            }
Ejemplo n.º 6
0
        public override void BeginContact(b2Contact contact)
        {
            //base.BeginContact (contact);

            b2Body bodyA = contact.GetFixtureA().Body;
            b2Body bodyB = contact.GetFixtureB().Body;
            BodyNode bodyNodeA = (BodyNode)bodyA.UserData;
            BodyNode bodyNodeB = (BodyNode)bodyB.UserData;

            ////////////////////////////////////////
            ////////////////////////////////////////
            //NINJA NODES WITH GROUNDPLANE

            if (bodyNodeA is Ninja && bodyNodeB is GroundPlane)
            {

                Ninja theNinja = (Ninja)bodyNodeA;
                //GroundPlane* theGroundPlane = (GroundPlane*)bodyNodeB;

                TheLevel.SharedLevel.StopDotting();
                TheLevel.SharedLevel.ShowNinjaOnGround(theNinja);
                TheLevel.SharedLevel.ProceedToNextTurn(theNinja);

            }
            else  if (bodyNodeA is GroundPlane && bodyNodeB is Ninja)
            {

                Ninja theNinja = (Ninja)bodyNodeB;
                // GroundPlane* theGroundPlane = (GroundPlane*)bodyNodeA;

                TheLevel.SharedLevel.StopDotting();
                TheLevel.SharedLevel.ShowNinjaOnGround(theNinja);
                TheLevel.SharedLevel.ProceedToNextTurn(theNinja);

            }

            ////////////////////////////////////////
            ////////////////////////////////////////
            //NINJA NODES WITH StackObject

            if (bodyNodeA is Ninja && bodyNodeB is StackObject)
            {

                //[[GameSounds sharedGameSounds] playStackImpactSound];

                Ninja theNinja = (Ninja)bodyNodeA;
                StackObject theStackObject = (StackObject)bodyNodeB;

                TheLevel.SharedLevel.StopDotting();
                TheLevel.SharedLevel.ShowNinjaImpactingStack(theNinja);

                theStackObject.PlayBreakAnimationFromNinjaContact();

                if (theStackObject.PointValue != 0) { // if it has a score value for impact with Ninja

                    TheLevel.SharedLevel.ShowPoints(theStackObject.PointValue, theStackObject.Position, theStackObject.SimpleScoreVisualFX);  //show points
                    theStackObject.MakeUnScoreable(); //prevents scoring off same object twice
                }

            }
            else  if (bodyNodeA is StackObject && bodyNodeB is Ninja)
            {

                //[[GameSounds sharedGameSounds] playStackImpactSound];

                Ninja theNinja = (Ninja)bodyNodeB;
                StackObject theStackObject = (StackObject)bodyNodeA;

                TheLevel.SharedLevel.StopDotting();
                TheLevel.SharedLevel.ShowNinjaImpactingStack(theNinja);

                theStackObject.PlayBreakAnimationFromNinjaContact();

                if (theStackObject.PointValue != 0) { // if it has a score value for impact with Ninja

                    TheLevel.SharedLevel.ShowPoints(theStackObject.PointValue, theStackObject.Position,  theStackObject.SimpleScoreVisualFX); //show points
                    theStackObject.MakeUnScoreable();  //prevents scoring off same object twice

                }

            }

            ////////////////////////////////////////
            ////////////////////////////////////////
            //NINJA NODES WITH Enemy

            if (bodyNodeA is Ninja && bodyNodeB is Enemy)
            {

                Ninja theNinja = (Ninja)bodyNodeA;
                Enemy theEnemy = (Enemy)bodyNodeB;

                TheLevel.SharedLevel.StopDotting();
                TheLevel.SharedLevel.ShowNinjaImpactingStack(theNinja);  //applies to stack objects or enemies

                if ( theEnemy.BreaksOnNextDamage ) {

                    if (theEnemy.PointValue != 0) { // if it has a score value for impact with Ninja

                        TheLevel.SharedLevel.ShowPoints(theEnemy.PointValue, theEnemy.Position, theEnemy.SimpleScoreVisualFX); //show points
                        theEnemy.MakeUnScoreable();  //prevents scoring off same object twice

                    }
                    theEnemy.BreakEnemy();

                } else {

                    theEnemy.DamageEnemy();

                }

            }
            else  if (bodyNodeA is Enemy && bodyNodeB is Ninja)
            {

                Ninja theNinja = (Ninja)bodyNodeB;
                Enemy theEnemy = (Enemy)bodyNodeA;

                TheLevel.SharedLevel.StopDotting();
                TheLevel.SharedLevel.ShowNinjaImpactingStack(theNinja ); //applies to stack objects or enemies

                if ( theEnemy.BreaksOnNextDamage) {

                    if (theEnemy.PointValue != 0) { // if it has a score value for impact with Ninja

                        TheLevel.SharedLevel.ShowPoints(theEnemy.PointValue, theEnemy.Position, theEnemy.SimpleScoreVisualFX); //show points
                        theEnemy.MakeUnScoreable();  //prevents scoring off same object twice

                    }
                    theEnemy.BreakEnemy();

                } else {

                    theEnemy.DamageEnemy();

                }

            }

            ////////////////////////////////////////
            ////////////////////////////////////////
            //StackObject WITH Enemy

            if ( bodyNodeA is StackObject && bodyNodeB is Enemy)
            {

                StackObject theStackObject = (StackObject)bodyNodeA;
                Enemy theEnemy = (Enemy)bodyNodeB;

                if (theStackObject.IsCanDamageEnemy && theEnemy.DamagesFromDamageEnabledStackObjects ) {

                    if ( theEnemy.BreaksOnNextDamage ) {

                        if (theEnemy.PointValue != 0) { // if it has a score value for impact with Ninja

                            TheLevel.SharedLevel.ShowPoints(theEnemy.PointValue, theEnemy.Position, theEnemy.SimpleScoreVisualFX); //show points

                            theEnemy.MakeUnScoreable();  //prevents scoring off same object twice

                        }
                        theEnemy.BreakEnemy();

                    } else {

                        theEnemy.DamageEnemy();

                    }

                }

            }
            else  if ( bodyNodeA is Enemy  && bodyNodeB is StackObject )
            {

                StackObject theStackObject = (StackObject)bodyNodeB;
                Enemy theEnemy = (Enemy)bodyNodeA;

                if (theStackObject.IsCanDamageEnemy && theEnemy.DamagesFromDamageEnabledStackObjects ) {

                    if ( theEnemy.BreaksOnNextDamage ) {

                        if (theEnemy.PointValue != 0) { // if it has a score value for impact with Ninja

                            TheLevel.SharedLevel.ShowPoints(theEnemy.PointValue, theEnemy.Position, theEnemy.SimpleScoreVisualFX); //show points

                            theEnemy.MakeUnScoreable();  //prevents scoring off same object twice

                        }
                        theEnemy.BreakEnemy();

                    } else {

                        theEnemy.DamageEnemy();

                    }

                }

            }

            ////////////////////////////////////////
            ////////////////////////////////////////
            //Ground WITH Enemy

            if (bodyNodeA is GroundPlane  && bodyNodeB is Enemy )
            {

                Enemy theEnemy = (Enemy)bodyNodeB;

                if ( theEnemy.DamagesFromGroundContact ) {

                    if ( theEnemy.BreaksOnNextDamage ) {

                        if (theEnemy.PointValue != 0) { // if it has a score value for impact with Ninja

                            TheLevel.SharedLevel.ShowPoints(theEnemy.PointValue, theEnemy.Position, theEnemy.SimpleScoreVisualFX); //show points

                            theEnemy.MakeUnScoreable();  //prevents scoring off same object twice

                        }
                        theEnemy.BreakEnemy();

                    } else {

                        theEnemy.DamageEnemy();

                    }

                }

            }
            else  if (bodyNodeA is Enemy  && bodyNodeB is GroundPlane )
            {

                Enemy theEnemy = (Enemy)bodyNodeA;

                if ( theEnemy.DamagesFromGroundContact ) {

                    if ( theEnemy.BreaksOnNextDamage ) {

                        if (theEnemy.PointValue != 0) { // if it has a score value for impact with Ninja

                            TheLevel.SharedLevel.ShowPoints(theEnemy.PointValue, theEnemy.Position, theEnemy.SimpleScoreVisualFX); //show points

                            theEnemy.MakeUnScoreable();  //prevents scoring off same object twice

                        }
                        theEnemy.BreakEnemy();

                    } else {

                        theEnemy.DamageEnemy();

                    }

                }

            }

            ////////////////////////////////////////
            ////////////////////////////////////////
            //Ground WITH StackObject

            if (bodyNodeA is GroundPlane  && bodyNodeB is StackObject )
            {

                StackObject theStackObject = (StackObject)bodyNodeB;

                theStackObject.PlayBreakAnimationFromGroundContact();

                if (theStackObject.PointValue != 0 && theStackObject.IsBreaksOnGroundContact)
                { // if it has a score value for impact with Ninja

                    TheLevel.SharedLevel.ShowPoints(theStackObject.PointValue, theStackObject.Position, theStackObject.SimpleScoreVisualFX);  //show points

                    theStackObject.MakeUnScoreable(); //prevents scoring off same object twice
                }

            }
            else  if (bodyNodeA is StackObject  && bodyNodeB is GroundPlane )
            {

                StackObject theStackObject = (StackObject)bodyNodeA;

                theStackObject.PlayBreakAnimationFromGroundContact();

                if (theStackObject.PointValue != 0 && theStackObject.IsBreaksOnGroundContact) { // if it has a score value for impact with Ninja

                    TheLevel.SharedLevel.ShowPoints(theStackObject.PointValue, theStackObject.Position, theStackObject.SimpleScoreVisualFX);  //show points
                    theStackObject.MakeUnScoreable();  //prevents scoring off same object twice

                }

            }
        }
        public void PostSolve(b2Contact contact, b2ContactImpulse impulse)
        {
            // http://stackoverflow.com/questions/11149091/box2d-damage-physics

            //M:\web\FlashHeatZeekerWithStarlingB2\XContactListener.as(34): col: 83 Error: Implicit coercion of a value of type __AS3__.vec:Vector.<Number> to an unrelated type __AS3__.vec:Vector.<*>.

            //double0 = __Enumerable.Sum_100669321(X.AsEnumerable_100664676(impulse.normalImpulses));

            // http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-6-collision-strength/
            var forceA = impulse.normalImpulses[0];
            // { impulse = { length = 2, forceA = 2.9642496469208197, forceB = 0 } }

            var forceB = impulse.normalImpulses[1];

            if (DiscardSmallImpulse)
                if (forceA < 0.5)
                    if (forceB < 0.5)
                    {
                        // do we care about friction?
                        return;
                    }

            //var min = impulse.normalImpulses.AsEnumerable().Min();
            //var max = impulse.normalImpulses.AsEnumerable().Max();

            //            System.Linq.Enumerable for Double Min(System.Collections.Generic.IEnumerable`1[System.Double]) used at
            //FlashHeatZeekerWithStarlingB2.XContactListener.PostSolve at offset 001d.

            var done = false;

            var fixA = contact.GetFixtureA();
            if (fixA != null)
            {
                var hitA = fixA.GetUserData() as Action<double>;
                if (hitA != null)
                {
                    //Console.WriteLine(new
                    //{
                    //    hitA = new
                    //    {
                    //        forceA,
                    //    }
                    //});

                    hitA(forceA);
                    done = true;
                }
            }

            var fixB = contact.GetFixtureB();
            if (fixB != null)
            {
                var hitB = fixB.GetUserData() as Action<double>;
                if (hitB != null)
                {
                    //Console.WriteLine(new
                    //{
                    //    hitB = new
                    //    {
                    //        forceA,
                    //    }
                    //});

                    hitB(forceA);
                    done = true;
                }
            }

            if (done) return;

            Console.WriteLine(new
            {
                impulse = new
                {
                    impulse.normalImpulses.length,
                    forceA,
                    fixA,
                    forceB,
                    fixB
                    //, min, max 
                }
            });
        }