Esempio n. 1
0
        //Generate objects on screen.
        private void Render(Graphics output)
        {
            screen.Clear(Color.White);

            //draw line
            screen.DrawLine(new Pen(Color.Blue), new Point(-1000, 0), new Point(1000, 0));

            //X-coordinate circle and rectangle
            circle.X    -= (int)((circle.speed * 0.010) * (double)numericPPM.Value);
            rectangle.X -= (int)((rectangle.speed * 0.010) * (double)numericPPM.Value);

            //Check collision
            if (collision.CheckCollision((Circle)circle, (Shapes.Rectangle)rectangle))
            {
                //set X correct.
                circle.X = (rectangle.X + (rectangle.width / 2)) + circle.radius;

                //stop when v=0
                if (collision.ResultAcceleration(circle.acceleration, standgrav, theta, (Circle)circle, (Shapes.Rectangle)rectangle) <= 0)
                {
                    stop();
                    startButton.Enabled  = false;
                    checkStopped.Checked = true;
                }
                else
                {
                    if (!hasCollision)
                    {
                        checkCollision.Checked = true;
                    }
                    hasCollision = true;
                }
            }

            //Draw circle
            System.Drawing.Rectangle boundingBox = new System.Drawing.Rectangle(new Point(circle.X - circle.radius, circle.Y), new Size(circle.radius * 2, circle.radius * 2));
            screen.FillEllipse(new SolidBrush(Color.Crimson), boundingBox);

            //Draw rectangle
            System.Drawing.Rectangle boundingBoxrect = new System.Drawing.Rectangle(new Point(rectangle.X - (rectangle.width / 2), rectangle.Y), new Size(rectangle.width, rectangle.height));
            screen.FillRectangle(new SolidBrush(Color.Green), boundingBoxrect);

            // toon backbuffer op display
            output.DrawImage(backBuffer, new System.Drawing.Rectangle(0, 0, display.Width, display.Height), new System.Drawing.Rectangle(0, 0, display.Width, display.Height), GraphicsUnit.Pixel);


            //check circle
            if (((circle.X <= -500) || (rectangle.X <= -500)) && !checkOutframe.Checked)
            {
                startButton_Click(new object(), new EventArgs());
                startButton.Enabled   = false;
                checkOutframe.Checked = true;
            }
            // display textboxes
            textBoxCircleSpeed.Text = "" + circle.speed;
            textBoxAccCircle.Text   = "" + circle.acceleration;
            textBoxSpeedRect.Text   = "" + rectangle.speed;
            textBoxRectAcc.Text     = "" + rectangle.acceleration;
            textBoxTime.Text        = "" + time;
        }