public Boolean collisionBullet(Fixture fixA, Fixture fixB, Contact contact) { if (!isHung) //je joins la balle a la cible avec un angle strict, et la balle au joueur avec un distance joint { Vector2 diff = bullet.FixtureObject.Body.Position - fixB.Body.Position; //ObjCercle bulletTP = new ObjCercle(diff, radius, 0.0f, worldPhysic, fixB.Body); //worldPhysic.RemoveBody(bullet.FixtureObject.Body); //bullet = bulletTP; //bullet.addDisplayer(); //juncture = new FarseerPhysics.Dynamics.Joints.DistanceJoint(juncturePoint.Body, bullet.FixtureObject.Body, new Vector2(1, 1)/*AnchorPointJuncturePoint*/, new Vector2(1, 1)); //juncture = JointFactory.CreateDistanceJoint(worldPhysic, juncturePoint.Body, bullet.FixtureObject.Body, new Vector2(10,0)/*AnchorPointJuncturePoint*/, new Vector2(10,0)); //worldPhysic.AddJoint(juncture); //junctureHook = JointFactory. CreateRevoluteJoint(worldPhysic, fixA.Body, fixB.Body, diff); //junctureHook.MaxImpulse = 3; //junctureHook. worldPhysic.RemoveBody(bullet.FixtureObject.Body); bullet = null; //bullet.FixtureObject.Body.BodyType = BodyType.Dynamic; juncture = new FarseerPhysics.Dynamics.Joints.DistanceJoint(juncturePoint.Body, fixB.Body, AnchorPointJuncturePoint, new Vector2(diff.X, diff.Y)); worldPhysic.AddJoint(juncture); isHung = true; } return false; }
public Bullet(Vector2 position, float radius, Fixture juncturePoint, World worldPhysic) { this.worldPhysic = worldPhysic; this.radius = radius; bullet = new ObjCercle(position, radius, 0, worldPhysic, BodyType.Dynamic); bullet.addDisplayer(); bullet.FixtureObject.OnCollision = new OnCollisionEventHandler(collisionBullet); this.juncturePoint = juncturePoint; }
public Character(Texture2D tex, World worldPhysic, ContentManager Content, BasicEffect effectPlayer, Vector2 position) { this.worldPhysic = worldPhysic; texJump = Content.Load<Texture2D>("textures/Run"); texRun = Content.Load<Texture2D>("textures/Run"); texIdle = Content.Load<Texture2D>("textures/Idle"); texWeapon = Content.Load<Texture2D>("textures/Weapon"); //Cercle qui représente la tete ObjectPhysicCircleTete = new ObjCercle(new Vector2(0, 0), 2.0f, 0.0f, worldPhysic, BodyType.Dynamic); ObjectPhysicCircleTete.addDisplayer(); ObjectPhysicCircleTete.FixtureObject.Friction = 1.0f; ObjectPhysicCircleTete.FixtureObject.Restitution = 0.0f; ObjectPhysicCircleTete.FixtureObject.CollisionFilter.CollisionCategories = Category.Cat20; //ObjectPhysicCircleTete.FixtureObject.CollisionFilter.RemoveCollidesWithCategory(Category.Cat30); //Cercle qui permet les déplacement ObjectPhysicCircle = new ObjCercle(new Vector2(0, -3.5f), 1.5f, 0.0f, worldPhysic, ObjectPhysicCircleTete.FixtureObject.Body);//, RectanglePhysic.FixtureObject.Body); ObjectPhysicCircle.addDisplayer(); ObjectPhysicCircle.FixtureObject.Friction = 0.8f; ObjectPhysicCircle.FixtureObject.Restitution = 0.0f; ObjectPhysicCircle.FixtureObject.CollisionFilter.CollisionCategories = Category.Cat20; //ObjectPhysicCircle.FixtureObject.CollisionFilter.RemoveCollidesWithCategory(Category.Cat30); //Rectangle qui permet d'afficher le charactere RectangleTexture = new ObjRectange(new Vector2(0, 0), 10, 10, 0.0f, BodyType.Dynamic, ObjectPhysicCircle.FixtureObject.Body/*ObjectPhysicCircle.FixtureObject.Body*/); //RectangleTexture.addDisplayer(); RectangleTexture.FixtureObject.Body.FixedRotation = true; RectangleTexture.addTexture(texIdle, 0.0f); //RectangleTexture.FixtureObject.CollisionFilter.RemoveCollisionCategory(Category.All); RectangleTexture.FixtureObject.CollisionFilter.RemoveCollidesWithCategory(Category.All); //Rectangle qui permet d'afficher le bras et l'arme RectangleTextureGun = new ObjRectange(new Vector2(0, 0), 10, 10, 0.0f, BodyType.Dynamic); //RectangleTextureGun.addDisplayer(); RectangleTextureGun.FixtureObject.Body.FixedRotation = true; RectangleTextureGun.addTexture(texWeapon, 0.5f); //RectangleTextureGun.FixtureObject.CollisionFilter.RemoveCollisionCategory(Category.All); RectangleTextureGun.FixtureObject.CollisionFilter.RemoveCollidesWithCategory(Category.All); JointFactory.CreateRevoluteJoint(worldPhysic, RectangleTexture.FixtureObject.Body, RectangleTextureGun.FixtureObject.Body, Vector2.Zero); //ObjectPhysicCircleTete.FixtureObject.Body.Position = position; }