]> git.r.bdr.sh - rbdr/super-polarity/blame - SuperPolarity/SuperPolarity.cs
Update README
[rbdr/super-polarity] / SuperPolarity / SuperPolarity.cs
CommitLineData
9ad526c0 1#region Using Statements
63a61ee2
BB
2using Microsoft.Xna.Framework;
3using Microsoft.Xna.Framework.Content;
4using Microsoft.Xna.Framework.Graphics;
5using Microsoft.Xna.Framework.Input;
63a61ee2 6using Microsoft.Xna.Framework.GamerServices;
b587e9d8 7using Microsoft.Xna.Framework.Audio;
63a61ee2
BB
8using SuperPolarity;
9#endregion
10
11namespace SuperPolarity
12{
9ad526c0
BB
13
14 using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer;
15
63a61ee2
BB
16 /// <summary>
17 /// This is the main type for your game
18 /// </summary>
19 public class SuperPolarity : Game
20 {
74c15570 21 public GraphicsDeviceManager graphics;
63a61ee2
BB
22 SpriteBatch spriteBatch;
23
38c7d3f9
BB
24 public static int OutlierBounds;
25
74c15570
BB
26 public Player Player;
27
28 Screen EntryScreen;
29
2d3615a1
BB
30 protected SoundEffect GameSong;
31 protected SoundEffectInstance GameSongHandle;
b587e9d8 32 protected SoundEffect GameOverSound;
74c15570 33
63a61ee2
BB
34 public SuperPolarity()
35 : base()
36 {
74c15570 37 graphics = new GraphicsDeviceManager(this);
bca44639
BB
38 Components.Add(new GamerServicesComponent(this));
39
2d3615a1
BB
40 graphics.PreferMultiSampling = true;
41 graphics.PreferredBackBufferHeight = 720;
42 graphics.PreferredBackBufferWidth = 1280;
9ad526c0 43 //graphics.ToggleFullScreen();
2d3615a1 44
63a61ee2 45 Content.RootDirectory = "Content";
2af83e98 46 ActorFactory.SetGame(this);
38c7d3f9
BB
47 ParticleEffectFactory.SetGame(this);
48 ActorManager.SetGame(this);
74c15570
BB
49 ScreenManager.SetGame(this);
50
b587e9d8 51 EntryScreen = (Screen)new TitleScreen(this);
63a61ee2
BB
52 }
53
54 /// <summary>
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.
59 /// </summary>
60 protected override void Initialize()
61 {
63a61ee2 62 base.Initialize();
2af83e98 63
74c15570
BB
64 InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
65 InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
38c7d3f9 66
74c15570 67 EntryScreen.Initialize();
2af83e98 68
74c15570
BB
69 OutlierBounds = 100;
70 }
71
72 protected void HandleFullScreenToggle(float value)
73 {
74 graphics.ToggleFullScreen();
75 graphics.ApplyChanges();
63a61ee2
BB
76 }
77
78 /// <summary>
79 /// LoadContent will be called once per game and is the place to load
80 /// all of your content.
81 /// </summary>
82 protected override void LoadContent()
83 {
b587e9d8
BB
84
85 MediaPlayer.IsRepeating = true;
2d3615a1
BB
86 GameSong = Content.Load<SoundEffect>("Sound\\polaritytheme");
87 GameSongHandle = GameSong.CreateInstance();
b587e9d8
BB
88 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
89
63a61ee2
BB
90 // Create a new SpriteBatch, which can be used to draw textures.
91 spriteBatch = new SpriteBatch(GraphicsDevice);
92
b587e9d8 93 ScreenManager.Push(EntryScreen);
63a61ee2 94
b587e9d8 95 Player = new Player(this);
63a61ee2
BB
96 }
97
98 /// <summary>
99 /// UnloadContent will be called once per game and is the place to unload
100 /// all content.
101 /// </summary>
102 protected override void UnloadContent()
103 {
104 // TODO: Unload any non ContentManager content here
105 }
106
107 /// <summary>
108 /// Allows the game to run logic such as updating the world,
109 /// checking for collisions, gathering input, and playing audio.
110 /// </summary>
111 /// <param name="gameTime">Provides a snapshot of timing values.</param>
112 protected override void Update(GameTime gameTime)
113 {
114 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
115 Exit();
116
74c15570 117 ScreenManager.Update(gameTime);
95d7601b 118
b587e9d8
BB
119 Player.Update();
120
63a61ee2
BB
121 base.Update(gameTime);
122 }
123
124 /// <summary>
125 /// This is called when the game should draw itself.
126 /// </summary>
127 /// <param name="gameTime">Provides a snapshot of timing values.</param>
128 protected override void Draw(GameTime gameTime)
129 {
95d7601b 130 GraphicsDevice.Clear(Color.White);
63a61ee2
BB
131
132 spriteBatch.Begin();
133
74c15570
BB
134 ScreenManager.Draw(spriteBatch);
135
63a61ee2
BB
136 spriteBatch.End();
137
138 base.Draw(gameTime);
139 }
b587e9d8
BB
140
141 public void PlaySong(string songName)
142 {
143 // temp stuff before media manager is in
144 if (songName == "game")
145 {
2d3615a1 146 GameSongHandle.Play();
b587e9d8
BB
147 }
148 }
149
150 public void GameOver()
151 {
bca44639
BB
152 var scoreScreen = new ScoreScreen(this);
153 scoreScreen.Initialize();
154
2d3615a1 155 GameSongHandle.Stop();
b587e9d8
BB
156 GameOverSound.Play();
157 ScreenManager.Pop();
bca44639 158 ScreenManager.Push(scoreScreen);
b587e9d8 159 }
63a61ee2
BB
160 }
161}