Esempio n. 1
0
        public void Insert(ObjectGame obj)
        {
            Rectangle r = new Rectangle(obj.location.X, obj.location.Y, obj.bm.Width, obj.bm.Height);

            if (LeftBot == null)
            {
                CreateSubNode();
            }

            if (LeftTop != null && LeftTop.rec.Contains(r))
            {
                LeftTop.Insert(obj);
                return;
            }
            if (RightTop != null && RightTop.rec.Contains(r))
            {
                RightTop.Insert(obj);
                return;
            }
            if (LeftBot != null && LeftBot.rec.Contains(r))
            {
                LeftBot.Insert(obj);
                return;
            }
            if (RightBot != null && RightBot.rec.Contains(r))
            {
                RightBot.Insert(obj);
                return;
            }

            this.listObj.Add(obj);
        }
Esempio n. 2
0
        private void pbMap_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (curObj != null)
                {
                    int tilewidth  = 16;
                    int tileheight = 16;
                    int x          = (mousePicMapX / tilewidth) * tilewidth;
                    int y;
                    if (curObj.bm.Height % tileheight == 0)
                    {
                        y = (mousePicMapY / tileheight) * tileheight;
                    }
                    else
                    {
                        y = (mousePicMapY / tileheight) * tileheight + (tileheight - curObj.bm.Height % tileheight);
                    }
                    Point p = new Point(x, y);
                    DrawImage(pbMap.BackgroundImage, curObj.bm, p, new Rectangle(0, 0, curObj.bm.Width, curObj.bm.Height));
                    ObjectGame obj = new ObjectGame(curObj.bm, curObj.ID, "Enemy");
                    obj.SetLocation(p.X, p.Y);
                    listobjmap.Add(obj);
                    curObj = obj;

                    if (flagNewMap == true)
                    {
                        DrawImage(newMap, curObj.bm, p, new Rectangle(0, 0, curObj.bm.Width, curObj.bm.Height));
                        btnSaveMap.Enabled = true;
                    }
                }
            }
        }
Esempio n. 3
0
 private void btnAddOtherObj_Click(object sender, EventArgs e) //them obj moi vao map
 {
     openFolder.ShowDialog();
     try
     {
         String[] listImg = Directory.GetFiles(openFolder.SelectedPath);
         foreach (String img in listImg)
         {
             int        id  = int.Parse(getName(img));
             Bitmap     bm  = (Bitmap)Bitmap.FromFile(img);
             ObjectGame obj = new ObjectGame(bm, id, "Enemy");
             //listobjmap.Add(obj);
             listobj.Add(obj);
             if (listobj.Count == 1)
             {
                 pbOthers.Width           = 16;
                 pbOthers.BackgroundImage = new Bitmap(pbOthers.Width, pbOthers.Height);
                 Graphics.FromImage(pbOthers.BackgroundImage).Clear(Color.DarkGray);
                 DrawImage(pbOthers.BackgroundImage, obj.bm, new Point((16 - obj.bm.Width), (pbOthers.Height - obj.bm.Height)), new Rectangle(0, 0, 16, obj.bm.Height));
                 pbOthers.BackgroundImage = obj.bm;
             }
             else
             {
                 Bitmap bm1 = (Bitmap)pbOthers.BackgroundImage;
                 pbOthers.Width          += 16;
                 pbOthers.BackgroundImage = new Bitmap(pbOthers.Width, pbOthers.Height);
                 Graphics.FromImage(pbOthers.BackgroundImage).Clear(Color.DarkGray);
                 DrawImage(pbOthers.BackgroundImage, bm1, Point.Empty, new Rectangle(0, 0, bm1.Width, bm1.Height));
                 DrawImage(pbOthers.BackgroundImage, obj.bm, new Point(bm1.Width + (16 - obj.bm.Width), (bm1.Height - obj.bm.Height)), new Rectangle(0, 0, obj.bm.Width, obj.bm.Height));
             }
         }
     }
     catch
     { }
 }
Esempio n. 4
0
        void addObject() //them obj
        {
            AddObject f = new AddObject();

            foreach (ObjectGame o in listobj)
            {
                f.comboBox1.Items.Add(o.ID);
            }
            f.comboBox1.Text = listobj.Count.ToString();
            f.ShowDialog();
            curObj = new ObjectGame(curTile, int.Parse(f.comboBox1.Text), f.cbType.Text);
            listobj.Add(curObj);
            btnSaveMatrix.Enabled = true;
        }
Esempio n. 5
0
 private void btnAddObj_Click(object sender, EventArgs e) //them obj vao list obj map
 {
     addObject();
     for (int i = 0; i < countRow; i++)
     {
         for (int j = 0; j < countCol; j++)
         {
             if (matTile[i, j].Equals(curTile.Tag))
             {
                 ObjectGame obj = new ObjectGame(curTile, curObj.ID, curObj.objectType.ToString());
                 obj.SetLocation(j * 16, i * 16);
                 listobjmap.Add(obj);
                 pbMap.Invalidate();
             }
         }
     }
 }
Esempio n. 6
0
        private void pbOthers_MouseDown(object sender, MouseEventArgs e)
        {
            pbOthers.Image = new Bitmap(pbOthers.BackgroundImage.Width, pbOthers.BackgroundImage.Height);

            int i = e.X / 16;

            Graphics.FromImage(pbOthers.Image).DrawRectangle(Pens.Red, new Rectangle(i * 16, 0, 16, 16));
            foreach (ObjectGame obj in listobj)
            {
                if (obj.ID == i)
                {
                    curObj = obj;
                    Graphics.FromImage(pbOthers.Image).DrawRectangle(Pens.Red, new Rectangle(i * 16, 0, 16, obj.bm.Height));
                    pbOthers.Invalidate();
                    return;
                }
            }
        }