Exemplo n.º 1
0
		public bool CanEatBubble (Bubble b)
		{
			if (!b.IsEaten)
			{
				var r2 = (this.Center.X - b.Center.X) * (this.Center.X - b.Center.X) + 
					(this.Center.Y - b.Center.Y) * (this.Center.Y - b.Center.Y);

				if (r2 < (this.R + b.R) * (this.R + b.R))
					if (this.R > b.R)
						return true;
			}
			return false;
		}
Exemplo n.º 2
0
		/// <summary>
		/// How this bubble eats another bubble.
		/// </summary>
		/// <param name="b">The blue component.</param>
		public void EatBubble (Bubble b)
		{
			// area ratio
			var Sd = b.S / this.S;
			b.IsEaten = true;

			// mixing colors (depending on area ratio)
			this.Color = new Color (
				(b.Color.R * Sd + this.Color.R * (1 - Sd)), 
				(b.Color.G * Sd + this.Color.G * (1 - Sd)), 
				(b.Color.B * Sd + this.Color.B * (1 - Sd)));

			// increase radius (depending on area ratio)
			this.R = Math.Sqrt ((this.S + b.S) / Math.PI);

			// calculating speed (depending on area / "mass" ratio)
			this.VX += b.VX * Sd;
			this.VY += b.VY * Sd;
		}
Exemplo n.º 3
0
		void InitScene (double w, double h)
		{
			bubbles = new Bubble[rnd.Next (20, 35)];

			for (int i=0; i < bubbles.Length; i++)
			{
				bubbles[i] = new Bubble ()
				{
					R = rnd.NextDouble () * 25 + 7,
					VX = rnd.NextDouble () * 2.0 - 1.0,
					VY = rnd.NextDouble () * 2.0 - 1.0,
					IsEaten = false,
					Color = new Color 
					(
						rnd.NextDouble (), 
						rnd.NextDouble (), 
						rnd.NextDouble (), 
						0.75
					),

					Center = new PointD (rnd.NextDouble () * w, rnd.NextDouble () * h)
				};
			}
		}