public void SetTile(int x, int y, Tiles.Tile tile) { if (x >= 0 && y >= 0 && x < Size.X && y < Size.Y) { TileMap[x, y] = tile; } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); Position2 screenTileCount = screenSize.Map(i => i / tileSize); for (int x = Math.Max(0, (int)Math.Floor(player.Position.X - screenTileCount.X / 2)); x < Math.Min(map.Size.X, (int)Math.Ceiling(player.Position.X + screenTileCount.X / 2) + 1); x++) { for (int y = Math.Max(0, (int)Math.Floor(player.Position.Y - screenTileCount.Y / 2)); y < Math.Min(map.Size.Y, (int)Math.Ceiling(player.Position.Y + screenTileCount.Y / 2) + 1); y++) { Tiles.Tile tile = map.TileMap[x, y]; if (tile != null) { spriteBatch.Draw( nullTexture, new Rectangle((int)((x - player.Position.X - 0.5f) * tileSize) + screenSize.X / 2, (int)((y - player.Position.Y - 0.5f) * tileSize) + screenSize.Y / 2, tileSize, tileSize), tile.Color ); } } } spriteBatch.Draw(nullTexture, new Rectangle((screenSize.X - (int)(player.Size.X * tileSize)) / 2, (screenSize.Y - (int)(player.Size.X * tileSize)) / 2, (int)(player.Size.X * tileSize), (int)(player.Size.Y * tileSize)), Color.GreenYellow); //Console.WriteLine(player.Position); //DEBUG spriteBatch.Draw(nullTexture, new Rectangle(screenSize.X / 2, screenSize.Y / 2, 2, 2), Color.LimeGreen); spriteBatch.End(); base.Draw(gameTime); }
public void SetTile(Position2 postion, Tiles.Tile tile) { SetTile(postion.X, postion.Y, tile); }
public bool TryGetTile(Position2 postion, out Tiles.Tile tile) { return(TryGetTile(postion.X, postion.Y, out tile)); }
public bool TryGetTile(int x, int y, out Tiles.Tile tile) { tile = GetTile(x, y); return(tile != null); }
public Map(Position2 size) { TileMap = new Tiles.Tile[size.X, size.Y]; Entities = new List <Entities.Entity>(); }