Example #1
0
        //---------------------------------------------------------------------------

        public Chunk(int x, int y)
        {
            X       = x;
            Y       = y;
            m_Cells = new ChunkCell[Width, Height];

            for (int _y = 0; _y < Height; _y++)
            {
                for (int _x = 0; _x < Width; _x++)
                {
                    m_Cells[_x, _y] = new ChunkCell();
                }
            }
        }
Example #2
0
        public IEntity CreateCollision()
        {
            IEntity entity = EntityManager.Get().Find(m_CollisionEntity);

            if (entity == null)
            {
                entity = EntityFactory.Create <Entity>(string.Format("Chunk[{0}|{0}]", X, Y));
                entity.AddComponent <TransformComponent>();
                entity.AddComponent <PhysicsComponent>();
                entity.AddComponent <MultiPathColliderComponent>().SetCollisionCategory(ECollisionCategory.Stage);
            }
            MultiPathColliderComponent path = entity.GetComponent <MultiPathColliderComponent>();

            if (path != null)
            {
                path.Reset();
                path.SetCollisionCategory(ECollisionCategory.Stage);

                for (int x = -1; x < Width - 1; x++)
                {
                    Vector2 start  = new Vector2((GlobalX(x) + 1) * 64, GlobalY(0) * 64);
                    int     length = 0;
                    for (int y = 0; y < Height; y++)
                    {
                        ChunkCell cell = null;
                        if (x < 0 && LeftChunk != null)
                        {
                            cell = LeftChunk[Width + x, y];
                        }
                        else if (x >= 0)
                        {
                            cell = m_Cells[x, y];
                        }

                        if (cell != null)
                        {
                            if (cell.IsBlocked != m_Cells[x + 1, y].IsBlocked)
                            {
                                length++;
                            }
                            else
                            {
                                if (length > 0)
                                {
                                    Vector2 end = new Vector2((GlobalX(x) + 1) * 64, GlobalY(y) * 64);
                                    path.AddPath(start, end);
                                    AddCorners(start, end);
                                    length = 0;
                                }
                                start = new Vector2((GlobalX(x) + 1) * 64, (GlobalY(y) + 1) * 64);
                            }
                        }
                    }
                    if (length > 0)
                    {
                        Vector2 end = new Vector2((GlobalX(x) + 1) * 64, GlobalY(Height) * 64);
                        path.AddPath(start, end);
                        AddCorners(start, end);
                    }
                }

                for (int y = -1; y < Height - 1; y++)
                {
                    Vector2 start  = new Vector2(GlobalX(0) * 64, (GlobalY(y) + 1) * 64);
                    int     length = 0;
                    for (int x = 0; x < Width; x++)
                    {
                        ChunkCell cell = null;
                        if (y < 0 && TopChunk != null)
                        {
                            cell = TopChunk[x, Height + y];
                        }
                        else if (y >= 0)
                        {
                            cell = m_Cells[x, y];
                        }

                        if (cell != null)
                        {
                            if (cell.IsBlocked != m_Cells[x, y + 1].IsBlocked)
                            {
                                length++;
                            }
                            else
                            {
                                if (length > 0)
                                {
                                    Vector2 end = new Vector2(GlobalX(x) * 64, (GlobalY(y) + 1) * 64);
                                    path.AddPath(start, end);
                                    AddCorners(start, end);
                                    length = 0;
                                }
                                start = new Vector2((GlobalX(x) + 1) * 64, (GlobalY(y) + 1) * 64);
                            }
                        }
                    }
                    if (length > 0)
                    {
                        Vector2 end = new Vector2(GlobalX(Width) * 64, (GlobalY(y) + 1) * 64);
                        path.AddPath(start, end);
                        AddCorners(start, end);
                    }
                }
            }
            return(entity);
        }