Пример #1
0
        private int y; // stores y-coordinate

        #endregion Fields

        #region Constructors

        /* Constructor for Raindrop */
        public Raindrop(Panel panel, Bucket theBucket, int x, int y, int width, int height)
        {
            raindropPanel = panel;  // Set the panel
            raindropPanel.Paint += new PaintEventHandler(raindropPanel_Paint);  // Set up the Paint Event
            g = raindropPanel.CreateGraphics();  // Create the Graphics object
            bucket = theBucket;  // Set the bucket
            X = x;  // Set the x-coordinate
            Y = y;  // Set the y-coordinate
            Width = width;  // Set the width
            Height = height;  // Set the height
        }
        /* rainDropTimer_Tick moves the Raindrop down (when the timer ticks) and checks if the Bucket and Raindrop intersect */
        private void rainDropTimer_Tick(object sender, EventArgs e)
        {
            if (raindrop.KeyActive == true)  // IF the Raindrop is accepting KeyDown events (animating on them)
            {
                raindrop.AnimateProgressDown(ref generateNewRaindropLocation);  // Animate down and check if it hit the bucket
                if (raindrop.Y > 580 && raindrop.Y < 605)  // IF the raindrop is in the appropriate location to check for intersections
                {
                    if (raindrop.X >= bucket.X - 50 && raindrop.X <= bucket.X + 50)  // IF it is within range of the bucket
                    {
                        buckets++;  // Increment buckets
                        AddPoints(50);  // They hit the bucket

                        // Stop the bucket animation
                        generateNewBucketLocation = true;
                        bucketAnimationTimer.Stop();

                        // Cover previous bucket to avoid issues
                        bucket.CoverPreviousBucket(graphics);

                        // Create new bucket
                        bucket = new Bucket(550, 600, 90, 100, 10);
                        bucket.PaintBucket(graphics);

                        // Start the animation
                        generateNewBucketLocation = false;
                        bucketAnimationTimer.Start();
                    }  // end IF
                }  // end IF
            }  // end IF
            else  // IF the Raindrop is not accepting KeyDown events
            {
                rainDropTimer.Stop();  // Stop the rainDropTimer
                raindrop = null;  // Set raindrop equal to null
                raindrop = new Raindrop(raindropPanel, bucket, 600, 15, 45, 45);  // Create a new instance of the Raindrop
                raindrop.PaintRaindrop();  // Paint the raindrop in its original location
                raindrop.KeyActive = true;  // Allow KeyDown events to animate the raindrop
                generateNewRaindropLocation = false;  // Allow the loops to begin running for Raindrop again (when called)
                raindrop.AnimateProgressDown(ref generateNewRaindropLocation);  // animate the raindrop down once
                rainDropTimer.Start();  // Start the rainDropTimer to begin the animation
            }  // end ELSE
        }
        /* LeakingLayout_Paint handles the general paint event for the form */
        private void LeakingLayout_Paint(object sender, PaintEventArgs e)
        {
            // Create the gradient brush for the scoreboard
            LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(0, 700), new Point(0, 800), Color.CadetBlue, Color.DarkSlateBlue);

            // Draw the ScoreBoard
            graphics.FillRectangle(linearGradientBrush, 0, 700, 1200, 100);

            // Construct & Draw the Bucket
            bucket = new Bucket(550, 600, 90, 100, 10);
            bucket.PaintBucket(graphics);

            // Construct the Raindrop
            raindrop = new Raindrop(raindropPanel, bucket, 600, 15, 45, 45);
            raindrop.PaintRaindrop();

            // Draw some base lines
            graphics.DrawLine(new Pen(Color.Black, 2), new Point(0, 600), new Point(1200,600));
        }