A 2D tile-based sandbox game.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

common.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <SFML/System/Vector2.hpp>
  3. #include <SFML/Graphics.hpp>
  4. #define UNIT_SIZE 32.0
  5. class Vec2: public sf::Vector2<float> {
  6. public:
  7. using sf::Vector2<float>::Vector2;
  8. Vec2 operator+(Vec2 &vec) {
  9. return Vec2(x + vec.x, y + vec.y);
  10. }
  11. Vec2 &operator+=(Vec2 &vec) {
  12. this->x += vec.x;
  13. this->y += vec.y;
  14. return *this;
  15. }
  16. Vec2 operator-(Vec2 &vec) {
  17. return Vec2(x - vec.x, y - vec.y);
  18. }
  19. Vec2 &operator-=(Vec2 &vec) {
  20. this->x -= vec.x;
  21. this->y -= vec.y;
  22. return *this;
  23. }
  24. Vec2 operator*(Vec2 &vec) {
  25. return Vec2(x * vec.x, y * vec.y);
  26. }
  27. Vec2 &operator*=(Vec2 &vec) {
  28. this->x *= vec.x;
  29. this->y *= vec.y;
  30. return *this;
  31. }
  32. Vec2 operator/(Vec2 &vec) {
  33. return Vec2(x / vec.x, y / vec.y);
  34. }
  35. Vec2 &operator/=(Vec2 &vec) {
  36. this->x /= vec.x;
  37. this->y /= vec.y;
  38. return *this;
  39. }
  40. };
  41. struct Win {
  42. public:
  43. sf::RenderWindow &window_;
  44. sf::Transform &transform_;
  45. Vec2 curr_pos_ = { 0, 0 };
  46. void setPos(Vec2 &pos) {
  47. transform_.translate(-curr_pos_.x, -curr_pos_.y);
  48. transform_.translate(pos.x, pos.y);
  49. curr_pos_ = pos;
  50. }
  51. void draw(const sf::Drawable &drawable) {
  52. window_.draw(drawable, transform_);
  53. }
  54. };