Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            for (int i = 0; i < ELEMENTS; ++i)
            {
                bouncingThings[i].Move(gameTime, maxX, minX, maxY, minY);
            }


            for (int i = 0; i < ELEMENTS; ++i)
            {
                for (int j = i + 1; j < ELEMENTS; ++j)
                {
                    Vector2 distanceBetween = bouncingThings[i].origin - bouncingThings[j].origin;
                    Vector2 vel             = bouncingThings[i].speed - bouncingThings[j].speed;
                    if (Vector2.Dot(distanceBetween, vel) < 0)                           // if not movin in the same direction
                    {
                        int radii = bouncingThings[i].radius + bouncingThings[j].radius; //bouncingBox

                        if (distanceBetween.X < bouncingThings[i].origin.X + radii || distanceBetween.Y < bouncingThings[i].origin.Y + radii)
                        {
                            if (CollisionMgr.CheckForSATCollisions(bouncingThings[i], bouncingThings[j]))
                            {
                                //switch velocities
                                Vector2 tempVel = bouncingThings[i].speed;
                                bouncingThings[i].speed = bouncingThings[j].speed;
                                bouncingThings[j].speed = tempVel;
                            }
                        }
                    }
                }
            }

            // quad.Optimise(boundaries, count);

            /*  frameCount += 1;
             * frameTime += (double)gameTime.ElapsedGameTime.Milliseconds;
             * if (frameTime >= 1000)
             * {
             *    //dont think this works
             *    frameRate = frameCount;
             *    frameCount = 0;
             *    frameTime = 0;
             * }*/
            base.Update(gameTime);
        }
Ejemplo n.º 2
0
 public void checkQuarters(BouncingThing[] obj, int lngth)
 {
     for (int i = 0; i < lngth; ++i)
     {
         for (int j = i + 1; j < lngth; ++j)
         {
             Vector2 pos = obj[i].origin - obj[j].origin;
             Vector2 vel = obj[i].speed - obj[j].speed;
             if (Vector2.Dot(pos, vel) < 0)// if not movin in the same direction
             {
                 if (cldMgr.CheckForSATCollisions(obj[i], obj[j]))
                 {
                     //switch velocities
                     Vector2 tempVel = obj[i].speed;
                     obj[i].speed = obj[j].speed;
                     obj[j].speed = tempVel;
                 }
             }
         }
     }
 }