示例#1
0
文件: menu.c 项目: kerheol/flobopuyo
  int
menu_switch_on_off (Menu * menu, const char *name)
{
  const char *value = menu_items_get_value (menu->items, name);

  if (!strcmp (value, "ON")) {
    menu_set_value (menu, name, "OFF");
    return 0;
  }
  else {
    menu_set_value (menu, name, "ON");
    return 1;
  }
}
示例#2
0
文件: menu.c 项目: kerheol/flobopuyo
  int
menu_progress_bar (Menu * menu, const char *name, int increment)
{
  const char *svalue = menu_items_get_value (menu->items, name);
  int     value = atoi (svalue);
  static char nval[5];

  if (increment == 0)
    return value;
  else {
    value += increment;
    if (value > 100)
      value = 100;
    if (value < 0)
      value = 0;
  }

  sprintf (nval, "%d %%", value);
  menu_set_value (menu, name, nval);
  return value;
}
示例#3
0
void PuyoCommander::controlsMenuLoop(PuyoDrawable *d)
{
  char newKeyName[250];

  getKeyName(kPlayer1LeftControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Left, newKeyName,0);
  getKeyName(kPlayer1RightControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Right, newKeyName,0);
  getKeyName(kPlayer1DownControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Down, newKeyName,0);
  getKeyName(kPlayer1ClockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Clockwise, newKeyName,0);
  getKeyName(kPlayer1CounterclockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Counterclockwise, newKeyName,0);


  getKeyName(kPlayer2LeftControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Left, newKeyName,0);
  getKeyName(kPlayer2RightControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Right, newKeyName,0);
  getKeyName(kPlayer2DownControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Down, newKeyName,0);
  getKeyName(kPlayer2ClockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Clockwise, newKeyName,0);
  getKeyName(kPlayer2CounterclockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Counterclockwise, newKeyName,1);


  menu_show(controlsMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      char *chosenControl = NULL;
      int chosenControlIndex;
      GameControlEvent controlEvent;
      getControlEvent(e, &controlEvent);

      switch (controlEvent.cursorEvent) {
        case GameControlEvent::kQuit:
          exit(0);
          goto mml_fin;
          break;
        case GameControlEvent::kUp:
          menu_prev_item (controlsMenu);
          break;
        case GameControlEvent::kDown:
          menu_next_item (controlsMenu);
          break;
        case GameControlEvent::kStart:
          menu_validate (controlsMenu);
          if (menu_active_is (controlsMenu, "Back"))
            goto mml_fin;

          if (menu_active_is (controlsMenu, kPlayer1Left)) {
            chosenControl = kPlayer1Left;
            chosenControlIndex = kPlayer1LeftControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Right)) {
            chosenControl = kPlayer1Right;
            chosenControlIndex = kPlayer1RightControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Down)) {
            chosenControl = kPlayer1Down;
            chosenControlIndex = kPlayer1DownControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Clockwise)) {
            chosenControl = kPlayer1Clockwise;
            chosenControlIndex = kPlayer1ClockwiseControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Counterclockwise)) {
            chosenControl = kPlayer1Counterclockwise;
            chosenControlIndex = kPlayer1CounterclockwiseControl;
          }

          if (menu_active_is (controlsMenu, kPlayer2Left)) {
            chosenControl = kPlayer2Left;
            chosenControlIndex = kPlayer2LeftControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Right)) {
            chosenControl = kPlayer2Right;
            chosenControlIndex = kPlayer2RightControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Down)) {
            chosenControl = kPlayer2Down;
            chosenControlIndex = kPlayer2DownControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Clockwise)) {
            chosenControl = kPlayer2Clockwise;
            chosenControlIndex = kPlayer2ClockwiseControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Counterclockwise)) {
            chosenControl = kPlayer2Counterclockwise;
            chosenControlIndex = kPlayer2CounterclockwiseControl;
          }

          if (chosenControl != NULL) {
            char prevValue[255];
            strcpy(prevValue, menu_get_value (controlsMenu, chosenControl));
            menu_set_value(controlsMenu, chosenControl, "<Choose>");
            if (changeControlLoop(chosenControlIndex, d)) {
              getKeyName(chosenControlIndex, newKeyName);
              menu_set_value(controlsMenu, chosenControl, newKeyName);
              menu_next_item (controlsMenu);
            }
            else {
              menu_set_value(controlsMenu, chosenControl, prevValue);
            }
          }
          break;
        case GameControlEvent::kBack:
          goto mml_fin;
          break;
        default:
          break;
      }
    }

    updateAll(d);
  }
