]> git.r.bdr.sh - rbdr/super-polarity/blame - SuperPolarityMac/SuperPolarity.cs
Works in win, compiles in mac
[rbdr/super-polarity] / SuperPolarityMac / 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
BB
12using SuperPolarity;
13#endregion
14
15namespace SuperPolarity
16{
17 /// <summary>
18 /// This is the main type for your game
19 /// </summary>
20 public class SuperPolarity : Game
21 {
74c15570 22 public GraphicsDeviceManager graphics;
63a61ee2
BB
23 SpriteBatch spriteBatch;
24
38c7d3f9
BB
25 public static int OutlierBounds;
26
74c15570
BB
27 public Player Player;
28
29 Screen EntryScreen;
30
b587e9d8
BB
31 protected Song TitleSong;
32 protected Song GameSong;
33 protected SoundEffect GameOverSound;
74c15570 34
63a61ee2
BB
35 public SuperPolarity()
36 : base()
37 {
74c15570 38 graphics = new GraphicsDeviceManager(this);
bca44639
BB
39 Components.Add(new GamerServicesComponent(this));
40
74c15570
BB
41 graphics.PreferMultiSampling = true;
42 graphics.PreferredBackBufferWidth = 1280;
43 graphics.PreferredBackBufferHeight = 720;
44 graphics.ToggleFullScreen();
45
63a61ee2 46 Content.RootDirectory = "Content";
2af83e98 47 ActorFactory.SetGame(this);
38c7d3f9
BB
48 ParticleEffectFactory.SetGame(this);
49 ActorManager.SetGame(this);
74c15570
BB
50 ScreenManager.SetGame(this);
51
b587e9d8 52 EntryScreen = (Screen)new TitleScreen(this);
63a61ee2
BB
53 }
54
55 /// <summary>
56 /// Allows the game to perform any initialization it needs to before starting to run.
57 /// This is where it can query for any required services and load any non-graphic
58 /// related content. Calling base.Initialize will enumerate through any components
59 /// and initialize them as well.
60 /// </summary>
61 protected override void Initialize()
62 {
63a61ee2 63 base.Initialize();
2af83e98 64
74c15570
BB
65 InputController.RegisterEventForKey("fullScreenToggle", Keys.F11);
66 InputController.Bind("fullScreenToggle", HandleFullScreenToggle);
38c7d3f9 67
74c15570 68 EntryScreen.Initialize();
2af83e98 69
74c15570
BB
70 OutlierBounds = 100;
71 }
72
73 protected void HandleFullScreenToggle(float value)
74 {
75 graphics.ToggleFullScreen();
76 graphics.ApplyChanges();
63a61ee2
BB
77 }
78
79 /// <summary>
80 /// LoadContent will be called once per game and is the place to load
81 /// all of your content.
82 /// </summary>
83 protected override void LoadContent()
84 {
b587e9d8
BB
85
86 MediaPlayer.IsRepeating = true;
87 GameSong = Content.Load<Song>("Sound\\polaritytheme.wav");
88 GameOverSound = Content.Load<SoundEffect>("Sound\\gameover");
89
63a61ee2
BB
90 // Create a new SpriteBatch, which can be used to draw textures.
91 spriteBatch = new SpriteBatch(GraphicsDevice);
92
b587e9d8 93 ScreenManager.Push(EntryScreen);
63a61ee2 94
b587e9d8 95 Player = new Player(this);
63a61ee2
BB
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
74c15570 117 ScreenManager.Update(gameTime);
95d7601b 118
b587e9d8
BB
119 Player.Update();
120
63a61ee2
BB
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 {
95d7601b 130 GraphicsDevice.Clear(Color.White);
63a61ee2
BB
131
132 spriteBatch.Begin();
133
74c15570
BB
134 ScreenManager.Draw(spriteBatch);
135
63a61ee2
BB
136 spriteBatch.End();
137
138 base.Draw(gameTime);
139 }
b587e9d8
BB
140
141 public void PlaySong(string songName)
142 {
143 // temp stuff before media manager is in
144 if (songName == "game")
145 {
146 MediaPlayer.Play(GameSong);
147 }
148 }
149
150 public void GameOver()
151 {
bca44639
BB
152 var scoreScreen = new ScoreScreen(this);
153 scoreScreen.Initialize();
154
b587e9d8
BB
155 MediaPlayer.Stop();
156 GameOverSound.Play();
157 ScreenManager.Pop();
bca44639 158 ScreenManager.Push(scoreScreen);
b587e9d8 159 }
63a61ee2
BB
160 }
161}