Add game system
This commit is contained in:
parent
427986f599
commit
d26fa699e5
3 changed files with 58 additions and 2 deletions
|
@ -15,4 +15,8 @@
|
||||||
</Resource>
|
</Resource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="WriteableBitmapEx" Version="1.6.8" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using Tetris.ViewsModels;
|
||||||
|
|
||||||
namespace Tetris.Views;
|
namespace Tetris.Views;
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ public partial class GameWindow : Window
|
||||||
{
|
{
|
||||||
AttachConsole(-1);
|
AttachConsole(-1);
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
// new GameManager((int)Width, (int)Height, ImageControl);
|
new GameModel((int)Width, (int)Height, ImageControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
[DllImport("kernel32.dll")]
|
||||||
|
|
51
ViewsModels/GameModel.cs
Normal file
51
ViewsModels/GameModel.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
|
||||||
|
namespace Tetris.ViewsModels;
|
||||||
|
|
||||||
|
public class GameModel
|
||||||
|
{
|
||||||
|
private const int RendererHertz = 5;
|
||||||
|
private const int GameRendererHertz = (1 / RendererHertz) * 1000;
|
||||||
|
private readonly WriteableBitmap _writeableBitmap;
|
||||||
|
|
||||||
|
public GameModel(int width, int height, Image image)
|
||||||
|
{
|
||||||
|
var random = new Random();
|
||||||
|
|
||||||
|
_writeableBitmap = BitmapFactory.New(width, height);
|
||||||
|
image.Source = _writeableBitmap;
|
||||||
|
|
||||||
|
var dispatcherRenderTimer = new DispatcherTimer
|
||||||
|
{
|
||||||
|
Interval = new TimeSpan(0, 0, 0, 0, GameRendererHertz)
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatcherRenderTimer.Tick += Render;
|
||||||
|
dispatcherRenderTimer.Start();
|
||||||
|
|
||||||
|
var dispatcherUpdateTimer = new DispatcherTimer
|
||||||
|
{
|
||||||
|
Interval = new TimeSpan(0, 0, 0, 0, 25)
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatcherUpdateTimer.Tick += Update;
|
||||||
|
dispatcherUpdateTimer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Render(object? sender, EventArgs eventArgs)
|
||||||
|
{
|
||||||
|
_writeableBitmap.Lock();
|
||||||
|
_writeableBitmap.Clear(Colors.Black);
|
||||||
|
|
||||||
|
_writeableBitmap.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update(object? sender, EventArgs eventArgs)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue