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