/* * Add a ball to the core's ball list */ public void AddBall(FixedBall f) { balls.Add(f); ballsSize++; CheckExplosions(); UpdateLoose(); }
public void removeBall(FixedBall f) { for (int i = 0; i < ballsSize; i++) { if (balls[i].Equals(f)) { balls.Remove(balls[i]); } } }
/* * 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; }
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; } }
/* * Add a support * */ public void AddSupport(FixedBall f) { supports.Add(f); }
/* * 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++; } } } }
/* * * */ 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; } }
public void addBall(FixedBall f) { balls.Add(f); ballsSize++; Console.WriteLine(ballsSize); }
/* * 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; } } }