/// <summary> /// Creates a new ball. Ball class must be initialised by calling Ball.Initialise or an exception is thrown. /// </summary> /// <param name="colour">The colour of the ball. Is clamped to a valid colour.</param> /// <param name="position">The position of the ball.</param> public Ball(BallColour colour, Vector2 position) { if (sColours.Count <= 0) throw new Exception("Textures not initialized"); mColour = (BallColour)MathHelper.Clamp((float)colour, 0, sColours.Count - 1); mOrigin = sSize * 0.5f; mState = BallState.Still; mDirection = Vector2.Zero; mPosition = position; }
/// <summary> /// Creates a new ball. Ball class must be initialised by calling Ball.Initialise or an exception is thrown. /// </summary> /// <param name="colour">The colour of the ball. Is clamped to a valid colour.</param> /// <param name="position">The position of the ball.</param> public Ball(BallColour colour, Vector2 position) { if (sColours.Count <= 0) { throw new Exception("Textures not initialized"); } mColour = (BallColour)MathHelper.Clamp((float)colour, 0, sColours.Count - 1); mOrigin = sSize * 0.5f; mState = BallState.Still; mDirection = Vector2.Zero; mPosition = position; }
/// <summary> /// Increase or decrease, as indicated by the increase parameter, the number of balls of a certain /// colour, specified by the parameter colour, that is still in play. /// </summary> /// <param name="colour">The colour of the added or removed ball.</param> /// <param name="wasAdded">Whether a ball of the specified was added or removed. True if it was /// added, else false.</param> private void ChangeNumberOfBalls(BallColour colour, bool wasAdded) { // Based on whether the ball was added or removed, update the colours in play and the total number of // balls in the game variables. int modifier = 0; if (wasAdded) { modifier = 1; } else { modifier = -1; } mColoursInPlay[(int)colour] += modifier; mNumberOfBalls += modifier; }