Пример #1
0
        public GameObject(double posX, double posY, DxImage image)
        {
            this.posX = posX;
            this.posY = posY;

            this.Image = image;
            Image.PosX = this.posX;
            Image.PosY = this.posY;

            this.Init();
        }
Пример #2
0
 public static bool LoadTexture(string Path, ref DxImage Image)
 {
     /* 这里的路径是相对路径
      * 不带头部的斜杠
      * 注意处理返回值
      */
     if (System.IO.File.Exists(Environment.CurrentDirectory + "\\" + Path))
     {
         Image.Handle = DX.LoadGraph(Environment.CurrentDirectory + "\\" + Path);
         Bitmap ImgTmp = new Bitmap(Environment.CurrentDirectory + "\\" + Path);
         Image.Width  = ImgTmp.Width;
         Image.Height = ImgTmp.Height;
         ImgTmp.Dispose();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        /// <summary>
        /// 四角と円のあたり判定
        /// </summary>
        /// <param name="box"></param>
        /// <param name="circle"></param>
        /// <returns></returns>
        public static bool CheckBoxToCircle(DxImage box, DxImage circle)
        {
            //0:右上,1:右下,2:左下,3:左上
            Vector[] vec = new Vector[4];
            for (int i = 0; i < vec.Length; i++)
            {
                vec[i] = new Vector();
            }

            vec[0].X = box.PosX + box.SizeX / 2;
            vec[0].Y = box.PosY - box.SizeY / 2;
            vec[1].X = box.PosX + box.SizeX / 2;
            vec[1].Y = box.PosY + box.SizeY / 2;
            vec[2].X = box.PosX - box.SizeX / 2;
            vec[2].Y = box.PosY + box.SizeY / 2;
            vec[3].X = box.PosX - box.SizeX / 2;
            vec[3].Y = box.PosY - box.SizeY / 2;

            //円の中に長方形の頂点が無いか
            for (int i = 0; i < vec.Length; i++)
            {
                if (circle.Radius * circle.Radius > vec[i].X * vec[i].X + vec[i].Y * vec[i].Y)
                {
                    return(true);
                }
            }

            //長方形の中に円が入り込んでい無いか
            Vector vecCircle = new Vector(circle.PosX, circle.PosY);

            Vector vec02         = Vector.Subtract(vec[1], vec[0]);
            Vector vec0r         = Vector.Subtract(vecCircle, vec[0]);
            double InnerProduct1 = Vector.Multiply(vec02, vec0r);
            double OuterProduct1 = Vector.CrossProduct(vec02, vec0r);
            double theta1        = Math.Atan2(OuterProduct1, InnerProduct1);

            Vector vec13         = Vector.Subtract(vec[3], vec[2]);
            Vector vec1r         = Vector.Subtract(vecCircle, vec[2]);
            double InnerProduct2 = Vector.Multiply(vec13, vec1r);
            double OuterProduct2 = Vector.CrossProduct(vec13, vec1r);
            double theta2        = Math.Atan2(OuterProduct2, InnerProduct2);

            if (0 <= theta1 && theta1 <= Math.PI / 2 && 0 <= theta2 && theta2 <= Math.PI / 2)
            {
                return(true);
            }

            //長方形の辺と円の中心との距離

            for (int i = 0; i < vec.Length; i++)
            {
                double dx, dy, a, b, t, tx, ty;
                double distance;
                dx = (vec[(i + 1) % 4].X - vec[i].X);
                dy = (vec[(i + 1) % 4].Y - vec[i].Y);
                a  = dx * dx + dy * dy;
                b  = dx * (vec[i].X - circle.PosX) + dy * (vec[i].Y - circle.PosY);
                t  = -b / a;
                if (t < 0)
                {
                    t = 0;
                }
                if (t > 1)
                {
                    t = 1;
                }
                tx       = vec[i].X + dx * t;
                ty       = vec[i].Y + dy * t;
                distance = Math.Sqrt((circle.PosX - tx) * (circle.PosX - tx) + (circle.PosY - ty) * (circle.PosY - ty));

                if (distance < circle.Radius)
                {
                    return(true);
                }
            }


            return(false);
        }
Пример #4
0
        private static void Overlay_OnGraphicsSetup(object sender, SetupGraphicsEventArgs e)
        {
            //textbox = new DxTextBox("2", "qwertyuiop[]asdfghjkl;'zxcvbnm,./1234567890") { Margin = new Thickness(650, 10, 0, 0), Width = 550 };
            //textbox1 = new DxTextBox("2", "qwertyuiop[]asdfghjkl;'zxcvbnm,./1234567890".ToUpperInvariant()) { Margin = new Thickness(650, 35, 0, 0), Width = 550 };
            //Controls.Add(textbox);
            //Controls.Add(textbox1);

            //l1 = new DxLabel("1", $"{g.Graphics.MeasureText(textbox.Text.Substring(0, textbox.CaretPos + 1), FontCollection.Get("Control.Font").Font).Width}") { Margin = new Thickness(10, 35, 0, 0), Width = 200 };
            //Controls.Add(l1);

            //tb = new DxTrackBar("3", "DxTrackBar")
            //{
            //    Margin = new Thickness(200,500,0,0),
            //    Min = 0,
            //    Max = 255,
            //    TickRate = 1,
            //    Value = 0,
            //    IsSnapToTick = true
            //};
            //Controls.Add(tb);
            ////l = new DxLabel("1", $"")
            ////{
            ////    Margin = new Thickness(10, 10, 0, 0), Width = 800, Height = 500
            ////};
            ////Controls.Add(l);

            //bmp = new Image(g.Graphics.GetRenderTarget(), "q.png");
            //var q = new DxImage("", bmp){Margin = new Thickness(10,10,0,0), Width = 200, Height = 200};
            //Controls.Add(q);

            var button = new DxButton("button", "Test")
            {
                Margin = new Thickness(10, 10, 0, 0)
            };

            button.Click += btn =>
            {
                //MsgBox();
            };

            Controls.Add(button);

            var image = new DxImage("image", new Image(g.Graphics.GetRenderTarget(), "q.png"))
            {
                Width = 50, Height = 75, Margin = new Thickness(100, 10, 0, 0)
            };

            Controls.Add(image);

            var panel = new DxPanel("panel")
            {
                Width       = 50,
                Height      = 75,
                Margin      = new Thickness(100, 10, 0, 0),
                StrokeBrush = BrushCollection.Get("Control.Stroke").Brush
            };

            Controls.Add(panel);

            var imagebutton = new DxImageButton("imagebutton", new Image(g.Graphics.GetRenderTarget(), "q.png"))
            {
                Width = 50, Height = 75, Margin = new Thickness(200, 10, 0, 0)
            };

            imagebutton.Click += btn =>
            {
                //MsgBox();
            };
            Controls.Add(imagebutton);

            var label = new DxLabel("label", "text")
            {
                Margin = new Thickness(300, 10, 0, 0)
            };

            Controls.Add(label);

            var textbox = new DxTextBox("textbox", "test")
            {
                Width  = 100,
                Margin = new Thickness(100, 150, 0, 0)
            };

            Controls.Add(textbox);

            var toggle = new DxToggle("toggle", "test toggle")
            {
                Width    = 200,
                Margin   = new Thickness(100, 200, 0, 0),
                IsActive = true
            };

            Controls.Add(toggle);

            var trackbar = new DxTrackBar("trackbar", "trackbar test")
            {
                Width        = 200,
                Max          = 250,
                Min          = 0,
                IsSnapToTick = true,
                TickRate     = 1,
                Margin       = new Thickness(100, 250, 0, 0)
            };

            Controls.Add(trackbar);
        }
Пример #5
0
 public static void DrawPic(DxImage Image, float x, float y)
 {
     DX.DrawGraphF(x - (Image.Width / 2), y - (Image.Height / 2), Image.Handle, 1);
 }