marioCommon.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "marioCommon.h"
  2. namespace mario
  3. {
  4. bool isSolid(int id)
  5. {
  6. return(collisionMap[id] == 'X');
  7. }
  8. glm::vec4 getTileUV(gl2d::TextureAtlasPadding atlas, int id, int flip)
  9. {
  10. int x = id % 8;
  11. int y = id / 8;
  12. return atlas.get(x, y, flip);
  13. }
  14. bool aabb(glm::vec4 b1, glm::vec4 b2, float delta)
  15. {
  16. b2.x += delta;
  17. b2.y += delta;
  18. b2.z -= delta * 2;
  19. b2.w -= delta * 2;
  20. if (((b1.x - b2.x < b2.z)
  21. && b2.x - b1.x < b1.z
  22. )
  23. && ((b1.y - b2.y < b2.w)
  24. && b2.y - b1.y < b1.w
  25. )
  26. )
  27. {
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. bool loadMap(RequestedContainerInfo &requestedInfo, std::string file, Block **map, glm::ivec2 &mapSize)
  33. {
  34. delete[] * map;
  35. if (!requestedInfo.readEntireFileBinary(file, &mapSize, sizeof(mapSize)))
  36. {
  37. return 0;
  38. }
  39. *map = new Block[mapSize.x * mapSize.y];
  40. Block d{27,0};
  41. memset(*map, *(int *)(&d), mapSize.x * mapSize.y);
  42. size_t s = 0;
  43. if (requestedInfo.getFileSizeBinary(file.c_str(), s))
  44. {
  45. if (s == mapSize.x * mapSize.y + sizeof(mapSize))
  46. {
  47. requestedInfo.readEntireFileBinary(file.c_str(), *map, mapSize.x * mapSize.y, sizeof(mapSize));
  48. }
  49. else
  50. {
  51. requestedInfo.consoleWindow->write("Error: mario file is corrupt\n");
  52. return 0;
  53. }
  54. }
  55. else { return 0; }
  56. return 1;
  57. }
  58. };