Update
This commit is contained in:
parent
38e3b197ba
commit
f93055315a
1 changed files with 12 additions and 7 deletions
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
@ -16,7 +14,7 @@ public class GameViewModel : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
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 RendererHertz = 5;
|
||||||
private const int GameRendererHertz = (1 / RendererHertz) * 1000;
|
private const int GameRendererHertz = (1 / RendererHertz) * 1000;
|
||||||
|
@ -53,12 +51,16 @@ public class GameViewModel : INotifyPropertyChanged
|
||||||
_writeableBitmap.Lock();
|
_writeableBitmap.Lock();
|
||||||
_writeableBitmap.Clear(Colors.Black);
|
_writeableBitmap.Clear(Colors.Black);
|
||||||
|
|
||||||
|
var colorGrid = Game.Grid.CGrid;
|
||||||
for (var x = 0; x < Game.Grid.MaxGrid.X + 1; x++)
|
for (var x = 0; x < Game.Grid.MaxGrid.X + 1; x++)
|
||||||
{
|
{
|
||||||
for (var y = 0; y < Game.Grid.MaxGrid.Y + 1; y++)
|
for (var y = 0; y < Game.Grid.MaxGrid.Y + 1; y++)
|
||||||
{
|
{
|
||||||
var color = Game.Grid.CGrid[x, y];
|
if (colorGrid[x, y] == Color.Empty) continue;
|
||||||
_writeableBitmap.FillRectangle(x * Multiplier, y * Multiplier, x * Multiplier + Multiplier, y * Multiplier + Multiplier, color.ToArgb());
|
|
||||||
|
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!;
|
var currentPiece = Game.CurrentTetrominoe!;
|
||||||
if (currentPiece.Shape[x, y] == false) continue;
|
if (currentPiece.Shape[x, y] == false) continue;
|
||||||
var color = currentPiece.Color;
|
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();
|
_writeableBitmap.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue