-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame1.cs
More file actions
101 lines (78 loc) · 3.04 KB
/
Game1.cs
File metadata and controls
101 lines (78 loc) · 3.04 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace ShogiClient
{
/// <summary>
/// Manages the current screen, states, rendering and other things.
/// </summary>
public class Game1 : Game
{
public const bool DEBUG_PLAYERONE = false;
public const bool DEBUG_DISPLAY = false;
public Vector2 WindowSize => Window.ClientBounds.Size.ToVector2();
public Screen CurrentScreen { get; private set; }
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private GameResources resources = new GameResources();
private MouseState prevMouseState = new MouseState();
private KeyboardState prevKeyboardState = new KeyboardState();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
Window.AllowUserResizing = false;
}
public void SetCurrentScreen(Screen screen, bool stopMusic = true)
{
CurrentScreen = screen;
if (stopMusic)
MediaPlayer.Stop();
CurrentScreen.Initialize(resources);
Console.WriteLine($"Loaded Screen {screen.GetType().Name}");
}
protected override void Initialize()
{
graphics.PreferredBackBufferWidth = 1366;
graphics.PreferredBackBufferHeight = 768;
graphics.ApplyChanges();
MediaPlayer.Volume = 0.05f;
SetCurrentScreen(new MainMenuScreen(this));
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
resources.LoadContent(Content);
base.LoadContent();
}
protected override void Update(GameTime gameTime)
{
var keyboardState = Keyboard.GetState();
var mouseState = Mouse.GetState();
CurrentScreen.Update(gameTime, keyboardState, prevKeyboardState, mouseState, prevMouseState);
prevMouseState = mouseState;
prevKeyboardState = keyboardState;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, null);
CurrentScreen.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
public Texture2D Screenshot()
{
var renderTarget = new RenderTarget2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
GraphicsDevice.SetRenderTarget(renderTarget);
Draw(new GameTime());
GraphicsDevice.SetRenderTarget(null);
return renderTarget;
}
}
}