public override void OnSceneLoad() { base.systems.Add(new TileRenderSystem()); base.systems.Add(new UISystem(BuildMainMenu())); //base.systems.Add(new DebugSystem()); var menuTiles = TileMap.Load(Assets.NameToPath("tm_menu.tiles")); var archetype = world.CreateArchetype(typeof(TileChunk), typeof(Position)); var background = world.CreateEntity(archetype, 6); var centerPos = new Vector2(TileChunk.PixelSize, 50f); SetChunk(background[0], TileType.Dirt, new Vector2(0f, -TileChunk.PixelSize)); SetChunk(background[1], TileType.Dirt, new Vector2(TileChunk.PixelSize, -TileChunk.PixelSize)); SetChunk(background[2], TileType.Dirt, new Vector2(TileChunk.PixelSize * 2, -TileChunk.PixelSize)); menuTiles.Instantiate(world, new Position(new Vector2(0f, 0f))); SetChunk(background[3], TileType.Stone, new Vector2(0f, TileChunk.PixelSize)); SetChunk(background[4], TileType.Stone, new Vector2(TileChunk.PixelSize, TileChunk.PixelSize)); SetChunk(background[5], TileType.Stone, new Vector2(TileChunk.PixelSize * 2, TileChunk.PixelSize)); Renderer.view.Center = new SFML.System.Vector2f(centerPos.X + TileChunk.PixelSize * 0.5f, centerPos.Y + TileChunk.PixelSize * 0.5f); }
public void Generate(World world) { int size = Math.Clamp(this.m_Random.Next() % this.m_MaxSize, this.m_MaxSize / 2, this.m_MaxSize); var archetype = world.CreateArchetype(typeof(Position), typeof(TileChunk)); var tileCollection = new RandomTileMapCollection(this.m_Random, size); tileCollection.Add(TileMap.Load(Assets.NameToPath("tm_flatland.tiles")), 30); tileCollection.Add(TileMap.Load(Assets.NameToPath("tm_hill.tiles")), 20); tileCollection.Add(TileMap.Load(Assets.NameToPath("tm_mountain.tiles")), 15); tileCollection.Add(TileMap.Load(Assets.NameToPath("tm_cliff.tiles")), 15); tileCollection.Add(TileMap.Load(Assets.NameToPath("tm_valley.tiles")), 15); var spawnLeft = GenerateSpawn( world, TileMap.Load(Assets.NameToPath("tm_spawn_left.tiles")), new Position(Vector2.Zero), new Spawn { damage = 0f, playerId = 0 }); var position = new Vector2(spawnLeft.Width, 0f); float maxDeepness = 0f; for (int i = 0; i < size; ++i) { var map = tileCollection.Choose(); var rect = map.Instantiate(world, new Position(position)); position.X += rect.Width; float deepness = rect.Top + rect.Height; if (deepness > maxDeepness) { maxDeepness = deepness; } } var spawnRight = GenerateSpawn( world, TileMap.Load(Assets.NameToPath("tm_spawn_right.tiles")), new Position(position.X, 0f), new Spawn { damage = 0f, playerId = 1 }); position.X += spawnRight.Width; world.ForEach(archetype, (batch) => { var chunks = batch.GetComponentDataReadWrite <TileChunk>(); var positions = batch.GetComponentData <Position>(); for (int i = 0; i < batch.length; ++i) { GenerateRandomizedTiles(positions[i].value, ref chunks[i]); } }); Vector2 bedrockPosition = new Vector2(0f, maxDeepness); while (bedrockPosition.X < position.X) { var entity = world.CreateEntity(archetype); world.SetComponentData <Position>(entity, new Position(bedrockPosition)); ref var chunk = ref world.RefComponentData <TileChunk>(entity); chunk.SetAll(new Tile(TileType.Bedrock)); chunk.flags = chunk.flags | TileChunkFlags.NoneDestructible | TileChunkFlags.StaticNotEmpty; bedrockPosition.X += TileChunk.PixelSize; }