aboutsummaryrefslogtreecommitdiff
path: root/cObject.h
blob: 50b9d18a43419f9d8ddeeb42f064c8aa852a5faa (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
#include <stdlib.h>

#include "cRender.h"

#define _HIT_TOP 1
#define _HIT_BOTTOM 2
#define _HIT_LEFT 3
#define _HIT_RIGHT 4

struct sObject
{
	sPos pos;
	WORD **wColor;
	char **cScreen;
	int sizeX;
	int sizeY;
};

/** cObject can be used standalone as well as inherited
* every cObject has its own framebuffer as well as position viariables to be moveable.
* cObject is used by cObjectHandler to manage all objects to be displayed.
*
* Minimal example for inheriting class
*
*
*			class example : cObject
*			{
*			public:
*				example() { setSize(10,5); }
*				~example() { destruct(); }
*			};
*
*/
class cObject : public cRender
{
public:
	/** Sets the size to _sx x _sy
	*/
	cObject(int _sx, int _sy);

	virtual ~cObject();

	/** Returns current position
	*/
	sPos getPosition();

	/** Sets position to _pos
	*/
	void setPosition(sPos _pos);
	/** Sets position by coordinates
	*/
	void setPosition(int _x, int _y);

	/** Returns sObject with framebuffer and current position
	*/
	sObject getObject();

	/** Called by cObjecthandler if cObject is clicked
	*/
	virtual void onClick(sPos _pos, unsigned int _button){}
	/** Called by cObjecthandler if cObject is active on keyboard input
	* _pos decribes the relative position of mousepointer to origin of object
	*/
	virtual void onChar(unsigned char _c){}


	/** Called by cObjectHandler if Object hits another during move operation
	*	return true to abort move, false to continue and allow overlap
	*/
	virtual bool onCollisionActive(unsigned int _hit, int _passiveObject) { return false; }

	/** Called by cObjectHandler if Object is hit by another object
	*	return any integer value to be identified by hitting object
	*/
	virtual int onCollisionPassive(unsigned int _hit) { return 0; }




protected: //For child classes
	cObject();
	/** For inheriting classes: sets size of framebuffer
	*/
	void setSize(int _sx, int _sy);

	/** For inheriting classes: frees the framebuffer
	*/
	void destruct();

private:
	//wColor, cScreen, sizeX and sizeY are inherited from cRender
	sPos pos;
	bool bSizeSet;
};