1 #region Using Statements
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Content;
4 using Microsoft.Xna.Framework.Graphics;
5 using Microsoft.Xna.Framework.Input;
6 using Microsoft.Xna.Framework.GamerServices;
7 using Microsoft.Xna.Framework.Audio;
11 namespace SuperPolarity
14 using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer;
17 /// This is the main type for your game
19 public class SuperPolarity : Game
21 public GraphicsDeviceManager graphics;
22 SpriteBatch spriteBatch;
24 public static int OutlierBounds;
30 protected SoundEffect GameSong;
31 protected SoundEffectInstance GameSongHandle;
32 protected SoundEffect GameOverSound;
34 public SuperPolarity()
37 graphics = new GraphicsDeviceManager(this);
38 Components.Add(new GamerServicesComponent(this));
40 graphics.PreferMultiSampling = true;
41 graphics.PreferredBackBufferHeight = 720;
42 graphics.PreferredBackBufferWidth = 1280;
43 //graphics.ToggleFullScreen();
45 Content.RootDirectory = "Content";
46 ActorFactory.SetGame(this);
47 ParticleEffectFactory.SetGame(this);
48 ActorManager.SetGame(this);
49 ScreenManager.SetGame(this);
51 EntryScreen = (Screen)new TitleScreen(this);
55 /// Allows the game to perform any initialization it needs to before starting to run.
56 /// This is where it can query for any required services and load any non-graphic
57 /// related content. Calling base.Initialize will enumerate through any components
58 /// and initialize them as well.
60 protected override void Initialize()
64 InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
65 InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
67 EntryScreen.Initialize();
72 protected void HandleFullScreenToggle(float value)
74 graphics.ToggleFullScreen();
75 graphics.ApplyChanges();
79 /// LoadContent will be called once per game and is the place to load
80 /// all of your content.
82 protected override void LoadContent()
85 MediaPlayer.IsRepeating = true;
86 GameSong = Content.Load<SoundEffect>("Sound\\polaritytheme");
87 GameSongHandle = GameSong.CreateInstance();
88 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
90 // Create a new SpriteBatch, which can be used to draw textures.
91 spriteBatch = new SpriteBatch(GraphicsDevice);
93 ScreenManager.Push(EntryScreen);
95 Player = new Player(this);
99 /// UnloadContent will be called once per game and is the place to unload
102 protected override void UnloadContent()
104 // TODO: Unload any non ContentManager content here
108 /// Allows the game to run logic such as updating the world,
109 /// checking for collisions, gathering input, and playing audio.
111 /// <param name="gameTime">Provides a snapshot of timing values.</param>
112 protected override void Update(GameTime gameTime)
114 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
117 ScreenManager.Update(gameTime);
121 base.Update(gameTime);
125 /// This is called when the game should draw itself.
127 /// <param name="gameTime">Provides a snapshot of timing values.</param>
128 protected override void Draw(GameTime gameTime)
130 GraphicsDevice.Clear(Color.White);
134 ScreenManager.Draw(spriteBatch);
141 public void PlaySong(string songName)
143 // temp stuff before media manager is in
144 if (songName == "game")
146 GameSongHandle.Play();
150 public void GameOver()
152 var scoreScreen = new ScoreScreen(this);
153 scoreScreen.Initialize();
155 GameSongHandle.Stop();
156 GameOverSound.Play();
158 ScreenManager.Push(scoreScreen);