Exemple #1
0
bool WinState::keyPressed(const OIS::KeyEvent &e) 
{
     MyGUI::UString txt = user_name_txt->getCaption();
    if ((int)e.key==14 && txt.size()>0) 
    {
        txt.resize(txt.size()-1);
    }
    else
    {
      if (((int)e.text >=65 && (int)e.text<=90) || ((int)e.text>=97 && (int)e.text<=122))
      {
        if (txt.size()<CONSTANTS_MAX_USERNAME_SIZE) txt.push_back(e.text);
      }
    }
    user_name_txt->setCaption(txt);
    if ((e.key == OIS::KC_ESCAPE) || (e.key == OIS::KC_RETURN) || (e.key == OIS::KC_R))
    {
        cout << "NEW RECORD TO SAVE" << endl;
        save_record();
        popState();
    }

  return true;
}
Exemple #2
0
bool PlayState::keyPressed(const OIS::KeyEvent &e)
{
  if (!user_name_txt->getVisible())
  {
//        if (paused) pause(); // ESTO NO ES NECESARIO. AL HACER UN PUSHSTATE EL GAMEMANAGER LLAMARÁ A PAUSE() AUTOMATICAMENTE
//        else
        if (!paused)
        {
              if (e.key == OIS::KC_P) {
                paused = true;
                pushState(PauseState::getSingletonPtr());
              }
              else if (e.key == OIS::KC_G) {
                paused = true;
                game_over();
              }
              else if (e.key == OIS::KC_W) {
                win();
             }
             else if (e.key == OIS::KC_UP)
             {
               _pacmanDir = UP_DIR;
             }
             else if (e.key == OIS::KC_DOWN) {
               _pacmanDir = DOWN_DIR;
             }
             else if (e.key == OIS::KC_LEFT) {
               _pacmanDir = LEFT_DIR;
             }
             else if (e.key == OIS::KC_RIGHT) {
               _pacmanDir = RIGHT_DIR;
             }
//             else if (e.key == OIS::KC_ESCAPE) {              
//               popState();
//               pushState(IntroState::getSingletonPtr());
//             }
        }
  }
  else
  {
    sounds::getInstance()->play_effect("eat_fruit");

    MyGUI::UString txt = user_name_txt->getCaption();
    if ((int)e.key==14 && txt.size()>0) txt.resize(txt.size()-1);
    else
    {
      if (((int)e.text >=65 && (int)e.text<=90) || ((int)e.text>=97 && (int)e.text<=122))
      {
        if (txt.size()<3) txt.push_back(e.text);
      }
    }
    user_name_txt->setCaption(txt);
    if (e.key==OIS::KC_RETURN)
    {
      cout << "NEW RECORD TO SAVE" << endl;
        records::getInstance()->add_record(txt,get_score());
        records::getInstance()->saveFile(NULL);
        sounds::getInstance()->play_effect("eat_ghost");
        user_name_txt->setVisible(false);
        popState();
        stopWorld = false;
    }
  }
  return true;

}