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; RenderTarget2D renderTarget; SpriteBatch spriteBatch; SpriteFont font; KeyboardInput keyboardInput = new KeyboardInput(); bool fullScreen = false; IDisplay display; Player player; 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); renderTarget = new RenderTarget2D( GraphicsDevice, 320, 180, false /* mipmap */, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); base.Initialize(); } // Called once per game. Loads all game content. protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load("font"); player = new Player(Content.Load("player_1x")); } // 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(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); List keysDown = keyboardInput.NewKeysDown(); if (keysDown.Contains(Keys.F12)) { fullScreen = !fullScreen; display.SetFullScreen(fullScreen); } if (gamePadState.Buttons.Start == ButtonState.Pressed || keysDown.Contains(Keys.Escape)) { Exit(); } player.Update(gameTime, gamePadState); base.Update(gameTime); } // Called when the game should draw itself. protected override void Draw(GameTime gameTime) { // Draw scene to RenderTarget. GraphicsDevice.SetRenderTarget(renderTarget); // GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true }; GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); player.Draw(gameTime, spriteBatch); spriteBatch.End(); // Draw RenderTarget to screen. GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone); Rectangle drawRect = new Rectangle( 0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); spriteBatch.Draw(renderTarget, drawRect, Color.White); // spriteBatch.DrawString(font, "hello world", new Vector2(10, 10), Color.Black); spriteBatch.End(); base.Draw(gameTime); } } }