소스 검색

Better way to center

Eiyeron Fulmincendii 9 년 전
부모
커밋
5cbbb50c3d
3개의 변경된 파일33개의 추가작업 그리고 31개의 파일을 삭제
  1. 1 1
      src/map/StateMap.cpp
  2. 26 22
      src/render/Camera.cpp
  3. 6 8
      src/render/Camera.h

+ 1 - 1
src/map/StateMap.cpp

@@ -19,7 +19,7 @@ namespace
     }
 }
 
-StateMap::StateMap(int x, int y, Map &map) : camera(x, y, CameraCenterType::CENTER), map(map)
+StateMap::StateMap(int x, int y, Map &map) : camera(x, y), map(map)
 {
     camera.set_x(0);
 }

+ 26 - 22
src/render/Camera.cpp

@@ -3,15 +3,12 @@
 #include "input/Input.h"
 
 using WalrusRPG::Camera;
-using WalrusRPG::CameraCenterType;
 using namespace WalrusRPG;
 using WalrusRPG::Input::Key;
 
-Camera::Camera(signed x, signed y, CameraCenterType center_type)
-: x(x), y(y), render_area_width(320), render_area_height(240), center_type(center_type)
+Camera::Camera(signed x, signed y)
+: x(x), y(y), render_area_width(320), render_area_height(240)
 {
-    set_x(x);
-    set_y(y);
 }
 
 Camera::~Camera()
@@ -43,27 +40,44 @@ void Camera::update(unsigned dt)
 void Camera::set_x(signed x)
 {
     this->x = x;
-    if(center_type == CENTER)
-        this->x -= render_area_width/2;
 }
 
 signed Camera::get_x() const
 {
-    return center_type == CENTER? this->x + render_area_width/2 : this->x;
+    return this->x;
 }
 
 void Camera::set_y(signed y)
 {
     this->y = y;
-    if(this->center_type == CENTER)
-        this->y -= render_area_height/2;
 }
 
 signed Camera::get_y() const
 {
-    return center_type == CENTER? this->y + render_area_height/2 : this->y;
+    return this->y;
 }
 
+void Camera::set_center_x(signed x)
+{
+    this->x = x - render_area_width/2;
+}
+
+signed Camera::get_center_x() const
+{
+    return this->x - render_area_height/2;
+}
+
+void Camera::set_center_y(signed y)
+{
+    this->y = y - render_area_width/2;
+}
+
+signed Camera::get_center_y() const
+{
+    return this->y - render_area_height/2;
+}
+
+
 bool Camera::is_visible(const WalrusRPG::Utils::Rect &object) const
 {
     if ((in_range(object.x, x, x + (signed) render_area_width) ||
@@ -79,14 +93,4 @@ bool Camera::is_visible(const WalrusRPG::Utils::Rect &object) const
     {
         return false;
     }
-}
-
-void Camera::set_center_type(CameraCenterType center_type)
-{
-    this->center_type = center_type;
-}
-
-CameraCenterType Camera::get_center_type()
-{
-    return this->center_type;
-}
+}

+ 6 - 8
src/render/Camera.h

@@ -5,7 +5,6 @@
 
 namespace WalrusRPG
 {
-    enum CameraCenterType{TOP_LEFT_CORNER, CENTER};
 
     class Camera
     {
@@ -17,8 +16,6 @@ namespace WalrusRPG
                                     // of the screen?
         unsigned render_area_height;
 
-        CameraCenterType center_type;
-
         // Do you want to use classes for coordinates and allow them to have vector-based
         // mathematics? With operator overriding that could be doable to have
         // Vector2 a(3, 2); Vector2 b(1, 2); Vector3 c = a+b;
@@ -27,7 +24,7 @@ namespace WalrusRPG
         // Vector2 acceleration;
 
       public:
-        Camera(signed x, signed y, CameraCenterType center_type = TOP_LEFT_CORNER);
+        Camera(signed x, signed y);
 
         ~Camera();
         // This doesn't need any render as it's the utility which helps rendering. Unless
@@ -40,13 +37,14 @@ namespace WalrusRPG
         void set_y(signed y);
         signed get_y() const;
 
+        void set_center_x(signed x);
+        signed get_center_x() const;
+        void set_center_y(signed y);
+        signed get_center_y() const;
+
         // Can you see me, senpai ? >.<
         bool is_visible(const WalrusRPG::Utils::Rect &object) const;
 
-        void set_center_type(CameraCenterType center_type);
-
-        CameraCenterType get_center_type();
-
     };
 }