diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2016-09-25 18:38:34 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2016-09-25 18:38:34 +0200 |
commit | 2c12d19204aa198bf8537bcdb137b40f0c7317e9 (patch) | |
tree | 2b0ea3e0feb0df50449fdd99e0b1dfa3a2f82c16 /AmpelJonas/cObjectHandler.cpp | |
download | termgl-2c12d19204aa198bf8537bcdb137b40f0c7317e9.tar.gz |
Initial
Diffstat (limited to 'AmpelJonas/cObjectHandler.cpp')
-rw-r--r-- | AmpelJonas/cObjectHandler.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/AmpelJonas/cObjectHandler.cpp b/AmpelJonas/cObjectHandler.cpp new file mode 100644 index 0000000..a5c5884 --- /dev/null +++ b/AmpelJonas/cObjectHandler.cpp @@ -0,0 +1,63 @@ +#include "cObjectHandler.h" + +cObjectHandler::cObjectHandler(cRender *_render) +{ + render = _render; +} + +int cObjectHandler::createObject(cObject *_object) +{ + objects.push_back(_object); + return objects.size() - 1; +} + +int cObjectHandler::moveObject(int _object, sPos _pos, int _mode) +{ + if (_object >= objects.size()) //prevent segmentation faults + return 1; + + if (!objects[_object]) + return 1; + + sPos objPosition = objects[_object]->getPosition(); + + if (_mode == _MOVE_RELATIVE) + objects[_object]->setPosition(sPos{ objPosition.x + _pos.x, objPosition.y + _pos.y }); + else if (_mode == _MOVE_ABSOULUTE) + objects[_object]->setPosition(_pos); + + return 0; +} + +int cObjectHandler::destroyObject(int _object) +{ + delete objects[_object]; + objects[_object] = NULL; + + return 0; +} + +int cObjectHandler::write() +{ + render->clear(); + + for (int i = 0; i < objects.size(); i++) + { + if (objects[i]) // Check if objects[i] is existent + { + //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, obj.pos.y + o }; + render->drawPoint(obj.cScreen[p][o], pos, true, obj.wColor[p][o]); + } + } + } + } + } + + return 0; +}
\ No newline at end of file |