-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game1.cs
145 lines (117 loc) · 4.59 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Colton K
// Main Class for Dungeon Game
using Dungeon;
using Dungeon.Levels;
using Dungeon.Utilities;
using DungeonGame.Entities;
using DungeonGame.Entities.Enemies;
using DungeonGame.Entities.Player;
using DungeonGame.Item;
using DungeonGame.Levels;
using DungeonGame.UI;
using DungeonGame.UI.Menus;
using DungeonGame.UI.Widgets;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Diagnostics;
namespace DungeonGame
{
enum EditorMode
{
TILES = 0,
TILE_ENTITIES = 1,
ENTITIES = 2
}
public class Game1 : GenericGame
{
private static Game1 instance;
private WorldGenerator worldGenerator;
public ClientPlayer player;
private TitleMenu titleMenu;
private PauseMenu pauseMenu;
private IngameGui ingameGui;
public static Effect _blur;
public Game1() : base()
{
Game1.instance = this;
}
public Gui getCurrentScreen() => this.currentScreen;
public void setCurrentScreen(Gui screen) => this.currentScreen = screen;
protected override void LoadAssets()
{
base.LoadAssets();
this.currentWorld = new DungeonGame.Levels.World(this, "dev");
this.player = new ClientPlayer(this, this.currentWorld, this.Content.Load<Texture2D>("Textures/player"), new Vector3(20f, 50f, 0.0f));
this.pauseMenu = new PauseMenu(this, null, this.font);
this.pauseMenu.Load(this.contentManager);
this.ingameGui = new IngameGui(this, null, this.font, this.player);
this.ingameGui.Load(this.contentManager);
this.currentWorld.addEntity(new EntityBat(this.currentWorld, new Vector3(35f, 40f, 0.0f)));
this.currentWorld.addPlayer(this.player);
this.mainCamera = new Camera(this, this.currentWorld, this.graphics, this.player);
this.titleMenu = new TitleMenu(this, null, this.font);
this.titleMenu.Load(this.contentManager);
this.currentScreen = titleMenu;
}
protected override void Update(GameTime gameTime)
{
this.mouseHelper.Update();
if (this.currentScreen != null)
{
this.currentScreen.Update(gameTime, this.mouseHelper);
}
elapsed_delta += gameTime.ElapsedGameTime.Milliseconds;
if (elapsed_delta >= millisecond_interval)
{
FixedUpdateGame(gameTime);
elapsed_delta = 0.0f;
}
this.UpdateGame(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
this.GraphicsDevice.Clear(Color.CornflowerBlue);
if (this.currentScreen != null)
{
if (this.currentScreen.isIngame)
this.RenderGame(gameTime);
this.spriteBatch.Begin(blendState: BlendState.AlphaBlend, samplerState: SamplerState.PointClamp, depthStencilState: DepthStencilState.None, rasterizerState: RasterizerState.CullCounterClockwise);
this.currentScreen.Draw(this.spriteBatch, this.font);
this.spriteBatch.End();
}
else
this.RenderGame(gameTime);
this.mouseHelper.Draw(this.spriteBatch);
base.Draw(gameTime);
}
public void UpdateGame(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
this.currentScreen = this.pauseMenu;
this.mainCamera.Update(this.graphics, gameTime);
this.currentWorld.Update(gameTime);
this.ingameGui.Update(gameTime, this.mouseHelper);
}
public void FixedUpdateGame(GameTime gameTime)
{
this.currentWorld.FixedUpdate(gameTime);
}
/**
* Draws the game.
*/
public void RenderGame(GameTime gameTime)
{
// Render World.
this.currentWorld.Draw(this.spriteBatch, this.mainCamera);
this.spriteBatch.Begin(blendState: BlendState.AlphaBlend, samplerState: SamplerState.PointClamp, depthStencilState: DepthStencilState.None, rasterizerState: RasterizerState.CullCounterClockwise);
this.ingameGui.Draw(this.spriteBatch, this.font);
this.spriteBatch.End();
}
public void exit() => this.Exit();
public static Game1 getInstance() => Game1.instance;
}
}