/// <summary> /// /// </summary> public Ball(eBallSize pSize, eBallType pType) : base() { mScaleFactorX = 5f; mScaleFactorY = 5f; mBallSize = pSize; mBallType = pType; // Create rectangles with sprite information for balls if (mSpriteRectangles == null || mSpriteRectangles.Count == 0) { Dictionary <eBallSize, SMX.Maths.Rectangle> dictRed, dictBlue, dictGreen; dictRed = new Dictionary <eBallSize, SMX.Maths.Rectangle>(); dictGreen = new Dictionary <eBallSize, SMX.Maths.Rectangle>(); dictBlue = new Dictionary <eBallSize, SMX.Maths.Rectangle>(); dictRed.Add(eBallSize.XL, new Rectangle { X = 1, Y = 6, Width = 48, Height = 40 }); dictRed.Add(eBallSize.L, new Rectangle { X = 52, Y = 13, Width = 32, Height = 26 }); dictRed.Add(eBallSize.M, new Rectangle { X = 86, Y = 19, Width = 16, Height = 14 }); dictRed.Add(eBallSize.S, new Rectangle { X = 106, Y = 23, Width = 8, Height = 7 }); dictBlue.Add(eBallSize.XL, new Rectangle { X = 1, Y = 56, Width = 48, Height = 40 }); dictBlue.Add(eBallSize.L, new Rectangle { X = 52, Y = 63, Width = 32, Height = 26 }); dictBlue.Add(eBallSize.M, new Rectangle { X = 86, Y = 69, Width = 16, Height = 14 }); dictBlue.Add(eBallSize.S, new Rectangle { X = 106, Y = 73, Width = 8, Height = 7 }); dictGreen.Add(eBallSize.XL, new Rectangle { X = 1, Y = 105, Width = 48, Height = 40 }); dictGreen.Add(eBallSize.L, new Rectangle { X = 52, Y = 112, Width = 32, Height = 26 }); dictGreen.Add(eBallSize.M, new Rectangle { X = 86, Y = 118, Width = 16, Height = 14 }); dictGreen.Add(eBallSize.S, new Rectangle { X = 106, Y = 122, Width = 8, Height = 7 }); mSpriteRectangles.Add(eBallType.Red, dictRed); mSpriteRectangles.Add(eBallType.Blue, dictBlue); mSpriteRectangles.Add(eBallType.Green, dictGreen); } }
/// <summary> /// Creates and configures a ball from an XML node /// </summary> /// <param name="pBallNd"></param> /// <returns></returns> public static Ball FromXml(System.Xml.XmlNode pBallNd) { eBallSize size = (eBallSize)Enum.Parse(typeof(eBallSize), pBallNd.Attributes["Size"].Value); eBallType type = (eBallType)Enum.Parse(typeof(eBallType), pBallNd.Attributes["Type"].Value); Ball b = new Ball(size, type); b.mOriginalPosition = b.mPos = SMX.Maths.Vector2.ReadVector2FromXmlAttribute(pBallNd, "Position"); return(b); }
/// <summary> /// Returns the next size for new balls, provided the size of the ball that is dying /// </summary> public static eBallSize GetNextSize(eBallSize pSize) { switch (pSize) { case eBallSize.XL: return(eBallSize.L); case eBallSize.L: return(eBallSize.M); case eBallSize.M: return(eBallSize.S); } return(eBallSize.S); }
/// <summary> /// Kills a ball and creates the next balls /// </summary> /// <param name="b"></param> public void KillBall(Ball b) { // Ball Hit by arrow mBalls.Remove(b); // Check if we should add prize if (b.BallSize != eBallSize.S) { Random r = new Random(DateTime.Now.Millisecond); double f = r.NextDouble(); if (f > 0.15f) { int numPrizes = Enum.GetValues(typeof(Prize.ePrize)).Length; int prize = (int)(f * numPrizes); Prize.ePrize type = (Prize.ePrize)prize; if (type != Prize.ePrize.None) { AddPrize(type, b.mPos); } } } // Create 2 new balls if (b.BallSize != eBallSize.S) { eBallSize newSize = Ball.GetNextSize(b.BallSize); float newVerticalVelocity = -Math.Min(Math.Abs(b.mVelocity.Y), Ball.GetMaxVelY(newSize)); Ball b1 = new Ball(newSize, b.BallType); b1.LoadContents(); b1.mPos = b.Center - new Maths.Vector2(b1.Radius * 2f, b1.Radius); b1.mVelocity.X = -Math.Abs(b.mVelocity.X); b1.mVelocity.Y = newVerticalVelocity; Ball b2 = new Ball(newSize, b.BallType); b2.LoadContents(); b2.mPos = b.Center + new Maths.Vector2(0, -b2.Radius); b2.mVelocity.X = Math.Abs(b.mVelocity.X); b2.mVelocity.Y = newVerticalVelocity; // First call to OnFrameMove to update positions and velocities b1.OnFrameMove(0.001f); b2.OnFrameMove(0.001f); mBalls.Add(b1); mBalls.Add(b2); } }
/// <summary> /// Returns the maximum vertical speed of balls, according to their size. This is a way to actually limit bounding height of balls /// </summary> /// <returns></returns> public static float GetMaxVelY(eBallSize pBallSize) { switch (pBallSize) { case eBallSize.XL: return(1100); case eBallSize.L: return(900); case eBallSize.M: return(700); case eBallSize.S: return(500); default: return(1000); } }
public void ConfigureFromXML(System.Xml.XmlNode pNode) { this.mInitialPosition = SMX.Maths.Vector2.ReadVector2FromString(pNode.Attributes["Position"].Value); this.mSize = (eBallSize)Enum.Parse(typeof(eBallSize), pNode.Attributes["Size"].Value); this.mColor = (eBallColor)Enum.Parse(typeof(eBallColor), pNode.Attributes["Type"].Value); }