//------------------------------------------------------------------------------ bool CManouver::OnLoop() { if( Type == M_WAIT ) { if( StartTime == 0 ) { StartTime = SDL_GetTicks(); } if(static_cast<unsigned int>(StartTime + Wait) < SDL_GetTicks()) { StartTime = 0; return true; } } else if( Type == M_MOVE_LEFT ) { Parent->MoveLeft = true; Parent->MoveRight = false; return true; } else if( Type == M_MOVE_RIGHT ) { Parent->MoveLeft = false; Parent->MoveRight = true; return true; } else if( Type == M_MOVE_UP ) { Parent->MoveUp = true; Parent->MoveDown = false; return true; } else if( Type == M_MOVE_DOWN ) { Parent->MoveUp = false; Parent->MoveDown = true; return true; } else if( Type == M_STOP_MOVE ) { Parent->MoveLeft = false; Parent->MoveRight = false; Parent->MoveUp = false; Parent->MoveDown = false; return true; } else if( Type == M_TURN ) { if( Parent->TargetAngle == 999 ){ // Take shorter path around the circle if( Parent->Angle == 180 && Wait < 0 ) { Parent->Angle = -180; } else if( Parent->Angle == -180 && Wait >= 0 ) { Parent->Angle = 180; } // Useful to know from which direction we are coming to target OriginalAngle = Parent->Angle; // This is where we aim at Parent->TargetAngle = Wait; } // It's hard to hit the target angle precicely, so in case we go over a bit, count it a hit if( (OriginalAngle <= Parent->TargetAngle && Parent->TargetAngle <= Parent->Angle ) || (OriginalAngle >= Parent->TargetAngle && Parent->TargetAngle >= Parent->Angle ) || (Parent->TargetAngle == 180 && Parent->Angle < -175 ) || (Parent->TargetAngle == -180 && Parent->Angle > 175 ) ) { if( Parent->TargetAngle == 0 ){ Parent->MoveLeft = false; Parent->MoveRight = true; Parent->MoveUp = false; Parent->MoveDown = false; Parent->SpeedY = Parent->AccelY = 0; } else if( Parent->TargetAngle == 90 ) { Parent->MoveLeft = false; Parent->MoveRight = false; Parent->MoveUp = false; Parent->MoveDown = true; Parent->SpeedX = Parent->AccelX = 0; } else if( Parent->TargetAngle == -90 ) { Parent->MoveLeft = false; Parent->MoveRight = false; Parent->MoveUp = true; Parent->MoveDown = false; Parent->SpeedX = Parent->AccelX = 0; } else if( Parent->TargetAngle == 180 || Parent->TargetAngle == -180 ) { Parent->MoveLeft = true; Parent->MoveRight = false; Parent->MoveUp = false; Parent->MoveDown = false; Parent->SpeedY = Parent->AccelY = 0; } Parent->Angle = Parent->TargetAngle; Parent->TargetAngle = 999; return true; } } else if( Type == M_AIM && !Aim_Set) { float Speed = Parent->MaxSpeedX; if( TargetX != -1 && TargetY != -1 ) { float YDifference = static_cast<float>(TargetY - Parent->Y); float XDifference = static_cast<float>(TargetX - Parent->X); int AngleToTarget = XDifference > 0.0 ? (int)(atan( YDifference / XDifference ) * 180 / PI) : (int)(atan( YDifference / XDifference ) * 180 / PI) + 180; Parent->SpeedX = cos(DegreesToRadian(AngleToTarget)) * Speed; Parent->SpeedY = sin(DegreesToRadian(AngleToTarget)) * Speed; Aim_Set = true; //Should be only set once, then keeps going to that direction } else { Type = M_MOVE_LEFT; //Currently only enemy uses this, so the default moving direction is meaningful to be left } } else if( Type == M_FOLLOW ) { float Speed = Parent->MaxSpeedX; if( TargetX != -1 && TargetY != -1 ) { float YDifference = static_cast<float>(TargetY+15 - Parent->Y); float XDifference = static_cast<float>(TargetX+10 - Parent->X); int AngleToTarget = XDifference > 0.0 ? (int)(atan( YDifference / XDifference ) * 180 / PI) : (int)(atan( YDifference / XDifference ) * 180 / PI) + 180; Parent->SpeedX = cos(DegreesToRadian(AngleToTarget)) * Speed; Parent->SpeedY = sin(DegreesToRadian(AngleToTarget)) * Speed; } } return false; }
void CaptureTheFlag::Initialize() { D3DXVECTOR3 startPositions[4]; startPositions[0] = D3DXVECTOR3(0,24.7f,-20); startPositions[1] = D3DXVECTOR3(0,24.7f,20); startPositions[2] = D3DXVECTOR3(-5,24.7f,-20); startPositions[3] = D3DXVECTOR3(-5,24.7f,20); this->mNet->SetStartPosistions(startPositions, 4); D3DXVECTOR3 forwardVectors[4]; for(int i = 0; i<4;i++) { if(i%2 == 0) forwardVectors[i] = D3DXVECTOR3(0,0,1); else forwardVectors[i] = D3DXVECTOR3(0,0,-1); } /* this if we want all to use TRD-Camera and forward vector at center D3DXVECTOR3 center = D3DXVECTOR3(0,0,0); for(int i = 0; i<4;i++) { D3DXVECTOR3 startPosXZ = D3DXVECTOR3(startPositions[i].x, 0, startPositions[i].z); D3DXVECTOR3 temp = center - startPosXZ; D3DXVECTOR3 tempN; D3DXVec3Normalize(&tempN, &temp); forwardVectors[i] = tempN; } */ D3DXVECTOR3 centerPlatform = D3DXVECTOR3(0,10,0); mGe->GetCamera()->setPosition(D3DXVECTOR3(0, 25, -10)); mGe->GetCamera()->LookAt(centerPlatform); this->mNet->SetStartForwardVectors(forwardVectors, 4); CTFInfo* gmi = (CTFInfo*)this->mServerInfo.GetGameModeInfo(); this->mNumberOfRounds = gmi->GetNumRounds(); this->mPlatform = new Map("Media/CTFMap1.obj", centerPlatform); this->mPlatform->SetShrinkValue(0.0f); this->mEnemyFlag = new FlagCTF(mGe->CreateAnimatedMesh("Media/FlagRed.ani", D3DXVECTOR3(0, 20, 25)), D3DXVECTOR3(0, 20, 25)); this->mEnemyFlag->GetMesh()->Scale(0.66f); this->mEnemyFlag->GetMesh()->RotateAxis(D3DXVECTOR3(0.0f, 1.0f, 0.0f), DegreesToRadian(90)); this->mEnemyFlag->GetMesh()->LoopSeamless(); this->mFriendlyFlag = new FlagCTF(mGe->CreateAnimatedMesh("Media/FlagBlue.ani", D3DXVECTOR3(0, 20, -25)), D3DXVECTOR3(0, 20, -25)); this->mFriendlyFlag->GetMesh()->Scale(0.66f); this->mFriendlyFlag->GetMesh()->RotateAxis(D3DXVECTOR3(0.0f, 1.0f, 0.0f), DegreesToRadian(-90)); this->mFriendlyFlag->GetMesh()->LoopSeamless(); this->mRedFlag = this->mEnemyFlag; this->mBlueFlag = this->mFriendlyFlag; /*D3DXVECTOR3 startPositions[4]; startPositions[0] = D3DXVECTOR3(0,24.7f,-14); startPositions[1] = D3DXVECTOR3(0,24.7f,14); startPositions[2] = D3DXVECTOR3(0,24.7f,-12); startPositions[3] = D3DXVECTOR3(0,24.7f,12);*/ this->mNet->SetStartPosistions(startPositions, 4); //D3DXVECTOR3 forwardVectors[4]; for(int i = 0; i<4;i++) { if(i%2 == 0) forwardVectors[i] = D3DXVECTOR3(0,0,1); else forwardVectors[i] = D3DXVECTOR3(0,0,-1); } /* this if we want all to use TRD-Camera and forward vector at center D3DXVECTOR3 center = D3DXVECTOR3(0,0,0); for(int i = 0; i<4;i++) { D3DXVECTOR3 startPosXZ = D3DXVECTOR3(startPositions[i].x, 0, startPositions[i].z); D3DXVECTOR3 temp = center - startPosXZ; D3DXVECTOR3 tempN; D3DXVec3Normalize(&tempN, &temp); forwardVectors[i] = tempN; } this->mNet->SetForwardVectors(forwardVectors, 4); mGe->GetCamera()->setPosition(D3DXVECTOR3(0, 25, -10)); mGe->GetCamera()->LookAt(centerPlatform); this->mNumberOfRounds = 3; this->mPlatform = new Map("Media/KOTHMap1.obj", centerPlatform); this->mPlatform->SetShrinkValue(0.0f); Vector3 hotZone = Vector3(0.0f,20.2f,0.0f); this->mPlatform->SetHotZonePosition(hotZone); float radius = 5.4f; this->mPlatform->SetHotZoneRadius(radius); float maxTime; if(this->mGameMode == KOTH) maxTime = 10.0f; else maxTime = 30.0f; this->mPlatform->SetMaxTimeInHotZone(maxTime); */ this->mLights[0] = mGe->CreateLight(D3DXVECTOR3(0, 50, 0)); this->mLights[1] = mGe->CreateLight(D3DXVECTOR3(0, 50, -25)); this->mLights[2] = mGe->CreateLight(D3DXVECTOR3(0, 50, 25)); this->mLights[3] = mGe->CreateLight(D3DXVECTOR3(10, 50, 0)); this->mLights[4] = mGe->CreateLight(D3DXVECTOR3(-10, 50, 0)); for(int i = 0; i < 5; i++) { this->mLights[i]->SetIntensity(30.0f); this->mLights[i]->SetLookAt(D3DXVECTOR3(0,10,0)); } this->mIGM = new InGameMenu(this->mGe); //this->mChooseTeamMenu = new ChooseTeamMenu(this->mGe); //generate memory leaks this->mTimeElapsedText = this->mGe->CreateText( "", D3DXVECTOR2(15.0f, 10.0f), 1.0f, "Media/Fonts/1"); }