From f93055315a7e1a698de4cf4428774dabfb6beb85 Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Wed, 4 May 2022 11:34:46 +0200 Subject: [PATCH] Update --- ViewsModels/GameViewModel.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ViewsModels/GameViewModel.cs b/ViewsModels/GameViewModel.cs index 5232abb..4d5aac4 100644 --- a/ViewsModels/GameViewModel.cs +++ b/ViewsModels/GameViewModel.cs @@ -2,8 +2,6 @@ using System; using System.ComponentModel; -using System.Drawing; -using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; @@ -16,7 +14,7 @@ public class GameViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler? PropertyChanged; - public static readonly Game Game = new("...", new Grid(new Color[25, 50])); + public static readonly Game Game = new("...", new Grid(new Color[20, 40])); private const int RendererHertz = 5; private const int GameRendererHertz = (1 / RendererHertz) * 1000; @@ -53,12 +51,16 @@ public class GameViewModel : INotifyPropertyChanged _writeableBitmap.Lock(); _writeableBitmap.Clear(Colors.Black); + var colorGrid = Game.Grid.CGrid; for (var x = 0; x < Game.Grid.MaxGrid.X + 1; x++) { for (var y = 0; y < Game.Grid.MaxGrid.Y + 1; y++) { - var color = Game.Grid.CGrid[x, y]; - _writeableBitmap.FillRectangle(x * Multiplier, y * Multiplier, x * Multiplier + Multiplier, y * Multiplier + Multiplier, color.ToArgb()); + if (colorGrid[x, y] == Color.Empty) continue; + + var startX = x * Multiplier; + var startY = y * Multiplier; + _writeableBitmap.FillRectangle(startX, startY, startX + Multiplier, startY + Multiplier, colorGrid[x, y].ToArgb()); } } @@ -72,10 +74,13 @@ public class GameViewModel : INotifyPropertyChanged var currentPiece = Game.CurrentTetrominoe!; if (currentPiece.Shape[x, y] == false) continue; var color = currentPiece.Color; - _writeableBitmap.FillRectangle((currentPiece.Coordinates.X + x) * Multiplier, (currentPiece.Coordinates.Y + y) * Multiplier, (currentPiece.Coordinates.X + x) * Multiplier + Multiplier, (currentPiece.Coordinates.Y + y) * Multiplier + Multiplier, color.ToArgb()); + + var startX = (currentPiece.Coordinates.X + x) * Multiplier; + var startY = (currentPiece.Coordinates.Y + y) * Multiplier; + _writeableBitmap.FillRectangle(startX, startY, startX + Multiplier, startY + Multiplier, color.ToArgb()); } } - + _writeableBitmap.Unlock(); }