| 1 |
using System; |
| 2 |
using System.Collections.Generic; |
| 3 |
using System.Linq; |
| 4 |
using Microsoft.Xna.Framework; |
| 5 |
using Microsoft.Xna.Framework.Audio; |
| 6 |
using Microsoft.Xna.Framework.Content; |
| 7 |
using Microsoft.Xna.Framework.GamerServices; |
| 8 |
using Microsoft.Xna.Framework.Graphics; |
| 9 |
using Microsoft.Xna.Framework.Input; |
| 10 |
using Microsoft.Xna.Framework.Media; |
| 11 |
using Microsoft.Xna.Framework.Net; |
| 12 |
using Microsoft.Xna.Framework.Storage; |
| 13 |
|
| 14 |
namespace Cold_Sun |
| 15 |
{ |
| 16 |
/// <summary> |
| 17 |
/// This is the main type for your game |
| 18 |
/// </summary> |
| 19 |
public class Game1 : Microsoft.Xna.Framework.Game |
| 20 |
{ |
| 21 |
GraphicsDeviceManager graphics; |
| 22 |
SpriteBatch spriteBatch; |
| 23 |
SpriteFont mainFont; |
| 24 |
ContentManager gameContent; |
| 25 |
StorageContainer gameStorage; |
| 26 |
|
| 27 |
Texture2D LogoGfx; |
| 28 |
Vector2 LogoPos; |
| 29 |
Texture2D TitleGfx; |
| 30 |
Vector2 TitlePos; |
| 31 |
|
| 32 |
protected Rectangle screenBounds; |
| 33 |
|
| 34 |
private KeyboardState previousKey = Keyboard.GetState(); |
| 35 |
private GamePadState previousButton = GamePad.GetState(PlayerIndex.One); |
| 36 |
|
| 37 |
int frameRate = 0; |
| 38 |
int frameCounter = 0; |
| 39 |
TimeSpan elapsedTime = TimeSpan.Zero; |
| 40 |
|
| 41 |
string[] StartGameSelection = new string[] { |
| 42 |
"New Game", |
| 43 |
"Load Game", |
| 44 |
"Game Options", |
| 45 |
"Exit Game", |
| 46 |
}; |
| 47 |
|
| 48 |
int Selected = 0; |
| 49 |
|
| 50 |
enum ScreenState |
| 51 |
{ |
| 52 |
LogoScreen, |
| 53 |
TitleScreen, |
| 54 |
GameOptionScreen, |
| 55 |
GameScreen, |
| 56 |
MenuScreen |
| 57 |
} |
| 58 |
|
| 59 |
enum GameState |
| 60 |
{ |
| 61 |
Field, |
| 62 |
Menu, |
| 63 |
Battle, |
| 64 |
Cinema |
| 65 |
} |
| 66 |
|
| 67 |
ScreenState gScreen = new ScreenState(); |
| 68 |
GameState gGame = new GameState(); |
| 69 |
|
| 70 |
public Game1() |
| 71 |
{ |
| 72 |
graphics = new GraphicsDeviceManager(this); |
| 73 |
Content.RootDirectory = "Content"; |
| 74 |
|
| 75 |
this.IsMouseVisible = true; |
| 76 |
|
| 77 |
this.graphics.PreferredBackBufferWidth = 640; |
| 78 |
this.graphics.PreferredBackBufferHeight = 480; |
| 79 |
|
| 80 |
gScreen = ScreenState.LogoScreen; |
| 81 |
gGame = GameState.Field; |
| 82 |
} |
| 83 |
|
| 84 |
/// <summary> |
| 85 |
/// Allows the game to perform any initialization it needs to before starting to run. |
| 86 |
/// This is where it can query for any required services and load any non-graphic |
| 87 |
/// related content. Calling base.Initialize will enumerate through any components |
| 88 |
/// and initialize them as well. |
| 89 |
/// </summary> |
| 90 |
protected override void Initialize() |
| 91 |
{ |
| 92 |
// TODO: Add your initialization logic here |
| 93 |
LogoPos = new Vector2(0, 0); |
| 94 |
TitlePos = new Vector2(0, 0); |
| 95 |
|
| 96 |
base.Initialize(); |
| 97 |
} |
| 98 |
|
| 99 |
/// <summary> |
| 100 |
/// LoadContent will be called once per game and is the place to load |
| 101 |
/// all of your content. |
| 102 |
/// </summary> |
| 103 |
protected override void LoadContent() |
| 104 |
{ |
| 105 |
// Create a new SpriteBatch, which can be used to draw textures. |
| 106 |
spriteBatch = new SpriteBatch(GraphicsDevice); |
| 107 |
|
| 108 |
// TODO: use this.Content to load your game content here |
| 109 |
mainFont = this.Content.Load<SpriteFont>("mainFont"); |
| 110 |
|
| 111 |
LogoGfx = this.Content.Load<Texture2D>("Img/Logo"); |
| 112 |
TitleGfx = this.Content.Load<Texture2D>("Img/Title"); |
| 113 |
} |
| 114 |
|
| 115 |
/// <summary> |
| 116 |
/// UnloadContent will be called once per game and is the place to unload |
| 117 |
/// all content. |
| 118 |
/// </summary> |
| 119 |
protected override void UnloadContent() |
| 120 |
{ |
| 121 |
// TODO: Unload any non ContentManager content here |
| 122 |
mainFont = null; |
| 123 |
LogoGfx = null; |
| 124 |
TitleGfx = null; |
| 125 |
StartGameSelection = null; |
| 126 |
gameContent = null; |
| 127 |
gameStorage = null; |
| 128 |
} |
| 129 |
|
| 130 |
/// <summary> |
| 131 |
/// Allows the game to run logic such as updating the world, |
| 132 |
/// checking for collisions, gathering input, and playing audio. |
| 133 |
/// </summary> |
| 134 |
/// <param name="gameTime">Provides a snapshot of timing values.</param> |
| 135 |
protected override void Update(GameTime gameTime) |
| 136 |
{ |
| 137 |
// Allows the game to exit |
| 138 |
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) |
| 139 |
this.Exit(); |
| 140 |
|
| 141 |
// TODO: Add your update logic here |
| 142 |
elapsedTime += gameTime.ElapsedGameTime; |
| 143 |
|
| 144 |
if (elapsedTime > TimeSpan.FromSeconds(1)) |
| 145 |
{ |
| 146 |
elapsedTime -= TimeSpan.FromSeconds(1); |
| 147 |
frameRate = frameCounter; |
| 148 |
frameCounter = 0; |
| 149 |
} |
| 150 |
|
| 151 |
UpdateInput(); |
| 152 |
|
| 153 |
base.Update(gameTime); |
| 154 |
} |
| 155 |
|
| 156 |
private void UpdateInput() |
| 157 |
{ |
| 158 |
KeyboardState currentKey = Keyboard.GetState(); |
| 159 |
GamePadState currentButton = GamePad.GetState(PlayerIndex.One); |
| 160 |
|
| 161 |
switch (gScreen) |
| 162 |
{ |
| 163 |
case ScreenState.LogoScreen: |
| 164 |
{ |
| 165 |
if ((currentKey.IsKeyDown(Keys.Enter) || currentButton.Buttons.Start == ButtonState.Pressed) && !previousKey.IsKeyDown(Keys.Enter)) |
| 166 |
{ |
| 167 |
gScreen = ScreenState.TitleScreen; |
| 168 |
} |
| 169 |
break; |
| 170 |
} |
| 171 |
case ScreenState.TitleScreen: |
| 172 |
{ |
| 173 |
if((currentKey.IsKeyDown(Keys.Up) || currentButton.DPad.Up == ButtonState.Pressed) && !previousKey.IsKeyDown(Keys.Up)) |
| 174 |
{ |
| 175 |
if (Selected > 0) |
| 176 |
--Selected; |
| 177 |
} |
| 178 |
else if ((currentKey.IsKeyDown(Keys.Down) || currentButton.DPad.Down == ButtonState.Pressed) && !previousKey.IsKeyDown(Keys.Down)) |
| 179 |
{ |
| 180 |
if (Selected < StartGameSelection.Length - 1) |
| 181 |
++Selected; |
| 182 |
} |
| 183 |
else if ((currentKey.IsKeyDown(Keys.Enter) || currentButton.Buttons.Start == ButtonState.Pressed) && !previousKey.IsKeyDown(Keys.Enter) && Selected == 3) |
| 184 |
{ |
| 185 |
this.Exit(); |
| 186 |
} |
| 187 |
break; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
previousButton = currentButton; |
| 192 |
previousKey = currentKey; |
| 193 |
} |
| 194 |
|
| 195 |
/// <summary> |
| 196 |
/// This is called when the game should draw itself. |
| 197 |
/// </summary> |
| 198 |
/// <param name="gameTime">Provides a snapshot of timing values.</param> |
| 199 |
protected override void Draw(GameTime gameTime) |
| 200 |
{ |
| 201 |
GraphicsDevice.Clear(Color.CornflowerBlue); |
| 202 |
|
| 203 |
// TODO: Add your drawing code here |
| 204 |
frameCounter++; |
| 205 |
|
| 206 |
string fps = string.Format("Cold Sun - DarkScar Games [FPS:{0}]", frameRate); |
| 207 |
|
| 208 |
spriteBatch.Begin(SpriteBlendMode.AlphaBlend); |
| 209 |
|
| 210 |
this.Window.Title = fps.ToString(); |
| 211 |
|
| 212 |
switch (gScreen) |
| 213 |
{ |
| 214 |
case ScreenState.LogoScreen: |
| 215 |
{ |
| 216 |
spriteBatch.Draw(LogoGfx, LogoPos, Color.CornflowerBlue); |
| 217 |
break; |
| 218 |
} |
| 219 |
case ScreenState.TitleScreen: |
| 220 |
{ |
| 221 |
spriteBatch.Draw(TitleGfx, TitlePos, Color.CornflowerBlue); |
| 222 |
for (int i = 0, n = StartGameSelection.Length; i != n; ++i) |
| 223 |
{ |
| 224 |
spriteBatch.DrawString(mainFont, StartGameSelection[i], new Vector2(200, 1500 + 50 * i), (i == Selected) ? Color.Yellow : Color.White); |
| 225 |
} |
| 226 |
break; |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
switch (gGame) |
| 231 |
{ |
| 232 |
case GameState.Field: |
| 233 |
{ |
| 234 |
break; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
spriteBatch.End(); |
| 239 |
|
| 240 |
base.Draw(gameTime); |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
|