void Character::charactersCollisions() { for(std::vector<Character*>::iterator it = MapManager::currentMap->characters()->begin() ; it != MapManager::currentMap->characters()->end() ; it++) { // Left and right if((m_vx != 0) && (((*it)->x() + (*it)->hitboxX() < m_x + m_hitboxX + m_vx && (*it)->x() + (*it)->hitboxX() + (*it)->hitboxW() > m_x + m_hitboxX + m_vx ) || ((*it)->x() + (*it)->hitboxX() < m_x + m_hitboxX + m_hitboxW + m_vx && (*it)->x() + (*it)->hitboxX() + (*it)->hitboxW() > m_x + m_hitboxX + m_hitboxW + m_vx)) && (((*it)->y() + (*it)->hitboxY() < m_y + m_hitboxY && (*it)->y() + (*it)->hitboxY() + (*it)->hitboxH() > m_y + m_hitboxY ) || ((*it)->y() + (*it)->hitboxY() < m_y + m_hitboxY + m_hitboxH && (*it)->y() + (*it)->hitboxY() + (*it)->hitboxH() > m_y + m_hitboxY + m_hitboxH ))) { // Reset horizontal movement vector m_vx = 0; // Execute collision action collisionAction(*it); } // Up and down if((m_vy != 0) && (((*it)->x() + (*it)->hitboxX() < m_x + m_hitboxX && (*it)->x() + (*it)->hitboxX() + (*it)->hitboxW() > m_x + m_hitboxX ) || ((*it)->x() + (*it)->hitboxX() < m_x + m_hitboxX + m_hitboxW && (*it)->x() + (*it)->hitboxX() + (*it)->hitboxW() > m_x + m_hitboxX + m_hitboxW )) && (((*it)->y() + (*it)->hitboxY() < m_y + m_hitboxY + m_vy && (*it)->y() + (*it)->hitboxY() + (*it)->hitboxH() > m_y + m_hitboxY + m_vy ) || ((*it)->y() + (*it)->hitboxY() < m_y + m_hitboxY + m_hitboxH + m_vy && (*it)->y() + (*it)->hitboxY() + (*it)->hitboxH() > m_y + m_hitboxY + m_hitboxH + m_vy))) { // Reset vertical movement vector m_vy = 0; // Execute collision action collisionAction(*it); } } }
// For a single word, returns the start of the result Docnode list. // Makes an exact copy of the docnode from index DocNode *getResultsForWord(char *word, INVERTED_INDEX *index) { // check for reserved words first if (!strncmp(word, "AND", 3) || !strncmp(word, "OR", 2)) { printf("AND and OR are reserved words. Please enter a different query.\n"); return NULL; } NormalizeWord(word); int h = makeHash(word); int word_not_found = 1; // 1 for true, 0 for false WordNode *cluster_end = NULL; // collisionAction is like getDatawith key for Dictionary.. cluster_end = collisionAction(index, h, word, &word_not_found); if (word_not_found) return NULL; else { DocNode *d = cluster_end->data; // page from the wordnode DocNode *dcopy = initDocNode(d->doc_id, d->page_word_frequency); // see if more documents exist for (d=d->next; d!=NULL; d=d->next) updateDocNode(dcopy, d->doc_id, d->page_word_frequency); // This also works but commented because ORhelper has to free // the incoming doc list... // since we are making exact copy of the docnode from index, // we need to add the docs that are not already in our copy. // So this is like an OR operation. // if (d->next != NULL) // ORHelper(&dcopy, d->next); return dcopy; } }
void Character::mapCollisions() { // Up and down if(m_vy != 0) { if (!passable(m_x + m_hitboxX , m_y + m_hitboxY + m_vy ) || !passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_vy ) || !passable(m_x + m_hitboxX , m_y + m_hitboxY + m_vy + m_hitboxH) || !passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_vy + m_hitboxH)) { /* Let player slide on tiles corners */ // Top left if (!passable(m_x + m_hitboxX + m_hitboxW + 8, m_y + m_hitboxY + m_vy) && passable(m_x + m_hitboxX , m_y + m_hitboxY + m_vy)) { m_vx = -1; } // Top right if (!passable(m_x + m_hitboxX - 8 , m_y + m_hitboxY + m_vy) && passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_vy)) { m_vx = 1; } // Bottom left if (!passable(m_x + m_hitboxX + m_hitboxW + 8, m_y + m_hitboxY + m_hitboxH + m_vy) && passable(m_x + m_hitboxX , m_y + m_hitboxY + m_hitboxH + m_vy)) { m_vx = -1; } // Bottom right if (!passable(m_x + m_hitboxX - 8 , m_y + m_hitboxY + m_hitboxH + m_vy) && passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_hitboxH + m_vy)) { m_vx = 1; } // Reset vertical movement vector m_vy = 0; // Execute collision action collisionAction(NULL); } } // Left and right if(m_vx != 0) { if (!passable(m_x + m_hitboxX + m_vx , m_y + m_hitboxY ) || !passable(m_x + m_hitboxX + m_vx + m_hitboxW, m_y + m_hitboxY ) || !passable(m_x + m_hitboxX + m_vx , m_y + m_hitboxY + m_hitboxH) || !passable(m_x + m_hitboxX + m_vx + m_hitboxW, m_y + m_hitboxY + m_hitboxH)) { /* Let player slide on tiles corners */ // Top left if (!passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY + m_hitboxH + 0) && passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY )) { m_vy = -1; } // Bottom left if (!passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY - 0 ) && passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY + m_hitboxH)) { m_vy = 1; } // Top right if (!passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY + m_hitboxH + 0) && passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY )) { m_vy = -1; } // Bottom right if (!passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY - 0 ) && passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY + m_hitboxH)) { m_vy = 1; } // Reset horizontal movement vector m_vx = 0; // Execute collision action collisionAction(NULL); } } }