]>
Commit | Line | Data |
---|---|---|
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; | |
10 | using Microsoft.Xna.Framework.Media; | |
11 | using Microsoft.Xna.Framework.Audio; | |
12 | using SuperPolarity; | |
13 | using Tao.Sdl; | |
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 | { | |
23 | public GraphicsDeviceManager graphics; | |
24 | SpriteBatch spriteBatch; | |
25 | ||
26 | public static int OutlierBounds; | |
27 | ||
28 | public Player Player; | |
29 | ||
30 | Screen EntryScreen; | |
31 | ||
32 | protected Song TitleSong; | |
33 | protected Song GameSong; | |
34 | protected SoundEffect GameOverSound; | |
35 | ||
36 | public SuperPolarity() | |
37 | : base() | |
38 | { | |
39 | graphics = new GraphicsDeviceManager(this); | |
40 | Components.Add(new GamerServicesComponent(this)); | |
41 | ||
42 | Content.RootDirectory = "Content"; | |
43 | ActorFactory.SetGame(this); | |
44 | ParticleEffectFactory.SetGame(this); | |
45 | ActorManager.SetGame(this); | |
46 | ScreenManager.SetGame(this); | |
47 | ||
48 | EntryScreen = (Screen)new TitleScreen(this); | |
49 | } | |
50 | ||
51 | /// <summary> | |
52 | /// Allows the game to perform any initialization it needs to before starting to run. | |
53 | /// This is where it can query for any required services and load any non-graphic | |
54 | /// related content. Calling base.Initialize will enumerate through any components | |
55 | /// and initialize them as well. | |
56 | /// </summary> | |
57 | protected override void Initialize() | |
58 | { | |
59 | base.Initialize(); | |
60 | ||
61 | graphics.PreferMultiSampling = true; | |
62 | graphics.PreferredBackBufferHeight = 720; | |
63 | graphics.PreferredBackBufferWidth = 1280; | |
64 | //graphics.ToggleFullScreen(); | |
65 | ||
66 | InputController.RegisterEventForKey("fullScreenToggle", Keys.F11); | |
67 | InputController.Bind("fullScreenToggle", HandleFullScreenToggle); | |
68 | ||
69 | EntryScreen.Initialize(); | |
70 | ||
71 | OutlierBounds = 100; | |
72 | } | |
73 | ||
74 | protected void HandleFullScreenToggle(float value) | |
75 | { | |
76 | graphics.ToggleFullScreen(); | |
77 | graphics.ApplyChanges(); | |
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 | { | |
86 | ||
87 | MediaPlayer.IsRepeating = true; | |
88 | GameSong = Content.Load<Song>("Sound\\polaritytheme.wav"); | |
89 | GameOverSound = Content.Load<SoundEffect>("Sound\\gameover"); | |
90 | ||
91 | // Create a new SpriteBatch, which can be used to draw textures. | |
92 | spriteBatch = new SpriteBatch(GraphicsDevice); | |
93 | ||
94 | ScreenManager.Push(EntryScreen); | |
95 | ||
96 | Player = new Player(this); | |
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 | ||
118 | ScreenManager.Update(gameTime); | |
119 | ||
120 | Player.Update(); | |
121 | ||
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 | { | |
131 | GraphicsDevice.Clear(Color.White); | |
132 | ||
133 | spriteBatch.Begin(); | |
134 | ||
135 | ScreenManager.Draw(spriteBatch); | |
136 | ||
137 | spriteBatch.End(); | |
138 | ||
139 | base.Draw(gameTime); | |
140 | } | |
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 | { | |
153 | var scoreScreen = new ScoreScreen(this); | |
154 | scoreScreen.Initialize(); | |
155 | ||
156 | MediaPlayer.Stop(); | |
157 | GameOverSound.Play(); | |
158 | ScreenManager.Pop(); | |
159 | ScreenManager.Push(scoreScreen); | |
160 | } | |
161 | } | |
162 | } |