void Application::DetectCollisions() { if(GetCollision(Players[0], Players[1])) { // If collision if(Players[0].isAttacking && Players[0].attackType != e_NO_ATTACK && (Players[0].AttackTimer.getElapsedTime() >= sf::seconds(0.35) && Players[0].AttackTimer.getElapsedTime() <= sf::seconds(0.4))) { // Damage enemy player Players[1].DepleteHealth(Players[0].attackType); // Knock player back if(Players[0].boundingBox.min.x < Players[1].boundingBox.min.x) { Players[1].Knockback(e_RIGHT, Players[1].attackType); } else { Players[1].Knockback(e_LEFT, Players[1].attackType); } Players[0].isAttacking = false; } if(Players[1].isAttacking && Players[1].attackType != e_NO_ATTACK && Players[1].AttackTimer.getElapsedTime() >= sf::seconds(0.35)) { // Damage enemy player Players[0].DepleteHealth(Players[1].attackType); // Knock player back if(Players[1].boundingBox.min.x < Players[0].boundingBox.min.x) { Players[0].Knockback(e_RIGHT, Players[0].attackType); } else { Players[0].Knockback(e_LEFT, Players[0].attackType); } Players[1].isAttacking = false; } } }
//'derruba' a peça até encostar em outra, ou no grid da base void TWorld::DropBlock(TBlockSingle *Peca) { float oy = Peca->y; while (Peca->y > 0 && GetCollision(Peca) == false) { Peca->y = Peca->y - 1/DIVISAO; } if (Peca->y <= 0) { Peca->y = MAX_Y/DIVISAO; while (Peca->y > 0 && GetCollision(Peca) == false) { Peca->y = Peca->y - 1/DIVISAO; } } if (Peca->y <= 0) Peca->y = floor_y/DIVISAO; return; }
void OgreNewtonSceneBody::EndAddRemoveCollision() { dNewtonCollisionScene* const scene = (dNewtonCollisionScene*) GetCollision(); scene->EndAddRemoveCollision(); // need to update the aabb in the broad phase, for this we call set matrix dMatrix matrix; NewtonBody* const body = GetNewtonBody(); NewtonBodyGetMatrix(body, &matrix[0][0]); NewtonBodySetMatrix(body, &matrix[0][0]); }
void CCollisionComponent::Update() { // GJ: On THPS4, we did the following test first before // updating the collision; I think this will be handled // by the suspend component, so we shouldn't have to do // this here... // if ( (m_object_flags & vINVISIBLE) && !initialize ) // { // return; // } // get the collision object Nx::CCollObj* p_coll = GetCollision(); // Update collision // Might be problem with things being LODed off, but still needing collision? if ( p_coll ) { // GJ TODO: Somehow remove the collision object's dependency on the model! Nx::CModel* p_model = NULL; Nx::CHierarchyObject* p_hierarchy = NULL; Obj::CModelComponent* p_model_component = GetModelComponentFromObject( GetObject() ); if ( p_model_component ) { p_model = p_model_component->GetModel(); Dbg_MsgAssert( p_model, ( "No model?!?" ) ); p_hierarchy = p_model->GetHierarchy(); } if (p_hierarchy) { Mth::Vector translation(p_hierarchy->GetSetupMatrix()[W]); translation[W] = 0.0f; // turn into vector p_hierarchy->GetSetupMatrix().Transform(translation); // Re-orients the translation p_coll->SetWorldPosition( GetObject()->GetPos() + translation ); p_coll->SetOrientation( p_hierarchy->GetSetupMatrix() * GetObject()->GetDisplayMatrix() ); } else { p_coll->SetWorldPosition( GetObject()->GetPos() ); p_coll->SetOrientation( GetObject()->GetDisplayMatrix() ); } } }
void OgreNewtonSceneBody::RemoveCollision (void* const handle) { dNewtonCollisionScene* const scene = (dNewtonCollisionScene*) GetCollision(); scene->RemoveCollision(handle); }
void* OgreNewtonSceneBody::AddCollision(const dNewtonCollision* const collision) { dNewtonCollisionScene* const scene = (dNewtonCollisionScene*) GetCollision(); return scene->AddCollision(collision); }
void OgreNewtonSceneBody::BeginAddRemoveCollision() { dNewtonCollisionScene* const scene = (dNewtonCollisionScene*) GetCollision(); scene->BeginAddRemoveCollision(); }
bool CDeathPirate::CheckCollision(CBase* pBase) { CBase::CheckCollision( pBase ); if(pBase->GetType() == OBJ_BLOCK) { CBlock* BLOCK = (CBlock*)pBase; RECT rIntersect; //Descriptive replacement variables RECT rMyRect = { (LONG)GetPosX(), (LONG)GetPosY(), 0, 0 }; rMyRect.right = rMyRect.left + GetWidth(); rMyRect.bottom = rMyRect.top + GetHeight(); RECT rHisRect = { (LONG)BLOCK->GetPosX(), (LONG)BLOCK->GetPosY(), 0, 0 }; rHisRect.right = rHisRect.left + BLOCK->GetWidth(); rHisRect.bottom = rHisRect.top + BLOCK->GetHeight(); if( IntersectRect( &rIntersect, &rMyRect, &rHisRect ) ) { if( (rIntersect.right-rIntersect.left) > (rIntersect.bottom-rIntersect.top) ) { if(BLOCK->GetBlock() == BLOCK_SOLID || BLOCK->GetBlock() == BLOCK_MOVING || BLOCK->GetBlock() == BLOCK_PARTIAL || BLOCK->GetBlock() == BLOCK_UNSTABLE) { if(rMyRect.bottom > rHisRect.top && rMyRect.top < rHisRect.top) { SetPosY( (float)rHisRect.top - GetHeight() ); SetGround(true); SetBaseVelY(0); SetCollision(true); } else if(rMyRect.top < rHisRect.bottom && rMyRect.bottom > rHisRect.top) SetPosY((float)rHisRect.bottom); } else if(BLOCK->GetBlock() == BLOCK_TRAP) { SetGround(true); SetCollision(true); SetBaseVelY(0); } } else if((rIntersect.right-rIntersect.left) < (rIntersect.bottom-rIntersect.top)) { if(BLOCK->GetBlock() == BLOCK_SOLID || BLOCK->GetBlock() == BLOCK_MOVING || BLOCK->GetBlock() == BLOCK_PARTIAL) { } else if(BLOCK->GetBlock() == BLOCK_TRAP) { SetGround(true); SetCollision(true); SetBaseVelY(0); } } return true; } } if(GetGround() && GetCollision() == false) { SetGround(false); } return false; }