void CEnemy1::CollisionEnemy(float elapsedTime, std::map<int, CEnemy*> listEnemyAlive) { float normalX, normalY; for (auto& enemy : listEnemyAlive) { float collisionTime = SweptAABB( elapsedTime, this->GetBox(), enemy.second->GetBox(), normalX, normalY); if (collisionTime < elapsedTime && this->id != enemy.second->GetID()) { if (this->hp > 1) // xả giao { this->velocity.x = (this->velocity.x*collisionTime) / elapsedTime; this->scale.x = this->direction = -this->direction; } else if (this->IsViolent()) // xả dao { if (enemy.second->IsViolent()) this->Die(enemy.second->GetVelocity().x); enemy.second->Die(this->velocity.x); } } } }
int RecF::Collide(RecF Rec, RecF block) { // RecF is the moving RecF // block is the static RecF RecF broadphaseRecF = GetSweptBroadphaseRec(Rec); if (AABBCheck(broadphaseRecF, block)) { float normalx, normaly; float collisiontime = SweptAABB(Rec, block, normalx, normaly); float remainingtime = 1.0f - collisiontime; if (collisiontime < 1.0f) { if (Rec.collisionTime > collisiontime) Rec.collisionTime = collisiontime; if (normalx == -1) return 2; if (normalx == 1) return 1; if (normaly == -1) return 4; if (normaly == 1) return 3; } else if (AABBCheck(Rec, block)) { return 5; } } return 0; }
void CEnemy1::CollisionLine(float elapsedTime, std::vector<std::pair<D3DXVECTOR2, D3DXVECTOR2>>* const listLine) { float normalX, normalY; for (int i = 0; i < listLine->size(); i++) { D3DXVECTOR2 point1 = listLine->at(i).first; D3DXVECTOR2 point2 = listLine->at(i).second; float collisionTime = SweptAABB( elapsedTime, this->GetBox(), BoudingBox(point1, point2), normalX, normalY); if (collisionTime < elapsedTime) { point1.x == point2.x ? this->CollisionLineX( elapsedTime, collisionTime, point1, point2, normalX, normalY) : this->CollisionLineY( elapsedTime, collisionTime, point1, normalX, normalY); } } }
bool CLuigi::CollisionEnemy() { bool result = false; float normalX, normalY; std::map<int, CEnemy*> listEnemyAlive = CEnemiesManager::GetListEnemyAlive();//sss for (auto& enemy : listEnemyAlive) { if (!enemy.second->IsDied()) { float collisionTime = SweptAABB( elapsedTime, this->getBox(), enemy.second->GetBox(), normalX, normalY); if (collisionTime < elapsedTime || this->getBox().Intersect(enemy.second->GetBox())) { if (this->invincibleTime>0.0f) { enemy.second->Die(this->velocity.x); CEnemiesManager::Playsound(); } else if (this->_position.y >= enemy.second->GetBox()._y) { jumpingFlag == JumpingFlag::JumpingFlag2 || this->velocity.y == LUIGI_LIMITVELOCITYY ? enemy.second->TrampledToDeath() : enemy.second->DescreaseHP(); CSEPointManager::AddPoint(this->_position); CEnemiesManager::Playsound(); this->velocity = (this->velocity*collisionTime) / elapsedTime; result = true; } else if (this->ghostTime <= 0.0f && enemy.second->Dame(this->velocity.x)) { this->type != LuigiType::Small ? this->ShrinkToSmall() : this->GoToHeaven(); } } } } return result; }
void CLuigi::CollisionLine(float elapsedTime, std::vector<std::pair<D3DXVECTOR2, D3DXVECTOR2>>* const listLine) { float normalX, normalY; int count = 0; for (int i = 0;i < listLine->size();i++) { D3DXVECTOR2 point1 = listLine->at(i).first; D3DXVECTOR2 point2 = listLine->at(i).second; float collisionTime = SweptAABB( elapsedTime, this->getBox(), BoudingBox(point1, point2), normalX, normalY); if (collisionTime < elapsedTime) { point1.x == point2.x ? this->CollisionLineX( elapsedTime, collisionTime, point1, point2, normalX, normalY) : this->CollisionLineY( elapsedTime, collisionTime, point1, normalX, normalY); if (this->velocity.x == 0.0f && this->moveType == LuigiMoveType::Running) this->moveType = LuigiMoveType::Standing; } else count++; } if (count == listLine->size()) { if (this->moveType != LuigiMoveType::Jumping) { this->moveType = LuigiMoveType::Jumping; jumpingFlag = JumpingFlag::JumpingFlag0; } } }