コード例 #1
0
ファイル: manager.cpp プロジェクト: renmaoting/616
void Manager::play() {
  SDL_Event event;
  bool done = false;

  while ( not done ) {
    while ( SDL_PollEvent(&event) ) {
      Uint8 *keystate = SDL_GetKeyState(NULL);
      if (event.type ==  SDL_QUIT) { done = true; break; }
      if(event.type == SDL_KEYDOWN) {
        if (keystate[SDLK_ESCAPE] || keystate[SDLK_q]) {
          done = true;
          break;
        }
        if ( keystate[SDLK_e] ) {
            sprites[currentSprite]->explode();
        }
        if ( keystate[SDLK_t] ) {
          switchSprite();
        }
        if ( keystate[SDLK_s] ) {
          clock.toggleSloMo();
        }
        if ( keystate[SDLK_p] ) {
            if(clock.isPaused() == true)
                clock.unPause();
            else
                clock.pause();
        }
        if (keystate[SDLK_F4] && !makeVideo) {
          std::cout << "Making video frames" << std::endl;
          makeVideo = true;
        }
      }
    }
    draw();
    update();
  }
}
コード例 #2
0
ファイル: manager.cpp プロジェクト: yuyaolong/8700AS4
void Manager::play() {
  SDL_Event event;
  bool done = false;
  clock.start();
  while ( not done ) {
    while ( SDL_PollEvent(&event) ) {
      Uint8 *keystate = SDL_GetKeyState(NULL);
      if (event.type ==  SDL_QUIT) { done = true; break; }
       
        if (event.type == SDL_KEYUP) {
            gundam->setStatus(STAND);
        }
        
      if(event.type == SDL_KEYDOWN) {
          
        if (keystate[SDLK_ESCAPE] || keystate[SDLK_q]) {
          done = true;
          break;
        }
        if ( keystate[SDLK_t] ) {
          switchSprite();
        }
        if ( keystate[SDLK_p] ) {
          if ( clock.isPaused() ) clock.unpause();
          else clock.pause();
        }
        if (keystate[SDLK_l]) {
          clock.toggleSloMo();
        }
        if (keystate[SDLK_F4] && !makeVideo) {
          std::cout << "Making video frames" << std::endl;
          makeVideo = true;
        }
          if (keystate[SDLK_F1]) {
              hud.toggle();
          }
          
      }
        
        if(keystate[SDLK_a])
        {
            gundam->setStatus(MOVELEFT);
            
        }
        if(keystate[SDLK_d])
        {
            gundam->setStatus(MOVERIGHT);
        }
        if(keystate[SDLK_s])
        {
            gundam->setStatus(MOVEDOWN);
        }
        if(keystate[SDLK_w])
        {
            gundam->setStatus(MOVEUP);
        }
        
        if (keystate[SDLK_w] && keystate[SDLK_d]) {
            gundam->setStatus(UPRIGHT);
        }
        if (keystate[SDLK_w] && keystate[SDLK_a]) {
            gundam->setStatus(UPLEFT);
        }
        if (keystate[SDLK_s] && keystate[SDLK_d]) {
            gundam->setStatus(DOWNRIGHT);
        }
        if (keystate[SDLK_s] && keystate[SDLK_a]) {
            gundam->setStatus(DOWNLEFT);
        }
        
        if(keystate[SDLK_a] && keystate[SDLK_d])
        {
            gundam->setStatus(STAND);
        }
        if(keystate[SDLK_w] && keystate[SDLK_s])
        {
            gundam->setStatus(STAND);
        }
        
        

    }

    update();
    draw();
    
  }
}