Collider.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "Log.hpp"
  3. #define CW 20
  4. #define CH 12
  5. class Collider: public IEntity {
  6. public:
  7. enum {
  8. AIR, SAND, FALLINGSAND, SOLID, SPIKE, LEVER
  9. };
  10. bool isSafe(int x, int y) {
  11. int tile = m_tile[getTile(x, y)];
  12. return tile == -1 ? true : tile != FALLINGSAND && tile != SPIKE;
  13. }
  14. bool isSolid(int x, int y) {
  15. int tile = m_tile[getTile(x, y)];
  16. return tile == -1 ? true : tile != AIR && tile != LEVER;
  17. }
  18. int getBlock(int x, int y) {
  19. return m_tile[getTile(x, y)];
  20. }
  21. void setBlock(int x, int y, int type) {
  22. m_tile[getTile(x, y)] = type;
  23. }
  24. void populate(std::vector<int> data) {
  25. std::copy(data.begin(), data.end(), m_tile);
  26. std::copy(data.begin(), data.end(), m_base);
  27. }
  28. float getLocalX() {
  29. return m_localX;
  30. }
  31. void setLocalX(float localX) {
  32. m_localX = localX;
  33. }
  34. void update(float delta) {
  35. std::copy(m_base, m_base + CW * CH, m_tile);
  36. }
  37. private:
  38. int getTile(int x, int y) {
  39. if(x < 0 || y < 0 || x >= CW || y >= CH) {
  40. return -1;
  41. }
  42. return x + CW * y;
  43. }
  44. int m_tile[CW * CH];
  45. int m_base[CW * CH];
  46. float m_localX;
  47. };