Advertisement
yung_rmk

move

Jan 31st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  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.  
  12. namespace WindowsGame2
  13. {
  14. public class Game1 : Microsoft.Xna.Framework.Game
  15. {
  16. GraphicsDeviceManager graphics; //экран
  17. SpriteBatch spriteBatch; //Перо для рисования
  18.  
  19. Texture2D tex;
  20. Rectangle rec;
  21. int speed = 5;
  22. int PanelW, PanelH;
  23.  
  24.  
  25. public Game1()
  26. {
  27. graphics = new GraphicsDeviceManager(this);
  28. Content.RootDirectory = "Content";
  29. }
  30.  
  31. protected override void Initialize()
  32. {
  33. //Выполняется при старте
  34. base.Initialize();
  35. }
  36.  
  37. //После старта. Загрузка контента в программу.
  38. protected override void LoadContent()
  39. {
  40. spriteBatch = new SpriteBatch(GraphicsDevice);
  41.  
  42. tex = Content.Load<Texture2D>("187806-earthwormjim");
  43. rec = new Rectangle(100, 100, 100, 100*tex.Height/tex.Width);
  44.  
  45. PanelW = graphics.PreferredBackBufferWidth;
  46. PanelH = graphics.PreferredBackBufferHeight;
  47. }
  48.  
  49. //Изменение логики игры, до отрисовки.
  50. int t = 1;
  51.  
  52. protected override void Update(GameTime gameTime)
  53. {
  54.  
  55.  
  56. if (Keyboard.GetState().IsKeyDown(Keys.Right))
  57. {
  58. rec.X += speed;
  59. }
  60. if (Keyboard.GetState().IsKeyDown(Keys.Down))
  61. {
  62. rec.Y += speed;
  63. }
  64. if (Keyboard.GetState().IsKeyDown(Keys.Left))
  65. {
  66. rec.X -= speed;
  67. }
  68. if (Keyboard.GetState().IsKeyDown(Keys.Up))
  69. {
  70. rec.Y -= speed;
  71. }
  72.  
  73.  
  74. base.Update(gameTime);
  75. }
  76.  
  77. protected override void Draw(GameTime gameTime)
  78. {
  79.  
  80.  
  81.  
  82.  
  83. GraphicsDevice.Clear(Color.White);
  84. //Отрисовка игры
  85. spriteBatch.Begin();
  86. spriteBatch.Draw(tex, rec, Color.White);
  87. spriteBatch.End();
  88.  
  89. base.Draw(gameTime);
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement