-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame1.cs
90 lines (71 loc) · 2.54 KB
/
Game1.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;
namespace LegendOfZelda
{
public enum Direction { down, right, up, left, upLeft, upRight, downLeft, downRight };
public class Game1 : Game
{
/* Graphics */
private GraphicsDeviceManager _graphics;
public SpriteBatch _spriteBatch { get; private set; }
/* Game State */
private GameState GameState;
/* Singleton */
private static Game1 instance;
/* Viewport */
private readonly int ViewportWidth = 1024;
private readonly int ViewportHeight = 896;
/* ini Config Reader */
public ReadConfig ReadConfig = new ReadConfig("config.ini");
/* Game Difficulty */
public float Difficulty;
public static int frameNumber { get; private set; } = 0;
private Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
public static Game1 getInstance()
{
if (instance == null)
instance = new Game1();
return instance;
}
protected override void Initialize()
{
instance = this;
SpriteFactory.getInstance();
SoundFactory.getInstance();
// Change size of viewport
_graphics.IsFullScreen = false;
_graphics.PreferredBackBufferWidth = ViewportWidth;
_graphics.PreferredBackBufferHeight = ViewportHeight;
_graphics.ApplyChanges();
if(ShaderHolder.ShadersOn) ShaderHolder.LoadShaders(Content);
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
SpriteFactory.getInstance().LoadTextures();
SoundFactory.getInstance().LoadTextures();
LevelUtilities.SetLevelLoadingValues(SpriteFactory.getInstance().scale);
Difficulty = float.Parse(ReadConfig.GameConfig["Game.Difficulty"]);
// Game state
GameState = GameState.GetInstance();
}
protected override void Update(GameTime gameTime)
{
frameNumber++;
GameState.Update(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
GameState.Draw(_spriteBatch);
base.Draw(gameTime);
}
}
}