-
Notifications
You must be signed in to change notification settings - Fork 1
/
Global.cs
90 lines (79 loc) · 2.89 KB
/
Global.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
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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using ThreadingInCsharp.States;
namespace ThreadingInCsharp
{
public class Global : Microsoft.Xna.Framework.Game
{
public Vector2 resize = new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
public InventoryState inventory;
public ShopState shop;
public MenuState menu;
public SettingState setting;
public GameState Game;
MouseState mouseState;
private State currentState;
private State nextState;
public void ChangeState(State state)
{
nextState = state;
}
public Global()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
mouseState = Mouse.GetState();
inventory = new InventoryState(this, graphics.GraphicsDevice, Content);
shop = new ShopState(this, graphics.GraphicsDevice, Content, inventory);
menu = new MenuState(this, graphics.GraphicsDevice, Content);
setting = new SettingState(this, graphics.GraphicsDevice, Content);
Game = new GameState(this, graphics.GraphicsDevice, Content, inventory, mouseState, shop);
IsMouseVisible = true;
IsFixedTimeStep = true;
TargetElapsedTime = TimeSpan.FromSeconds(1d / 60d);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
currentState = menu;
}
void _ChangeState(GameTime gameTime)
{
if (nextState != null)
{
currentState = nextState;
nextState = null;
}
currentState.Update(gameTime);
currentState.PostUpdate(gameTime);
base.Update(gameTime);
}
public void _Resize()
{
//makes the game fullscree and the mouse responsive
graphics.IsFullScreen = true;
graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
graphics.ApplyChanges();
}
protected override void Update(GameTime gameTime)
{
IsFixedTimeStep = false;
_ChangeState(gameTime);
_Resize();
}
protected override void Draw(GameTime gameTime)
{
currentState.Draw(gameTime, spriteBatch);
base.Draw(gameTime);
}
}
}