Advertisement
Guest User

aaaa

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. namespace Game3
  5. {
  6.  
  7. public class Game1 : Microsoft.Xna.Framework.Game
  8. {
  9. GraphicsDeviceManager graphics;
  10. SpriteBatch spriteBatch;
  11. SpriteBatch spriteBatch2;
  12. int speed = 3;
  13. Texture2D bg;
  14. int x = 0;
  15. private AnimatedTexture SpriteTexture;
  16. private AnimatedTexture SpriteTexture2;
  17. private const float Rotation = 0;
  18. private const float Scale = 1.0f;
  19. private const float Depth = 0.5f;
  20. public Game1()
  21. {
  22. graphics = new GraphicsDeviceManager(this);
  23. SpriteTexture = new AnimatedTexture(Vector2.Zero, Rotation, Scale, Depth);
  24. SpriteTexture2 = new AnimatedTexture(Vector2.Zero, Rotation, Scale, Depth);
  25. Content.RootDirectory = "Content";
  26. }
  27.  
  28. protected override void Initialize()
  29. {
  30.  
  31. base.Initialize();
  32. }
  33. private Vector2 xPos = new Vector2(0, 335);
  34. private Vector2 xPos2 = new Vector2(0, 650);
  35. private const int Frames = 8;
  36. private const int FramesPerSec = 15;
  37. private const int FramesRow = 2;
  38.  
  39. protected override void LoadContent()
  40. {
  41.  
  42. bg = Content.Load<Texture2D>("mission");
  43. spriteBatch = new SpriteBatch(GraphicsDevice);
  44. SpriteTexture.Load(Content, "Rockman_walk", Frames, FramesRow, FramesPerSec);
  45. spriteBatch2 = new SpriteBatch(GraphicsDevice);
  46. SpriteTexture2.Load(Content, "Rockman_warp", 10, 1, FramesPerSec);
  47.  
  48. }
  49.  
  50. protected override void UnloadContent()
  51. {
  52.  
  53. }
  54.  
  55. protected override void Update(GameTime gameTime)
  56. {
  57. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  58. this.Exit();
  59. float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
  60. SpriteTexture.UpdateFrame(elapsed);
  61.  
  62.  
  63. xPos.X += speed;
  64. if (xPos.X > 650 && x == 0)
  65. {
  66. speed *= 0;
  67. x = 0;
  68. SpriteTexture2.UpdateFrame(elapsed);
  69. }
  70. base.Update(gameTime);
  71. }
  72.  
  73. protected override void Draw(GameTime gameTime)
  74. {
  75.  
  76. GraphicsDevice.Clear(Color.CornflowerBlue);
  77. spriteBatch.Begin();
  78. spriteBatch.Draw(bg, new Vector2(0, -100), Color.White);
  79. if (xPos.X < 650)
  80. {
  81. SpriteTexture.DrawFrame(spriteBatch, xPos);
  82. }
  83. else if (speed == 0 && x == 0)
  84. {
  85. SpriteTexture2.DrawFrame(spriteBatch, xPos);
  86. if (SpriteTexture2.Frame == 9)
  87. {
  88. x = 2;
  89. }
  90.  
  91. }
  92. spriteBatch.End();
  93.  
  94. base.Draw(gameTime);
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement