]> git.r.bdr.sh - rbdr/super-polarity/blob - Super Polarity/SuperPolarity.cs
6689167f16aed7939c044b54e4fffdcc08cf1d7a
[rbdr/super-polarity] / Super Polarity / SuperPolarity.cs
1 #region Using Statements
2 using System;
3 using System.Collections.Generic;
4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Content;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Input;
8 using Microsoft.Xna.Framework.Storage;
9 using Microsoft.Xna.Framework.GamerServices;
10 using SuperPolarity;
11 #endregion
12
13 namespace SuperPolarity
14 {
15 /// <summary>
16 /// This is the main type for your game
17 /// </summary>
18 public class SuperPolarity : Game
19 {
20 public GraphicsDeviceManager graphics;
21 SpriteBatch spriteBatch;
22
23 public static int OutlierBounds;
24
25 public Player Player;
26
27 Screen EntryScreen;
28
29 SpriteFont DebugFont;
30
31 public SuperPolarity()
32 : base()
33 {
34 graphics = new GraphicsDeviceManager(this);
35 graphics.PreferMultiSampling = true;
36 graphics.PreferredBackBufferWidth = 1280;
37 graphics.PreferredBackBufferHeight = 720;
38 graphics.ToggleFullScreen();
39
40 Content.RootDirectory = "Content";
41 ActorFactory.SetGame(this);
42 ParticleEffectFactory.SetGame(this);
43 ActorManager.SetGame(this);
44 ScreenManager.SetGame(this);
45
46 EntryScreen = (Screen)new GameScreen(this);
47 }
48
49 /// <summary>
50 /// Allows the game to perform any initialization it needs to before starting to run.
51 /// This is where it can query for any required services and load any non-graphic
52 /// related content. Calling base.Initialize will enumerate through any components
53 /// and initialize them as well.
54 /// </summary>
55 protected override void Initialize()
56 {
57 base.Initialize();
58
59 InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
60 InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
61
62 EntryScreen.Initialize();
63 ScreenManager.Push(EntryScreen);
64
65 OutlierBounds = 100;
66 }
67
68 protected void HandleFullScreenToggle(float value)
69 {
70 graphics.ToggleFullScreen();
71 graphics.ApplyChanges();
72 }
73
74 /// <summary>
75 /// LoadContent will be called once per game and is the place to load
76 /// all of your content.
77 /// </summary>
78 protected override void LoadContent()
79 {
80 // Create a new SpriteBatch, which can be used to draw textures.
81 spriteBatch = new SpriteBatch(GraphicsDevice);
82
83 EntryScreen.LoadContent();
84
85 Player = new Player();
86 DebugFont = Content.Load<SpriteFont>("Fonts\\SegoeUIMono14");
87 }
88
89 /// <summary>
90 /// UnloadContent will be called once per game and is the place to unload
91 /// all content.
92 /// </summary>
93 protected override void UnloadContent()
94 {
95 // TODO: Unload any non ContentManager content here
96 }
97
98 /// <summary>
99 /// Allows the game to run logic such as updating the world,
100 /// checking for collisions, gathering input, and playing audio.
101 /// </summary>
102 /// <param name="gameTime">Provides a snapshot of timing values.</param>
103 protected override void Update(GameTime gameTime)
104 {
105 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
106 Exit();
107
108 ScreenManager.Update(gameTime);
109
110 base.Update(gameTime);
111 }
112
113 /// <summary>
114 /// This is called when the game should draw itself.
115 /// </summary>
116 /// <param name="gameTime">Provides a snapshot of timing values.</param>
117 protected override void Draw(GameTime gameTime)
118 {
119 GraphicsDevice.Clear(Color.White);
120
121 spriteBatch.Begin();
122
123 ScreenManager.Draw(spriteBatch);
124
125 spriteBatch.DrawString(DebugFont, "Score: " + Player.Score.ToString(), new Vector2(10, 10), Color.LightGray);
126 spriteBatch.DrawString(DebugFont, "Multiplier: " + Player.Multiplier.ToString(), new Vector2(10, 30), Color.LightGray);
127 spriteBatch.DrawString(DebugFont, "Lives: " + Player.Lives.ToString(), new Vector2(10, 50), Color.LightGray);
128
129 spriteBatch.End();
130
131 base.Draw(gameTime);
132 }
133 }
134 }