Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- namespace WindowsGame1
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- KeyboardState oldState;
- Color backColor = Color.CornflowerBlue;
- Color upColor = Color.CornflowerBlue;
- Color frontColor = Color.Red;
- SpriteBatch spriteBatch;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- }
- protected override void Initialize()
- {
- base.Initialize();
- oldState = Keyboard.GetState();
- }
- private Texture2D SpriteTexture;
- private Rectangle TitleSafe;
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- SpriteTexture = Content.Load<Texture2D>("ship");
- TitleSafe = GetTitleSafeArea(.8f);
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
- ButtonState.Pressed)
- this.Exit();
- UpdateInput();
- base.Update(gameTime);
- }
- protected Rectangle GetTitleSafeArea(float percent)
- {
- Rectangle retval = new Rectangle(
- graphics.GraphicsDevice.Viewport.X,
- graphics.GraphicsDevice.Viewport.Y,
- graphics.GraphicsDevice.Viewport.Width,
- graphics.GraphicsDevice.Viewport.Height);
- #if XBOX
- // Find Title Safe area of Xbox 360.
- float border = (1 - percent) / 2;
- retval.X = (int)(border * retval.Width);
- retval.Y = (int)(border * retval.Height);
- retval.Width = (int)(percent * retval.Width);
- retval.Height = (int)(percent * retval.Height);
- return retval;
- #else
- return retval;
- #endif
- }
- private void UpdateInput()
- {
- KeyboardState newState = Keyboard.GetState();
- // Is the SPACE key down?
- if (newState.IsKeyDown(Keys.Space))
- {
- // If not down last update, key has just been pressed.
- if (!oldState.IsKeyDown(Keys.Space))
- {
- backColor =
- frontColor;
- }
- }
- else if (oldState.IsKeyDown(Keys.Space))
- {
- // Key was down last update, but not down now, so
- // it has just been released.
- }
- else
- {
- //backColor = upColor;
- }
- //backColor = upColor;
- // Update saved state.
- oldState = newState;
- }
- protected override void Draw(GameTime gameTime)
- {
- graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- Vector2 pos = new Vector2(TitleSafe.Left, TitleSafe.Top);
- spriteBatch.Draw(SpriteTexture, pos, Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Add Comment
Please, Sign In to add comment