summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cObject.cpp15
-rw-r--r--src/cObject.h5
-rw-r--r--src/cObjectHandler.cpp15
3 files changed, 22 insertions, 13 deletions
diff --git a/src/cObject.cpp b/src/cObject.cpp
index 7dc194c..217affc 100644
--- a/src/cObject.cpp
+++ b/src/cObject.cpp
@@ -32,6 +32,21 @@ sObject cObject::getObject()
{
return sObject{pos, wColor, cScreen, sizeX, sizeY};
}
+void cObject::write(cRender *_render, sPos _cameraPosition)
+{
+ if(!bSizeSet)
+ return;
+
+ for (int o = 0; o < sizeY; o++) { //y axis
+ for (int p = 0; p < sizeX; p++) { //x axis
+ if (cScreen[p][o]) { //Dont overwrite empty pixels
+ sPos npos{ pos.x + p - _cameraPosition.x,
+ pos.y + o - _cameraPosition.y };
+ _render->drawPoint(cScreen[p][o], npos, true, wColor[p][o]);
+ }
+ }
+ }
+}
//protected
cObject::cObject() : pos({0,0}) , bSizeSet(false){}
diff --git a/src/cObject.h b/src/cObject.h
index 48e41a4..08594b3 100644
--- a/src/cObject.h
+++ b/src/cObject.h
@@ -49,9 +49,14 @@ public:
void setPosition(int _x, int _y);
/** Returns sObject with framebuffer and current position
+ * DEPRECATED
*/
sObject getObject();
+ /** Writes object to framebuffer with offset _cameraPosition
+ */
+ void write(cRender *_render, sPos _cameraPosition);
+
/** Called by cObjecthandler if cObject is clicked
*/
virtual void onClick(sPos _pos, unsigned int _button){}
diff --git a/src/cObjectHandler.cpp b/src/cObjectHandler.cpp
index eca340b..1168b86 100644
--- a/src/cObjectHandler.cpp
+++ b/src/cObjectHandler.cpp
@@ -95,20 +95,9 @@ int cObjectHandler::write()
for (unsigned long int i = 0; i < objects.size(); i++)
{
- if (objects[i]) // Check if objects[i] is existent
+ if (objects[i])
{
- //Draw every Object
- sObject obj = objects[i]->getObject(); //get Object #i
-
- for (int o = 0; o < obj.sizeY; o++) { //y axis
- for (int p = 0; p < obj.sizeX; p++) { //x axis
- if (obj.cScreen[p][o]) { //Dont overwrite empty pixels
- sPos pos{ obj.pos.x + p - cameraPosition.x,
- obj.pos.y + o - cameraPosition.y };
- render->drawPoint(obj.cScreen[p][o], pos, true, obj.wColor[p][o]);
- }
- }
- }
+ objects[i]->write(render, cameraPosition);
}
}