From 149ecf80754a00d7749323bb4916c47665b5d47f Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 4 Dec 2019 13:16:38 -0500 Subject: [PATCH] Basic working skeleton in OpenGL and UWP. GitOrigin-RevId: 762b683654e20eb28346d9b2de7fbb8c826a2966 --- Jumpy.Shared/Jumpy.Shared.projitems | 4 +- Jumpy.Shared/JumpyGame.cs | 64 +++++++++++++++++++++++++++++ Jumpy.Shared/KeyboardInput.cs | 24 +++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 Jumpy.Shared/JumpyGame.cs create mode 100644 Jumpy.Shared/KeyboardInput.cs diff --git a/Jumpy.Shared/Jumpy.Shared.projitems b/Jumpy.Shared/Jumpy.Shared.projitems index 8fe3ed1..88dcb13 100644 --- a/Jumpy.Shared/Jumpy.Shared.projitems +++ b/Jumpy.Shared/Jumpy.Shared.projitems @@ -9,5 +9,7 @@ Jumpy.Shared + + - + \ No newline at end of file diff --git a/Jumpy.Shared/JumpyGame.cs b/Jumpy.Shared/JumpyGame.cs new file mode 100644 index 0000000..36901c1 --- /dev/null +++ b/Jumpy.Shared/JumpyGame.cs @@ -0,0 +1,64 @@ +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(); + + public JumpyGame() { + graphics = new GraphicsDeviceManager(this); + Content.RootDirectory = "Content"; + } + + // Performs initialization that's needed before starting to run. + protected override void Initialize() { + base.Initialize(); + } + + // Called once per game. Loads all game content. + protected override void LoadContent() { + spriteBatch = new SpriteBatch(GraphicsDevice); + font = Content.Load("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 keysDown = keyboardInput.NewKeysDown(); + + //if (keysDown.Contains(Keys.F12)) + //{ + // 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); + } + } +} diff --git a/Jumpy.Shared/KeyboardInput.cs b/Jumpy.Shared/KeyboardInput.cs new file mode 100644 index 0000000..38ffd30 --- /dev/null +++ b/Jumpy.Shared/KeyboardInput.cs @@ -0,0 +1,24 @@ +using Microsoft.Xna.Framework.Input; +using System.Collections.Generic; + +namespace Jumpy { + public class KeyboardInput { + private KeyboardState oldState = Keyboard.GetState(); + private List newKeysDown = new List(); + + public void Update() { + KeyboardState newState = Keyboard.GetState(); + newKeysDown.Clear(); + foreach (Keys k in newState.GetPressedKeys()) { + if (!oldState.IsKeyDown(k)) { + newKeysDown.Add(k); + } + } + oldState = newState; + } + + public List NewKeysDown() { + return newKeysDown; + } + } +} \ No newline at end of file