void World::Update(float deltaTime) { _currentTime += deltaTime; CalcWorldCapturingState(); for (Investigator::Ptr investigator : _investigators) { investigator->UpdateToTime(_currentTime); } _taskManager.UpdateToTime(_currentTime); _cellsNetwork.UpdateToTime(_currentTime); _bonusOnMap.UpdateToTime(_currentTime); MessageManager::Instance().CallAcceptMessages(); if (!_cellsNetwork.GetRootCell().expired()) { if (!_cellsNetwork.GetRootCell().lock()->IsState(Cell::State::READY)) { SetGameOver(); } } for (Investigators::iterator it = _investigators.begin(); it != _investigators.end(); ++it) { Investigator::Ptr ptr = (*it); if (ptr->IsStateType(Investigator::State::FINISHED)) { RemoveInvestigator(ptr); break; } } }
void CTetris::ProcessGameRunning(double dt) { m_timeSinceGravity += dt; if (m_timeSinceGravity < GRAVITYTIME) { if (!m_forceGravity) return; else if (m_timeSinceGravity < (GRAVITYTIME / 20.0f)) return; } if (LockCheck()) { LockCurBrick(); delete m_curBrick; m_curBrick = nullptr; } else ApplyGravity(); if (!GetCurBrick()) { delete m_curBrick; m_curBrick = nullptr; CheckDeleteFilledRows(); m_curBrick = CreateRandomBrick(); if (IsFail()) { EndGame(); SetGameOver(); } } // Even if gravity wasn't applied, we set it to 0, // because a new brick would been created if Gravity never // got applied, and we want the timer to start over. m_timeSinceGravity = 0; }
void GameScene::Draw(float gameTime, User& user) { RECT rcSrcRect; RECT bgRect; D3DXVECTOR3 vecCenter; static int offset =0; rcSrcRect.left = 0; rcSrcRect.top = 0; rcSrcRect.right = 59; rcSrcRect.bottom = 88; vecCenter.x = .0f; vecCenter.y = .0f; vecCenter.z = .0f; srand((unsigned int)time(NULL)); if( currentEnemyNum < om->ManageMaxEnemy() ) { if(GetTickCount()%60==0) { om->insertObj(); currentEnemyNum++; } } if ((GetKeyState(VK_LEFT) & 0x80000000) && vecPosition.x > 0) vecPosition.x -= 7.0f; if ((GetKeyState(VK_RIGHT) & 0x80000000) && vecPosition.x+rcSrcRect.right < SCREEN_WIDTH) vecPosition.x += 7.0f; if ((GetKeyState(VK_UP) & 0x80000000) && vecPosition.y > 0 ) vecPosition.y -= 5.0f; if ((GetKeyState(VK_DOWN) & 0x80000000) && vecPosition.y+rcSrcRect.bottom < SCREEN_HEIGHT) vecPosition.y += 10.0f; // 충돌체크 // 보이는 적중에 부딪히면 파괴 if(currentEnemyNum>=0) { for(int i=0; i<om->ManageMaxEnemy(); i++) if(om->getAlive(i)) { if( !(om->getEnemy(i).manageMoving(gDevice->g_pd3dDevice, i*100+100)) ) { //새의 위치가 위아래로 벗어나면 파괴 om->deleteObj(i); currentEnemyNum--; } else { // 충돌체크 보이는 적중에 부딪히면 파괴 D3DXVECTOR3* pos = om->getEnemy(i).getPosition(); if( vecPosition.x < pos->x + BIRD_RECT_RIGHT &&pos->x < vecPosition.x + rcSrcRect.right &&vecPosition.y < pos->y + BIRD_RECT_BOTTOM &&pos->y < vecPosition.y + rcSrcRect.bottom) { currentScore -= 50; if(currentScore < 0) currentScore =0; life -= 10; om->deleteObj(i); currentEnemyNum--; } } } } if(life<=0) { MessageBox(NULL, _T("Oops! ,You are dead!"), NULL, MB_OK); exit(1); } gDevice->Clear(D3DCOLOR_XRGB(0,0,255)); gDevice->Begin(); if(spriter != NULL && balloonTexture != NULL && backGroundTexture!= NULL) { spriter->Begin(D3DXSPRITE_ALPHABLEND); bgRect.left = 0; bgRect.right = SCREEN_WIDTH; bgRect.top = 0; bgRect.bottom = SCREEN_HEIGHT; vecPosBG.y = -(float)offset; spriter->Draw(backGroundTexture, &bgRect, NULL, &vecPosBG, 0xFFFFFFFF); bgRect.top = 0; bgRect.bottom = offset; D3DXVECTOR3 vecPosBG2(0,(float)(SCREEN_HEIGHT-offset),0); spriter->Draw(backGroundTexture, &bgRect, NULL, &vecPosBG2, 0xFFFFFFFF); offset++; offset = offset%SCREEN_HEIGHT; //시작하고 10초뒤에 골라인 올라옴 time_t crtTime; time(&crtTime); if(goalTime < crtTime) { g_GoalLine.Position.y -= 3.0f; spriter->Draw( g_GoalLine.Texture, &g_GoalLine.Source, &g_GoalLine.Center, &g_GoalLine.Position, 0xffffffff ); } if(currentEnemyNum > 0) { for(int i=0; i<om->ManageMaxEnemy(); i++) { if(om->getAlive(i) == TRUE) spriter->Draw( om->getEnemy(i).getTexture(), om->getEnemy(i).getSource(), om->getEnemy(i).getCenter(), om->getEnemy(i).getPosition(), 0xffffffff ); } } // 골라인과 플레이어가 만나면 if ( g_GoalLine.Position.y < vecPosition.y ) { if(currentStage == 5) { // 스테이지 클리어 user.SetScore(currentScore); user.SetStage(currentStage); user.SetUserState(user.GAME_CLEAR); SetGameOver(true); //MessageBox(NULL, _T("ALL STAGE CLEAR!, Congraturations!"), NULL, MB_OK); //exit(0); } currentStage++; delete om; InitStage(currentStage); } spriter->Draw(balloonTexture, &rcSrcRect, &vecCenter, &vecPosition, 0xffffffff); RECT scoreRect = {400,20,-1,-1}; RECT lifeRect = {20,20,-1,-1}; RECT stageRect = {220,20,-1,-1}; if(prevTimer == NULL) prevTimer = crtTime; if(crtTime-prevTimer != 0) { currentScore+=5; } prevTimer = crtTime; std::string scoreStr = "SCORE "; scoreStr.append(std::to_string(currentScore)); std::string lifeStr = "LIFE "; lifeStr.append(std::to_string(life)); std::string stageStr = "STAGE "; stageStr.append(std::to_string(om->GetStageNumber())); std::wstring scoreWstr = std::wstring(scoreStr.begin(), scoreStr.end()); std::wstring lifeWstr = std::wstring(lifeStr.begin(), lifeStr.end()); std::wstring stageWstr = std::wstring(stageStr.begin(), stageStr.end()); //LPCWSTR scoreResult = _T(scoreStr.c_str()); if(scoreFont) scoreFont->DrawText(spriter, scoreWstr.c_str(), scoreWstr.length(), &scoreRect, DT_NOCLIP, D3DXCOLOR(0,0,0,1)); if(lifeFont) lifeFont->DrawText(spriter, lifeWstr.c_str(), lifeWstr.length(), &lifeRect,DT_NOCLIP, D3DXCOLOR(0,0,0,1)); if(stageFont) stageFont->DrawText(spriter, stageWstr.c_str(), stageWstr.length(), &stageRect, DT_NOCLIP, D3DXCOLOR(0,0,0,1)); spriter->End(); } //else //MessageBox(NULL, _T("Error"), NULL, NULL); gDevice->End(); gDevice->Present(); }