Exemplo n.º 1
0
        public void Render(Graphics g)
        {
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            g.DrawString(
                sumRect.ToString(),
                new Font("Ubuntu", 300),
                new SolidBrush(Color.FromArgb(255, 200, 200, 200)),
                new PointF(size.X / 2.0f, size.Y / 2.0f),
                stringFormat
                );
            foreach (RectObject rect in rects)
            {
                rect.Render(g);
            }
            g.DrawString(
                "chance : " + changeTarget.ToString(),
                new Font("Ubuntu", 50),
                new SolidBrush(Color.FromArgb(255, 120, 120, 120)),
                new PointF(10.0f, 10.0f)
                );
            if (finishFlag)
            {
                g.DrawString(
                    "Your score is " + sumRect.ToString() + "\nPress 'R' to try again",
                    new Font("Ubuntu", 50),
                    new SolidBrush(Color.FromArgb(255, 120, 120, 120)),
                    new PointF(size.X / 2.0f, size.Y / 2.0f),
                    stringFormat
                    );
                return;
            }
            if ((!startFlag) || (Math.Abs(ball.Velocity.X) < 1.0f && Math.Abs(ball.Velocity.Y) < 1.0f && ball.Position.Y >= size.Y - ball.Radius))
            {
                g.FillRectangle(
                    new SolidBrush(Color.FromArgb(200, 255, 255, 255)),
                    0, 0, size.X, size.Y
                    );
                g.DrawString(
                    "Please drag the ball",
                    new Font("Ubuntu", 50),
                    new SolidBrush(Color.FromArgb(255, 120, 120, 120)),
                    new PointF(size.X / 2.0f, size.Y / 2.0f + 60.0f),
                    stringFormat
                    );
            }
            ball.Render(g);
        }
Exemplo n.º 2
0
        public void Render(Graphics g)
        {
            g.DrawString(
                "スペースキーで当たり判定表示/非表示\nGキーで重力考慮/無視\nRキーで矩形回転/停止\nスクロールでボール半径変更\nクリックでボール位置移動",
                new Font("Ubuntu", 18),
                new SolidBrush(Color.FromArgb(128, 30, 30, 30)),
                new PointF(20.0f, 20.0f)
                );

            foreach (RectObject rect in rects)
            {
                rect.Render(g);
                if (view)
                {
                    rect.RenderHitArea(g, ball.Position, ball.Radius);
                }
            }
            ball.Render(g);

            PointF pos = mouse;
            PointF v   = new PointF(
                ball.Position.X - mouse.X,
                ball.Position.Y - mouse.Y
                );

            if (!gr)
            {
                foreach (RectObject rect in rects)
                {
                    if (rect.Hit(mouse, ball.Radius) != 0)
                    {
                        (pos, v) = rect.GetReflection(mouse, ball.Position, ball.Radius);
                    }
                }
                Pen p = new Pen(Color.FromArgb(255, 255, 0, 0), 3.0f);
                g.DrawEllipse(p, pos.X - ball.Radius, pos.Y - ball.Radius, ball.Radius * 2.0f, ball.Radius * 2.0f);
                g.DrawLine(p, ball.Position, pos);
                g.DrawLine(p, pos, new PointF(pos.X + v.X, pos.Y + v.Y));
            }
            else
            {
                EllipseObject ball_ = new EllipseObject(ball.Position, ball.Radius, 0.8f);
                ball_.Velocity = new PointF(v.X * -0.1f, v.Y * -0.1f);
                ball_.Friction = 0.9f;
                PointF pos_ = ball_.Position;
                int    len  = 100;
                for (int i = 0; i < len; i++)
                {
                    ball_.Update();
                    ball_.Acceleration = new PointF(0.0f, 0.7f);
                    ball_.Friction     = 0.99f;
                    Pen p = new Pen(Color.FromArgb(255 - 255 * i / len, 255, 0, 0), 3.0f);
                    foreach (RectObject rect in rects)
                    {
                        if (rect.Hit(ball_.Position, ball_.Radius) != 0)
                        {
                            (ball_.Position, ball_.Velocity) = rect.GetReflection(ball_.Position, pos_, ball_.Radius);
                            ball.Velocity = new PointF(ball.Velocity.X * 0.9f, ball.Velocity.Y * 0.9f);
                            g.DrawEllipse(
                                p, ball_.Position.X - ball_.Radius, ball_.Position.Y - ball_.Radius, ball_.Radius * 2.0f, ball_.Radius * 2.0f
                                );
                        }
                    }
                    if (ball_.Position.X - ball_.Radius < 0.0f)
                    {
                        ball_.Position = new PointF(ball_.Radius, ball_.Position.Y);
                    }
                    if (ball_.Position.X + ball_.Radius > size.X)
                    {
                        ball_.Position = new PointF(size.X - ball_.Radius, ball_.Position.Y);
                    }
                    if (ball_.Position.Y - ball_.Radius < 0.0f)
                    {
                        ball_.Position = new PointF(ball_.Position.X, ball_.Radius);
                    }
                    if (ball_.Position.Y + ball_.Radius > size.Y)
                    {
                        ball_.Position = new PointF(ball_.Position.X, size.Y - ball_.Radius);
                    }
                    g.DrawLine(p, pos_, ball_.Position);
                    pos_ = ball_.Position;
                }
            }
        }