-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame1.cs
More file actions
100 lines (81 loc) · 2.91 KB
/
Game1.cs
File metadata and controls
100 lines (81 loc) · 2.91 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
using EndlessFight.GameStates;
using EndlessFight.Models;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using static EndlessFight.Resources;
namespace EndlessFight
{
public class Game1 : Game
{
private State menuState;
private State gameState;
#region Window Size
public const int windowWidth = 750;
public const int windowHeight = 900;
#endregion
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private Resources gameResources;
#region State
private static State currentState;
#endregion
#region Background
private Background currentBackground;
#endregion
public Game1()
{
graphics = new GraphicsDeviceManager(this);
gameResources = new(Content);
Content.RootDirectory = "Content";
IsMouseVisible = true;
Globals.MainGame = this;
menuState = new MenuState(this, Content, graphics);
gameState = new GameState(this, Content, graphics);
}
protected override void Initialize()
{
graphics.PreferredBackBufferWidth = 750;
graphics.PreferredBackBufferHeight = 900;
graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
gameResources.InitializeResources();
currentBackground = new Background(BackgroundTexture, 1f);
currentState = menuState;
currentState.LoadContent();
}
protected override void Update(GameTime gameTime)
{
Globals.Update(gameTime);
if (!GameState.IsPaused && !GameState.IsGameOver)
currentBackground.Update();
currentState.Update(gameTime);
Globals.StartGamePulsation.Update(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
spriteBatch.Begin(sortMode: SpriteSortMode.Immediate, samplerState: SamplerState.PointClamp);
currentBackground.Draw(spriteBatch, graphics.GraphicsDevice);
//if (GameState.IsPaused)
//{
// spriteBatch.Draw(BackgroundTexture, new Rectangle(0, 0, windowWidth, windowHeight),
// Color.FromNonPremultiplied(0, 0, 0, 185));
//}
currentState.Draw(gameTime, spriteBatch);
Globals.StartGamePulsation.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
public void ChangeState()
{
currentState.OnExit();
if (currentState is MenuState) currentState = gameState;
else currentState = menuState;
currentState.LoadContent();
}
}
}