1 #region Using Statements
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 Microsoft.Xna.Framework.Media;
11 using Microsoft.Xna.Framework.Audio;
16 namespace SuperPolarity
19 /// This is the main type for your game
21 public class SuperPolarity : Game
23 public GraphicsDeviceManager graphics;
24 SpriteBatch spriteBatch;
26 public static int OutlierBounds;
32 protected SoundEffect GameSong;
33 protected SoundEffectInstance GameSongHandle;
34 protected SoundEffect GameOverSound;
36 public SuperPolarity()
39 graphics = new GraphicsDeviceManager(this);
40 Components.Add(new GamerServicesComponent(this));
42 graphics.PreferMultiSampling = true;
43 graphics.PreferredBackBufferHeight = 720;
44 graphics.PreferredBackBufferWidth = 1280;
45 //graphics.ToggleFullScreen();
47 Content.RootDirectory = "Content";
48 ActorFactory.SetGame(this);
49 ParticleEffectFactory.SetGame(this);
50 ActorManager.SetGame(this);
51 ScreenManager.SetGame(this);
53 EntryScreen = (Screen)new TitleScreen(this);
57 /// Allows the game to perform any initialization it needs to before starting to run.
58 /// This is where it can query for any required services and load any non-graphic
59 /// related content. Calling base.Initialize will enumerate through any components
60 /// and initialize them as well.
62 protected override void Initialize()
66 InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
67 InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
69 EntryScreen.Initialize();
74 protected void HandleFullScreenToggle(float value)
76 graphics.ToggleFullScreen();
77 graphics.ApplyChanges();
81 /// LoadContent will be called once per game and is the place to load
82 /// all of your content.
84 protected override void LoadContent()
87 MediaPlayer.IsRepeating = true;
88 GameSong = Content.Load<SoundEffect>("Sound\\polaritytheme");
89 GameSongHandle = GameSong.CreateInstance();
90 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
92 // Create a new SpriteBatch, which can be used to draw textures.
93 spriteBatch = new SpriteBatch(GraphicsDevice);
95 ScreenManager.Push(EntryScreen);
97 Player = new Player(this);
101 /// UnloadContent will be called once per game and is the place to unload
104 protected override void UnloadContent()
106 // TODO: Unload any non ContentManager content here
110 /// Allows the game to run logic such as updating the world,
111 /// checking for collisions, gathering input, and playing audio.
113 /// <param name="gameTime">Provides a snapshot of timing values.</param>
114 protected override void Update(GameTime gameTime)
116 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
119 ScreenManager.Update(gameTime);
123 base.Update(gameTime);
127 /// This is called when the game should draw itself.
129 /// <param name="gameTime">Provides a snapshot of timing values.</param>
130 protected override void Draw(GameTime gameTime)
132 GraphicsDevice.Clear(Color.White);
136 ScreenManager.Draw(spriteBatch);
143 public void PlaySong(string songName)
145 // temp stuff before media manager is in
146 if (songName == "game")
148 GameSongHandle.Play();
152 public void GameOver()
154 var scoreScreen = new ScoreScreen(this);
155 scoreScreen.Initialize();
157 GameSongHandle.Stop();
158 GameOverSound.Play();
160 ScreenManager.Push(scoreScreen);