summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:22:43 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:22:43 +0100
commit35e7c375a2f96bd8dffcadc800f7e9d4354217a5 (patch)
tree862efea304e651142dd4419c6f72a2e912ec5f3e /src
parentacaf96c4930d88ebbabcea809473e623ba361ef9 (diff)
downloadtermgl-35e7c375a2f96bd8dffcadc800f7e9d4354217a5.tar.gz
Collision update
Changed collision parameters for onCollision fuinctions to pass the movement delta of moved Object
Diffstat (limited to 'src')
-rw-r--r--src/cObject.h16
-rw-r--r--src/cObjectHandler.cpp2
2 files changed, 10 insertions, 8 deletions
diff --git a/src/cObject.h b/src/cObject.h
index 50b9d18..48e41a4 100644
--- a/src/cObject.h
+++ b/src/cObject.h
@@ -3,11 +3,6 @@
#include "cRender.h"
-#define _HIT_TOP 1
-#define _HIT_BOTTOM 2
-#define _HIT_LEFT 3
-#define _HIT_RIGHT 4
-
struct sObject
{
sPos pos;
@@ -20,6 +15,7 @@ struct sObject
/** 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.
+* It inherits all drawing functions from cRender.
*
* Minimal example for inheriting class
*
@@ -67,13 +63,19 @@ public:
/** Called by cObjectHandler if Object hits another during move operation
* return true to abort move, false to continue and allow overlap
+ *
+ * _hit: position delta of moved object
+ *
+ * _passiveObject: return from onCollisionPassive to identify what was hit
*/
- virtual bool onCollisionActive(unsigned int _hit, int _passiveObject) { return false; }
+ virtual bool onCollisionActive(sPos _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
+ *
+ * _hit: position delta of moved object
*/
- virtual int onCollisionPassive(unsigned int _hit) { return 0; }
+ virtual int onCollisionPassive(sPos _hit) { return 0; }
diff --git a/src/cObjectHandler.cpp b/src/cObjectHandler.cpp
index 11c02e6..7af0f3c 100644
--- a/src/cObjectHandler.cpp
+++ b/src/cObjectHandler.cpp
@@ -52,7 +52,7 @@ int cObjectHandler::moveObject(int _object, sPos _pos, int _mode)
for(int i = 0; i < coll.idc; i++)
{
if(coll.idv[i] != _object)
- abort += objects[_object]->onCollisionActive(0, objects[coll.idv[0]]->onCollisionPassive(0));
+ abort += objects[_object]->onCollisionActive(_pos, objects[coll.idv[0]]->onCollisionPassive(_pos));
}
}