sneak/Jumpy.Shared/JumpyGame.cs
Colin McMillen 3f603d6bd3 add Android app skeleton
GitOrigin-RevId: 35018deabaa16e9b80e9a87b937fa7f24b6e06dd
2020-02-13 14:44:43 -05:00

75 lines
2.2 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
namespace Jumpy {
public class JumpyGame : Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
KeyboardInput keyboardInput = new KeyboardInput();
bool fullScreen = false;
IDisplay display;
public JumpyGame() {
graphics = new GraphicsDeviceManager(this);
IsMouseVisible = true;
Content.RootDirectory = "Content";
}
// Performs initialization that's needed before starting to run.
protected override void Initialize() {
display = (IDisplay) Services.GetService(typeof(IDisplay));
display.Initialize(Window, graphics);
display.SetFullScreen(fullScreen);
// TODO: something like this for mobile devices?
// graphics.SupportedOrientations =
// DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
base.Initialize();
}
// Called once per game. Loads all game content.
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("font");
}
// Called once per game. Unloads all game content.
protected override void UnloadContent() {
// TODO: Unload any non ContentManager content here.
}
// Updates the game world.
protected override void Update(GameTime gameTime) {
keyboardInput.Update();
List<Keys> keysDown = keyboardInput.NewKeysDown();
if (keysDown.Contains(Keys.F12)) {
fullScreen = !fullScreen;
display.SetFullScreen(fullScreen);
}
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
keysDown.Contains(Keys.Escape)) {
Exit();
}
base.Update(gameTime);
}
// Called when the game should draw itself.
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.DrawString(font, "hello world", new Vector2(100, 100), Color.Black);
spriteBatch.End();
base.Draw(gameTime);
}
}
}