diff --git a/Sources/libewol/ewol/Game/SceneElement.cpp b/Sources/libewol/ewol/Game/SceneElement.cpp index db731250..4f97077b 100644 --- a/Sources/libewol/ewol/Game/SceneElement.cpp +++ b/Sources/libewol/ewol/Game/SceneElement.cpp @@ -26,61 +26,90 @@ #include #include - -int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement) +ewol::SceneElement::SceneElement(void) { - if (NULL == newElement) { - return -1; + m_id = 1; + numberOfGroup = 0; + for (int32_t iii=0; iii not added at the system ..."); + return; + } + if (group < 0 || group >= MAX_GROUP_NUMBER) { + EWOL_ERROR("group is wrong " << group << "!=[0," << MAX_GROUP_NUMBER << "]==> not added at the system ..."); + return; + } + for (int32_t iii=0; iiiGetElementProperty(element, id) ) { - return true; - } - } + if (id.group > numberOfGroup || id.group > MAX_GROUP_NUMBER) { + return false; } - return false; + if (id.listId >= listAnimatedElements[id.group].Size()) { + return false; + if (NULL == listAnimatedElements[id.group][id.listId]) { + return false; + } + // copy the properties + element.id = id; + // get the sub properties ... + return listAnimatedElements[id.group][id.listId]->GetElementProperty(element, id.id); } -int32_t ewol::SceneElement::GetNearestEnemy(coord2D_ts position, int32_t groupId) +elementIdentifier_ts ewol::SceneElement::GetNearestEnemy(coord2D_ts position, int32_t groupId) { - int32_t findId = -1; + elementIdentifier_ts findId; + findId.id = -1; + findId.group = -1; + findId.listId = -1; etkFloat_t lastQuadDistance = 9999999999999999.0; - for (int32_t iii=0; iiiGetNearestEnemy(position, groupId, lastQuadDistance); - if (-1 != newID) { - findId = newID; + int32_t jjj=0; + while (groupEnemy[jjj] != -1) { + for (int32_t iii=0; iiiGetNearestEnemy(position, lastQuadDistance); + if (-1 != newID) { + findId.id = newID; + findId.group = groupEnemy[jjj]; + findId.listId = iii; + } } } + jjj++; } return findId; } - bool ewol::SceneElement::HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size) { - for (int32_t iii=0; iiiHaveImpact(group, type, position, size )) { - return true; + for (int32_t jjj=0; jjjHaveImpact(group, type, position, size )) { + return true; + } } } } @@ -89,9 +118,55 @@ bool ewol::SceneElement::HaveImpact(int32_t group, int32_t type, coord2D_ts posi void ewol::SceneElement::Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power) { - for (int32_t iii=0; iiiExplosion(group, type, position, pxAtenuation, power); + for (int32_t jjj=0; jjjExplosion(group, type, position, pxAtenuation, power); + } } } -} \ No newline at end of file +} + +elementIdentifier_ts ewol::SceneElement::GetElementAtPos(coord2D_ts position, int32_t maxDistanceDetection) +{ + elementIdentifier_ts findId; + findId.id = -1; + findId.group = -1; + findId.listId = -1; + etkFloat_t lastQuadDistance = 9999999999999999.0; + int32_t jjj=0; + for (int32_t jjj=0; jjjGetNearestEnemy(position, lastQuadDistance); + if (-1 != newID) { + findId.id = newID; + findId.group = groupEnemy[jjj]; + findId.listId = iii; + } + } + } + } + if (lastQuadDistance > maxDistanceDetection*maxDistanceDetection) { + findId.id = -1; + findId.group = -1; + findId.listId = -1; + } + return findId; +} + +void ewol::SceneElement::SetEventInput(elementIdentifier_ts& id, coord2D_ts position) +{ + EWOL_TODO("but when ..."); +} + +void ewol::SceneElement::SetEventExternButton(elementIdentifier_ts& id, int32_t btId, int32_t state) +{ + EWOL_TODO("but when ..."); +} + +void ewol::SceneElement::SetEventExternJoystick(elementIdentifier_ts& id, int32_t joyId, etkFloat_t angle, etkFloat_t distance, int32_t state) +{ + EWOL_TODO("but when ..."); +} + diff --git a/Sources/libewol/ewol/Game/SceneElement.h b/Sources/libewol/ewol/Game/SceneElement.h index 5c6508e4..7dec0dfb 100644 --- a/Sources/libewol/ewol/Game/SceneElement.h +++ b/Sources/libewol/ewol/Game/SceneElement.h @@ -32,32 +32,47 @@ namespace ewol { class GameElement; + // this is to simplify the time to acces at a specific element typedef struct { - int32_t id; //!< Unique ID int32_t group; //!< the element group - int32_t type; //!< element type - coord2D_ts position; //!< current position - coord2D_ts speed; //!< current speed - coord2D_ts size; //!< curent size of the element - etkFloat_t angle; //!< element angle + int32_t listId; //!< the id in the list of element + int32_t id; //!< Unique ID + } elementIdentifier_ts; + + typedef struct { + elementIdentifier_ts id; //!< the element definition + int32_t type; //!< element type + coord2D_ts position; //!< current position + coord2D_ts speed; //!< current speed + coord2D_ts size; //!< curent size of the element + etkFloat_t angle; //!< element angle } gameElementGenericProperty_ts; + #define MAX_GROUP_NUMBER (32) + class SceneElement { private: - int32_t m_id; //!< Unique element ID + int32_t m_id; //!< Unique element ID ==> to reference the element unicly public: - SceneElement(void) { m_id = 1; }; + SceneElement(void); ~SceneElement(void) { }; - etk::VectorType backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first - etk::VectorType listAnimatedElements; //!< generic element to display... - int32_t GetUniqueId(void) { int32_t iddd = m_id; m_id++; return iddd; }; - int32_t AddElement(ewol::GameElement* newElement); - bool GetElementProperty(gameElementGenericProperty_ts& element, int32_t id); - int32_t GetNearestEnemy(coord2D_ts position, int32_t groupId); - bool HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size); - void Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power); + int32_t numberOfGroup; //!< curent scene number of group + etk::UString groupDescription[MAX_GROUP_NUMBER]; //!< name of all the groups + int32_t groupEnemy[MAX_GROUP_NUMBER][MAX_GROUP_NUMBER]; //!< list of the ennemy + etk::VectorType backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first + etk::VectorType animated[NB_BOUBLE_BUFFER]; //!< element that must be display the second + etk::VectorType effects[NB_BOUBLE_BUFFER]; //!< element that must be display the third + etk::VectorType listAnimatedElements[MAX_GROUP_NUMBER]; //!< generic element to display order in the diffferent group + int32_t GetUniqueId(void) { int32_t iddd = m_id; m_id++; return iddd; }; + void AddElement(int32_t group, ewol::GameElement* newElement); + bool GetElementProperty(gameElementGenericProperty_ts& element, elementIdentifier_ts& id); + elementIdentifier_ts GetNearestEnemy(coord2D_ts position, int32_t groupId); + bool HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size); + void Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power); + elementIdentifier_ts GetElementAtPos(coord2D_ts position, int32_t maxDistanceDetection); + void SetEventInput(elementIdentifier_ts& id, coord2D_ts position); + void SetEventExternButton(elementIdentifier_ts& id, int32_t btId, int32_t state); + void SetEventExternJoystick(elementIdentifier_ts& id, int32_t joyId, etkFloat_t angle, etkFloat_t distance, int32_t state); }; };