aboutsummaryrefslogtreecommitdiff
path: root/AmpelJonas/cObjectHandler.cpp
blob: d35653af26cb09b11bcb7f1a1133f7eb86bf8ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 (unsigned long 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;
}