-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameWindow.cs
47 lines (39 loc) · 962 Bytes
/
GameWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
namespace CrappyGame
{
public abstract class GameWindow : Window
{
protected GameTimer Timer;
protected InputManager Input;
public GameWindow()
{
Timer = new GameTimer();
Input = new InputManager();
Input.RegisterKeyDown(System.Windows.Input.Key.Escape, (k, d) => Close());
Loaded += GameWindow_Loaded;
CompositionTarget.Rendering += CompositionTarget_Rendering;
}
private void GameWindow_Loaded(object sender, RoutedEventArgs e)
{
Timer.Reset();
}
private void CompositionTarget_Rendering(object sender, EventArgs e)
{
GameTime time = Timer.GetGameTimeSinceLastCall();
HandleInput(time);
RenderFrame(time);
}
protected virtual void HandleInput(GameTime time)
{
Input.ProcessInput(time);
}
protected virtual void RenderFrame(GameTime time)
{
}
}
}