From 4912eb6946734a540a81cef97bcf0d418b73406f Mon Sep 17 00:00:00 2001 From: jonas Date: Thu, 3 Jan 2019 21:19:20 +0100 Subject: a --- cObject.h | 4 ++-- cObjectHandler.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cObject.h b/cObject.h index 607af4e..f9b42c4 100644 --- a/cObject.h +++ b/cObject.h @@ -30,9 +30,9 @@ public: sObject getObject(); - virtual void onClick(sPos _pos, unsigned int _button){}; + virtual void onClick(sPos _pos, unsigned int _button){} - virtual void onChar(unsigned char _c){}; + virtual void onChar(unsigned char _c){} protected: //For child classes cObject(); diff --git a/cObjectHandler.cpp b/cObjectHandler.cpp index 68abace..0b4bb65 100644 --- a/cObjectHandler.cpp +++ b/cObjectHandler.cpp @@ -77,11 +77,13 @@ int cObjectHandler::clickEvent(sPos _pos, unsigned int _button) return 1; if(_pos.y >= iHitMap[_pos.x].size()) return 1; - - iActiveObject = iHitMap[_pos.x][_pos.y]; //Set active object + if(objects[ iHitMap[_pos.x][_pos.y] ]) + { + iActiveObject = iHitMap[_pos.x][_pos.y]; //Set active object objects[ iHitMap[_pos.x][_pos.y] ]->onClick(_pos, _button); + } else return 1; @@ -139,9 +141,9 @@ void cObjectHandler::buildHitmap() sPos oPos = objects[i]->getPosition(); sPos oSize = objects[i]->getSize(); - for(unsigned int x = oPos.x; x <= oPos.x + oSize.x; x++) + for(int x = oPos.x; x <= oPos.x + oSize.x; x++) { - for(unsigned int y = oPos.y; y <= oPos.y + oSize.y; y++) + for(int y = oPos.y; y <= oPos.y + oSize.y; y++) { if(x < size.x && y < size.y) //Objects can be outside the screen. iHitMap[x][y] = i; -- cgit v1.2.3