Camera.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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
  23. align the corner OR the center to this point.
  24. position += velocity * dt;
  25. velocity += acceleration * dt;
  26. */
  27. if (isKeyPressed(KEY_NSPIRE_5))
  28. y++;
  29. if (isKeyPressed(KEY_NSPIRE_8))
  30. y--;
  31. if (isKeyPressed(KEY_NSPIRE_6))
  32. x++;
  33. if (isKeyPressed(KEY_NSPIRE_4))
  34. x--;
  35. }
  36. void CAMERA::set_x(signed x)
  37. {
  38. this->x = x;
  39. }
  40. signed CAMERA::get_x() const
  41. {
  42. return this->x;
  43. }
  44. void CAMERA::set_y(signed y)
  45. {
  46. this->y = y;
  47. }
  48. signed CAMERA::get_y() const
  49. {
  50. return this->y;
  51. }
  52. bool CAMERA::is_visible(const WalrusRPG::Utils::Rect &object) const
  53. {
  54. if ((in_range(object.x, x, x + (signed) render_area_width) ||
  55. in_range(object.x + (signed) object.width - 1, x,
  56. x + (signed) render_area_width)) &&
  57. (in_range(object.y, y, y + (signed) render_area_height) ||
  58. in_range(object.y + (signed) object.height - 1, y,
  59. y + (signed) render_area_height)))
  60. {
  61. return true;
  62. }
  63. else
  64. {
  65. return false;
  66. }
  67. }