mml_fin:
  saveControls();
  menu_hide (controlsMenu);
}
示例#4
0
void PuyoCommander::startSingleGameLoop()
{
  char playerName[256];

    char * defaultName = getenv("USER");
    if (defaultName == NULL)
      defaultName = "Player";
    if (!(defaultName[0]>=32))
      defaultName = "Player";
    if ((defaultName[0]>='a') && (defaultName[0]<='z'))
      defaultName[0] += 'A' - 'a';

  GetStrPreference("Player Name", playerName, defaultName);
  menu_set_value(singleGameMenu, kPlayerName, playerName, 0);

  while (!menu_active_is(singleGameMenu,kLevelMedium))
    menu_next_item(singleGameMenu);

  menu_show(singleGameMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      GameControlEvent controlEvent;
        getControlEvent(e, &controlEvent);
        switch (controlEvent.cursorEvent) {
            case GameControlEvent::kQuit:
                exit(0);
                break;
            case GameControlEvent::kDown:
                menu_next_item (singleGameMenu);
                break;
            case GameControlEvent::kUp:
                menu_prev_item (singleGameMenu);
                break;
            case GameControlEvent::kStart:
                menu_validate (singleGameMenu);
                if (menu_active_is(singleGameMenu,kPlayerName))
                  enterStringLoop(singleGameMenu,kPlayerName,playerName);
                else
                  goto mml_play;
                break;
            case GameControlEvent::kBack:
                menu_hide(singleGameMenu);
                return;
                break;
        }
    }
    updateAll(NULL);
  }

