//-------------------------------------------------------------------------------- // Read Crash Sound //-------------------------------------------------------------------------------- void CVehicleSound::ReadCrashSounds(SStream *st) { CAudioManager *snd = globals->snd; char txt[128]; char fn[64]; char go = 1; Tag tg = 0; while (go) { ReadString(txt,128,st); if (1 == sscanf(txt," gear , %s",fn)) { snd->ReserveSoundBUF('crgr',fn,0) ; continue; } if (1 == sscanf(txt," body , %s",fn)) { snd->ReserveSoundBUF('crby',fn,0); continue; } if (1 == sscanf(txt," shok , %s",fn)) { snd->ReserveSoundBUF('shok',fn,0); continue; } go = 0; } return; }
void CPlasmaShot::SetUp(int shotowner, CGameObject * projectileowner, float damage, float damageradius, float velocity) { // Save the type of object that shot this weapon SetOwner(shotowner); // Damage of the projectile SetDamage((int)damage); m_ProjectileOwner = projectileowner; if(shotowner == PLAYER_SHOT || FRIENDLY_SHOT) { m_PlasmaExplode = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_EXP_TINY], 9); m_PlasmaInAir = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_PLASMAINAIR], 1); } else if(shotowner == ENEMY_SHOT) { m_PlasmaExplode = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_EXP_TINY], 7); m_PlasmaInAir = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_PLASMAINAIR], 6); } m_PlasmaInAir->Play3DAudio(10.0f, 10000.0f, 100); m_Active = true; m_Velocity = velocity; m_DamageRadius = damageradius; m_CreationTime = g_time; m_LifeTime = 3.0f; // Get the position of the object GetPosition(&m_CurPosition, 0); m_LastPosition = m_CurPosition; }
//-------------------------------------------------------------------------------- // SetSound with parameters //-------------------------------------------------------------------------------- void CVehicleSound::SetEngineSound(Tag ids,char *fn) { CAudioManager *snd = globals->snd; CSoundBUF *sbf = snd->ReserveSoundBUF(ids,fn,sample); sbf->SetPMAX(pMax); sbf->SetPMIN(pMin); return; }
bool CGameOverState::Input( void ) { CController* pCtrl = CController::GetInstance(); CAudioManager* pAUM = CAudioManager::GetInstance(); if( pCtrl->Cancel() ) { pAUM->Play(SFX::CURSOR); CGame::GetInstance()->GetState()->ChangeState( CHomeMenuState::GetInstance() ); return true; } if (pCtrl->Confirm()) { pAUM->Play(SFX::CURSOR); switch(m_nSelect) { case EXIT: CGame::GetInstance()->GetState()->ChangeState( CHomeMenuState::GetInstance() ); return true; break; } } return true; }
cGameStateObject* cGameStateIntro::update(double timeDifference, Camera &cam, CGameData &data, CGraphics &con){ m_event = EVENT_GO_NO_WHERE; //initialize data first time this state is called static bool bFirstTime = true; if(bFirstTime == true){ CAudioManager *pAudio = CAudioManager::Instance(); if(pAudio->IsPlaying(0) == false) //nature sounds pAudio->PlaySoundClip(0, 1); if(pAudio->IsPlaying(13) == false) //birds pAudio->PlaySoundClip(13, 1); bFirstTime = false; } //keystrokes if(::GetActiveWindow() == data.m_hWnd && keyDown(VK_SPACE)) m_event = EVENT_GO_MAIN; for(unsigned int i=0; i< m_TE.size(); i++){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
DWORD WINAPI CAudioManager::WorkThread( LPVOID lparam ) { CAudioManager *pThis = (CAudioManager *)lparam; while (pThis->m_bIsWorking) pThis->sendRecordBuffer(); return -1; }
//-------------------------------------------------------------------------------- // SetSound with parameters //-------------------------------------------------------------------------------- void CVehicleSound::SetSound(Tag ids,char *fn) { CAudioManager *snd = globals->snd; CSoundBUF *sbf = snd->ReserveSoundBUF(ids,fn,sample); sample = 0; sbf->SetGain(volu); volu = 1; return; }
//--------------------------------------------------------------------- // Add a sound by tag to the list //--------------------------------------------------------------------- void CSoundOBJ::AddSound(int No,Tag idn) { CAudioManager *snd = globals->snd; CSoundBUF *sbf = snd->GetSoundBUF(idn); if (sounds[No]) gtfo("Sound conflict"); sounds[No] = sbf; if (0 == sbf) return; if (No > sEnd) sEnd = No; return; }
//--------------------------------------------------------------------- // destroy this object //--------------------------------------------------------------------- CSoundOBJ::~CSoundOBJ() { CAudioManager *snd = globals->snd; snd->DeleteSource(alSRC); for (int k=0; k < ENGINE_MAX_SOUND; k++) { CSoundBUF *sbf = sounds[k]; if (0 == sbf) continue; sbf->Release(); } }
cGameStateObject* cGameStateFireControl::update(double timeDifference){ m_event = EVENT_GO_NO_WHERE; //loads mouse position into global variable. POINT pt; POINT *ppt = &pt; ::GetCursorPos(ppt); RECT rct; ::GetWindowRect(g_hWnd, &rct); g_Global.g_mouse.x = pt.x - rct.left; g_Global.g_mouse.y = pt.y - rct.top; CGameData *pData = CGameData::Instance(); pData->Update(timeDifference); CAudioManager *pAudio = CAudioManager::Instance(); static double timeDiffTotal = 0; timeDiffTotal += timeDifference; if(timeDiffTotal > .1){ timeDiffTotal = 0; if(keyDown(VK_SPACE) && ::GetActiveWindow() == g_hWnd){ CTorpedo torpedo(pData->m_Player.m_heading, pData->m_Player.m_heading, pData->m_Player.m_posX, pData->m_Player.m_posY); pData->m_torpedos.push_back(torpedo); //there are 2 torpedo sounds...play 1..if busy play 2 if(pAudio->IsPlaying(SOUND_TORPEDO1) == false) pAudio->PlaySoundClip(SOUND_TORPEDO1, 0); else{ if(pAudio->IsPlaying(SOUND_TORPEDO2) == false) pAudio->PlaySoundClip(SOUND_TORPEDO2, 0); } } //process short cut buttons if(g_Global.g_mouse.y > 10 && g_Global.g_mouse.y < 130 && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){ if(g_Global.g_mouse.x > 10 && g_Global.g_mouse.x < 110) m_event = EVENT_GO_SONAR; else if(g_Global.g_mouse.x > 120 && g_Global.g_mouse.x < 220) m_event = EVENT_GO_RADAR; else if(g_Global.g_mouse.x > 230 && g_Global.g_mouse.x < 330) m_event = EVENT_GO_CONTROL; else if(g_Global.g_mouse.x > 804 && g_Global.g_mouse.x < 904) m_event = EVENT_GO_STATUS; else if(g_Global.g_mouse.x > 914 && g_Global.g_mouse.x < 1014) m_event = EVENT_GO_CHART; } } for(unsigned int i=0; i< m_TE.size(); i++){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
CGameState* CStateIntro::Update(double timeDifference){ m_event = GO_NO_WHERE; if(g_audio.IsPlaying(2) == false) g_audio.PlaySoundClip(2, 1); //process this code for the very first Update(...) call static bool bFirstTime = false; if(bFirstTime == false){ bFirstTime = true; } //check user interface INPUT_RECORD InRec = GetConsoleInputInfo(); //key press events if(InRec.EventType == KEY_EVENT){ m_event = GO_MENU;//press any key } //mouse events else if(InRec.EventType == MOUSE_EVENT){ //left mouse if(InRec.Event.MouseEvent.dwButtonState == 0x01){ } //right mouse else if(InRec.Event.MouseEvent.dwButtonState == 0x02){ } //mouse move else if(InRec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED){ m_mouseX = InRec.Event.MouseEvent.dwMousePosition.X; m_mouseY = InRec.Event.MouseEvent.dwMousePosition.Y; } } //animated border if(m_timerBorder.GetTimer(.05)== true){ m_borderCount++; if(m_borderCount > 205) m_borderCount = 0; } //game state transition code...very important for(unsigned int i=0; i< m_TE.size(); ++i){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
//--------------------------------------------------------------------- // Play a sound //--------------------------------------------------------------------- void CSoundSRC::Play(CSoundBUF *sbf) { CAudioManager *snd = globals->snd; //---Stop current sound if any ---------------- alSourceStop(alSRC); alSourcei (alSRC, AL_BUFFER, 0); sPlay = sbf; //-- Play the current sound ------------------- if (0 == sbf) return; ALint buf = sPlay->GetBuffer(); alSourcei(alSRC,AL_BUFFER,buf); alSourcei(alSRC,AL_LOOPING,loop); alSourcePlay(alSRC); snd->Check(); return; }
//--------------------------------------------------------------------- // Loop current sound from offset position //--------------------------------------------------------------------- void CSoundOBJ::PlayFromOffset(int No) { CAudioManager *snd = globals->snd; ALint state; alGetSourcei (alSRC, AL_SOURCE_STATE, &state); if ((sPlay == sounds[No]) && (state == AL_PLAYING)) return; sPlay = sounds[No]; if (0 == sPlay) return; offset = sPlay->GetOffset(); alSourcei(alSRC,AL_BUFFER, sPlay->GetBuffer()); alSourcei(alSRC,AL_SAMPLE_OFFSET,offset); alSourcei(alSRC,AL_LOOPING,false); alSourcef(alSRC,AL_PITCH,pitch); alSourcePlay(alSRC); snd->Check(); return; }
/************************************* U P D A T E *****************************************/ cGameStateObject* CGameStatePlay::update(double timeDifference){ m_event = EVENT_GO_NO_WHERE; static double timeDiffTotal = 0; static double thingTimeDiff = 0; //GRAPHIC_IMAGE gi; int spriteID; int frameMax = 0; int frameCount = 0; //start ambient sound loop CAudioManager *pAudio = CAudioManager::Instance(); if(pAudio->IsPlaying(SOUND_ANCHORS) == false) pAudio->PlaySoundClip(SOUND_ANCHORS, 0); //loads mouse position into global variable. POINT pt; POINT *ppt = &pt; ::GetCursorPos(ppt); RECT rct; ::GetWindowRect(g_hWnd, &rct); g_Global.g_mouse.x = pt.x - rct.left; g_Global.g_mouse.y = pt.y - rct.top; //accept...go to control if(g_Global.g_mouse.x > 289 && g_Global.g_mouse.x < 407 && g_Global.g_mouse.y > 683 && g_Global.g_mouse.y < 718 && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){ m_event = EVENT_GO_CONTROL; } //reject..return to menu if(g_Global.g_mouse.x > 626 && g_Global.g_mouse.x < 743 && g_Global.g_mouse.y > 683 && g_Global.g_mouse.y < 718 && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){ m_event = EVENT_GO_SELECT; } //game state transition code...very important for(unsigned int i=0; i< m_TE.size(); i++){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
void CTrackingMissile::SetUp(int shotOwner, int damage, bool left, float damageradius, float accuracy, CGameObject * projectileowner) { // Save the type of object that shot this weapon SetOwner(shotOwner); m_Tracking = false; m_UpdatePeriod = accuracy; m_SlerpScale = 1.0f / m_UpdatePeriod; m_DamageRadius = damageradius; // Damage of the projectile SetDamage(damage); m_Velocity = 40.0f; // Pointer to the game object that owns this shot m_ProjectileOwner = projectileowner; if(shotOwner == PLAYER_SHOT) { m_MissileExplode = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_EXP_TINY], 9); m_MissileInAir = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_MISSILEINAIR], 7); } else if(shotOwner == ENEMY_SHOT) { m_MissileExplode = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_EXP_TINY], 7); m_MissileInAir = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_MISSILEINAIR], 6); } m_MissileInAir->Play3DAudio(10.0f, 10000.0f, 75); m_Active = true; m_CreationTime = g_time; m_LifeTime = 10.0f; CObjFrame temp = *m_RenderObj.GetFrame(0); temp.GetOrientation(&m_Q0); m_Q2 = m_Q0; temp.RotateLocalX(-PI / 6.0f); temp.GetOrientation(&m_Q1); // Get the position of the object GetPosition(&m_CurPosition, 0); m_LastPosition = m_CurPosition; }
//===================================================================================== // JS: Sound Buffer: An AL buffer dedicated to one sound // SoundBUF are managed by CAudioManager in a buffer cache. Do not delete them. //===================================================================================== CSoundBUF::CSoundBUF(Tag t, char *nf) { CAudioManager *snd = globals->snd; user = 1; idn = t; offset = 0; nfile = 0; alSRC = 0; TagToString(itag,t); ALuint buf; alGenBuffers(1,&buf); alBUF = buf; snd->Check(); snd->LoadFile(this,nf); snd->IncBUF(); gain = 1; pMin = 1; pMax = 1; }
//--------------------------------------------------------------------- // Init sound object //--------------------------------------------------------------------- void CSoundOBJ::Init(Tag t, SVector &pos) { CAudioManager *snd = globals->snd; sEnd = 0; idn = t; sPlay = 0; gain = 1; pitch = 1; loop = false; offset = 0; for (int k=0; k<8; k++) sounds[k] = 0; alGenSources (1, &alSRC); snd->Check(); snd->IncSRC(); alSource3f(alSRC,AL_POSITION,pos.x,pos.y,pos.z); alSourcef (alSRC,AL_REFERENCE_DISTANCE,8.0f); snd->Check(); for (int k=0; k<ENGINE_MAX_SOUND; k++) sounds[k] = 0; }
//--------------------------------------------------------------------- // Play the requested sound in the indicated mode // NOTE: Same sound request does nothing. Use changeMode to // change playing conditions // TODO: Check if same sound is playing //--------------------------------------------------------------------- void CSoundOBJ::Play(int No) { CAudioManager *snd = globals->snd; ALint state; alGetSourcei (alSRC, AL_SOURCE_STATE, &state); if ((sPlay == sounds[No]) && (state == AL_PLAYING)) return; //---Stop current sound if any ---------------- StopSound(); //-- Play the current sound ------------------- sPlay = sounds[No]; if (0 == sPlay) return; offset = sPlay->GetOffset(); ALint buf = sPlay->GetBuffer(); alSourcei(alSRC,AL_BUFFER,buf); alSourcei(alSRC,AL_LOOPING,false); alSourcef(alSRC,AL_GAIN,gain); alSourcef(alSRC,AL_PITCH,pitch); alSourcei(alSRC,AL_SAMPLE_OFFSET,offset); alSourcePlay(alSRC); snd->Check(); }
void Shutdown() { CLog *pLog = CLog::Instance(); CAudioManager *pAudio = CAudioManager::Instance(); pLog->Log("************ Shutting Down ************"); // Properly shut down the current game object first g_pCurrent->deactivate(); delete g_pStatePlay; delete g_pStateMain; delete g_pStateIntro; delete g_pStateHistory; delete g_pStateReload; delete g_pStateCredits; delete g_pStateSelect; delete g_pStateAwards; delete g_pStateWin; delete g_pStateLose; delete g_pStateStatus; delete g_pStateChart; delete g_pStateControl; delete g_pStateEnd; delete g_pStateScope; delete g_pStateSonar; delete g_pStateFireControl; delete g_pStateRadar; pLog->Log("Game state pointers deleted!"); pAudio->KillAll(); ::ShowCursor(false); //::Sleep(2000); //::ShowCursor(true); //turn mouse cursor back on pLog->Log("Audio sounds are all killed!"); pLog->Log("*************************************"); pLog->Log("Program ended!"); pLog->Log("*************************************"); // Kill the main window DestroyWindow( g_hWnd ); g_hWnd = NULL; }
//--------------------------------------------------------------------- // Store Flap positions // NOTE: for each position there is a corresponding keyframe // and the full range (0, 1) needs T seconds. //--------------------------------------------------------------------- void CAnimatedModel::InitFlap(int n,FLAP_POS *p,float time) { nPos = n; aPos = p; cPos = 0; int dg0 = p[0].degre; int dtv = p[n-1].degre - dg0; float dkf = float(1) / dtv; //----Compute positional keyframe in table ------------ for (int k=0; k != n; k++) {float kf = float(p[k].degre - dg0) * dkf; p[k].kFrame = kf; } //---Propagate the time constant to all flaps --------- aFlap.SetTime(time); //---Init sounds -------------------------------------- CAudioManager *snd = globals->snd; Tag id1 = '1flp'; CVector lef(-10,0,0); s1Flap = new CSoundOBJ(id1,lef); s1Flap->SetGain(0.4f); Tag id2 = '2flp'; CVector rit(+10,0,0); //MEMORY_LEAK_MARKER ("s2Flap"); s2Flap = new CSoundOBJ(id2,rit); //MEMORY_LEAK_MARKER ("s2Flap"); s2Flap->SetGain(0.4f); //---Init flap sounds -------------------------------- for (int k=1; k < n; k++) { Tag snn = 'Flp0' + k; CSoundBUF *sb1 = snd->GetSoundBUF(snn); if (sb1) s1Flap->SetSBUF(k,sb1); CSoundBUF *sb2 = snd->GetSoundBUF(snn); if (sb2) s2Flap->SetSBUF(k,sb2); } //---Dupplicate sound up to max ----------------------- s1Flap->FillFlaps(); s2Flap->FillFlaps(); return; }
cGameStateObject* cGameStateIntro::update(double timeDifference){ m_event = EVENT_GO_NO_WHERE; // if(keyDown(VK_SPACE) && ::GetActiveWindow() == g_hWnd){ // m_event = EVENT_GO_MAIN; // ::ShowCursor(true); // } //loads mouse position into global variable. //loads mouse position into global variable. POINT pt; POINT *ppt = &pt; ::GetCursorPos(ppt); RECT rct; ::GetWindowRect(g_hWnd, &rct); g_Global.g_mouse.x = pt.x - rct.left; g_Global.g_mouse.y = pt.y - rct.top; if(m_motionTimer.getTimer(0.005) == true){ m_motionCount += m_motionStep; } if(g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd) m_event = EVENT_GO_MAIN; //play music CAudioManager *pAudio = CAudioManager::Instance(); if(pAudio->IsPlaying(SOUND_REMEMBER) == false) pAudio->PlaySoundClip(SOUND_REMEMBER, 0); for(unsigned int i=0; i< m_TE.size(); i++){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
void CIonFlare::SetUp(int shotowner, CGameObject * projectileowner, float damage, float damageradius, float velocity) { // Save the type of object that shot this weapon SetOwner(shotowner); // Damage of the projectile SetDamage((int)damage); m_PlasmaExplode = g_AudioManager.CreateSound(g_AudioManager.samples[SFX_PLAYER_IONCANNON], 10); m_Active = true; m_Velocity = velocity; m_DamageRadius = damageradius; m_CreationTime = g_time; m_LifeTime = 3.0f; }
//****************************************************************************** void Initialize(){ // I N I T I A L I Z E //****************************************************************************** //define transition events for game states g_pStateIntro->AddTransitionEvent(GO_MENU, g_pStateMenu); g_pStateMenu->AddTransitionEvent(GO_QUIT, g_pStateQuit); g_pStateMenu->AddTransitionEvent(GO_RULES, g_pStateRules); g_pStateMenu->AddTransitionEvent(GO_SCORE, g_pStateScore); g_pStateMenu->AddTransitionEvent(GO_PLAY, g_pStatePlay); g_pStateRules->AddTransitionEvent(GO_MENU, g_pStateMenu); g_pStateScore->AddTransitionEvent(GO_MENU, g_pStateMenu); g_pStatePlay->AddTransitionEvent(GO_MENU, g_pStateMenu); g_pStatePlay->AddTransitionEvent(GO_SCORE, g_pStateScore);//if new high score //perform any required game state initialization g_pStateIntro->Initialize(); g_pStateMenu->Initialize(); g_pStateQuit->Initialize(); g_pStateRules->Initialize(); g_pStateScore->Initialize(); g_pStatePlay->Initialize(); //start game g_pCurrent = g_pStateIntro;//g_pStatePlay;// //initialize sound if audio initializes correctly if(g_audio.IsValidSound() == true){ g_audio.LoadSample(0, "sounds\\burns_fired.wav"); g_audio.LoadSample(1, "sounds\\Kids_Music_1.wav"); g_audio.LoadSample(2, "sounds\\Kids_Music_2.wav"); g_audio.LoadSample(3, "sounds\\Kids_Music_3.wav"); g_audio.LoadSample(4, "sounds\\victory_fanfare.mp3"); g_audio.LoadSample(5, "sounds\\burns_started.wav"); g_audio.LoadSample(6, "sounds\\burns_succeed.wav"); g_audio.LoadSample(7, "sounds\\truckhorn.wav"); g_audio.LoadSample(8, "sounds\\trucks021.wav"); } }
cGameStateObject* cGameStateChart::update(double timeDifference){ m_event = EVENT_GO_NO_WHERE; //loads mouse position into global variable. POINT pt; POINT *ppt = &pt; ::GetCursorPos(ppt); RECT rct; ::GetWindowRect(g_hWnd, &rct); g_Global.g_mouse.x = pt.x - rct.left; g_Global.g_mouse.y = pt.y - rct.top; CGameData *pData = CGameData::Instance(); //start ambient sound loop CAudioManager *pAudio = CAudioManager::Instance(); if(pAudio->IsPlaying(SOUND_AMBIENCE1) == false) pAudio->PlaySoundClip(SOUND_AMBIENCE1, 1); if(pData->m_bAttack == true){ if(pAudio->IsPlaying(SOUND_PING) == false) pAudio->PlaySoundClip(SOUND_PING,0); } if(pData->m_bDropped == true && pAudio->IsPlaying(SOUND_DEPTH_CHARGE2) == false) pAudio->PlaySoundClip(SOUND_DEPTH_CHARGE2, 0); //update all targets, sub, torpedos, and depth charges pData->Update(timeDifference); static double timeDiffTotal = 0; timeDiffTotal += timeDifference; if(timeDiffTotal > .11){ timeDiffTotal = 0; if(keyDown(VK_SPACE) == true && ::GetActiveWindow() == g_hWnd){ CLog *pLog = CLog::Instance(); pLog->Log("Tautog ..............."); pLog->Log("subX", (long)pData->m_Player.m_posX); pLog->Log("subY", (long)pData->m_Player.m_posY); pLog->Log("subH", pData->m_Player.m_heading); pLog->Log("subS", pData->m_Player.m_speed); pLog->Log(".............."); for(int i = 0; i < pData->m_targets.size(); ++i){ pLog->Log("target", i); pLog->Log("targetX", (long)pData->m_targets[i].m_posX); pLog->Log("targetY", (long)pData->m_targets[i].m_posY); pLog->Log("targetH", pData->m_targets[i].m_heading); pLog->Log("targetS", pData->m_targets[i].m_speed); pLog->Log("targetTB", pData->m_targets[i].m_trueBearing); pLog->Log("targetRB", pData->m_targets[i].m_relativeBearing); pLog->Log("targetAOB",(int)pData->m_targets[i].m_AOB); pLog->Log("targetAOBindex", pData->m_targets[i].m_AOBindex); pLog->Log("......................."); } } //process short cut buttons if(g_Global.g_mouse.y > 10 && g_Global.g_mouse.y < 130 && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){ //if(g_Global.g_mouse.x > 10 && g_Global.g_mouse.x < 110) // m_event = EVENT_GO_SONAR; //else if(g_Global.g_mouse.x > 120 && g_Global.g_mouse.x < 220) // m_event = EVENT_GO_RADAR; if(g_Global.g_mouse.x > 230 && g_Global.g_mouse.x < 330) m_event = EVENT_GO_CONTROL; //else if(g_Global.g_mouse.x > 694 && g_Global.g_mouse.x < 794) // m_event = EVENT_GO_FIRECONTROL; //else if(g_Global.g_mouse.x > 804 && g_Global.g_mouse.x < 904) // m_event = EVENT_GO_STATUS; } else if(g_Global.g_mouse.x > 806 && g_Global.g_mouse.x < 1006 && g_Global.g_bLeftMouseDown == true && ::GetActiveWindow() == g_hWnd){ if(g_Global.g_mouse.y > 134 && g_Global.g_mouse.y < 249){//zoom in m_chartScaleIndex++; if(m_chartScaleIndex > 4) m_chartScaleIndex = 4; } else if(g_Global.g_mouse.y > 269 && g_Global.g_mouse.y < 384){//zoom out m_chartScaleIndex--; if(m_chartScaleIndex < 0) m_chartScaleIndex = 0; } } } //this controls game states if(pData->m_missionOver == MISSION_OVER_WIN ) m_event = EVENT_GO_WIN; else if(pData->m_missionOver == MISSION_OVER_DEAD || pData->m_missionOver == MISSION_OVER_TIMEOVER || pData->m_missionOver == MISSION_OVER_COLLISION ) m_event = EVENT_GO_LOSE; for(unsigned int i=0; i< m_TE.size(); i++){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
void cGameStateChart::deactivate(){ CAudioManager *pAudio = CAudioManager::Instance(); pAudio->KillAll(); //g_Audio.KillAll(); }
void CGameStateHelp::Deactivate(CGameData &data){ CAudioManager *pAudio = CAudioManager::Instance(); pAudio->KillAll(); }
CGameStateObject* CGameStateHelp::Update(double timeDifference, CGameData &data, CConfigData &cfg, CGraphics &con){ m_event = EVENT_GO_NO_WHERE; CAudioManager *pAudio = CAudioManager::Instance(); //play background music if(cfg.PlayMusic == true && pAudio->IsPlaying(4) == false) pAudio->PlaySoundClip(4, 1); //first time static bool bFirstTime = true; if(bFirstTime == true){ bFirstTime = false; m_screenNumber = 0; m_arrowX = 150; m_arrowY = 150; } //CAudioManager *pAudio = CAudioManager::Instance(); m_mouse.SetHandle(data.m_hWnd); static double screenTime = 0; screenTime += timeDifference; if(::GetActiveWindow() == data.m_hWnd && screenTime > 0.4 && data.m_bLeftMouseDown == true){ //previous button if(m_mouse.MouseX() > 212 && m_mouse.MouseX() < 312 && m_mouse.MouseY() > 650 && m_mouse.MouseY() < 700){ m_screenNumber--; if(m_screenNumber < 0) m_screenNumber = 0; } //next button else if(m_mouse.MouseX() > 712 && m_mouse.MouseX() < 812 && m_mouse.MouseY() > 650 && m_mouse.MouseY() < 700){ m_screenNumber++; if(m_screenNumber > 9) m_screenNumber = 9; } screenTime = 0; } //animate arrow static double arrowTime = 0; arrowTime += timeDifference; if(arrowTime > 0.05 && m_screenNumber == 1){ m_arrowX += 10; m_arrowY += 5; if(m_arrowX > 750){ m_arrowX = 150; m_arrowY = 150; } arrowTime = 0; } if(::GetActiveWindow() == data.m_hWnd && data.m_bLeftMouseDown == true){ //main menu if(m_mouse.MouseX() > 812 && m_mouse.MouseX() < 1012 && m_mouse.MouseY() > 50 && m_mouse.MouseY() < 100){ m_event = EVENT_GO_MAIN; } } for(unsigned int i=0; i< m_TE.size(); i++){ if (m_TE[i].event == m_event){ return m_TE[i].p_gso; } } return 0; }
void CGameStatePlay2::Deactivate(){ CAudioManager *pAudio = CAudioManager::Instance(); pAudio->KillAll(); }
void cGameStateFireControl::deactivate(){ CAudioManager *pAudio = CAudioManager::Instance(); pAudio->KillAll(); //g_Audio.KillAll(); }
//******************************************************************** // main() //******************************************************************** int main(){ //instantiate log object and log CLog *pLog = CLog::Instance(); pLog->Log("*********************************************************"); pLog->Log("Program starting.................."); pLog->SetDelimiter(':'); pLog->LogDate(); pLog->LogTime(); pLog->Log("************************ *********************************"); cout << "Enter name: "; cin >> g_playerName; //system("cls"); //initialize console Console con(80, 25);//50); con.SetConsolePosition(0,0); con.CenterConsoleWindow(); con.cls(); Initialize(); CONSOLE_SCREEN_BUFFER_INFO csbi = con.GetScreenBufferInfo(); pLog->LogPair("Screen Buffer Size",csbi.dwSize.X, csbi.dwSize.Y); pLog->LogPair("Window Size",csbi.dwMaximumWindowSize.X, csbi.dwMaximumWindowSize.Y); pLog->LogPair("Left-Top",csbi.srWindow.Left, csbi.srWindow.Top); pLog->LogPair("Right-Bottom",csbi.srWindow.Right, csbi.srWindow.Bottom); pLog->LogPair("Maximum Window Size", csbi.dwMaximumWindowSize.X, csbi.dwMaximumWindowSize.Y); COORD maxSize = con.GetMaximumScreenSize(); pLog->LogPair("Max Size",maxSize.X, maxSize.Y); //game timer CTimer loopTimer; CTimer renderTimer; loopTimer.Initialize(); renderTimer.Initialize(); double timeDelta = 0; char buffer[] = "Chuck's Factory Game"; con.setTitle(buffer); //main game loop //******************************************** bool quit = false; while(!quit){ timeDelta = loopTimer.GetTimeDifference(); g_pNext = g_pCurrent->Update(timeDelta); if(NULL != g_pNext) { g_pCurrent = g_pNext; } if(g_pCurrent == g_pStateQuit ) quit = true; // Render our current game object //if(renderTimer.GetTimer(0.1)== true) g_pCurrent->Render(con); } //******************************************** //end game loop //free resources delete g_pStateIntro; delete g_pStateMenu; delete g_pStateQuit; delete g_pStateRules; delete g_pStateScore; delete g_pStatePlay; for(int i = 0; i < 9; ++i) g_audio.StopSoundClip(i); system("cls"); //normal termination of game pLog->Log("*********************************************************"); pLog->Log("Program terminating normally.................."); pLog->SetDelimiter(':'); pLog->LogTime(); pLog->Log("*********************************************************"); return 0; }