コード例 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //r.Load();
            img = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            G   = Graphics.FromImage(img);
            pictureBox1.Image = img;

            app = new Vector2(1536, 864);
            ell = new Elemento(app, app, 10, 100, Color.Red);
            r.Add(ell);
            app = new Vector2(1336, 864);
            ell = new Elemento(app, app, 10, 100, Color.Blue);
            r.Add(ell);
            app = new Vector2(1136, 864);
            ell = new Elemento(app, app, 10, 30, Color.Yellow);
            r.Add(ell);
            app = new Vector2(1336, 564);
            ell = new Elemento(app, app, 10, 50, Color.Green);
            r.Add(ell);
            app = new Vector2(936, 864);
            ell = new Elemento(app, app, 10, 100, Color.Magenta);
            r.Add(ell);

            app = new Vector2(300, 864);
            TimeSpan time = new TimeSpan(0, 10, 20);

            b = new BucoNero(app, time, false, 10, 900);
            r.Add(b);

            app = new Vector2(300, 364);
            Gravita g = new Gravita(app, new TimeSpan(10, 10, 10), false, new Vector2(100, 50));

            r.Add(g);

            app = new Vector2(100, 164);
            Attrito at = new Attrito(app, new TimeSpan(10, 10, 10), false, new Vector2(100, 50), 5);

            r.Add(at);

            app = new Vector2(1000, 164);
            CampoMinato min = new CampoMinato(app, new TimeSpan(20, 2, 2), false, new Vector2(400, 50));

            r.Add(min);
            //r.Save();

            app.X = pictureBox1.Width;
            app.Y = pictureBox1.Height;
            c     = new Camera(app);

            //clock
            t.Interval = 5;
            t.Tick    += T_Tick;
            t.Start();
        }
コード例 #2
0
        public void Draw()
        {
            G.Clear(Color.Black);

            /* Elemento ee = new Elemento(app, app, 10, 30, Color.AliceBlue);
             * r.Modify(ell, ee);*/
            float  dpiX       = G.DpiX;
            double multiplier = 1 - ((((dpiX / 96) - 1) * 4) * 0.4);

            foreach (KeyValuePair <int, Modificatore> kv in r.Modificarori)
            {
                bool Todraw = true;
                switch (kv.Value.GetType().Name.ToString())
                {
                case "Attrito":
                    Attrito m = (Attrito)kv.Value;
                    if (m.Pos.X + m.GiveDistanceFromCenter().X < c.Origin.X - c.Dim.X || m.Pos.X - m.GiveDistanceFromCenter().X > c.Origin.X + c.Dim.X || m.Pos.Y - m.GiveDistanceFromCenter().Y > c.Origin.Y + c.Dim.Y || m.Pos.Y + m.GiveDistanceFromCenter().Y < c.Origin.Y - c.Dim.Y)
                    {
                        Todraw = false;
                    }
                    break;

                case "CampoMinato":
                    CampoMinato mc = (CampoMinato)kv.Value;
                    if (mc.Pos.X + mc.GiveDistanceFromCenter().X < c.Origin.X - c.Dim.X || mc.Pos.X - mc.GiveDistanceFromCenter().X > c.Origin.X + c.Dim.X || mc.Pos.Y - mc.GiveDistanceFromCenter().Y > c.Origin.Y + c.Dim.Y || mc.Pos.Y + mc.GiveDistanceFromCenter().Y < c.Origin.Y - c.Dim.Y)
                    {
                        Todraw = false;
                    }
                    break;

                case "Gravita":
                    Gravita mg = (Gravita)kv.Value;
                    if (mg.Pos.X + mg.GiveDistanceFromCenter().X < c.Origin.X - c.Dim.X || mg.Pos.X - mg.GiveDistanceFromCenter().X > c.Origin.X + c.Dim.X || mg.Pos.Y - mg.GiveDistanceFromCenter().Y > c.Origin.Y + c.Dim.Y || mg.Pos.Y + mg.GiveDistanceFromCenter().Y < c.Origin.Y - c.Dim.Y)
                    {
                        Todraw = false;
                    }
                    break;

                case "Vento":
                    break;

                case "BucoNero":
                    BucoNero mb = (BucoNero)kv.Value;
                    if (mb.Pos.X + mb.GiveDistanceFromCenter().X < c.Origin.X - c.Dim.X || mb.Pos.X - mb.GiveDistanceFromCenter().X > c.Origin.X + c.Dim.X || mb.Pos.Y - mb.GiveDistanceFromCenter().Y > c.Origin.Y + c.Dim.Y || mb.Pos.Y + mb.GiveDistanceFromCenter().Y < c.Origin.Y - c.Dim.Y)
                    {
                        Todraw = false;
                    }
                    break;
                }

                if (Todraw == true)
                {
                    Rectangle rApp = c.GiveIconDim(kv.Value);
                    G.DrawImage(ResizeImage(kv.Value.Img, (int)(rApp.Width * multiplier), (int)(rApp.Height * multiplier)), rApp.Location);
                    if (kv.Value.GetType().Name.ToString() == "BucoNero")
                    {
                        G.DrawEllipse(Pens.White, c.GiveRect(kv.Value));
                    }
                    else
                    {
                        G.DrawRectangle(Pens.White, c.GiveRect(kv.Value));
                    }
                }
            }
            foreach (KeyValuePair <int, Elemento> kv in r.Elementi)
            {
                if (kv.Value.Pos.X + kv.Value.R < c.Origin.X - c.Dim.X || kv.Value.Pos.X - kv.Value.R > c.Origin.X + c.Dim.X || kv.Value.Pos.Y - kv.Value.R > c.Origin.Y + c.Dim.Y || kv.Value.Pos.Y + kv.Value.R < c.Origin.Y - c.Dim.Y)
                {
                }
                else
                {
                    SolidBrush b = new SolidBrush(kv.Value.Col);
                    G.FillEllipse(b, c.GiveRect(kv.Value));
                    label3.Text = c.GiveRect(kv.Value).Location.ToString();
                    label4.Text = c.GiveRect(kv.Value).Width.ToString();
                }
            }

            G.DrawLine(Pens.White, c.Screen.X / 2 - 10, c.Screen.Y / 2, c.Screen.X / 2 + 10, c.Screen.Y / 2);
            G.DrawLine(Pens.White, c.Screen.X / 2, c.Screen.Y / 2 - 10, c.Screen.X / 2, c.Screen.Y / 2 + 10);
            pictureBox1.Refresh();
        }