public static Boolean testCollision(Object obj1, BoundingBox obj2)
        {
            // On réalise le mvt dans une bounding box de test et on renvoie le résultat de l'intersection avec l'objet obj
            Vector3 upperLeftCorner   = new Vector3(0, 0, 0);
            Vector3 bottomRightCorner = new Vector3(0, 0, 0);

            if (obj1 is Balle)
            {
                Balle balle = (Balle)obj1;
                upperLeftCorner.X   = balle.Uneballe.Position.X + balle.Uneballe.Vitesse.X;
                upperLeftCorner.Y   = balle.Uneballe.Position.Y + balle.Uneballe.Vitesse.Y;
                bottomRightCorner.X = balle.Uneballe.Position.X + balle.Uneballe.Size.X + balle.Uneballe.Vitesse.X;
                bottomRightCorner.Y = balle.Uneballe.Position.Y + balle.Uneballe.Size.Y + balle.Uneballe.Vitesse.Y;
            }
            else if (obj1 is Raquette)
            {
                Raquette raquette = (Raquette)obj1;
                upperLeftCorner.X   = raquette.Uneraquette.Position.X;
                upperLeftCorner.Y   = raquette.Uneraquette.Position.Y + raquette.Uneraquette.Vitesse.Y;
                bottomRightCorner.X = raquette.Uneraquette.Position.X + raquette.Uneraquette.Size.X;
                bottomRightCorner.Y = raquette.Uneraquette.Position.Y + raquette.Uneraquette.Size.Y + raquette.Uneraquette.Vitesse.Y;
            }

            BoundingBox bbox_test = new BoundingBox(upperLeftCorner, bottomRightCorner);

            return(bbox_test.Intersects(obj2));
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            int offsetX = 60;
            int offsetY = 60;

            TAILLEH       = 1024; // this.GraphicsDevice.Viewport.Width à mettre + tard
            TAILLEV       = 760;  //this.GraphicsDevice.Viewport.Height à mettre + tard
            TAILLEBRIQUEX = 119;  //trouver la bonne équation à mettre
            TAILLEBRIQUEY = 50;   // same

            // TODO: Add your initialization logic here
            uneballe          = new Balle(this, TAILLEH, TAILLEV);
            raquette          = new Raquette(this, TAILLEH, TAILLEV);
            uneballe.Raquette = raquette;
            raquette.Balle    = uneballe;
            mesBriques        = new Brique[NBLIGNES, NBBRIQUES];
            // On passe à la balle le tableau de briques
            int xpos, ypos;

            for (int x = 0; x < NBLIGNES; x++)
            {
                ypos = offsetY + x * TAILLEBRIQUEY;
                for (int y = 0; y < NBBRIQUES; y++)
                {
                    xpos = offsetX + y * TAILLEBRIQUEX;

                    Vector2 pos = new Vector2(xpos, ypos);
                    // On mémorise les positions de la brique
                    mesBriques[x, y] = new Brique(this, pos, new Vector2(TAILLEBRIQUEX, TAILLEBRIQUEY));
                }
            }

            uneballe.MesBriquesballe = mesBriques;

            base.Initialize();
        }