The class for the balls that have become stationary due to a colission Author Hugh Corrigan
Inheritance: MovingBall
コード例 #1
0
ファイル: Core.cs プロジェクト: kiniry-teaching/UCD
 /*
  * Add a ball to the core's ball list
  */
 public void AddBall(FixedBall f)
 {
     balls.Add(f);
     ballsSize++;
     CheckExplosions();
     UpdateLoose();
 }
コード例 #2
0
ファイル: Core.cs プロジェクト: kiniry-teaching/UCD
 public void removeBall(FixedBall f)
 {
     for (int i = 0; i < ballsSize; i++)
     {
         if (balls[i].Equals(f))
         {
             balls.Remove(balls[i]);
         }
     }
 }
コード例 #3
0
ファイル: MovingBall.cs プロジェクト: kiniry-teaching/UCD
        /*
         * 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;
        }
コード例 #4
0
ファイル: MovingBall.cs プロジェクト: kiniry-teaching/UCD
        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;
            }
        }
コード例 #5
0
ファイル: FixedBall.cs プロジェクト: kiniry-teaching/UCD
 /*
  * Add a support
  * */
 public void AddSupport(FixedBall f)
 {
     supports.Add(f);
 }
コード例 #6
0
ファイル: FixedBall.cs プロジェクト: kiniry-teaching/UCD
 /*
  * 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++;
             }
         }
     }
 }
コード例 #7
0
ファイル: FixedBall.cs プロジェクト: kiniry-teaching/UCD
 /*
  *
  * */
 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;
     }
 }
コード例 #8
0
ファイル: Core.cs プロジェクト: kiniry-teaching/UCD
 public void addBall(FixedBall f)
 {
     balls.Add(f);
     ballsSize++;
     Console.WriteLine(ballsSize);
 }
コード例 #9
0
ファイル: MovingBall.cs プロジェクト: kiniry-teaching/UCD
        /*
         * 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;
                }
            }
        }