mml_play:
  menu_hide (singleGameMenu);

  SelIA ia1[] = { {RANDOM, 350}, {FLOBO, 350}, {FLOBO, 250}, {FLOBO, 180}, {FLOBO,  90}, {JEKO, 350}, {TANIA, 320}, {FLOBO, 62}, {RANDOM,0} };
  SelIA ia2[] = { {FLOBO,  190}, {JEKO , 180}, {TANIA, 160}, {FLOBO,  90}, {GYOM , 210}, {TANIA, 90}, {JEKO,   80}, {GYOM,  90}, {RANDOM,0} };
  SelIA ia3[] = { {TANIA,  130}, {JEKO , 100}, {GYOM ,  90}, {JEKO,   80}, {TANIA,  60}, {GYOM,  60}, {GYOM,   40}, {GYOM,  30}, {RANDOM,0} };

  SelIA *ia = &(ia1[0]);

  gameLevel = 1;
  GAME_ACCEL = 2000;
  if (menu_active_is (singleGameMenu, kLevelMedium)) {
    ia = &(ia2[0]);
    GAME_ACCEL = 1500;
    gameLevel = 2;
  }
  else if (menu_active_is (singleGameMenu, kLevelHard)) {
    ia = &(ia3[0]);
    GAME_ACCEL = 1000;
    gameLevel = 3;
  }

  int score1 = 0;
  int score2 = 0;
  int lives  = 3;
  if (menu_active_is(finishedMenu,  "NO"))
    menu_next_item(finishedMenu);
  if (menu_active_is(looserMenu   ,  "NO"))
    menu_next_item(looserMenu);
  if (menu_active_is(nextLevelMenu,  "NO"))
    menu_next_item(nextLevelMenu);
  if (menu_active_is(gameOver2PMenu, "NO"))
    menu_next_item(gameOver2PMenu);
  gameOverMenu = nextLevelMenu;

  int lastPoints = 0;
  int currentMusicTheme = 0;

  int fini = 0;
  while (!fini)
  {
    PuyoStory myStory(this, score2+1);
    myStory.loop();
    PuyoStarter myStarter(this, true, ia[score2].level, ia[score2].type, currentMusicTheme);
    p1name = playerName;
    p2name = AI_NAMES[score2];
    doom_melt_start(melt, menuBGImage);
    audio_music_switch_theme(currentMusicTheme);
    myStarter.run(score1, score2, lives, lastPoints, 0);
    lastPoints = myStarter.rightPlayerPoints();
    score1 += myStarter.leftPlayerWin();
    score2 += myStarter.rightPlayerWin();
    if (!myStarter.rightPlayerWin())
      lives--;
    else {
      currentMusicTheme = (currentMusicTheme + 1) % NB_MUSIC_THEME;
    }

    if (ia[score2].level == 0) {
      lastPoints += 100000;
      if (menu_active_is (singleGameMenu, kLevelMedium))
        lastPoints += 150000;
      if (menu_active_is (singleGameMenu, kLevelHard))
        lastPoints += 250000;
      fini = 1;
    }

    if (!(menu_active_is(gameOverMenu, "YES") && (lives >= 0)))
      fini = 1;

    if (fini)
    {
      audio_music_start(0);
      doom_melt_start(melt, gameScreen);
      int newOne = setHiScore(lastPoints, p1name);
      if (newOne >= 0)
      {
        updateHighScoresMenu(newOne);
        backLoop(highScoresMenu, NULL);
      }
    }
  }
  SetStrPreference("Player Name", playerName);
}
示例#5
0
void PuyoCommander::startTwoPlayerGameLoop()
{
  char player1Name[256];
  char player2Name[256];

  GetStrPreference("Player1 Name", player1Name, "Player 1");
  GetStrPreference("Player2 Name", player2Name, "Player 2");
  menu_set_value(twoPlayerGameMenu, kPlayer1Name, player1Name, 0);
  menu_set_value(twoPlayerGameMenu, kPlayer2Name, player2Name, 0);

  while (!menu_active_is(twoPlayerGameMenu,kLevelMedium))
    menu_next_item(twoPlayerGameMenu);

  menu_show(twoPlayerGameMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      GameControlEvent controlEvent;
        getControlEvent(e, &controlEvent);
        switch (controlEvent.cursorEvent) {
            case GameControlEvent::kQuit:
                exit(0);
                break;
            case GameControlEvent::kDown:
                menu_next_item (twoPlayerGameMenu);
                break;
            case GameControlEvent::kUp:
                menu_prev_item (twoPlayerGameMenu);
                break;
            case GameControlEvent::kStart:
                menu_validate (twoPlayerGameMenu);
                if (menu_active_is(twoPlayerGameMenu,kPlayer2Name)) {
                  enterStringLoop(twoPlayerGameMenu,kPlayer2Name,player2Name);
                  menu_next_item (twoPlayerGameMenu);
                }
                else if (menu_active_is(twoPlayerGameMenu,kPlayer1Name)) {
                  enterStringLoop(twoPlayerGameMenu,kPlayer1Name,player1Name);
                  menu_next_item (twoPlayerGameMenu);
                }
                else
                  goto mml_play;
                break;
            case GameControlEvent::kBack:
                menu_hide(twoPlayerGameMenu);
                return;
                break;
        }
    }
    updateAll(NULL);
  }

