The class for the balls that have become stationary due to a colission Author Hugh Corrigan
Inheritance: MovingBall
Ejemplo n.º 1
0
 /*
  * Add a ball to the core's ball list
  */
 public void AddBall(FixedBall f)
 {
     balls.Add(f);
     ballsSize++;
     CheckExplosions();
     UpdateLoose();
 }
Ejemplo n.º 2
0
 public void removeBall(FixedBall f)
 {
     for (int i = 0; i < ballsSize; i++)
     {
         if (balls[i].Equals(f))
         {
             balls.Remove(balls[i]);
         }
     }
 }
Ejemplo n.º 3
0
        /*
         * Check for Collisions with the FixedBalls and the Core
         */
        public bool Collide()
        {
            if (Collide(core)) {
                return true;
            }

            for (int i = 0; i < core.ballsSize; i++)
            {
                if (Collide(core.balls[i]))
                {
                    collisionBall = core.balls[i];
                    return true;
                }
            }
            return false;
        }
Ejemplo n.º 4
0
        public virtual void Move()
        {
            if (!Collide())
            {
                hypotenuse = Vector2.Distance(this.Position, core.Position);
                x = core.Position.X - this.Position.X;
                y = core.Position.Y - this.Position.Y;

                Position = new Vector2(2 * (x / hypotenuse) + Position.X, 2 * (y / hypotenuse) + Position.Y);
                //move with gravity
            }
            else
            {
                FixedBall f = new FixedBall(core, colour);
                f.Initialise(size, Position);
                f.LoadGraphicsContent(spriteBatch, texture);
                core.addBall(f);
                live = false;
            }
        }
Ejemplo n.º 5
0
 /*
  * Add a support
  * */
 public void AddSupport(FixedBall f)
 {
     supports.Add(f);
 }
Ejemplo n.º 6
0
 /*
  * Collect the list of balls touching this ball
  * */
 public void SetCollisionBall(FixedBall f)
 {
     // if touching a ball of the same colour
     if (f.colour == colour)
     {
         bool isThere;
         //traverse the list of balls the contacted ball touches
         for (int i = 0; i < f.numInContact; i++)
         {
             isThere = false;
             //traverse the list of balls this contacts
             for (int j = 0; j < this.numInContact; j++)
             {
                 if (f.inContact[i] == this.inContact[j])
                 {
                     isThere = true;
                 }
             }
             //actions if this ball has not "observed" that it is touching the ball in the contacting balls group
             if (isThere == false)
             {
                 inContact.Add(f.inContact[i]);
                 numInContact++;
                 f.inContact[i].inContact.Add(this);
                 f.inContact[i].numInContact++;
             }
         }
     }
 }
Ejemplo n.º 7
0
 /*
  *
  * */
 public void CorrectPostion(FixedBall f)
 {
     if (Vector2.Distance(f.Position, Position) < size.X)
     {
         Vector2 d = f.Position - Position;
         d.Normalize();
         d = d * size.X;
         Position = f.Position - d;
     }
 }
Ejemplo n.º 8
0
 public void addBall(FixedBall f)
 {
     balls.Add(f);
     ballsSize++;
     Console.WriteLine(ballsSize);
 }
Ejemplo n.º 9
0
        /*
         * Move towards the core
         */
        public virtual void Move()
        {
            if (colourTexture == null)
            {
                colourTexture = texture;
            }
            SwitchBlack();
            if (toFollow == null)
            {
                if (!Collide())
                {
                    oldPosition = Position;
                    hypotenuse = Vector2.Distance(this.Position, core.Position);
                    x = core.Position.X - this.Position.X;
                    y = core.Position.Y - this.Position.Y;

                    Position = new Vector2(2 * (x / hypotenuse) + Position.X, 2 * (y / hypotenuse) + Position.Y);
                    //move with gravity
                }
                else
                {
                    FixedBall f = new FixedBall(core, colour);
                    f.Initialise(size, Position, game);
                    if (collisionBall == null)
                    {
                        f.SetAgainstCore();
                        f.DoAngles();
                    }
                    else
                    {
                        f.CorrectPostion(collisionBall);
                        f.DoAngles();
                        f.AddSupport(collisionBall);
                        f.SetCollisionBall(collisionBall);
                    }
                    f.UpdateContactBalls();
                    f.LoadGraphicsContent(spriteBatch, colourTexture);
                    core.AddBall(f);
                    live = false;
                }
            }
            else
            {
                if (!Collide())
                {
                    Position += (toFollow.Position - toFollow.oldPosition);
                }
                else
                {
                    FixedBall f = new FixedBall(core, colour);
                    f.Initialise(size, Position, game);
                    if (collisionBall == null)
                    {
                        f.SetAgainstCore();
                        f.DoAngles();
                    }
                    else
                    {
                        f.CorrectPostion(collisionBall);
                        f.DoAngles();
                        f.AddSupport(collisionBall);
                        f.SetCollisionBall(collisionBall);
                    }
                    f.UpdateContactBalls();
                    f.LoadGraphicsContent(spriteBatch, colourTexture);
                    core.AddBall(f);
                    live = false;
                }
            }
        }