// Update method bool CGameManager::Update( CD3DManager* d3dManager, float updateTime ) { if( m_GameState == FrontEnd ) { return FrontEndUpdate( d3dManager, updateTime ); } else if( m_GameState == Game ) { if( KeyHit( Key_Escape ) ) { if( m_GUI->GetState() != GUIRaceStarting ) { m_Pause = !m_Pause; ShowCursor( m_Pause ); if( m_GUI->GetState() != GUIPaused ) m_GUI->SetState( GUIPaused ); else m_GUI->SetState( GUIRacing ); } } if( !m_Pause ) return GameUpdate( d3dManager, updateTime ); else return GamePaused( d3dManager, updateTime ); } return true; }
bool CGameManager::GameUpdate( CD3DManager* d3dManager, float updateTime ) { // Update the entity manager and all entities m_EntityManager->Update( updateTime ); // Update all systems m_PSManager->UpdateSystems( updateTime ); // Update the sound manager m_SoundManager->Update( updateTime ); // Controls for switching between chase cam and roam cam //#ifdef _DEBUG if( KeyHit( Key_1 ) ) { if( MainCamera == chaseCam ) { MainCamera = roamCam; MainCamera->Matrix().SetPosition( chaseCam->Matrix().Position() ); MainCamera->Matrix().FaceDirection( chaseCam->Matrix().ZAxis() ); } else if( MainCamera == roamCam ) { MainCamera = chaseCam; } } //#endif // Update the main camera MainCamera->Update( updateTime, m_Messenger ); return true; }
/********************************************************************************************************* ** 函数名称: FlushKeyBuffer ** 函数名称: FlushKeyBuffer ** ** 功能描述: 清空 ** ** 输 入: void ** ** 输 出: void ** ** 全局变量: ** 调用模块: 无 ** ** 作 者: LiJin ** 日 期: 2008年10月23日 ** 备 注: **------------------------------------------------------------------------------------------------------- ** 修改人: ** 日 期: ** 备 注: **------------------------------------------------------------------------------------------------------ ********************************************************************************************************/ void FlushKeyBuffer (void) { while (KeyHit()) { /* While there are keys in the buffer... */ GetKey(0); /* ... extract the next key from the buffer */ } }
bool CGameManager::GamePaused( CD3DManager* d3dManager, float updateTime ) { if( KeyHit( Mouse_LButton ) ) { if( m_GUI->Update( updateTime, true ) == 2 ) { return false; } } return true; }
bool CGameManager::FrontEndUpdate( CD3DManager* d3dManager, float updateTime ) { bool mouse = KeyHit( Mouse_LButton ); int result = m_GUI->Update( updateTime, mouse ); if( result == 1 ) { m_GUI->SetState( GUILoading ); Render( d3dManager, updateTime ); ShowCursor( false ); m_GameState = Game; GameSetup( d3dManager ); } else if( result == 2 ) return false; return true; }
// Update the scene between rendering void UpdateScene( float updateTime ) { // Call all entity update functions EntityManager.UpdateAllEntities( updateTime ); // Set camera speeds // Key F1 used for full screen toggle if (KeyHit( Key_F2 )) CameraMoveSpeed = 5.0f; if (KeyHit( Key_F3 )) CameraMoveSpeed = 40.0f; //Start and stop tanks if (KeyHit (Key_1) || KeyHit (Key_2)) { SMessage Message; if (KeyHeld(Key_1)) { Message.type = Msg_Stop; } else { Message.type = Msg_Go; } for (int i = 0; i < TankVector.size(); i++) { Messenger.SendMessage(TankVector.at(i), Message); } } //Show detailed tank information if (KeyHit( Key_0 )) ShowTankDetail = !ShowTankDetail; // Move the camera MainCamera->Control( Key_Up, Key_Down, Key_Left, Key_Right, Key_W, Key_S, Key_A, Key_D, CameraMoveSpeed * updateTime, CameraRotSpeed * updateTime ); //Set Camera to chase a tank. if (KeyHit (Key_3) || KeyHit (Key_4)) { if (KeyHeld(Key_3)) { ChaseTankA = !ChaseTankA; ChaseTankB = false; } else { ChaseTankB = !ChaseTankB; ChaseTankA = false; } } if(ChaseTankA) { if (EntityManager.GetEntity(TankA)!=0) { MainCamera->Matrix() = EntityManager.GetEntity(TankA)->Matrix(); MainCamera->Matrix().MoveY(10.0f); MainCamera->Matrix().MoveLocalZ(-30.0f); MainCamera->Matrix().FaceTarget(EntityManager.GetEntity(TankA)->Matrix().Position()); } } if(ChaseTankB) { if (EntityManager.GetEntity(TankB)!=0) { MainCamera->Matrix() = EntityManager.GetEntity(TankB)->Matrix(); MainCamera->Matrix().MoveY(10.0f); MainCamera->Matrix().MoveLocalZ(-30.0f); MainCamera->Matrix().FaceTarget(EntityManager.GetEntity(TankB)->Matrix().Position()); } } AmmoBoxTimer -= updateTime; if (AmmoBoxTimer <0) { CVector3 SpawnPoint; float radius = rand()% 200; float angle = rand()% 200; SpawnPoint.x = (radius *cos(angle)); SpawnPoint.z = (radius *sin(angle)); SpawnPoint.y = 1.0f; EntityManager.CreateAmmoBox("AmmoBox", &TankVector,"AmmoBox",SpawnPoint, CVector3((0.0f),(0.0f),(0.0f)),CVector3((0.25f),(0.25f),(0.25f))); AmmoBoxTimer = 7.5f; } }
// Update the scene - move/rotate each model and the camera, then update their matrices void CScene::UpdateScene( float frameTime ) { //Show Framerate char caption[100]; char buffer[6]; //copy in base text strcpy_s( caption, "Final Project - Project SPARTA - FPS:"); //calculate FPS int FPS = int ( 1.0f / frameTime ); //convert to string in base 10 and add to caption _itoa_s( FPS,buffer,10 ); strcat_s( caption, buffer ); //add in object and light counts as above strcat_s( caption, " O: " ); _itoa_s( miNumObjects, buffer, 10 ); strcat_s( caption, buffer ); strcat_s( caption, " L: " ); _itoa_s( miNumLights, buffer, 10 ); strcat_s( caption, buffer ); //pass the new caption to the window SetWindowTextA( HWnd, caption ); // Control camera position and update its matrices (view matrix, projection matrix) each frame // Don't be deceived into thinking that this is a new method to control models - the same code we used previously is in the camera class Camera.Control( frameTime, Key_Up, Key_Down, Key_Left, Key_Right, Key_W, Key_S, Key_A, Key_D ); Camera.UpdateMatrices(); //update all the objects, including calculating the matrix for(int i = 0; i < miNumObjects; i++) { mpObjects[i]->Update(frameTime); } //same for the lights for(int i = 0; i < miNumLights; i++) { mpLights[i]->Update(frameTime); } // Allow user to quit with escape key if (KeyHit( Key_Escape )) { DestroyWindow( HWnd ); } if (KeyHit( Key_F1 ) ) { mb_showCost = !mb_showCost; mb_showWallIM = false; mb_showPathIM = false; mb_showBaseIM = false; mb_showBase2IM = false; mb_showHTIM = false; mb_showLTIM = false; mb_showMTIM = false; } if (KeyHit( Key_F2 ) ) { mb_showCost = false; mb_showWallIM = !mb_showWallIM; mb_showPathIM = false; mb_showBaseIM = false; mb_showBase2IM = false; mb_showHTIM = false; mb_showLTIM = false; mb_showMTIM = false; } if (KeyHit( Key_F3 ) ) { mb_showCost = false; mb_showWallIM = false; mb_showPathIM = !mb_showPathIM; mb_showBaseIM = false; mb_showBase2IM = false; mb_showHTIM = false; mb_showLTIM = false; mb_showMTIM = false; } if (KeyHit( Key_F4 ) ) { mb_showCost = false; mb_showWallIM = false; mb_showPathIM = false; mb_showBaseIM = !mb_showBaseIM; mb_showBase2IM = false; mb_showHTIM = false; mb_showLTIM = false; mb_showMTIM = false; } if (KeyHit( Key_F5 ) ) { mb_showCost = false; mb_showWallIM = false; mb_showPathIM = false; mb_showBaseIM = false; mb_showBase2IM = !mb_showBase2IM; mb_showHTIM = false; mb_showLTIM = false; mb_showMTIM = false; } if (KeyHit( Key_F6 ) ) { mb_showCost = false; mb_showWallIM = false; mb_showPathIM = false; mb_showBaseIM = false; mb_showBase2IM = false; mb_showHTIM = !mb_showHTIM; mb_showLTIM = false; mb_showMTIM = false; } if (KeyHit( Key_F7 ) ) { mb_showCost = false; mb_showWallIM = false; mb_showPathIM = false; mb_showBaseIM = false; mb_showBase2IM = false; mb_showHTIM = false; mb_showLTIM = !mb_showLTIM; mb_showMTIM = false; } if (KeyHit( Key_F8 ) ) { mb_showCost = false; mb_showWallIM = false; mb_showPathIM = false; mb_showBaseIM = false; mb_showBase2IM = false; mb_showHTIM = false; mb_showLTIM = false; mb_showMTIM = !mb_showMTIM; } }
char main() { int i, sec_left = 5; // give player secs to pick letter char pick, str[100]; srand(getpid()); // seed rand for random pick if user not pick in secs sprintf(str, "%c[2J", 27); write( 1, str, strlen(str) ); sprintf( str, "%c[2;1H%s", 27, "Pick a winner A~Z " ); write( 1, str, strlen(str) ); NonBlock(1); // turn on non-block stdin while(1) { if( KeyHit() ) // check if key pressed { read(0, &pick, 1); // read key-in as a char // if not uppercase, reduce ASCII value to uppercase range if ( pick >= 'a' && pick <= 'z' ) pick -= ( 'a' - 'A' ); write(1, "You've picked: ", 15); // msg to show write(1, &pick, 1); // display pick write(1, " ", 2); // display " " sleep(1); // give time to let see msg if ( pick >= 'A' && pick <= 'Z' ) return pick; // good range } sprintf(str, "%c[4;1H%2d seconds! ", 27, sec_left); write(1, str, strlen(str)); if( sec_left == 0 ) { pick = rand()%26 + 'A'; sprintf(str, "%c[4;13HI've picked for you: ", 27); // row 4, col 13 write(1, str, strlen(str)); for( i=0; i<5; i++ ) // flash random pick { usleep(250000); sprintf(str, "%c[4;34H ", 27); // erase row 4, col 34 write(1, str, strlen(str)); usleep(250000); sprintf(str, "%c[4;34H%c ", 27, pick); write(1, str, strlen(str)); } sleep(1); // give time to let see msg return pick; } sleep(1); sec_left--; } NonBlock(0); }
void updatePauseWindow() { if (KeyHit(KEY_ESCAPE) == true) { exitPause(); } }
BOOLEAN PauseGame (void) { RECT r; STAMP s; BOOLEAN ClockActive; CONTEXT OldContext; FRAME F; HOT_SPOT OldHot; if (ActivityFrame == 0 || (GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_PAUSE)) || (LastActivity & (CHECK_LOAD | CHECK_RESTART))) return (FALSE); GLOBAL (CurrentActivity) |= CHECK_PAUSE; ClockActive = (BOOLEAN)( LOBYTE (GLOBAL (CurrentActivity)) != SUPER_MELEE && GameClockRunning () ); if (ClockActive) SuspendGameClock (); else if (CommData.ConversationPhrases && PlayingTrack ()) PauseTrack (); SetSemaphore (GraphicsSem); OldContext = SetContext (ScreenContext); OldHot = SetFrameHot (Screen, MAKE_HOT_SPOT (0, 0)); GetFrameRect (ActivityFrame, &r); r.corner.x = (SCREEN_WIDTH - r.extent.width) >> 1; r.corner.y = (SCREEN_HEIGHT - r.extent.height) >> 1; s.origin = r.corner; s.frame = ActivityFrame; F = CaptureDrawable (LoadDisplayPixmap (&r, (FRAME)0)); DrawStamp (&s); FlushGraphics (); { BYTE scan; scan = KBDToUNICODE (SK_F1); while (KeyDown (scan)) TaskSwitch (); } FlushInput (); while (KeyHit () != SK_F1) TaskSwitch (); s.frame = F; DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); SetFrameHot (Screen, OldHot); SetContext (OldContext); WaitForNoInput (ONE_SECOND / 4); FlushInput (); ClearSemaphore (GraphicsSem); if (ClockActive) ResumeGameClock (); else if (CommData.ConversationPhrases && PlayingTrack ()) ResumeTrack (); TaskSwitch (); GLOBAL (CurrentActivity) &= ~CHECK_PAUSE; return (TRUE); }
int main ( int argc, char** argv ) { // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window SDL_Surface* screen = SDL_SetVideoMode(800, 600, 24, SDL_SWSURFACE); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } SDL_WM_SetCaption("Raw Viewer","Raw Viewer"); // load an image SDL_Surface* buffer = SDL_CreateRGBSurface(SDL_SWSURFACE,600,524,32,0,0,0,0); fl=fopen(argv[1],"rb"); fseek(fl,0,SEEK_END); Max=ftell(fl); Render(buffer,rejim,WIDT,HIGH,DX); // program main loop bool done = false; while (!done) { // message processing loop FlushHits(); SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { SetHit(event.key.keysym.sym); break; } } // end switch } // end of message processing UpdateKeyboard(); // DRAWING STARTS HERE if (KeyDown(SDLK_ESCAPE)) done=true; // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_BlitSurface(buffer,0,screen,0); lineColor(screen,0,524,600,524,0xFFFFFFFF); lineColor(screen,600,0,600,524,0xFFFFFFFF); char buf[255]; sprintf(buf,"Offset:%X",Offs); stringColor(screen,700,10,buf,0xFFFFFFFF); sprintf(buf,"Width:%d",WIDT); stringColor(screen,700,20,buf,0xFFFFFFFF); rectangleColor(screen,663,7,670,509,0xFF0000FF); FillRect(screen,665,9,4,501*(Offs/(float)Max),0x00FF00);//rectangleColor(screen,664,8,669,8+500*Offs/Max,0x00FF00FF); if (WIDT>150) { rectangleColor(screen,9,549,511,556,0xFF0000FF); //Rect 9,549,502,7,0 FillRect(screen,10,550,500*DX/(WIDT-150),5,0x00FF00);// Rect 10,550,500*(Float(DX)/Float(widt-150)),5,1 } switch (rejim) { case 1: sprintf(buf,"1 Bit mode"); break; case 2: sprintf(buf,"2 Bit mode"); break; case 3: sprintf(buf,"4 Bit mode"); break; case 4: sprintf(buf,"8 Bit mode"); break; case 5: sprintf(buf,"16 Bit mode RGBA5551"); break; case 6: sprintf(buf,"16 Bit mode RGBA4444"); break; case 7: sprintf(buf,"16 Bit mode RGB565"); break; case 8: sprintf(buf,"16 Bit mode BGRA5551"); break; case 9: sprintf(buf,"16 Bit mode BGRA4444"); break; case 10: sprintf(buf,"16 Bit mode BGR565"); break; case 11: sprintf(buf,"24 Bit mode RGB"); break; case 12: sprintf(buf,"24 Bit mode BGR"); break; } stringColor(screen,5,580,buf,0xFFFFFFFF); if (KeyHit(SDLK_SPACE)) { setka=!setka; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PERIOD)) { WIDT++; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_COMMA)) { WIDT--; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_SEMICOLON)) { WIDT+=10; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_l)) { WIDT-=10; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_LEFTBRACKET)) { WIDT+=100; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_p)) { WIDT-=100; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (MouseDown(1)) { if (MouseX()>663 && MouseX()<670 && MouseY()>7 && MouseY()<507) { Offs=(float)Max*((MouseY()-8.0))/500.0; Render(buffer,rejim,WIDT,HIGH,DX); } if (WIDT>150) { if (MouseX()>9 && MouseX()<511 && MouseY()>549 && MouseY()<556) { DX=(WIDT -150)*((MouseX()-10)/500.0); Render(buffer,rejim,WIDT,HIGH,DX); } } } if (MouseDown(3)) { HIGH=MouseY()/4; if (HIGH<1) HIGH=1; if (HIGH> 130) HIGH=130; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_1)) { rejim=1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_2)) { rejim=2; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_3)) { rejim=3; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_4)) { rejim=4; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_5)) { rejim=5; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_6)) { rejim=6; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_7)) { rejim=7; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_8)) { rejim=8; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_9)) { rejim=9; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_0)) { rejim=10; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_MINUS)) { rejim=11; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_EQUALS)) { rejim=12; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_RIGHT)) { Offs++; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_LEFT)) { Offs--; Render(buffer,rejim,WIDT,HIGH,DX); } if (rejim<5) { if (KeyDown(SDLK_DOWN)) { Offs+=WIDT; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_UP)) { Offs-=WIDT; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEUP)) { Offs-=WIDT*10; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEDOWN)) { Offs+=WIDT*10; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_HOME)) { Offs-=WIDT*100; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_END)) { Offs+=WIDT*100; Render(buffer,rejim,WIDT,HIGH,DX); } } else if (rejim < 11) { if (KeyDown(SDLK_DOWN)) { Offs+=WIDT*2; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_UP)) { Offs-=WIDT*2; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEUP)) { Offs-=WIDT*20; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEDOWN)) { Offs+=WIDT*20; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_HOME)) { Offs-=WIDT*200; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_END)) { Offs+=WIDT*200; Render(buffer,rejim,WIDT,HIGH,DX); } } else if (rejim < 13) { if (KeyDown(SDLK_DOWN)) { Offs+=WIDT*3; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_UP)) { Offs-=WIDT*3; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEUP)) { Offs-=WIDT*30; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEDOWN)) { Offs+=WIDT*30; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_HOME)) { Offs-=WIDT*300; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_END)) { Offs+=WIDT*300; Render(buffer,rejim,WIDT,HIGH,DX); } } // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(screen); SDL_Delay(10); } // end main loop fclose(fl); return 0; }