예제 #1
0
파일: WinState.cpp 프로젝트: jalcolea/cars
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;
}
예제 #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;

}
예제 #3
0
		//--------------------------------------------------------------------------------
		void	Chat::_Log(const MyGUI::UString& str, const MyGUI::UString& color)
		{
			while(mList->getItemCount() > 200)
				mList->removeItemAt(0);

			std::wstring tmp;

			std::vector<std::wstring> lines;
			lines.clear();

			MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(MyGUI::FontManager::getInstance().getDefaultFont());

			int ctr = 0;

			for(size_t i = 0; i < str.size(); i++)
			{
				if(ctr + font->getGlyphInfo((int)str[i])->width > mList->getWidth() - 35)
				{
					ctr = 0;

					if(str[i] != L' ')
						tmp.push_back(L'-');
					else
						while(str[i] == L' ' && i < str.size()){i++;}

						lines.push_back(tmp);
						tmp.clear();
				}

				tmp.push_back(str[i]);

				ctr += font->getGlyphInfo((int)str[i])->width;

				if (i >= str.size() - 1)
				{
					ctr = 0;
					lines.push_back(tmp);
					tmp.clear();
				}
			}

			for (unsigned int i = 0 ; i < lines.size() ; i++)
			{
				if (i == 0)
				{
					std::wstring toAdd;
					toAdd += lines[i].substr(0, lines[i].find(L":") + 1);
					toAdd += color;
					toAdd += lines[i].substr(lines[i].find(L":") + 1, lines[i].size());

					mList->addItem(toAdd);
				}
				else
				{
					std::wstring toAdd = color;
					toAdd += lines[i];
					mList->addItem(toAdd);
				}
			}

			mList->beginToItemLast();
		}