]> git.r.bdr.sh - rbdr/super-polarity/blob - SuperPolarity/SuperPolarity.cs
7fa387cb3710926215431e70a772d15959fc801e
[rbdr/super-polarity] / SuperPolarity / SuperPolarity.cs
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 SoundEffect GameSong;
33 protected SoundEffectInstance GameSongHandle;
34 protected SoundEffect GameOverSound;
35
36 public SuperPolarity()
37 : base()
38 {
39 graphics = new GraphicsDeviceManager(this);
40 Components.Add(new GamerServicesComponent(this));
41
42 graphics.PreferMultiSampling = true;
43 graphics.PreferredBackBufferHeight = 720;
44 graphics.PreferredBackBufferWidth = 1280;
45 //graphics.ToggleFullScreen();
46
47 Content.RootDirectory = "Content";
48 ActorFactory.SetGame(this);
49 ParticleEffectFactory.SetGame(this);
50 ActorManager.SetGame(this);
51 ScreenManager.SetGame(this);
52
53 EntryScreen = (Screen)new TitleScreen(this);
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 {
64 base.Initialize();
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<SoundEffect>("Sound\\polaritytheme");
89 GameSongHandle = GameSong.CreateInstance();
90 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
91
92 // Create a new SpriteBatch, which can be used to draw textures.
93 spriteBatch = new SpriteBatch(GraphicsDevice);
94
95 ScreenManager.Push(EntryScreen);
96
97 Player = new Player(this);
98 }
99
100 /// <summary>
101 /// UnloadContent will be called once per game and is the place to unload
102 /// all content.
103 /// </summary>
104 protected override void UnloadContent()
105 {
106 // TODO: Unload any non ContentManager content here
107 }
108
109 /// <summary>
110 /// Allows the game to run logic such as updating the world,
111 /// checking for collisions, gathering input, and playing audio.
112 /// </summary>
113 /// <param name="gameTime">Provides a snapshot of timing values.</param>
114 protected override void Update(GameTime gameTime)
115 {
116 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
117 Exit();
118
119 ScreenManager.Update(gameTime);
120
121 Player.Update();
122
123 base.Update(gameTime);
124 }
125
126 /// <summary>
127 /// This is called when the game should draw itself.
128 /// </summary>
129 /// <param name="gameTime">Provides a snapshot of timing values.</param>
130 protected override void Draw(GameTime gameTime)
131 {
132 GraphicsDevice.Clear(Color.White);
133
134 spriteBatch.Begin();
135
136 ScreenManager.Draw(spriteBatch);
137
138 spriteBatch.End();
139
140 base.Draw(gameTime);
141 }
142
143 public void PlaySong(string songName)
144 {
145 // temp stuff before media manager is in
146 if (songName == "game")
147 {
148 GameSongHandle.Play();
149 }
150 }
151
152 public void GameOver()
153 {
154 var scoreScreen = new ScoreScreen(this);
155 scoreScreen.Initialize();
156
157 GameSongHandle.Stop();
158 GameOverSound.Play();
159 ScreenManager.Pop();
160 ScreenManager.Push(scoreScreen);
161 }
162 }
163 }