This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.cs
76 lines (64 loc) · 2.46 KB
/
Main.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using GP_Midterm_BubblePuzzle.Managers;
namespace GP_Midterm_BubblePuzzle {
public class Main : Game {
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private Song BGM;
private SpriteFont Arial;
public Main() {
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = (int)Singleton.Instance.Diemensions.X;
graphics.PreferredBackBufferHeight = (int)Singleton.Instance.Diemensions.Y;
graphics.SynchronizeWithVerticalRetrace = false;
IsFixedTimeStep = false;
IsMouseVisible = true;
Content.RootDirectory = "Content";
Window.Position = new Point((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / 2) - (graphics.PreferredBackBufferWidth / 2), (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / 2) - (graphics.PreferredBackBufferHeight / 2));
graphics.ApplyChanges();
}
protected override void Initialize() {
BGM = Content.Load<Song>("Audios/Spirit_of_the_Dead");
MediaPlayer.IsRepeating = true;
MediaPlayer.Volume = Singleton.Instance.BGM_MasterVolume;
MediaPlayer.Play(BGM);
base.Initialize();
}
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
ScreenManager.Instance.LoadContent(Content);
Arial = Content.Load<SpriteFont>("Fonts/Arial");
}
protected override void UnloadContent() {
ScreenManager.Instance.UnloadContent();
}
protected override void Update(GameTime gameTime) {
ScreenManager.Instance.Update(gameTime);
Singleton.Instance.IsFullScreen = graphics.IsFullScreen;
MediaPlayer.Volume = Singleton.Instance.BGM_MasterVolume;
if (Singleton.Instance.cmdExit) {
Exit();
}
if (Singleton.Instance.cmdFullScreen) {
graphics.ToggleFullScreen();
graphics.ApplyChanges();
Singleton.Instance.cmdFullScreen = false;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
ScreenManager.Instance.Draw(spriteBatch);
if (Singleton.Instance.cmdShowFPS) {
float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
FrameCounter.Instance.Update(deltaTime);
spriteBatch.DrawString(Arial, string.Format("FPS: " + FrameCounter.Instance.AverageFramesPerSecond.ToString("F")), new Vector2(1090,10), Color.Yellow);
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}