Camera.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <os.h>
  2. #include "Camera.h"
  3. #include "Entity.h"
  4. #include "misc.h"
  5. #define CAMERA WalrusRPG::Camera
  6. CAMERA::Camera(signed x, signed y)
  7. {
  8. this->x = x;
  9. this->y = y;
  10. render_area_width = 320;
  11. render_area_height = 240;
  12. }
  13. CAMERA::~Camera()
  14. {
  15. // TODO if you allocate dynamically members
  16. }
  17. void CAMERA::update(unsigned dt)
  18. {
  19. UNUSED(dt);
  20. // TODO update map's data according to elasped time
  21. /*
  22. // Need to think aagain on how to go to a target point and/or we need to align the corner OR the center to this point.
  23. position += velocity * dt;
  24. velocity += acceleration * dt;
  25. */
  26. if (isKeyPressed(KEY_NSPIRE_5))
  27. y++;
  28. if (isKeyPressed(KEY_NSPIRE_8))
  29. y--;
  30. if (isKeyPressed(KEY_NSPIRE_6))
  31. x++;
  32. if (isKeyPressed(KEY_NSPIRE_4))
  33. x--;
  34. }
  35. void CAMERA::set_x(signed x)
  36. {
  37. this->x = x;
  38. }
  39. signed CAMERA::get_x() const
  40. {
  41. return this->x;
  42. }
  43. void CAMERA::set_y(signed y)
  44. {
  45. this->y = y;
  46. }
  47. signed CAMERA::get_y() const
  48. {
  49. return this->y;
  50. }
  51. bool CAMERA::is_visible(const WalrusRPG::Utils::Rect &object) const
  52. {
  53. if ((in_range(object.x, x, x + (signed) render_area_width) || in_range(object.x + (signed) object.width - 1, x, x + (signed) render_area_width))
  54. && (in_range(object.y, y, y + (signed) render_area_height) || in_range(object.y + (signed) object.height - 1, y, y + (signed) render_area_height)))
  55. {
  56. return true;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }