/// <summary> /// Creates a server-side version of the map /// </summary> public Map(string name, string description, int width, int height, int id) { ID = id; Name = name; Description = description; Width = width; Height = height; IsServer = true; //Running a client Tiles = new Tile[Width, Height, 2]; Players = new List<Player>(); Generate(); }
/// <summary> /// Creates a client-side version of a map at the specified width and height (To be changed later once Init packet recieved) /// </summary> public Map(Game game, int width, int height) { Game = game; Width = width; Height = height; //Running the client! IsServer = false; //Select default block SelectedBlock = BlockType.Default; //Initialize tile array Tiles = new Tile[Width, Height, 2]; Players = new List<Player>(); //Setup camera CreateCamera(); LoadContent(); Spawn = new Vector2(Tile.Width, Tile.Height); pixel = new Texture2D(game.GraphicsDevice, 1, 1); pixel.SetData<Color>(new Color[1] { Color.White }); SetMinimapColors(); }
/// <summary> /// Generates a simple world with borders /// </summary> private void Generate() { //Temporary Generation int[] heightMap = new int[Width]; //Config int offset = Height - 17; float peakheight = 5; float flatness = 40; int iterations = 8; double[] rands = new double[iterations]; for (int i = 0; i < iterations; i++) { rands[i] = random.NextDouble() + i; } for (int x = 0; x < Width; x++) { double height = 0; for (int i = 0; i < iterations; i++) { height += peakheight / rands[i] * Math.Sin((float)x / flatness * rands[i] + rands[i]); } heightMap[x] = (int)height + offset; } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (x == 0 || y == 0 || x == Width - 1 || y == Height - 1) Tiles[x, y, 1] = new Tile(BlockType.Default); else { if (y > heightMap[x] + 8) Tiles[x, y, 1] = new Tile(BlockType.Stone); else if (y > heightMap[x]) Tiles[x, y, 1] = new Tile(BlockType.Dirt); else if (y == heightMap[x]) Tiles[x, y, 1] = new Tile(BlockType.Grass); else Tiles[x, y, 1] = new Tile(BlockType.Empty); } Tiles[x, y, 0] = new Tile(BlockType.Empty); } } }
/// <summary> /// Places a tile at the specified position, WHILE taking into account it's TileType /// Mainly used for player block placement, if you are looking to place a block through the code /// Either use `Tiles[x,y,z] =` or, set sendMessage to false /// </summary> /// <param name="x">The X position on the grid</param> /// <param name="y">The Y position on the grid</param> /// <param name="layer">The layer, either background or foreground</param> /// <param name="block">The block to place</param> /// <param name="sendMessage">Should the block be sent to the server or not</param> public void PlaceTile(int x, int y, Layer layer, BlockType block, bool sendMessage) { int z = layer == Layer.Foreground ? 1 : 0; if (CanPlaceBlock(x, y, z, block)) { //If the block has changed, and we should send a message, send one if (sendMessage && Tiles[x, y, z].Block.ID != block.ID) { Game.NetManager.Send(new BlockMessage(block, x, y, z)); } //Set the block switch (block.Type) { case TileType.Default: Tiles[x, y, z] = new Tile(block); break; case TileType.Animated: Tiles[x, y, z] = new AnimatedTile(block); break; } } }
public bool Equals(Tile compareTo) { return Block.ID == compareTo.Block.ID; }