public static IEntity CreateDummyBuilding(int x, int y, int width ,int height, NamelessGame namelessGame)
        {

            IEntity worldEntity = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;
            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType<TimeLine>().CurrentTimelineLayer.Chunks;
            }

            IEntity building = new Entity();

            building.AddComponent(new Description("",""));
            building.AddComponent(new Position(x,y));

            Building buildingComponent = new Building();

            for (int i = 0;i< width; i++)
            {
                for (int j = 0;j< height; j++)
                {
                    var tile = worldProvider.GetTile(x + i, y + j);
                    tile.Terrain = TerrainTypes.Road;
                    tile.Biome = Biomes.None;
                    if (i == 0 || j == 0 || i == width - 1 || j == height - 1)
                    {
                        if (i == width / 2)
                        {
                            IEntity door = CreateDoor(x + i, y + j);
                            buildingComponent.getBuildingParts().Add(door);
                            namelessGame.AddEntity(door);
                            tile.AddEntity((Entity) door);
                        }
                        else
                        {
                            var wall = TerrainFurnitureFactory.WallEntity;
                            tile.AddEntity(wall);
                            namelessGame.AddEntity(wall);
                        }
                    }
                }



            }
            building.AddComponent(buildingComponent);
            return building;

        }
예제 #2
0
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            IEntity        worldEntity   = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
            }


            IEntity playerentity = namelessGame.PlayerEntity;

            if (playerentity != null)
            {
                Chunk    currentChunk    = null;
                Point?   currentChunkKey = null;
                Position playerPosition  = playerentity.GetComponentOfType <Position>();
                //look for current chunk
                foreach (Point key in worldProvider.GetRealityBubbleChunks().Keys)
                {
                    Chunk ch = worldProvider.GetRealityBubbleChunks()[key];
                    if (ch.IsPointInside(playerPosition.Point))
                    {
                        currentChunk    = ch;
                        currentChunkKey = key;
                        break;
                    }
                }

                //if there is none, that means we just loaded the namelessGame, look for current in all chunks
                if (currentChunk == null)
                {
                    foreach (Point key in worldProvider.GetChunks().Keys)
                    {
                        Chunk ch = worldProvider.GetChunks()[key];
                        if (ch.IsPointInside(playerPosition.Point))
                        {
                            currentChunk    = ch;
                            currentChunkKey = key;
                            break;
                        }
                    }
                }

                if (currentChunk != null)
                {
                    for (int x = -Constants.RealityBubbleRangeInChunks + currentChunkKey.Value.X;
                         x <= Constants.RealityBubbleRangeInChunks + currentChunkKey.Value.X;
                         x++)
                    {
                        for (int y = -Constants.RealityBubbleRangeInChunks + currentChunkKey.Value.Y;
                             y <= Constants.RealityBubbleRangeInChunks + currentChunkKey.Value.Y;
                             y++)
                        {
                            Point p = new Point(x, y);
                            if (!worldProvider.GetRealityBubbleChunks().ContainsKey(p))
                            {
                                if (worldProvider.GetChunks().ContainsKey(p))
                                {
                                    Chunk chunk = worldProvider.GetChunks()[p];



                                    worldProvider.GetRealityBubbleChunks().Add(p, chunk);
                                    worldProvider.RealityChunks.Add(chunk);
                                }
                            }
                        }
                    }

                    List <Point> keysToRemove = new List <Point>();
                    foreach (Point key in
                             worldProvider.GetRealityBubbleChunks().Keys)
                    {
                        double distX = Math.Abs(key.X - currentChunkKey.Value.X);
                        double distY = Math.Abs(key.Y - currentChunkKey.Value.Y);
                        if (distX > Constants.RealityBubbleRangeInChunks || distY > Constants.RealityBubbleRangeInChunks)
                        {
                            keysToRemove.Add(key);
                        }
                    }

                    foreach (Point key in
                             keysToRemove)
                    {
                        if (worldProvider.GetRealityBubbleChunks()[key].IsActive)
                        {
                            worldProvider.GetRealityBubbleChunks()[key].Deactivate();
                            worldProvider.RealityChunks.Remove(worldProvider.GetRealityBubbleChunks()[key]);
                            worldProvider.GetRealityBubbleChunks().Remove(key);
                        }
                    }
                }
            }

            var justcreated = worldProvider.GetRealityBubbleChunks().Where(x => x.Value.JustCreated);

            foreach (var realityBubbleChunk in justcreated)
            {
                foreach (var tileArray in realityBubbleChunk.Value.GetChunkTiles())
                {
                    foreach (var tile in tileArray)
                    {
                        var entity = TerrainFurnitureFactory.GetExteriorEntities(namelessGame, tile);
                        if (entity != null)
                        {
                            if (tile.GetEntities().Count == 0)
                            {
                                tile.AddEntity(entity);

                                namelessGame.AddEntity(entity);
                            }
                        }
                    }
                }
                realityBubbleChunk.Value.JustCreated = false;
            }
        }
 private static void AddToTileAndGame(Tile tile, IEntity entity, NamelessGame namelessGame)
 {
     namelessGame.AddEntity(entity);
     tile.AddEntity((Entity)entity);
 }