/// <summary> /// Returns the X's and Y's to draw. Min and Max. /// </summary> /// <param name="spriteBatch"></param> /// <param name="cameraPosition"></param> /// <param name="Tile"></param> /// <returns></returns> private Boundaries GetDrawTiles(SpriteBatch spriteBatch, Vector2 cameraPosition, float TileSize, float zoom, PlanetLevel level) { TileSize = ConvertUnits.ToDisplayUnits(TileSize); // Tiles need to be resized depending upon zoom level. Performance optimization float ZoomedTile = TileSize * zoom; // Everything is relative to the ship Vector2 TileShipIsOver = new Vector2( // Ceiling indicates the max. A few pixels offscreen is better than black bar! (float)Math.Floor(cameraPosition.X / TileSize), (float)Math.Floor(cameraPosition.Y / TileSize)); float width, height; // # of tiles across screen width = (float)Math.Ceiling(spriteBatch.GraphicsDevice.Viewport.Width / ZoomedTile); height = (float)Math.Ceiling(spriteBatch.GraphicsDevice.Viewport.Height / ZoomedTile); // Define boundaries for drawing, this is hackish still. Boundaries boundaries = new Boundaries(); boundaries.Left = (int)(TileShipIsOver.X - Math.Floor(width / 2f)) - 1; // Left boundaries.Right = (int)(TileShipIsOver.X + Math.Ceiling(width / 2f)) + 3; // Right boundaries.Top = (int)(TileShipIsOver.Y - Math.Floor(height / 2f)) - 1; // Top boundaries.Bottom = (int)(TileShipIsOver.Y + Math.Ceiling(height / 2f)) + 4; // Bottom return(boundaries); }
public Vector2 GetMiddlePosition(PlanetLevel l) { return(new Vector2(((l.xSize * _tileSize) / 2), // Start in Middle ((l.ySize * _tileSize) / 2))); }
public Vector2 SetToMiddle(PlanetLevel l) { return(new Vector2(((l.xSize * _wallWidth) / 2), // Start in Middle ((l.ySize * _wallHeight) / 2))); }
public virtual void Draw(SpriteBatch spriteBatch, Camera2D layoutCamera, float TileSize, PlanetLevel level) { drawArea = GetDrawTiles(spriteBatch, layoutCamera.Pos, TileSize, layoutCamera.Zoom, level); // Get variables from Vector Array right = (int)drawArea.Right; left = (int)drawArea.Left; top = (int)drawArea.Top; bottom = (int)drawArea.Bottom; for (int y = top; y <= bottom; y++) { for (int x = left; x <= right; x++) { if (x < 0 || x > level.PlanetMap.GetLength(0) - 1 || y < 0 || y > level.PlanetMap.GetLength(1) - 1) // Draw into the infinite distance. { DrawTile(spriteBatch, new Tile { position = new Vector2(x * TileSize, y * TileSize), type = TileTypes.Wall }); continue; } DrawTile(spriteBatch, level.PlanetMap[x, y]); } } }