Beispiel #1
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;
                }
            }
        }
Beispiel #2
0
 public void Update()
 {
     frame++;
     //foreach (RectObject rect in rects) rect.Update();
     for (int i = 0; i < rects.Count() && i < frame * 3; i++)
     {
         rects[i].Update();
     }
     foreach (RectObject block in blocks)
     {
         block.targetRadian += 0.01f;
     }
     if (finishFlag)
     {
         foreach (RectObject block in blocks)
         {
             block.targetSize = new PointF(0.0f, 0.0f);
         }
     }
     if (!startFlag || finishFlag)
     {
         return;
     }
     ball.Update();
     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);
     }
     if (enableTarget)
     {
         ball.Acceleration =
             new PointF((target.X - ball.Position.X) * 0.1f, (target.Y - ball.Position.Y) * 0.1f);
         ball.Friction = 0.9f;
     }
     else
     {
         ball.Acceleration = new PointF(0.0f, 0.7f);
         ball.Friction     = 0.99f;
     }
     if (preEnableTarget == true && enableTarget == false)
     {
         changeTarget--;
     }
     preEnableTarget = enableTarget;
     if (enableTarget)
     {
         enableTarget = false;
         return;
     }
     for (int i = 0; i < rects.Count(); i++)
     {
         RectObject rect = rects[i];
         if (rect.Hit(ball.Position, ball.Radius) == 0)
         {
             continue;
         }
         (PointF pos, PointF v) =
             rect.GetReflection(
                 ball.Position,
                 new PointF(
                     ball.Position.X - ball.Velocity.X,
                     ball.Position.Y - ball.Velocity.Y
                     ),
                 ball.Radius
                 );
         ball.Position = pos;
         ball.Velocity = v;
         if (blocks.Contains(rect))
         {
             rect.Velocity = new PointF(
                 (rect.Velocity.X - ball.Velocity.X) * 2.0f,
                 (rect.Velocity.Y - ball.Velocity.Y) * 2.0f
                 );
             rect.color = Color.FromArgb(((int)rect.color.A - 64) < 0 ? 0 : rect.color.A - 64, rect.color.R, rect.color.G, rect.color.B);
             if (rect.color.A != 0)
             {
                 sumRect++;
             }
         }
         ball.Velocity = new PointF(
             ball.Velocity.X * 0.9f,
             ball.Velocity.Y * 0.9f
             );
     }
     if (changeTarget == 0 && Math.Abs(ball.Velocity.X) < 1.0f && Math.Abs(ball.Velocity.Y) < 1.0f && ball.Position.Y >= size.Y - ball.Radius)
     {
         finishFlag = true;
     }
 }
Beispiel #3
0
        public void Update()
        {
            frame++;
            foreach (RectObject rect in rects)
            {
                rect.Update();
            }
            if (!r)
            {
                foreach (RectObject block in blocks)
                {
                    block.targetRadian += 0.01f;
                }
            }
            ball.Update();
            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);
            }

            if (enableTarget)
            {
                ball.Position = target;
            }

            if (enableTarget)
            {
                enableTarget = false;
            }

            for (int i = 0; i < rects.Count(); i++)
            {
                RectObject rect = rects[i];
                if (rect.Hit(ball.Position, ball.Radius) == 0)
                {
                    continue;
                }
                (PointF pos, PointF v) =
                    rect.GetReflection(
                        ball.Position,
                        new PointF(
                            ball.Position.X - ball.Velocity.X,
                            ball.Position.Y - ball.Velocity.Y
                            ),
                        ball.Radius
                        );
                ball.Position = pos;
                ball.Velocity = v;
                ball.Velocity = new PointF(
                    ball.Velocity.X * 0.9f,
                    ball.Velocity.Y * 0.9f
                    );
            }
        }