From: SakirSoft <sak...@us...> - 2005-07-06 19:00:39
|
Update of /cvsroot/openmugen/OpenMugen/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10959 Modified Files: player.cpp Log Message: Added Guard handling Collsion detection is better now Index: player.cpp =================================================================== RCS file: /cvsroot/openmugen/OpenMugen/src/player.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -p -r1.10 -r1.11 --- player.cpp 2 Jul 2005 17:13:05 -0000 1.10 +++ player.cpp 6 Jul 2005 19:00:21 -0000 1.11 @@ -47,6 +47,7 @@ CPlayer::CPlayer() xVel=0; yVel=0; nSprPrio=5; + //this should be a unique player id number nPlayerID=0; @@ -278,23 +279,27 @@ all this states are defined in Common1.c */ void CPlayer::CheckInternalState() { - strcpy(strCommand,"none"); + strcpy(strCommand,"none"); + const char *Command=m_pCmdManager->GetCurrentCommandName(); + + if(Command) + strcpy(strCommand,m_pCmdManager->GetCurrentCommandName()); //#if 1 if ( inputs[ GAME_INPUT_UP ] ) { - if( nPhysic != air && nCurrStateNumber != 40) + if( nStateType == stand && nCurrStateNumber != 40) ChangeState(40); } if( inputs[ GAME_INPUT_RIGHT ] ) { - if(nCurrStateNumber != 20 && nCurrStateNumber < 40 && nCurrStateNumber != 100 ) + if(nCurrStateNumber != 20 && nCurrStateNumber < 40 && nStateType == stand ) ChangeState(20); } else if( inputs[ GAME_INPUT_LEFT ] ) { - if(nCurrStateNumber != 20 && nCurrStateNumber < 40) + if(nCurrStateNumber != 20 && nCurrStateNumber < 40 && nStateType == stand ) ChangeState(20); } else @@ -306,10 +311,7 @@ void CPlayer::CheckInternalState() - const char *Command=m_pCmdManager->GetCurrentCommandName(); - if(Command) - strcpy(strCommand,m_pCmdManager->GetCurrentCommandName()); //#endif @@ -457,20 +459,25 @@ w,h = right corner of the rect ClsnRECT CPlayer::ConvertClsnRectToGlobalRect(Clsn clsn) { ClsnRECT temp; - + if(!bRightFaced) { - temp.w=-clsn.ClsnRect.w+x; - temp.x=-clsn.ClsnRect.x+x; + temp.w = abs(clsn.ClsnRect.x-clsn.ClsnRect.w); + temp.h = abs(clsn.ClsnRect.h-clsn.ClsnRect.y); + temp.x = clsn.ClsnRect.x > clsn.ClsnRect.w ? (-clsn.ClsnRect.x)+x : (-clsn.ClsnRect.w)+x; + temp.y = clsn.ClsnRect.y < clsn.ClsnRect.h ? clsn.ClsnRect.y+y : clsn.ClsnRect.h+y; } else { - temp.w=clsn.ClsnRect.w+x; - temp.x=clsn.ClsnRect.x+x; + temp.w = abs(clsn.ClsnRect.x-clsn.ClsnRect.w); + temp.h = abs(clsn.ClsnRect.h-clsn.ClsnRect.y); + temp.x = clsn.ClsnRect.x < clsn.ClsnRect.w ? clsn.ClsnRect.x+x : clsn.ClsnRect.w+x; + temp.y = clsn.ClsnRect.y < clsn.ClsnRect.h ? clsn.ClsnRect.y+y : clsn.ClsnRect.h+y; + + } - temp.y=clsn.ClsnRect.y+y; - temp.h=clsn.ClsnRect.h+y; + return temp; @@ -488,12 +495,41 @@ void CPlayer::HandleHitDef(CPlayer *oppo bool bP1Hit=false; bool bP2Hit=false; - //bHitDef=false; + CheckHitCollid( bP1Hit,bP2Hit,opponent); + + + bool bGuard = false; - //First lets check us if we hit the opponent + + //Is the opponent guarding this hit? + if( opponent->GetDistX() <= GetAttackDist() && IsHitDef() && + opponent->IsHoldBack() ) + { + HandleGuard( opponent , bP1Hit); + bGuard = true; + } + + + if( bP1Hit && IsHitDef() && !bGuard ) + HandleHit( opponent ); + + +} + +/* +================================================================================ +Check aginst the opponent for a hit +================================================================================ +*/ +void CPlayer::CheckHitCollid(bool &p1Hit,bool p2Hit,CPlayer *opponent) +{ + //First lets check us if we hit the opponent u16 nClsnNumberOfP1=0; u16 nClsnNumberOfP2=0; + p1Hit = false; + p2Hit = false; + ClsnRECT rectP1; ClsnRECT rectP2; @@ -517,7 +553,7 @@ void CPlayer::HandleHitDef(CPlayer *oppo rectP2=opponent->ConvertClsnRectToGlobalRect(p2Clsn[j]); if( CheckClsn1Collision(rectP1,rectP2) ) { - bP1Hit=true; + p1Hit=true; break; } } @@ -544,7 +580,7 @@ void CPlayer::HandleHitDef(CPlayer *oppo rectP1=ConvertClsnRectToGlobalRect(p1Clsn[j]); if( CheckClsn1Collision(rectP2,rectP1) ) { - bP2Hit=true; + p2Hit=true; break; } } @@ -553,10 +589,20 @@ void CPlayer::HandleHitDef(CPlayer *oppo } } + - if( bP1Hit && bHitDef ) - { +} + +/* +================================================================================ +Handles a hit +PlayHit sound, apply hit pause, Create spark.... +================================================================================ +*/ +void CPlayer::HandleHit(CPlayer *opponent) +{ opponent->SetInHitVar(myGetHitVar); + if(myGetHitVar.groundtype == 3) opponent->ChangeState(5070); else @@ -579,7 +625,9 @@ void CPlayer::HandleHitDef(CPlayer *oppo pause->SetPauseTime( myGetHitVar.pauseTime ); mugen->GetEngine()->AddObject( pause ); - CExplod *explod = new CExplod( new CSffManager(mugen->GetEngine()->GetEngineSff() ), + CSffManager *p = myGetHitVar.bPlayerSpark ? GetSff() : mugen->GetEngine()->GetEngineSff(); + + CExplod *explod = new CExplod( new CSffManager( p ), myGetHitVar.spark_nr, opponent ); explod->SetPosX( myGetHitVar.spark_x); @@ -587,12 +635,47 @@ void CPlayer::HandleHitDef(CPlayer *oppo mugen->GetEngine()->AddObject( explod ); - bHitDef=false; + bHitDef=false; + +} +/* +================================================================================ + +================================================================================ +*/ +void CPlayer::HandleGuard(CPlayer *opponent,bool bP1Hit) +{ + if( opponent->GetStateNumber() < 120 || opponent->GetStateNumber() > 140 ) + opponent->ChangeState(120); + + if( bP1Hit ) + { + + /*Play guard sound*/ + if( myGetHitVar.bGuardPlayerSnd ) + PlaySnd(myGetHitVar.guard_snd_grp,myGetHitVar.guard_snd_item); + else + mugen->GetEngine()->PlaySnd( myGetHitVar.guard_snd_grp,myGetHitVar.guard_snd_item ); + + /*Apply guard spark*/ + + CSffManager *p = myGetHitVar.bPlayerSpark ? GetSff() : mugen->GetEngine()->GetEngineSff(); - - } - - + CExplod *explod = new CExplod( new CSffManager( p ), + myGetHitVar.guard_spark_no, opponent ); + + explod->SetPosX( myGetHitVar.spark_x); + explod->SetPosY( myGetHitVar.spark_y); + + mugen->GetEngine()->AddObject( explod ); + + /*Apply guard pause */ + CPause *pause = new CPause(); + pause->SetPauseTime( myGetHitVar.guardPauseTime); + mugen->GetEngine()->AddObject( pause ); + + bHitDef=false; + } } /* ================================================================================ @@ -646,53 +729,16 @@ funcion is in its name ;-) */ bool CPlayer::CheckClsn1Collision(ClsnRECT Clsn1,ClsnRECT Clsn2) { - int Clsn1Width = abs(Clsn1.x - Clsn1.w) / 2; - int Clsn1Height = abs(Clsn1.y - Clsn1.h) / 2; - - int Clsn2Width = abs(Clsn2.x - Clsn2.w) /2; - int Clsn2Height = abs(Clsn2.y - Clsn2.h) /2; - - int Clsn1Dx= 0; - int Clsn1Dy= 0; - int Clsn2Dx=0; - int Clsn2Dy=0; + //taken from SDL_CollideBoundingBox from the SDL Collid lib + if(Clsn2.x + Clsn2.w < Clsn1.x) return 0; //just checking if their + if(Clsn2.x > Clsn1.x + Clsn1.w) return 0; //bounding boxes even touch - - //calculate the middle x value of the box - if( Clsn1.x < Clsn1.w) - Clsn1Dx = Clsn1.x + ( Clsn1Width ); - else - Clsn1Dx = Clsn1.w + ( Clsn1Width ); - - if( Clsn2.x < Clsn2.w) - Clsn2Dx = Clsn2.x + ( Clsn2Width ); - else - Clsn2Dx = Clsn2.w + ( Clsn2Width ); - - //calculate the middle y value of the box - if( Clsn1.y < Clsn1.h ) - Clsn1Dy = Clsn1.y + ( Clsn1Height ); - else - Clsn1Dy = Clsn1.h + ( Clsn1Height ); - - if( Clsn2.y < Clsn2.h ) - Clsn2Dy = Clsn2.y + ( Clsn2Height ); - else - Clsn2Dy = Clsn2.h + ( Clsn2Height ); - - //m_pVideoSystem->DrawLine(Clsn2Dx, Clsn2Dy ,Clsn1Dx,Clsn1Dy,255,255,255); - - //calculate the distance between the two clsn boxes - int DistX= abs( Clsn1Dx - Clsn2Dx ); - int DistY= abs( Clsn1Dy - Clsn2Dy ); - - - if ( (DistX <= Clsn1Width) && (DistY <= Clsn2Height) ) - return true; - + if(Clsn2.y + Clsn2.h < Clsn1.y) return 0; + if(Clsn2.y > Clsn1.y + Clsn1.h) return 0; + + return 1; - return false; - + } /* @@ -724,11 +770,9 @@ void CPlayer::HandlePushBehavior(CPlayer //calculate the distance between the axis //Tood:this should only checked for nearenemy in teammode - if(bRightFaced) - nDistanceX = opponent->GetPosX()- GetPosX(); - else - nDistanceX = GetPosX() - opponent->GetPosX(); - + CalculateValues( opponent ); + + //This is for turning if( (nDistanceX < 0) && ( y == nGround ) && (nCurrAnimNumber != 5 ) && (nCurrStateNumber != 52) ) @@ -760,6 +804,20 @@ void CPlayer::HandlePushBehavior(CPlayer } } +/* +================================================================================ +Calculates values for triggers like P2Dist , p2Body dist ... +================================================================================ +*/ +void CPlayer::CalculateValues(CPlayer *opponent) +{ + if(bRightFaced) + nDistanceX = opponent->GetPosX()- GetPosX(); + else + nDistanceX = GetPosX() - opponent->GetPosX(); + + nDistanceY = -GetPosY()+opponent->GetPosY(); +} /* @@ -812,14 +870,13 @@ ToDo: Handle interaction with other play void CPlayer::Think() { DrawPlayer(); - // ShowClsn(); +// ShowClsn(); if( bPause ) return; - m_pInputProcessor->Update( inputs, m_pEngine->GetJoyCount(), m_pEngine->GetJoyInfo() ); - m_pCmdManager->Update( inputs, bRightFaced ); - + m_pCmdManager->Update( inputs, bRightFaced ); + m_pInputProcessor->Update( inputs, m_pEngine->GetJoyCount(), m_pEngine->GetJoyInfo() ); CheckGlobalStatus(); @@ -891,7 +948,8 @@ void CPlayer::Debug() m_pVideoSystem->DrawText(0,40,"x=%3f,y=%3f | xVel = %2.3f,yVel = %2.3f",x-XMAX/2,y-nGround,xVel,yVel); m_pVideoSystem->DrawText(0,50,"Name=%s",defInfo.info.strDisplayName); m_pVideoSystem->DrawText(0,60,"Life=%i | Power= %i",nLife,nPower); - m_pVideoSystem->DrawText(0,70,"Ctrl = %i | Command = %s | %i",bCtrl,strCommand,InHitVar.recovertime); + m_pVideoSystem->DrawText(0,70,"Ctrl = %i | Command = %s | facing %i ",bCtrl,strCommand,bRightFaced ? 1 : -1 ); + m_pVideoSystem->DrawText(0,80,"P2Dist %f %f", nDistanceX , nDistanceY ); } @@ -914,7 +972,7 @@ void CPlayer::ShowClsn() { ClsnRECT temp=ConvertClsnRectToGlobalRect(pData[i]); if(!pData[i].bClsn1) - m_pVideoSystem->AddRect(temp.x,temp.y,temp.w,temp.h,0,0,255,128,nSprPrio,CVideoSystem::RECT_FILLED); + m_pVideoSystem->AddRect(temp.x,temp.y,temp.w+temp.x,temp.h+temp.y,0,0,255,128,nSprPrio,CVideoSystem::RECT_FILLED); } //draw Clsn1 box first @@ -922,7 +980,7 @@ void CPlayer::ShowClsn() { ClsnRECT temp=ConvertClsnRectToGlobalRect(pData[i]); if(pData[i].bClsn1) - m_pVideoSystem->AddRect(temp.x,temp.y,temp.w,temp.h,255,0,0,128,nSprPrio,CVideoSystem::RECT_FILLED); + m_pVideoSystem->AddRect(temp.x,temp.y,temp.w+temp.x,temp.h+temp.y,255,0,0,128,nSprPrio,CVideoSystem::RECT_FILLED); } //draw width bar of the player @@ -955,7 +1013,7 @@ void CPlayer::ResetPlayer() //rest GetHitVar memset(&myGetHitVar,0,sizeof(myGetHitVar)); - ChangeState(191); + ChangeState(0); } @@ -1105,6 +1163,7 @@ float CPlayer::GetVelY(){return yVel;} float CPlayer::GetFront(){if(bRightFaced) return x+nFront; else return x-nBack;} float CPlayer::GetBack(){if(bRightFaced) return x-nBack; else return x+nFront;} bool CPlayer::GetRightFaced(){return bRightFaced;} +bool CPlayer::IsHitDef() {return bHitDef;} s16 CPlayer::GetLife(){return nLife;} u8 CPlayer::GetMoveType(){return nMoveType;} u8 CPlayer::GetStateType(){return nStateType;} @@ -1125,10 +1184,10 @@ void CPlayer::SetGroundValue(float yLim float CPlayer::GetGroundValue() {return nGround;} bool CPlayer::IsAnimLooped() {return m_pSffManager->isLooped();} -u16 CPlayer::GetCurrentImageNr() {return m_pSffManager->GetCurrentImageNr();} -u16 CPlayer::GetCurrentImageTime() {return m_pSffManager->GetCurrentImageTime();} -u16 CPlayer::GetCurrentAnimTime() {return m_pSffManager->GetCurrentAnimTime();} -u16 CPlayer::GetDuringTime() {return m_pSffManager->GetDuringTime();} +u32 CPlayer::GetCurrentImageNr() {return m_pSffManager->GetCurrentImageNr();} +u32 CPlayer::GetCurrentImageTime() {return m_pSffManager->GetCurrentImageTime();} +u32 CPlayer::GetCurrentAnimTime() {return m_pSffManager->GetCurrentAnimTime();} +u32 CPlayer::GetDuringTime() {return m_pSffManager->GetDuringTime();} void CPlayer::SetPosX(float xPos){x=320/2+xPos;} @@ -1142,6 +1201,10 @@ void CPlayer::VelAddX(float xvel){xVel+= void CPlayer::VelAddY(float yvel){yVel+=yvel;} void CPlayer::VelMulX(float xvel){xVel*=xvel;} void CPlayer::VelMulY(float yvel){yVel*=yvel;} +float CPlayer::GetAttackDist() {return nGuardDist; } +float CPlayer::GetDistX() {return nDistanceX;} +float CPlayer::GetDistY() {return nDistanceY;} +void CPlayer::SetAttackDist(float dist){nGuardDist=dist;} void CPlayer::SetDebug(bool bDebug){bDebugInfo=bDebug;} void CPlayer::SetCtrl(bool ctrl){bCtrl=ctrl;} |