Archived
1
0
Fork 0
This commit is contained in:
Ziedelth 2022-05-04 11:34:46 +02:00
parent 38e3b197ba
commit f93055315a

View file

@ -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,7 +74,10 @@ 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());
}
}