-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.cs
133 lines (101 loc) · 3.98 KB
/
GameManager.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Diagnostics;
using Higurashi_Game.Entities;
using Higurashi_Game.System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Higurashi_Game;
public class GameManager : Game
{
public const int VIRTUAL_WINDOW_WIDTH = 1600;
public const int VIRTUAL_WINDOW_HEIGHT = 900;
public const int WINDOW_WIDTH = 1600;
public const int WINDOW_HEIGHT = 900;
public float scaleX;
public float scaleY;
private Matrix matrix;
private const string ASSETNAME_SPRITESHEET = "spritesheet";
private const string ASSETNAME_TEST = "test1 - Kopie";
private const string ASSETNAME_BG = "bgtest";
public const int CHARACTER_START_POS_Y = VIRTUAL_WINDOW_HEIGHT - 188;
public const int KEIICHI_START_POS_X = 1;
private Texture2D _spritesheet;
private Texture2D _test;
private Texture2D _bg;
private GameState _gameState;
private EntityManager _entityManager;
private Keiichi _keiichi;
private InputManager _inputManager;
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public GameManager()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
_graphics.PreferredBackBufferWidth = WINDOW_WIDTH;
_graphics.PreferredBackBufferHeight = WINDOW_HEIGHT;
_graphics.ApplyChanges();
scaleX = (float)GraphicsDevice.Viewport.Width / VIRTUAL_WINDOW_WIDTH;
scaleY = (float)GraphicsDevice.Viewport.Height / VIRTUAL_WINDOW_HEIGHT;
matrix = Matrix.CreateScale(scaleX, scaleY, 1.0f);
base.Initialize();
}
protected override void LoadContent()
{
Vector2 keiichiStartPos = new Vector2(KEIICHI_START_POS_X, CHARACTER_START_POS_Y);
_spriteBatch = new SpriteBatch(GraphicsDevice);
_spritesheet = Content.Load<Texture2D>(ASSETNAME_SPRITESHEET);
_test = Content.Load<Texture2D>(ASSETNAME_TEST);
_bg = Content.Load<Texture2D>(ASSETNAME_BG);
_entityManager = new EntityManager();
_gameState = GameState.Menu;
_keiichi = new Keiichi(_test , keiichiStartPos);
//_keiichi.jumpComplete += keiichi_JumpComplete;
_inputManager = new InputManager(_keiichi);
_entityManager.AddEntity(_keiichi);
}
protected override void Update(GameTime gameTime)
{
Debug.WriteLine((float)GraphicsDevice.Viewport.Width);
KeyboardState keyboard = Keyboard.GetState();
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
switch (_gameState)
{
case GameState.Menu:
_gameState = keyboard.IsKeyDown(Keys.Q) ? GameState.InGame : _gameState;
break;
case GameState.InGame:
if (keyboard.IsKeyDown(Keys.E))
_gameState = GameState.Menu;
_inputManager.ProcessControls(gameTime);
_entityManager.Update(gameTime);
break;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
switch (_gameState)
{
case GameState.Menu:
GraphicsDevice.Clear(Color.Wheat);
break;
case GameState.Transition:
break;
case GameState.InGame:
GraphicsDevice.Clear(Color.Black);
_spriteBatch.Begin(transformMatrix: matrix);
_spriteBatch.Draw(_bg, new Rectangle(0, 0, VIRTUAL_WINDOW_WIDTH, VIRTUAL_WINDOW_HEIGHT), Color.White);
_entityManager.Draw(_spriteBatch, gameTime);
_spriteBatch.End();
break;
}
base.Draw(gameTime);
}
}