Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace PacmanPrototype
  10. {
  11. class Map
  12. {
  13. public int[,] map = new int[,]
  14. {
  15. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
  16. {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0},
  17. {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  18. {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
  19. {0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0},
  20. {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0},
  21. {0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0},
  22. {0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
  23. {0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0}
  24. };
  25.  
  26. private Texture2D wand;
  27. private Texture2D boden;
  28. public Map()
  29. {
  30.  
  31. }
  32.  
  33. public Map(Texture2D wand, Texture2D boden)
  34. {
  35. this.wand = wand;
  36. this.boden = boden;
  37.  
  38. }
  39.  
  40. public void Draw(SpriteBatch spriteBatch)
  41. {
  42. //map.GetLength(0) -> Gibt die Länge des 1. Dimension des Arrays zurück
  43. //map.GetLength(1) -> Gibt die Länge des 2. Dimension des Arrays zurück
  44.  
  45. Texture2D aktTex = wand;
  46. int pos_i = 0; // hohe -> y
  47. int pos_j = 0; // breite -> x
  48.  
  49. spriteBatch.Begin();
  50.  
  51. for (int i = 0; i < map.GetLength(0); i++) // -> 0
  52. {
  53. for (int j = 0; j < map.GetLength(1); j++) // j -> 1
  54. {
  55. if (map[i,j] == 0)
  56. {
  57. aktTex = wand;
  58. }
  59. else if (map[i, j] == 1)
  60. {
  61. aktTex = boden;
  62. }
  63. spriteBatch.Draw(aktTex, new Microsoft.Xna.Framework.Vector2(pos_j, pos_i), Color.White);
  64. pos_j += aktTex.Width; // pox x
  65. }
  66. pos_j = 0;
  67. pos_i += aktTex.Height;
  68. }
  69.  
  70. spriteBatch.End();
  71. }
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement