Advertisement
yung_rmk

+mouse!

Jan 31st, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 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.  
  51. protected override void Update(GameTime gameTime)
  52. {
  53.  
  54.  
  55. if (Keyboard.GetState().IsKeyDown(Keys.Right))
  56. {
  57. rec.X += speed;
  58. }
  59. if (Keyboard.GetState().IsKeyDown(Keys.Down))
  60. {
  61. rec.Y += speed;
  62. }
  63. if (Keyboard.GetState().IsKeyDown(Keys.Left))
  64. {
  65. rec.X -= speed;
  66. }
  67. if (Keyboard.GetState().IsKeyDown(Keys.Up))
  68. {
  69. rec.Y -= speed;
  70. }
  71.  
  72. rec.X = Mouse.GetState().X;
  73. rec.Y = Mouse.GetState().Y;
  74.  
  75. base.Update(gameTime);
  76. }
  77.  
  78. protected override void Draw(GameTime gameTime)
  79. {
  80.  
  81.  
  82.  
  83.  
  84. GraphicsDevice.Clear(Color.White);
  85. //Отрисовка игры
  86. spriteBatch.Begin();
  87. spriteBatch.Draw(tex, rec, Color.White);
  88. spriteBatch.End();
  89.  
  90. base.Draw(gameTime);
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement