Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna;
- namespace Game1
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- SpriteFont font;
- private Animated SpriteTexture;
- private const float Rotation = 0;
- private const float Scale = 0.5f;
- private Viewport viewport;
- private Vector2 Position = new Vector2(0, 0);
- private const int FrameX = 6;
- private const int FrameY = 3;
- private const int FramesPerSec = 90;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- this.IsMouseVisible = true;
- graphics.PreferredBackBufferHeight = 600;
- graphics.PreferredBackBufferWidth = 800;
- SpriteTexture = new Animated(Vector2.Zero, Rotation, Scale);
- TargetElapsedTime = TimeSpan.FromSeconds(1 / 24.0);
- }
- protected override void Initialize()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- SpriteTexture.Load(Content, "sprite", FrameX, FrameY);
- font = Content.Load<SpriteFont>("Courier New");
- viewport = graphics.GraphicsDevice.Viewport;
- Position = new Vector2(viewport.Width / 2, viewport.Height / 2);
- }
- protected override void Update(GameTime gameTime)
- {
- if (Keyboard.GetState().IsKeyDown(Keys.Escape))
- this.Exit();
- float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
- float posx = Position.X;
- float posy = Position.Y;
- int maxH = viewport.Height;
- int maxW = viewport.Width;
- if (Keyboard.GetState().IsKeyDown(Keys.Left) && (posx > 0))
- {
- posx--;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Left) && (Keyboard.GetState().IsKeyDown(Keys.Up)) && (posx > 0))
- {
- posx -= 2;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Right) && (posx < maxW - 100))
- {
- posx++;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Right) && (Keyboard.GetState().IsKeyDown(Keys.Up)) && (posx < maxW - 100))
- {
- posx += 2;
- }
- Position.X = posx;
- SpriteTexture.UpdateFrame(elapsed, Position);
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- // TODO: Add your drawing code here
- float game = (float)(1 / gameTime.ElapsedGameTime.TotalSeconds);
- spriteBatch.Begin();
- SpriteTexture.DrawFrame(spriteBatch, Position);
- spriteBatch.DrawString(font, "FPS:" + game.ToString(), new Vector2(0, 0), Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Add Comment
Please, Sign In to add comment