summaryrefslogtreecommitdiff
path: root/src/cObject.h
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:04:57 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:04:57 +0100
commitf439ae911923ee70937592b1ee535e8e8e133808 (patch)
tree7e23e023d0187caf2d81b26217b3a484bd37f799 /src/cObject.h
parent6856fcf08c8c4686ddf9e5cb60862184e15d6f0b (diff)
downloadtermgl-f439ae911923ee70937592b1ee535e8e8e133808.tar.gz
Directory updates
Moved source files to ./src and exmaple and test to ./example Updated Makefile and .doxygen to use those directorys
Diffstat (limited to 'src/cObject.h')
-rw-r--r--src/cObject.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/cObject.h b/src/cObject.h
new file mode 100644
index 0000000..50b9d18
--- /dev/null
+++ b/src/cObject.h
@@ -0,0 +1,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;
+};