forked from Memorix101/MonoGame_Platformer_Editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame1.cs
143 lines (109 loc) · 4.18 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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using FarseerPhysics.Dynamics;
using FarseerPhysics;
using System;
namespace RogueLikePlatfromer
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
public static World world { get; private set; }
//public static DebugViewXNA DebugView { get; private set; }
public static PhysicsDebugCam DebugCam { get; private set; }
public static Camera2D camera { get; private set; }
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Editor editor;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Setup.Init(Content, graphics);
Screen.resolution(800, 600);
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
ControlInput.keyState = Keyboard.GetState();
camera = new Camera2D();
DebugCam = new PhysicsDebugCam();
PhysicLoad();
editor = new Editor();
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
// if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
// Exit();
ControlInput.Update(Keyboard.GetState());
Menu.Update();
editor.Update();
if (Menu.gameState == GameState.Play)
{
world.Step(Math.Min((float)gameTime.ElapsedGameTime.TotalSeconds, (1f / 30f)));
camera.Update();
Scene.Update(gameTime);
}
base.Update(gameTime);
}
private void PhysicLoad()
{
if (world == null)
{
// Farseer expects objects to be scaled to MKS (meters, kilos, seconds)
ConvertUnits.SetDisplayUnitToSimUnitRatio(64f); // 1 meters equals 64 pixels here
//Create a world with gravity.
world = new World(new Vector2(0, 9.82f));
}
else
{
world.Clear();
}
}
//void DebugDraw()
//{
// Matrix view2 = Matrix.CreateScale(32); //default 32
// view2 *= Game1.DebugCam.view;
// // debugActive = true;
// DebugView = new DebugViewXNA(Game1.world);
// // DebugView.AppendFlags(FarseerPhysics.DebugViewFlags.DebugPanel);
// DebugView.DefaultShapeColor = Color.Red;
// DebugView.SleepingShapeColor = Color.Green;
// DebugView.StaticShapeColor = Color.Violet;
// DebugView.LoadContent(Setup.graphics.GraphicsDevice, Setup.ContentDevice);
// DebugView.RenderDebugData(ref Game1.DebugCam.projection, ref view2);
//}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.TransparentBlack);
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);
//Scene.Sky(spriteBatch);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, camera.view);
Scene.Draw(spriteBatch);
editor.Draw(spriteBatch);
spriteBatch.End();
//#if DEBUG
// DebugDraw();
//#endif
//UI & HUD stuff here
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);
Menu.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
}