-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cs
More file actions
76 lines (64 loc) · 2.1 KB
/
Controller.cs
File metadata and controls
76 lines (64 loc) · 2.1 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Chip8.Engine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace Chip8
{
/// <summary>
/// Main class that handles updating everything else.
/// </summary>
public class Controller : Game
{
GraphicsDeviceManager graphics;
public static Controller Instance;
private CPU cpu = new CPU("Roms/Lunar Lander.ch8");
private const int scale = 10;
public Controller()
{
Instance = this;
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 64 * scale;
graphics.PreferredBackBufferHeight = 32 * scale;
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
Render.Initialize(graphics.GraphicsDevice);
MouseInput.Initialize();
KeyboardInput.Initialize();
base.Initialize();
Console.WriteLine("engine initialized");
cpu.Initialize();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
cpu.Cycle();
MouseInput.Update();
KeyboardInput.Update();
}
protected override void Draw(GameTime gameTime)
{
if (!cpu.DrawFlag)
return;
GraphicsDevice.Clear(Color.Black);
Render.Begin();
for (int x = 0; x < 64; x++)
{
for (int y = 0; y < 32; y++)
{
if (cpu.Get(x, y))
{
Render.Rect(new Vector2(x * scale, y * scale), scale, scale, Color.White);
}
}
}
Render.End();
base.Draw(gameTime);
}
}
}