Beispiel #1
0
/*****************************************************************************
 *
 * Description:
 *    Implements a menu
 *    
 ****************************************************************************/
tU8
drawMenu(tMenu newMenu)
{
  tU8 anyKey;
  
  menu = newMenu;
  
  //draw boarder
  lcdRect(menu.xPos, menu.yPos, menu.xLen, menu.yLen, menu.borderColor);
  lcdRect(menu.xPos+1, menu.yPos+16, menu.xLen-2, menu.yLen-17, menu.bgColor);
  
  //write header text
  lcdGotoxy(menu.headerTextXpos,menu.yPos+1);
  lcdColor(menu.borderColor,menu.headerColor);
  lcdPuts(menu.pHeaderText);
  
  //write choices
  cursor = menu.initialChoice;
  drawMenuCursor();
  
  //dummy call just to reset previous key strokes
  checkKey();

  while(1)
  {
    anyKey = checkKey();
    
    if (anyKey != KEY_NOTHING)
    {
      //select specific function
      if (anyKey == KEY_CENTER)
      {
        return cursor;
      }
      
      else if (anyKey == KEY_UP)
      {
        if (cursor > 0)
          cursor--;
        else
          cursor = menu.noOfChoices - 1;
        drawMenuCursor();
      }
      
      else if (anyKey == KEY_DOWN)
      {
        if (cursor < menu.noOfChoices - 1)
          cursor++;
        else
          cursor = 0;
        drawMenuCursor();
      }
    }
    else
      osSleep(1);
  }
}
Beispiel #2
0
/**
 * \brief The main game loop. This just cycles endlessly, it uses the game's 'state' to determine which screen to show and what to do.
 */
int main(){
	//looping back and forth forever (cards against humanity reference)
	while(1)
	{
		//some basic prep work performed once before our custom intro
		if(game_state == INTRO)
		{
			initialSetup();
			initIntro();
		}
		//perform custom intro
		while(game_state == INTRO)
		{
			//wait until the next frame
			WaitVsync(1);
			drawIntro();
			processIntro();
		}
		//prep the main menu
		if(game_state == MAIN_MENU)
		{
			FadeOut(0,true);
			ClearVram();
			SetTileTable(title_tiles);
			SetFontTilesIndex(TITLE_TILES_SIZE);
			drawMainMenu();
			FadeIn(0,false);
		}
		//draw menu and handle input
		while(game_state == MAIN_MENU)
		{
			WaitVsync(1);
			drawMenuCursor();
			processMainMenu();
		}
		if(game_state== GAME)
		{
			//run our setup for the main game
			ClearVram();
			FadeOut(0,true);
			gameSetup();
			FadeIn(0,false);
		}
		//when we're in the gameplay portion, draw and accept input for the game
		while(game_state == GAME)
		{
			WaitVsync(1);
			processScrollSpeed(); //scrolls screen as appropriate
			updateCity(); //offsets city for parallax
			processControls(); //accepts and processes controller input
			processPlayerMotion(); //update player position
			processSprites(); //updates and moves player image to player position
		}
		if(game_state == HIGH_SCORES)
		{
			FadeOut(0,true);
			SetTileTable(title_tiles);
			SetFontTilesIndex(TITLE_TILES_SIZE);
			drawLocalHighScoreMenu(); //draw up the high score screen
			FadeIn(0,false);
			deathclock=120; //reset death timer to 2 seconds
			if(score > topscores[9])
			{
			    LoadScore(0, 9); //load top 10 saved high scores
			    SaveScore(score); //save our current score if it's high enough
			    drawLocalHighScoreMenu(); //draw up the high score screen
			}
		}
		//draw and accepts input for the local high score screen
		while(game_state == HIGH_SCORES)
		{
			WaitVsync(1);
			processHighScoreMenu();
		}
    }
}