0

I am creating an andengine game (with reference to this tutorial http://www.matim-dev.com/full-game-tutorial---part-1.html), where my main charachter walks and gets hit by the falling bricks from the top. He dies if he is hit by a falling brick. But once the brick is on the ground, the main charachter can touch it and jump on it. Now I know how to find if two bodies contact with each other. But how to find if the contact is on the upper side of the charachter or the left or right side of the body.

My code used for contact is as follows

private ContactListener contactListener()
{
    ContactListener contactListener = new ContactListener()
    {
        public void beginContact(Contact contact)
        {
            final Fixture x1 = contact.getFixtureA();
            final Fixture x2 = contact.getFixtureB();


            Vector2[] contactPoints = contact.getWorldManifold().getPoints();

            System.out.println("the points are as ::"+contactPoints);


            if (x1.getBody().getUserData() != null && x2.getBody().getUserData() != null)
            {
                if (x2.getBody().getUserData().equals("player"))
                {
                    player.increaseFootContacts();
                }

                if (x1.getBody().getUserData().equals("platform2") && x2.getBody().getUserData().equals("player"))
                {
                    engine.registerUpdateHandler(new TimerHandler(0.2f, new ITimerCallback()
                    {                                   
                        public void onTimePassed(final TimerHandler pTimerHandler)
                        {
                            pTimerHandler.reset();
                            engine.unregisterUpdateHandler(pTimerHandler);
                            x1.getBody().setType(BodyType.DynamicBody);
                        }
                    }));
                }

                if (x1.getBody().getUserData().equals("platform3") && x2.getBody().getUserData().equals("player"))
                {
                    x1.getBody().setType(BodyType.DynamicBody);
                }
            }
        }

        public void endContact(Contact contact)
        {
            final Fixture x1 = contact.getFixtureA();
            final Fixture x2 = contact.getFixtureB();



            if (x1.getBody().getUserData() != null && x2.getBody().getUserData() != null)
            {
                if (x2.getBody().getUserData().equals("player"))
                {
                    player.decreaseFootContacts();
                }
            }
        }

        public void preSolve(Contact contact, Manifold oldManifold)
        {

        }

        public void postSolve(Contact contact, ContactImpulse impulse)
        {

        }
    };
    return contactListener;
}

Please suggest me some ideas.

Sandeep R
  • 2,284
  • 3
  • 25
  • 51

1 Answers1

0

does this help you enough or you need more information about body contact methods?

public boolean areBodiesContacted(Body pBody1, Body pBody2,
Contact pContact)
{
if(pContact.getFixtureA().getBody().equals(pBody1) ||
       pContact.getFixtureB().getBody().equals(pBody1))
   if(pContact.getFixtureA().getBody().equals(pBody2) ||
           pContact.getFixtureB().getBody().equals(pBody2))
       return true;
return false;
}
Izu
  • 235
  • 1
  • 5