mml_play:
  menu_hide (twoPlayerGameMenu);

  GAME_ACCEL = 2000;
  gameLevel = 1;
  if (menu_active_is (twoPlayerGameMenu, kLevelMedium)) {
    GAME_ACCEL = 1500;
    gameLevel = 2;
  }
  else if (menu_active_is (twoPlayerGameMenu, kLevelHard)) {
    GAME_ACCEL = 1000;
    gameLevel = 3;
  }

  int score1 = 0;
  int score2 = 0;
  gameOverMenu = gameOver2PMenu;
  int currentMusicTheme = 0;
  if (menu_active_is(gameOverMenu, "NO"))
    menu_next_item(gameOverMenu);
  while (menu_active_is(gameOverMenu, "YES")) {
    menu_next_item(gameOverMenu);
    PuyoStarter myStarter(this,false,0,RANDOM,currentMusicTheme);
    audio_music_switch_theme(currentMusicTheme);
    p1name = player1Name;
    p2name = player2Name;
    GAME_ACCEL = 1500;
    doom_melt_start(melt, menuBGImage);
    myStarter.run(score1, score2, 0, 0, 0);
    score1 += myStarter.leftPlayerWin();
    score2 += myStarter.rightPlayerWin();
    currentMusicTheme = (currentMusicTheme + 1) % NB_MUSIC_THEME;
  }

  SetStrPreference("Player1 Name", player1Name);
  SetStrPreference("Player2 Name", player2Name);
  doom_melt_start(melt, gameScreen);
}
示例#6
0
void PuyoCommander::enterStringLoop(Menu *menu, const char *kItem, char out[256])
{
      enum MAP_KEY
        {
	    VK_UP         , // 0
	    VK_UP_LEFT    , // 1
	    VK_LEFT       , // 2
	    VK_DOWN_LEFT  , // 3
	    VK_DOWN       , // 4
	    VK_DOWN_RIGHT , // 5
	    VK_RIGHT      , // 6
	    VK_UP_RIGHT   , // 7
	    VK_START      , // 8
	    VK_SELECT     , // 9
	    VK_FL         , // 10
	    VK_FR         , // 11
	    VK_FA         , // 12
	    VK_FB         , // 13
	    VK_FX         , // 14
	    VK_FY         , // 15
	    VK_VOL_UP     , // 16
	    VK_VOL_DOWN   , // 17
	    VK_TAT          // 18
        };

  int len = 0;
  char prevValue[256];
  strcpy(prevValue, menu_get_value (menu, kItem));
  out[0] = 'A';
  out[1] = 0;
  menu_set_value(menu, kItem, "A");

  while (1)
  {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      GameControlEvent controlEvent;
      getControlEvent(e, &controlEvent);
      switch (controlEvent.cursorEvent) {
        case GameControlEvent::kQuit:
          exit(0);
          break;
        case GameControlEvent::kStart:
           len++;
          out[len] = 0;
          menu_set_value(menu, kItem, out);
          menu_validate (menu);
          return;
        case GameControlEvent::kBack:
          strcpy(out, prevValue);
          menu_set_value(menu, kItem, prevValue);
          return;
      }
      switch (e.type) {
#ifdef GP2X
      	  case SDL_JOYBUTTONDOWN:
           {
    		char ch = 0;
		   if (e.jbutton.button==VK_UP){ //VK_UP
		    ch=out[len]+1;
		    if(ch>=127)ch=32;
		    out[len]=ch;
            menu_set_value(menu, kItem, out, 0);
	        break;
		    }
		    if (e.jbutton.button==VK_DOWN){ //VK_DOWN
		       ch=out[len]-1;
	           if (ch<32)ch=127;
		       out[len]=ch;
            menu_set_value(menu, kItem, out, 0);
	        break;
            }
		    if (e.jbutton.button==VK_LEFT){ //VK_LEFT
               if (len >0){                                            
		          out[len] = 0;
		          len--;
                  menu_set_value(menu, kItem, out, 0);
               }
	        break;
            }
		    if (e.jbutton.button==VK_RIGHT){ //VK_RIGHT
		       if (len < 12){
		          len++;
                  out[len]   = out[len-1];
                  out[len+1] = 0;
                  menu_set_value(menu, kItem, out, 0);
               }
               break;
            }
            }
#else
        case SDL_KEYDOWN:
            char ch = 0;

		if (e.key.keysym.sym ==SDLK_UP){ //VK_UP
		    ch=out[len]+1;
		    if(ch>=127)ch=32;
		    out[len]=ch;
            menu_set_value(menu, kItem, out, 0);
	    break;
		}
		if (e.key.keysym.sym ==SDLK_DOWN){ //VK_DOWN
		    ch=out[len]-1;
		    if (ch<32)ch=127;
   		    out[len]=ch;
            menu_set_value(menu, kItem, out, 0);
	    break;
		}
		if (e.key.keysym.sym ==SDLK_LEFT){ //VK_LEFT
            if (len > 0){
		       out[len] = 0;
		       len--;
		       if(len<0)len=0;
               menu_set_value(menu, kItem, out, 0);
            }
         break;
		}
		if (e.key.keysym.sym ==SDLK_RIGHT){ //VK_RIGHT
            if (len < 12){
		       len++;
		       out[len]   = out[len-1];
		       out[len+1] = 0;
               menu_set_value(menu, kItem, out, 0);
            }
	    break;
		}
#endif
      }
    }
    updateAll(NULL);
  }

}