-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame1.cs
111 lines (87 loc) · 3.95 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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using Mars;
using Mars.Primitivies;
using Mars.Components;
namespace gameExample
{
public class Game1 : Game
{
private GraphicsAdapter adapter;
private GraphicsProfile graphicsProfile;
public MarsConsole console;
public World world;
private PresentationParameters presentationParameters;
public Game1(){
this.Window.ClientSizeChanged += delegate { Resolution.WasResized = true; };
Content.RootDirectory = "Content";
Global.content = Content;
Global.graphics = new GraphicsDeviceManager(this);
IsMouseVisible = true;
}
protected override void Initialize(){
graphicsProfile = new GraphicsProfile();
presentationParameters = new PresentationParameters();
#region Resolution stuff
Resolution.Initialize(Global.graphics);
Global.graphics.IsFullScreen = false;
Global.graphics.PreferredBackBufferWidth = Resolution.GameWidth;
Global.graphics.PreferredBackBufferHeight = Resolution.GameHeight;
//TODO: add this into the engine
//============== Fulll Screen ===========
// this.Window.Position = new Point(0, 0);
// this.Window.IsBorderless = true;
// Global.graphics.PreferredBackBufferWidth = Resolution.ScreenWidth;
// Global.graphics.PreferredBackBufferHeight = Resolution.ScreenHeight;
//=========== Wide Screen ==========================
this.Window.Position = new Point((Resolution.ScreenWidth - Resolution.GameWidth) / 2, ((Resolution.ScreenHeight - Resolution.GameHeight) / 2) - 40);
this.Window.IsBorderless = false;
Global.graphics.PreferredBackBufferWidth = Resolution.GameWidth;
Global.graphics.PreferredBackBufferHeight = Resolution.GameHeight;
Global.graphics.ApplyChanges();
#endregion
adapter = new GraphicsAdapter();
Global.device = new GraphicsDevice(adapter,graphicsProfile,presentationParameters);
Global.console = new MarsConsole(5);
world = new World(this);
base.Initialize();
}
protected override void LoadContent(){
base.LoadContent();
Global.keyboard = new InputKeyboard();
Global.mouseControl = new MouseControl();
Global.spriteFont = Content.Load<SpriteFont>("font");
Global.content = this.Content;
Global.spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime){
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
Global.gameTime = gameTime;
Global.keyboard.Update();
Global.mouseControl.Update();
if(Global.keyboard.GetPress("Insert")){
Global.debugging = true;
}
if(Global.keyboard.GetPress("Home")){
Global.debugging = false;
}
Resolution.Update(this, Global.graphics);
world.Update();
Global.console.Update();
Global.keyboard.UpdateOld();
Global.mouseControl.UpdateOld();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime){
base.Draw(gameTime);
GraphicsDevice.Clear(Color.PapayaWhip);
Global.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp);
world.Draw(Vector2.Zero);
Global.console.Draw();
Global.spriteBatch.End();
}
}
}