diff --git a/ThemeParkClicker/GameImpl.cs b/ThemeParkClicker/GameImpl.cs index a13f2d0..c00c546 100644 --- a/ThemeParkClicker/GameImpl.cs +++ b/ThemeParkClicker/GameImpl.cs @@ -26,10 +26,10 @@ namespace ThemeParkClicker { protected override void LoadContent() { base.LoadContent(); - + if (!SaveHandler.Load(this)) this.Map = new ParkMap(10, 10); - + this.Ui = new Ui(this.UiSystem); this.Camera = new Camera(this.GraphicsDevice) { Scale = 5, @@ -67,7 +67,7 @@ namespace ThemeParkClicker { this.GraphicsDevice.Clear(Color.Black); if (this.DrawMap) { this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, transformMatrix: this.Camera.ViewMatrix); - this.Map.Draw(gameTime, this.SpriteBatch, Vector2.Zero, 1, 1); + this.Map.Draw(gameTime, this.SpriteBatch, Vector2.Zero, 1, 1, true, this.Camera.GetVisibleRectangle()); this.SpriteBatch.End(); } base.DoDraw(gameTime); diff --git a/ThemeParkClicker/ParkMap.cs b/ThemeParkClicker/ParkMap.cs index 4d34bf1..a5b52a6 100644 --- a/ThemeParkClicker/ParkMap.cs +++ b/ThemeParkClicker/ParkMap.cs @@ -105,11 +105,16 @@ namespace ThemeParkClicker { } } - public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, int additionalRadius = AdditionalRadius) { + public void Draw(GameTime time, SpriteBatch batch, Vector2 position, float scale, float alpha, bool showSurroundings, RectangleF visibleArea) { var tileSize = Attraction.TileSize * scale; // draw ground - for (var x = -additionalRadius; x < this.Width + additionalRadius; x++) { - for (var y = -additionalRadius; y < this.Height + additionalRadius; y++) { + var additionalRadius = showSurroundings ? AdditionalRadius : 0; + var minX = Math.Max(-additionalRadius, visibleArea.Left / tileSize.X).Floor(); + var minY = Math.Max(-additionalRadius, visibleArea.Top / tileSize.Y).Floor(); + var maxX = Math.Min(this.Width + additionalRadius, visibleArea.Right / tileSize.X).Ceil(); + var maxY = Math.Min(this.Height + additionalRadius, visibleArea.Bottom / tileSize.Y).Ceil(); + for (var x = minX; x < maxX; x++) { + for (var y = minY; y < maxY; y++) { var pos = new Vector2(x, y); var drawPos = position + pos * tileSize; batch.Draw(TilesTexture[0, 0], drawPos, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); diff --git a/ThemeParkClicker/ThemeParkClicker.csproj b/ThemeParkClicker/ThemeParkClicker.csproj index 98497eb..00997ad 100644 --- a/ThemeParkClicker/ThemeParkClicker.csproj +++ b/ThemeParkClicker/ThemeParkClicker.csproj @@ -6,7 +6,7 @@ - + all diff --git a/ThemeParkClicker/Ui.cs b/ThemeParkClicker/Ui.cs index a2b5691..b44c190 100644 --- a/ThemeParkClicker/Ui.cs +++ b/ThemeParkClicker/Ui.cs @@ -83,7 +83,7 @@ namespace ThemeParkClicker { var (scaleX, scaleY) = e.DisplayArea.Size / mapSize; var scale = Math.Min(scaleX, scaleY); var pos = e.DisplayArea.Location + (e.DisplayArea.Size - mapSize * scale) / 2; - map.Draw(time, batch, pos, scale, alpha, 0); + map.Draw(time, batch, pos, scale, alpha, false, new RectangleF(Vector2.Zero, mapSize * scale)); }, OnPressed = e => { var map = GameImpl.Instance.Map;