]> git.r.bdr.sh - rbdr/super-polarity/blame - SuperPolarity/SuperPolarity.cs
Adds instructions to readme
[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
2d3615a1
BB
32 protected SoundEffect GameSong;
33 protected SoundEffectInstance GameSongHandle;
b587e9d8 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
2d3615a1
BB
42 graphics.PreferMultiSampling = true;
43 graphics.PreferredBackBufferHeight = 720;
44 graphics.PreferredBackBufferWidth = 1280;
45 //graphics.ToggleFullScreen();
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;
2d3615a1
BB
88 GameSong = Content.Load<SoundEffect>("Sound\\polaritytheme");
89 GameSongHandle = GameSong.CreateInstance();
b587e9d8
BB
90 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
91
63a61ee2
BB
92 // Create a new SpriteBatch, which can be used to draw textures.
93 spriteBatch = new SpriteBatch(GraphicsDevice);
94
b587e9d8 95 ScreenManager.Push(EntryScreen);
63a61ee2 96
b587e9d8 97 Player = new Player(this);
63a61ee2
BB
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
74c15570 119 ScreenManager.Update(gameTime);
95d7601b 120
b587e9d8
BB
121 Player.Update();
122
63a61ee2
BB
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 {
95d7601b 132 GraphicsDevice.Clear(Color.White);
63a61ee2
BB
133
134 spriteBatch.Begin();
135
74c15570
BB
136 ScreenManager.Draw(spriteBatch);
137
63a61ee2
BB
138 spriteBatch.End();
139
140 base.Draw(gameTime);
141 }
b587e9d8
BB
142
143 public void PlaySong(string songName)
144 {
145 // temp stuff before media manager is in
146 if (songName == "game")
147 {
2d3615a1 148 GameSongHandle.Play();
b587e9d8
BB
149 }
150 }
151
152 public void GameOver()
153 {
bca44639
BB
154 var scoreScreen = new ScoreScreen(this);
155 scoreScreen.Initialize();
156
2d3615a1 157 GameSongHandle.Stop();
b587e9d8
BB
158 GameOverSound.Play();
159 ScreenManager.Pop();
bca44639 160 ScreenManager.Push(scoreScreen);
b587e9d8 161 }
63a61ee2
BB
162 }
163}