Streetwalrus Einstein преди 10 години
родител
ревизия
f863241f47
променени са 3 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 5 0
      include/Camera.h
  2. 2 0
      include/misc.h
  3. 15 0
      src/Camera.cpp

+ 5 - 0
include/Camera.h

@@ -1,6 +1,8 @@
 #ifndef INCLUDE_CAMERA_H
 #define INCLUDE_CAMERA_H
 
+#include "Rect.h"
+
 namespace WalrusRPG
 {
     class Camera
@@ -29,6 +31,9 @@ namespace WalrusRPG
         signed get_x() const;
         void set_y(signed y);
         signed get_y() const;
+
+        // Can you see me, senpai ? >.<
+        bool is_visible(const WalrusRPG::Utils::Rect &object) const;
     };
 }
 

+ 2 - 0
include/misc.h

@@ -6,4 +6,6 @@
 #define min(a, b) (((a) < (b)) ? (a) : (b))
 #define max(a, b) (((a) > (b)) ? (a) : (b))
 
+#define in_range(x, a, b) (((x) >= (a)) && ((x) < (b)))
+
 #endif

+ 15 - 0
src/Camera.cpp

@@ -9,6 +9,8 @@ CAMERA::Camera(signed x, signed y)
 {
     this->x = x;
     this->y = y;
+    render_area_width = 320;
+    render_area_height = 240;
 }
 
 CAMERA::~Camera()
@@ -55,3 +57,16 @@ signed CAMERA::get_y() const
 {
     return this->y;
 }
+
+bool CAMERA::is_visible(const WalrusRPG::Utils::Rect &object) const
+{
+    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))
+        && (in_range(object.y, y, y + (signed) render_area_height) || in_range(object.y + (signed) object.height - 1, y, y + (signed) render_area_height)))
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}