Advertisement
Guest User

bricked up rn

a guest
Mar 11th, 2025
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. public static class BrickMap
  2. {
  3. private static Texture2D[] images = new Texture2D[4];
  4. private static int numOfBricks;
  5.  
  6. private static int offset = 6;
  7. private static int[,] map = // map of bricks
  8. {
  9. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  10. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  11. {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
  12. {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
  13. {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  14. {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  15. {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  16. {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
  17. };
  18.  
  19. private static Game1 _game;
  20. private static List<Brick> listBricks = new List<Brick>(); // every brick instance
  21.  
  22. public static void Initialize(Game1 game)
  23. {
  24. _game = game;
  25. for (int index = 0; index < 4; index++) // load brick images (fake automation)
  26. {
  27. images[index] = GetContent.GetTexture($"Game/brick_final_{index}");
  28. }
  29.  
  30. for (int column = 0; column < map.GetLength(0); column++) // iterate through map array, for every number create new brick and add to brick list
  31. {
  32. for (int row = 0; row < map.GetLength(1); row++)
  33. {
  34. if (map[column, row] == 1)
  35. {
  36. listBricks.Add(new Brick(images[0], new Vector2((row * images[0].Width + offset), column * images[0].Height + offset * 6), 2));
  37. }
  38. if (map[column, row] == 2)
  39. {
  40. listBricks.Add(new Brick(images[1], new Vector2((row * images[0].Width + offset), column * images[0].Height + offset * 6), 2));
  41. }
  42. if (map[column, row] == 3)
  43. {
  44. listBricks.Add(new Brick(images[2], new Vector2((row * images[0].Width + offset), column * images[0].Height + offset * 6), 1));
  45. }
  46. if (map[column, row] == 4)
  47. {
  48. listBricks.Add(new Brick(images[3], new Vector2((row * images[0].Width + offset), column * images[0].Height + offset * 6), 1));
  49. }
  50. numOfBricks++;
  51. }
  52. }
  53. }
  54.  
  55. public static int RowLength
  56. {
  57. get { return map.GetLength(1); }
  58. }
  59.  
  60. public static int NumOfBricks
  61. {
  62. get { return numOfBricks; }
  63. }
  64.  
  65. public static void Update() // iterate through brick list and call each brick's update function
  66. {
  67. foreach (Brick brick in listBricks)
  68. {
  69. brick.Update();
  70. if (_game.ball.collisionBox.Intersects(brick.Rect))
  71. {
  72. // ball will immediately destroy brick if it hits its corner or side
  73. // side collision checks obvs but any code I write for it does jack shit
  74. // how do I do tilemap collisions l;asd;asjkfopiasdjfiodwgjLKSDCVJoiflgrj
  75. // better idea: don't check for collisions in the fucken brickmap class
  76.  
  77. brick.Weaken();
  78. _game.ball.ReverseDirectionY();
  79. }
  80. }
  81. }
  82.  
  83. public static void Draw(SpriteBatch window)
  84. {
  85. foreach (Brick brick in listBricks)
  86. {
  87. brick.Draw(window);
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement