]>
Commit | Line | Data |
---|---|---|
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; | |
8 | using SuperPolarity; | |
9 | #endregion | |
10 | ||
11 | namespace SuperPolarity | |
12 | { | |
13 | ||
14 | using MediaPlayer = Microsoft.Xna.Framework.Media.MediaPlayer; | |
15 | ||
16 | /// <summary> | |
17 | /// This is the main type for your game | |
18 | /// </summary> | |
19 | public class SuperPolarity : Game | |
20 | { | |
21 | public GraphicsDeviceManager graphics; | |
22 | SpriteBatch spriteBatch; | |
23 | ||
24 | public static int OutlierBounds; | |
25 | ||
26 | public Player Player; | |
27 | ||
28 | Screen EntryScreen; | |
29 | ||
30 | protected SoundEffect GameSong; | |
31 | protected SoundEffectInstance GameSongHandle; | |
32 | protected SoundEffect GameOverSound; | |
33 | ||
34 | public SuperPolarity() | |
35 | : base() | |
36 | { | |
37 | graphics = new GraphicsDeviceManager(this); | |
38 | Components.Add(new GamerServicesComponent(this)); | |
39 | ||
40 | graphics.PreferMultiSampling = true; | |
41 | graphics.PreferredBackBufferHeight = 720; | |
42 | graphics.PreferredBackBufferWidth = 1280; | |
43 | //graphics.ToggleFullScreen(); | |
44 | ||
45 | Content.RootDirectory = "Content"; | |
46 | ActorFactory.SetGame(this); | |
47 | ParticleEffectFactory.SetGame(this); | |
48 | ActorManager.SetGame(this); | |
49 | ScreenManager.SetGame(this); | |
50 | ||
51 | EntryScreen = (Screen)new TitleScreen(this); | |
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 | { | |
62 | base.Initialize(); | |
63 | ||
64 | InputController.RegisterEventForKey("fullScreenToggle", Keys.F11); | |
65 | InputController.Bind("fullScreenToggle", HandleFullScreenToggle); | |
66 | ||
67 | EntryScreen.Initialize(); | |
68 | ||
69 | OutlierBounds = 100; | |
70 | } | |
71 | ||
72 | protected void HandleFullScreenToggle(float value) | |
73 | { | |
74 | graphics.ToggleFullScreen(); | |
75 | graphics.ApplyChanges(); | |
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 | { | |
84 | ||
85 | MediaPlayer.IsRepeating = true; | |
86 | GameSong = Content.Load<SoundEffect>("Sound\\polaritytheme"); | |
87 | GameSongHandle = GameSong.CreateInstance(); | |
88 | GameOverSound = Content.Load<SoundEffect>("Sound\\gameover"); | |
89 | ||
90 | // Create a new SpriteBatch, which can be used to draw textures. | |
91 | spriteBatch = new SpriteBatch(GraphicsDevice); | |
92 | ||
93 | ScreenManager.Push(EntryScreen); | |
94 | ||
95 | Player = new Player(this); | |
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 | ||
117 | ScreenManager.Update(gameTime); | |
118 | ||
119 | Player.Update(); | |
120 | ||
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 | { | |
130 | GraphicsDevice.Clear(Color.White); | |
131 | ||
132 | spriteBatch.Begin(); | |
133 | ||
134 | ScreenManager.Draw(spriteBatch); | |
135 | ||
136 | spriteBatch.End(); | |
137 | ||
138 | base.Draw(gameTime); | |
139 | } | |
140 | ||
141 | public void PlaySong(string songName) | |
142 | { | |
143 | // temp stuff before media manager is in | |
144 | if (songName == "game") | |
145 | { | |
146 | GameSongHandle.Play(); | |
147 | } | |
148 | } | |
149 | ||
150 | public void GameOver() | |
151 | { | |
152 | var scoreScreen = new ScoreScreen(this); | |
153 | scoreScreen.Initialize(); | |
154 | ||
155 | GameSongHandle.Stop(); | |
156 | GameOverSound.Play(); | |
157 | ScreenManager.Pop(); | |
158 | ScreenManager.Push(scoreScreen); | |
159 | } | |
160 | } | |
161 | } |