protected override void Draw(SpriteBatch spriteBatch) { if (!Context.IsPlayerFree) { return; } // get on-screen tiles IEnumerable <Vector2> visibleTiles = TileHelper.GetTiles( x: Game1.viewport.X / Game1.tileSize, y: Game1.viewport.Y / Game1.tileSize, width: (int)(Game1.viewport.Width / (decimal)Game1.tileSize) + 2, // extend off-screen slightly to avoid overlay edges being visible height: (int)(Game1.viewport.Height / (decimal)Game1.tileSize) + 2 ); // draw each tile foreach (Vector2 tile in visibleTiles) { // get tile's screen coordinates float screenX = tile.X * Game1.tileSize - Game1.viewport.X; float screenY = tile.Y * Game1.tileSize - Game1.viewport.Y; int tileSize = Game1.tileSize; // get machine group this.GroupTiles.TryGetValue(tile, out MachineGroup group); bool isGrouped = group != null; bool isActive = isGrouped && group.HasInternalAutomation; // draw background { Color color = Color.Black * 0.5f; if (isActive) { color = Color.Green * 0.2f; } else if (isGrouped) { color = Color.Red * 0.2f; } spriteBatch.DrawLine(screenX + this.TileGap, screenY + this.TileGap, new Vector2(tileSize - this.TileGap * 2, tileSize - this.TileGap * 2), color); } // draw group edge borders if (group != null) { this.DrawEdgeBorders(spriteBatch, group, tile, group.HasInternalAutomation ? Color.Green : Color.Red); } } // draw cursor this.DrawCursor(); }
/// <summary>Get the tile coordinates in the tile area.</summary> /// <param name="area">The tile area to search.</param> public static IEnumerable <Vector2> GetTiles(this Rectangle area) { return(TileHelper.GetTiles(area.X, area.Y, area.Width, area.Height)); }
/********* ** Public methods *********/ /// <summary>Get the tile coordinates in the game location.</summary> /// <param name="location">The game location to search.</param> public static IEnumerable <Vector2> GetTiles(this GameLocation location) { Layer layer = location.Map.Layers[0]; return(TileHelper.GetTiles(0, 0, layer.LayerWidth, layer.LayerHeight)); }