A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include <SFML/System/Vector2.hpp>
  3. #include <utility>
  4. namespace Swan {
  5. template<typename T>
  6. class Vector2 {
  7. public:
  8. T x_;
  9. T y_;
  10. constexpr Vector2(T x = 0, T y = 0): x_(x), y_(y) {}
  11. operator sf::Vector2<T>() const {
  12. return sf::Vector2<T>(x_, y_);
  13. }
  14. operator std::pair<T, T>() const {
  15. return std::pair<T, T>(x_, y_);
  16. }
  17. Vector2<T> operator-() const {
  18. return Vector2<T>(-x_, -y_);
  19. }
  20. Vector2<T> operator+(const Vector2<T> &vec) const {
  21. return Vector2<T>(x_ + vec.x_, y_ + vec.y_);
  22. }
  23. Vector2<T> &operator+=(const Vector2<T> &vec) {
  24. x_ += vec.x_;
  25. y_ += vec.y_;
  26. return *this;
  27. }
  28. Vector2<T> operator-(const Vector2<T> &vec) const {
  29. return Vector2<T>(x_ - vec.x_, y_ - vec.y_);
  30. }
  31. Vector2<T> &operator-=(const Vector2<T> &vec) {
  32. x_ -= vec.x_;
  33. y_ -= vec.y_;
  34. return *this;
  35. }
  36. Vector2<T> operator*(const Vector2<T> &vec) const {
  37. return Vector2<T>(x_ * vec.x_, y_ * vec.y_);
  38. }
  39. Vector2<T> &operator*=(const Vector2<T> &vec) {
  40. x_ *= vec.x_;
  41. y_ *= vec.y_;
  42. return *this;
  43. }
  44. Vector2<T> operator*(T num) const {
  45. return Vector2<T>(x_ * num, y_ * num);
  46. }
  47. Vector2<T> operator*=(T num) {
  48. x_ *= num;
  49. y_ *= num;
  50. return *this;
  51. }
  52. Vector2<T> operator/(const Vector2<T> &vec) const {
  53. return Vector2<T>(x_ / vec.x_, y_ / vec.y_);
  54. }
  55. Vector2<T> &operator/=(const Vector2<T> &vec) {
  56. x_ /= vec.x_;
  57. y_ /= vec.y_;
  58. return *this;
  59. }
  60. Vector2<T> operator/(T num) const {
  61. return Vector2<T>(x_ / num, y_ / num);
  62. }
  63. Vector2<T> operator/=(T num) {
  64. x_ /= num;
  65. y_ /= num;
  66. return *this;
  67. }
  68. };
  69. using Vec2 = Vector2<float>;
  70. }