/// <summary> /// Initializes a new instance of the Supply class. /// </summary> /// <param name="supplyKind">Specifies whether this supply is double-bullet supply or bomb supply.</param> /// <param name="startX">X-coordinate of top-left point of the Image to show.</param> public Supply(SupplyKind supplyKind, int startX) { // Get the kind of this supply. this.SupplyKind = supplyKind; // Initialize a new Image to show. this.SupplyImage = new Image(); // Set the coordinate of the image to show. Canvas.SetLeft(this.SupplyImage, startX); Canvas.SetTop(this.SupplyImage, Settings.SupplyStartY); // Configure image source and rectangle collider for this supply. if (supplyKind == SupplyKind.BulletSupply) { this.SupplyImage.Source = BulletSupplyImage; rectangleCollider = new Rectangle2D(startX + Settings.BulletSupplyRectangleColliderLeftOffset, Settings.SupplyStartY + Settings.BulletSupplyRectangleColliderTopOffset, Settings.BulletSupplyRectangleColliderWidth, Settings.BulletSupplyRectangleColliderHeight); } else { this.SupplyImage.Source = BombSupplyImage; rectangleCollider = new Rectangle2D(startX + Settings.BombSupplyRectangleColliderLeftOffset, Settings.SupplyStartY + Settings.BombSupplyRectangleColliderTopOffset, Settings.BombSupplyRectangleColliderWidth, Settings.BombSupplyRectangleColliderHeight); } }
/// <summary> /// Generates next supply. /// </summary> private void GenerateSupply() { // Determine which kind of supply to generate. double r = random.NextDouble(); SupplyKind nextSupplyKind = r < 0.5 ? SupplyKind.BulletSupply : SupplyKind.BombSupply; // Calculate its startX. int startX = random.Next(Settings.SupplyLeftMin, Settings.SupplyLeftMax); // Generate the supply. supply = new Supply(nextSupplyKind, startX); // Add it to the main scene. mainScene.Children.Add(supply.SupplyImage); }