コード例 #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);
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: kemthichem/rockman-game
        public void AddObjectToNode(ObjectGame ob)
        {
            if(!Bound.IntersectsWith(ob.BoundInQuadTree))
                return;
            if (LeftTop == null && Width > 512)
                CreateSubNode();
            if (LeftTop != null)
            {
                //Loop in child Node
                if (CanAddToNode(LeftTop, ob) ||
                    CanAddToNode(RightTop, ob) ||
                    CanAddToNode(LeftBottom, ob) ||
                    CanAddToNode(RightBottom, ob))
                    return;
                //else
                //{
                //    if (LeftBottom.ListObject.Count == 0)
                //        LeftBottom = null;
                //    if (LeftTop.ListObject.Count == 0)
                //        LeftTop = null;
                //    if (RightTop.ListObject.Count == 0)
                //        RightTop = null;
                //    if (RightBottom.ListObject.Count == 0)
                //        RightBottom = null;
                //}
            }

            ListObject.Add(ob);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: kemthichem/rockman-game
        //---------add range
        public static void AddRange(int fromR, int toR, int fromC, int toC, string name)
        {
            int id;
            ObjectType _type = (ObjectType)Enum.Parse(typeof(ObjectType), name);

            int widthType = 0;
            int heightType = 0;
            Image image = null;
            ObjectGame.SetKind(_type, false, ref widthType, ref heightType, ref image);
            int nextXObject;
            if (toR <= fromR) toR = fromR;
            if (toC <= fromC) toC = fromC + 1;

            for (int i = fromR; i <= toR ; i++)
            {
                nextXObject = 0;
                for (int j = fromC; j < toC && nextXObject < toC * 32; j++)
                {
                    ObjectGame ob = new ObjectGame(new Point(fromC * 32 + (j - fromC) * widthType + 32, (SizeHeightMap - i) * 32 ), _type);
                    listContents.Add(ob);
                    nextXObject = ob.Pos.X + widthType;

                }
            }
        }
コード例 #4
0
 bool objInRange(Point clickPoint, ObjectGame obj)
 {
     if (clickPoint.X < obj.location.X || clickPoint.X > obj.location.X + obj.bm.Width || clickPoint.Y > obj.location.Y + obj.bm.Height || clickPoint.Y < obj.location.Y)
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
 void addObject(ObjectGame obj)
 {
     foreach (ObjectGame objectGame in listobjmap)
     {
         if (obj == objectGame)
         {
             return;
         }
     }
     listobjmap.Add(obj);
 }
コード例 #6
0
        private void drawItem(String path, int ID)
        {
            Bitmap bm = new Bitmap(Path.Combine(Application.StartupPath, path));

            if (ID == (int)EnumID.Brick_ID || ID == (int)EnumID.StairUpLeft_ID || ID == (int)EnumID.StairUpRight_ID || ID == (int)EnumID.Door_ID)
            {
                currentMouse = new Point((currentMouse.X / 32) * 32, (currentMouse.Y / 32) * 32);
            }
            DrawImage(pictureBox1.Image, bm, currentMouse, new Rectangle(0, 0, bm.Width, bm.Height));
            pictureBox1.Refresh();
            ObjectGame obj = new ObjectGame(bm, ID);

            obj.SetLocation(currentMouse.X, currentMouse.Y);
            addObject(obj);
        }
コード例 #7
0
        private void decodeObj(string readObj)
        {
            int currentIndex = 0;
            int numOfObj     = int.Parse(readObj.Substring(currentIndex, readObj.IndexOf("\r\n\r\n", currentIndex) - currentIndex));

            currentIndex = readObj.IndexOf("\r\n\r\n", currentIndex) + 4;
            for (int i = 0; i < numOfObj; i++)
            {
                int id = int.Parse(readObj.Substring(currentIndex, readObj.IndexOf("\r\n", currentIndex) - currentIndex));
                currentIndex = readObj.IndexOf("\r\n", currentIndex) + 2;
                int x = int.Parse(readObj.Substring(currentIndex, readObj.IndexOf("\r\n", currentIndex) - currentIndex));
                currentIndex = readObj.IndexOf("\r\n", currentIndex) + 2;
                int        y   = int.Parse(readObj.Substring(currentIndex, readObj.IndexOf("\r\n", currentIndex) - currentIndex));
                ObjectGame obj = new ObjectGame(getImage(id), id);
                obj.SetLocation(x, y);
                listobjmap.Add(obj);
                currentIndex = readObj.IndexOf("\r\n\r\n", currentIndex) + 4;
            }
        }
コード例 #8
0
ファイル: QuadTree.cs プロジェクト: kemthichem/rockman-game
 public void AddObject(ObjectGame ob)
 {
     if (NodeRoot.Bound.Contains (ob.BoundInQuadTree))
         NodeRoot.AddObjectToNode(ob);
 }
コード例 #9
0
ファイル: Node.cs プロジェクト: kemthichem/rockman-game
 private bool CanAddToNode(Node _node, ObjectGame ob)
 {
     if (_node.Bound.IntersectsWith(ob.BoundInQuadTree))
     {
         _node.AddObjectToNode(ob);
         return true;
     }
     return false;
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: kemthichem/rockman-game
        private void ReadFile(StreamReader reader)
        {
            btCAll.PerformClick();
            string line;
            String[] arrString;
            line = reader.ReadLine();
            arrString = line.Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            size = 32;
            numWidth = Int32.Parse(arrString[0]) / size;
            numHeight = Int32.Parse(arrString[1]) / size;
            HeightOfMap = numHeight * size;

            while ((line = reader.ReadLine()) != null && line != "<End>")
            {
                arrString = line.Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                int mapId = Int32.Parse(arrString[0]);
                string mapTypeStr = arrString[1];
                ObjectType typeMap = (ObjectType)Enum.Parse(typeof(ObjectType), mapTypeStr);
                int mapX = Int32.Parse(arrString[2]) + 32;
                int mapY = HeightOfMap - Int32.Parse(arrString[3]) + size;

                ObjectGame ob = new ObjectGame(new Point(mapX, mapY), typeMap);
                listContents.Add(ob);
            }

            reader.Dispose();
            reader.Close();

            pbGridMap.Invalidate();
            tbHeight.Text = numHeight.ToString();
            tbWidth.Text = numWidth.ToString();
            btCreate.PerformClick();
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: kemthichem/rockman-game
        //------event pbGridMap----------
        private void pbGridMap_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Point p = new Point(e.Location.X - 32, e.Location.Y - 32);
                int index = IndexObject(p);
                if (index != -1)
                {
                    listContents.RemoveAt(index);
                }
            }

            else
                if (e.Button == MouseButtons.Left)
                {
                    if (RectGrid.Contains(e.Location))
                    {
                        ObjectGame ob = null;
                        Point p = new Point(e.Location.X - 32, e.Location.Y - 32);
                        int index = IndexObject(p);
                        if (index != -1)
                        {
                            ob = listContents[index];
                        }
                        if (ob == null || (ob != null && ob.TypeOb != TypeCurrent))
                        {
                            ObjectGame _ob = new ObjectGame(e.Location, TypeCurrent);
                            listContents.Add(_ob);
                        }
                    }
                }
            pbGridMap.Invalidate();
        }