bool CRoom_1x2::correctMapCollision_down() { // get the x coord in map space for a fast search int column = m_topLeft.x + m_sAtributes.velosity_x; int row = m_topLeft.y + m_sAtributes.velosity_y; m_pMap_collision->convertScreenToMap(&column, &row); const std::vector<STileData<int>*>* pMapTiles = m_pMap_collision->getMapTiles(); for (int i = 0; i < pMapTiles->size(); ++i) { STileData<int>* pTile = pMapTiles->at(i); // we are only looking for a specific column (falling down), no need to search needlessly if (pTile->mapCoords.x != column) { continue; } SCoords2<int> midBottom; midBottom.setCoords(m_bottomLeft.x + m_width / 2, (int)(m_bottomLeft.y + m_sAtributes.velosity_y)); if (pTile->collision(&midBottom)) { setBottomRight(pTile->screenCoords_topLeft.x + pTile->width, pTile->screenCoords_topLeft.y); isFalling = false; m_sAtributes.gravityTimer.start(); return true; } } return false; }
void Square::setHalfEdge(double he) { QPointF c = center(); setTopLeft(QPointF(c.x()-he, c.y()-he)); setBottomRight(QPointF(c.x()+he, c.y()+he)); }
bool CRoom_1x2::correctRoomCollision_down() { for (int i = 0; i < m_pRoom_collision->size(); ++i) { CRoom* pRoom = m_pRoom_collision->at(i); if (this->equals(pRoom)) { continue; } SCoords2<int> other_topLeft; SCoords2<int> other_topRight; SCoords2<int> other_bottomLeft; SCoords2<int> other_bottomRight; pRoom->getEverything(&other_topLeft, &other_topRight, &other_bottomLeft, &other_bottomRight); // Point collision detection extended from the midpoint on the bottom row SCoords2<int> midBottom; midBottom.setCoords(m_bottomLeft.x + m_width / 2, (int)(m_bottomLeft.y + m_sAtributes.velosity_y)); if (pRoom->collision(&midBottom)) { if (pRoom->getLayout()->x == 1) { setBottomRight(other_topRight.x, other_topRight.y); } else if (pRoom->getLayout()->x == 2) { SCoords2<int> subRoom = pRoom->whichSubRoom(&midBottom); if (subRoom.x == 1) // left side { setBottomLeft(other_topLeft.x, other_topLeft.y); } else if (subRoom.x == 2) // right side { setBottomRight(other_topRight.x, other_topRight.y); } } m_sAtributes.gravityTimer.start(); isFalling = false; return true; } } return false; }
void PiShape::configure(const std::string& parameters) { if (parameters.empty()) return; std::vector<std::string> values = Op::split(parameters, " "); std::size_t required = 4; if (values.size() < required) { std::ostringstream ex; ex << "[configuration error] term <" << className() << ">" << " requires <" << required << "> parameters"; throw fl::Exception(ex.str(), FL_AT); } setBottomLeft(Op::toScalar(values.at(0))); setTopLeft(Op::toScalar(values.at(1))); setTopRight(Op::toScalar(values.at(2))); setBottomRight(Op::toScalar(values.at(3))); if (values.size() > required) setHeight(Op::toScalar(values.at(required))); }
bool CRoom_2x1::correctMapCollision_down() { //int left_column = m_topLeft.x; //int left_row = m_topLeft.y + m_sAtributes.velosity_y; //m_pMap_collision->convertScreenToMap(&left_column, &left_row); //int right_column = m_topRight.x; //int right_row = m_topRight.y + m_sAtributes.velosity_y; //m_pMap_collision->convertScreenToMap(&right_column, &right_row); // Here we are going to do a point collision detection on the extended midpoint // from all of the sub rooms along the bottom row. If ANY of them collide with something, // the respective corner is set, and this room will not fall any farther SCoords2<int> this_midBottomLeft, this_midBottomRight; this_midBottomLeft.setCoords( m_bottomLeft.x + m_width / 4, (int)(m_bottomLeft.y + m_sAtributes.velosity_y)); this_midBottomRight.setCoords( m_bottomRight.x - m_width / 4, (int)(m_bottomLeft.y + m_sAtributes.velosity_y)); const std::vector<STileData<int>*>* pMapTiles = m_pMap_collision->getMapTiles(); for (int i = 0; i < pMapTiles->size(); ++i) { STileData<int>* pTile = pMapTiles->at(i); // [OPTIMIZATION]: how to column check when this is a 1x2 room? //if (pTile->mapCoords.x != left_column && // pTile->mapCoords.x != right_column) //{ // continue; //} bool collision_bottomLeft = pTile->collision(&this_midBottomLeft); bool collision_bottomRight = pTile->collision(&this_midBottomRight); #ifdef DEBUG if (collision_bottomLeft && collision_bottomRight) // dead on collision { assert(false);// this should never happen because tiles are 1x1, and this room is 1x2 } #endif // !DEBG if (collision_bottomLeft && !collision_bottomRight) // hanging off of the right side { setBottomLeft(pTile->screenCoords_topLeft.x, pTile->screenCoords_topLeft.y); m_sAtributes.gravityTimer.start(); isFalling = false; return true; } else if (!collision_bottomLeft && collision_bottomRight) // hanging off of the left side { setBottomRight(pTile->screenCoords_bottomRight.x, pTile->screenCoords_bottomRight.y - pTile->height); m_sAtributes.gravityTimer.start(); isFalling = false; return true; } } return false; }
bool CRoom_2x1::correctRoomCollision_down() { for (int i = 0; i < m_pRoom_collision->size(); ++i) { CRoom* pRoom = m_pRoom_collision->at(i); if (this->equals(pRoom)) { continue; } SCoords2<int> other_topLeft; SCoords2<int> other_topRight; SCoords2<int> other_bottomLeft; SCoords2<int> other_bottomRight; pRoom->getEverything(&other_topLeft, &other_topRight, &other_bottomLeft, &other_bottomRight); // Here we are going to do a point collision detection on the extended midpoint // from all of the sub rooms along the bottom row. If ANY of them collide with something, // the respective corner is set, and this room will not fall any farther SCoords2<int> this_midBottomLeft, this_midBottomRight; this_midBottomLeft.setCoords( m_bottomLeft.x + m_width / 4, (int)(m_bottomLeft.y + m_sAtributes.velosity_y)); this_midBottomRight.setCoords( m_bottomRight.x - m_width / 4, (int)(m_bottomLeft.y + m_sAtributes.velosity_y)); bool collision_bottomLeft = pRoom->collision(&this_midBottomLeft); bool collision_bottomRight = pRoom->collision(&this_midBottomRight); if (collision_bottomLeft && collision_bottomRight) // dead on collision { setBottomLeft(other_topLeft); m_sAtributes.gravityTimer.start(); isFalling = false; return true; } else if (collision_bottomLeft && !collision_bottomRight) // hanging off of the right side { if (pRoom->getLayout()->x == 1) { setBottomLeft(other_topLeft); } else if (pRoom->getLayout()->x == 2) { setBottomLeft(other_topLeft.x + pRoom->getWidth() / 2, other_topLeft.y); } m_sAtributes.gravityTimer.start(); isFalling = false; return true; } else if (!collision_bottomLeft && collision_bottomRight) // hanging off of the left side { if (pRoom->getLayout()->x == 1) { setBottomRight(other_topRight); } else if (pRoom->getLayout()->x == 2) { setBottomRight(other_topLeft.x + pRoom->getWidth() / 2, other_topLeft.y); } m_sAtributes.gravityTimer.start(); isFalling = false; return true; } } return false; }
bool setBottomRight(const Point& p, RepaintOption repaint = repaintNot) {return setBottomRight(p.x, p.y, repaint);}