public bool IntersectsWithBall(Ball b) { foreach (ModelMesh mesh in Model.Meshes) { BoundingSphere boundingSphere = mesh.BoundingSphere.Transform(World); foreach(ModelMesh bMesh in b.Model.Meshes) { BoundingSphere ballboundingSphere = bMesh.BoundingSphere.Transform(b.World); if (ballboundingSphere.Intersects(boundingSphere)) { return true; } } } return false; }
private void RefreshBallPosition(int rowIndex, int colIndex, Ball ball) { if (rowIndex % 2 == 0) { ball.Position = Position + new Vector3(rowIndex * 2 * Ball.BALL_RADIUS, colIndex * 2 * Ball.BALL_RADIUS, 0); } else { ball.Position = Position + new Vector3(rowIndex * 2 * Ball.BALL_RADIUS, colIndex * 2 * Ball.BALL_RADIUS + ODD_ROW_OFFSET, 0); ; } ball.Normalize(); }
private void GetAllPieceOfSameColorAlignedAtSlot(BallSlot ballSlot, Ball.BallColor color, List<BallSlot> slots) { Ball ball = GetBallAtSlot(ballSlot.RowIndex, ballSlot.ColumnIndex); if (ball != null && ball.Color == color && !slots.Contains(ballSlot)) { slots.Add(ballSlot); GetAllAdjacentSlots(ballSlot).ForEach(slot => GetAllPieceOfSameColorAlignedAtSlot(slot, color, slots)); } }
public void SetNewBallAtPosition(int rowIndex, int colIndex, Ball ball) { PuzzleBooble3dGame.Components.Add(ball); this.SetBallAtPosition(rowIndex, colIndex, ball); }
public void SetBallToNearestSlot(Ball ball, BallSlot interSectingSlot) { int nearestRowIndex; int nearestColumnIndex; List<BallSlot> emptySlots; if (interSectingSlot != null) { // Get the nearest empty slots. emptySlots = GetAllAdjacentLowerSlots(interSectingSlot); emptySlots.AddRange(GetAdjacentSlotsOnSameRow(interSectingSlot)); } else // The ball reached the ceiling { emptySlots = GetAllTopSlots(); } emptySlots.RemoveAll(slot => GetBallAtSlot(slot) != null); emptySlots.Sort(delegate(BallSlot slot, BallSlot otherSlot) { float length1 = (GetSlotCenter(slot) - ball.Position).Length(); float length2 = (GetSlotCenter(otherSlot) - ball.Position).Length(); return length1.CompareTo(length2); }); if (emptySlots.Count > 0) { try { nearestRowIndex = emptySlots.ElementAt(0).RowIndex; nearestColumnIndex = emptySlots.ElementAt(0).ColumnIndex; SetBallAtPosition(nearestRowIndex, nearestColumnIndex, ball); DestroyAlignedPieceAtSlot(nearestRowIndex, nearestColumnIndex); int numOfBallsFallen = FallDownAllBallsWithNoUpperAdjacentBalls(nearestRowIndex, nearestColumnIndex); CurrentScore.Value += (numOfBallsFallen > 0) ? (int)Math.Pow(2, numOfBallsFallen) * 10 : 0; CheckIfPlayerWins(); CheckIfPlayerLost(); } catch (SlotOccupiedException ex) { } } else { //Set All balls to Dark foreach (List<Ball> list in Balls) { foreach (Ball b in list) { if (b != null) { b.GoDark(); } } } Observer.ForEach(observer => observer.OnPlayerLoses()); } }
public void SetBallAtPosition(int rowIndex, int colIndex, Ball ball) { if (Balls.ElementAt(rowIndex).ElementAt(colIndex) != null) { throw new SlotOccupiedException(rowIndex, colIndex); } Balls[rowIndex][colIndex] = ball; RefreshBallPosition(rowIndex, colIndex, ball); }
public BallSlot BallsIntersectingWithBall(Ball ball) { for (int i = 0; i < NUMBER_OF_ROWS; i++) { for (int j = 0; j < GetNumberOfColumnForRow(i); j++) { Ball b = Balls.ElementAt(i).ElementAt(j); if (b != null && ball.IntersectsWithBall(b)) { return new BallSlot(i, j); } } } return null; }
private void SetNextBall(Ball ball) { NextBall = ball; NextBall.Position = GetNextBallPosition(); PuzzleBooble3dGame.Components.Add(NextBall); NextBall.Load(); }
private void SetCurrentBall(Ball ball) { if(!PuzzleBooble3dGame.Components.Contains(ball)) { PuzzleBooble3dGame.Components.Add(ball); } CurrentBall = ball; CurrentBall.Position = GetCurrentBallPosition(); CurrentBall.Load(); }