]> git.r.bdr.sh - rbdr/super-polarity/blame - SuperPolarity/SuperPolarity.cs
Consolidate with mac project.
[rbdr/super-polarity] / SuperPolarity / SuperPolarity.cs
CommitLineData
63a61ee2
BB
1#region Using Statements
2using System;
3using System.Collections.Generic;
4using Microsoft.Xna.Framework;
5using Microsoft.Xna.Framework.Content;
6using Microsoft.Xna.Framework.Graphics;
7using Microsoft.Xna.Framework.Input;
8using Microsoft.Xna.Framework.Storage;
9using Microsoft.Xna.Framework.GamerServices;
b587e9d8
BB
10using Microsoft.Xna.Framework.Media;
11using Microsoft.Xna.Framework.Audio;
63a61ee2 12using SuperPolarity;
63419029 13using Tao.Sdl;
63a61ee2
BB
14#endregion
15
16namespace 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
63a61ee2 42 Content.RootDirectory = "Content";
2af83e98 43 ActorFactory.SetGame(this);
38c7d3f9
BB
44 ParticleEffectFactory.SetGame(this);
45 ActorManager.SetGame(this);
74c15570
BB
46 ScreenManager.SetGame(this);
47
b587e9d8 48 EntryScreen = (Screen)new TitleScreen(this);
63a61ee2
BB
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 {
63a61ee2 59 base.Initialize();
2af83e98 60
6fceaa7b
BB
61 graphics.PreferMultiSampling = true;
62 graphics.PreferredBackBufferHeight = 720;
63 graphics.PreferredBackBufferWidth = 1280;
64 //graphics.ToggleFullScreen();
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;
d7a43ae2 88 GameSong = Content.Load<Song>("Sound\\polaritytheme");
b587e9d8
BB
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}