Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. {
  2. {1,1,1,1,1,1,1,1,1,1}
  3. {0,0,0,0,0,0,0,0,0,0}
  4. {0,0,0,0,0,0,0,0,0,0}
  5. }
  6.  
  7. class Game1 : Game
  8. {
  9. GraphicsDeviceManager graphics;
  10. SpriteBatch spriteBatch;
  11. Texture2D gameBackround;
  12. SpriteFont font;
  13. int[,] map ;
  14.  
  15. public Game1()
  16. {
  17. graphics = new GraphicsDeviceManager(this);
  18. Content.RootDirectory = "Content";
  19. graphics.PreferredBackBufferWidth = 1920;
  20. graphics.PreferredBackBufferHeight = 1080;
  21. graphics.GraphicsProfile = GraphicsProfile.HiDef;
  22.  
  23. }
  24.  
  25.  
  26.  
  27.  
  28. protected override void LoadContent()
  29. {
  30.  
  31.  
  32. this.IsMouseVisible = true;
  33. gameBackround = Content.Load<Texture2D>("level_01_A");//this is the background
  34.  
  35. map = new int[gameBackround.Width / 64, gameBackround.Height / 64];
  36.  
  37. font = Content.Load<SpriteFont>("Fonts/Font");
  38. spriteBatch = new SpriteBatch(GraphicsDevice);
  39. }
  40.  
  41. protected override void Draw(GameTime gameTime)
  42. {
  43. GraphicsDevice.Clear(Color.CornflowerBlue);
  44. spriteBatch.Begin();
  45. spriteBatch.Draw(gameBackround, new Rectangle(0, -700, 3840, 1984), Color.White);
  46. DrawGrid(map, spriteBatch, font);
  47. base.Draw(gameTime);
  48. spriteBatch.End();
  49. }
  50.  
  51. public void DrawGrid(int[,] gameMap, SpriteBatch spriteBatch, SpriteFont f)
  52. {
  53. for (int x = 0; x < gameMap.GetLength(1); x++)
  54. {
  55. for (int y = 0; y < gameMap.GetLength(0); y++)
  56. {
  57. spriteBatch.DrawString(f, x + " / " + y, new Vector2(x * 64, y * 64), Color.White);
  58. }
  59.  
  60. }
  61.  
  62. }
  63.  
  64. var mouseState = Mouse.GetState();
  65.  
  66. if (mouseState.LeftButton == ButtonState.Pressed)
  67. {
  68. // do something here
  69. }
  70.  
  71. var xIndex = mouseState.X / 64;
  72. var yIndex = mouseState.Y / 64;
  73.  
  74. map[xIndex, yIndex] = 1;
  75.  
  76. if (xIndex >= 0 && xIndex < map.GetLength(0) && yIndex >= 0 && yIndex < map.GetLength(1)) {
  77. map[xIndex][yIndex] = 1;
  78. }
  79.  
  80. var mouseState = Mouse.GetState();
  81.  
  82. if (mouseState.LeftButton == ButtonState.Pressed)
  83. {
  84. var xIndex = mouseState.X / 64;
  85. var yIndex = mouseState.Y / 64;
  86.  
  87. if (xIndex >= 0 && xIndex < map.GetLength(0) && yIndex >= 0 && yIndex < map.GetLength(1)) {
  88. map[xIndex][yIndex] = 1;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement