daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Aug 18th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 WindowsGame1
  15. {
  16.     public class Game1 : Microsoft.Xna.Framework.Game
  17.     {
  18.         GraphicsDeviceManager graphics;
  19.         KeyboardState oldState;
  20.         Color backColor = Color.CornflowerBlue;
  21.         Color upColor = Color.CornflowerBlue;
  22.         Color frontColor = Color.Red;
  23.         SpriteBatch spriteBatch;
  24.  
  25.  
  26.  
  27.  
  28.         public Game1()
  29.         {
  30.             graphics = new GraphicsDeviceManager(this);
  31.         }
  32.  
  33.         protected override void Initialize()
  34.         {
  35.             base.Initialize();
  36.             oldState = Keyboard.GetState();
  37.         }
  38.  
  39.         private Texture2D SpriteTexture;
  40.         private Rectangle TitleSafe;
  41.         protected override void LoadContent()
  42.         {
  43.             spriteBatch = new SpriteBatch(GraphicsDevice);
  44.             SpriteTexture = Content.Load<Texture2D>("ship");
  45.             TitleSafe = GetTitleSafeArea(.8f);
  46.         }
  47.  
  48.         protected override void UnloadContent()
  49.         {
  50.         }
  51.  
  52.         protected override void Update(GameTime gameTime)
  53.         {
  54.             // Allows the game to exit
  55.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
  56.                 ButtonState.Pressed)
  57.                 this.Exit();
  58.  
  59.             UpdateInput();
  60.  
  61.             base.Update(gameTime);
  62.         }
  63.  
  64.         protected Rectangle GetTitleSafeArea(float percent)
  65.         {
  66.             Rectangle retval = new Rectangle(
  67.                 graphics.GraphicsDevice.Viewport.X,
  68.                 graphics.GraphicsDevice.Viewport.Y,
  69.                 graphics.GraphicsDevice.Viewport.Width,
  70.                 graphics.GraphicsDevice.Viewport.Height);
  71. #if XBOX
  72.             // Find Title Safe area of Xbox 360.
  73.             float border = (1 - percent) / 2;
  74.             retval.X = (int)(border * retval.Width);
  75.             retval.Y = (int)(border * retval.Height);
  76.             retval.Width = (int)(percent * retval.Width);
  77.             retval.Height = (int)(percent * retval.Height);
  78.             return retval;            
  79. #else
  80.             return retval;
  81. #endif
  82.         }
  83.  
  84.         private void UpdateInput()
  85.         {
  86.             KeyboardState newState = Keyboard.GetState();
  87.  
  88.             // Is the SPACE key down?
  89.             if (newState.IsKeyDown(Keys.Space))
  90.             {
  91.                 // If not down last update, key has just been pressed.
  92.                 if (!oldState.IsKeyDown(Keys.Space))
  93.                 {
  94.                     backColor =
  95.                         frontColor;
  96.                 }
  97.             }
  98.             else if (oldState.IsKeyDown(Keys.Space))
  99.             {
  100.                 // Key was down last update, but not down now, so
  101.                 // it has just been released.
  102.             }
  103.             else
  104.             {
  105.                 //backColor = upColor;
  106.             }
  107.             //backColor = upColor;
  108.             // Update saved state.
  109.             oldState = newState;
  110.         }
  111.  
  112.         protected override void Draw(GameTime gameTime)
  113.         {
  114.             graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  115.             spriteBatch.Begin();
  116.             Vector2 pos = new Vector2(TitleSafe.Left, TitleSafe.Top);
  117.             spriteBatch.Draw(SpriteTexture, pos, Color.White);
  118.             spriteBatch.End();
  119.             base.Draw(gameTime);
  120.         }
  121.     }
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top