// Main Function void _main(void) { HANDLE handle = PopupNew ("EXAMPLE", 40); PopupAddText (handle, -1, "Option 1", 1); PopupAddText (handle, -1, "Option 2", 2); PopupAddText (handle, 0, "Submenu 3", 3); PopupAddText (handle, 0, "Submenu 4", 4); PopupAddText (handle, -1, "Option 5", 5); PopupAddText (handle, 3, "Suboption 3.1", 6); PopupAddText (handle, 3, "Suboption 3.2", 7); PopupAddText (handle, 3, "Suboption 3.3", 8); PopupAddText (handle, 4, "Suboption 4.1", 9); HANDLE exec_handle = PopupBegin (handle, 0); MenuCheck (exec_handle, 2, MC_CHECK); MenuCheck (exec_handle, 5, MC_FLIP); short result = PopupBeginDo (exec_handle, CENTER, CENTER, 0); push_longint (result); MenuEnd (exec_handle); }
// Main Function void _main( void ){ //Create or load savefile SAVE gameState; if(readSave(&gameState)) makeSave(&gameState); writeSave(&gameState); /*just to test whether writing is possible here so the player doesn't spend a long time and lose their progress*/ //Buffer for the text at the bottom of the scoreString = (char*)malloc(60*sizeof(char)); if(scoreString == NULL) exit(ER_MEMORY); //Pause menu pauseMenu = PopupNew(strConv[11], 50); if(pauseMenu == H_NULL) memkill(4, ER_MEMORY); PopupAddText(pauseMenu, -1, "New Game", 1); PopupAddText(pauseMenu, 0, "Options", 2); PopupAddText(pauseMenu,2,"Toggle Animations",5); PopupAddText(pauseMenu,2,"Reset Save Data",6); PopupAddText(pauseMenu, -1, "Exit", 3); PopupAddText(pauseMenu, -1, "About", 4); //Hiscore Name Entry nameBox = DialogNewSimple(140,35); if(nameBox == H_NULL) memkill(3, ER_MEMORY); DialogAddTitle(nameBox,"NEW HISCORE!",BT_OK,BT_NONE); DialogAddRequest(nameBox,3,14,"Name:", 0, 10, 14); //Game Over Entry gameOver = PopupNew("GAME OVER!", 40); if(gameOver == H_NULL) memkill(2, ER_MEMORY); PopupAddText(gameOver,-1,"Try Again",1); PopupAddText(gameOver,-1,"Exit",2); //About Dialouge aboutBox = DialogNewSimple(140,80); if(aboutBox == H_NULL) memkill(1, ER_MEMORY); DialogAddTitle(aboutBox,"ABOUT",BT_OK,BT_NONE); DialogAddText(aboutBox, 3, 13, "2048: A sliding tile puzzle"); DialogAddText(aboutBox, 3, 21, "Ti68k port by Harrison Cook"); DialogAddText(aboutBox, 3, 29, "Original game by Gabriele Cirulli"); DialogAddText(aboutBox, 3, 37, "\"Based on\" 1024 by Veewo Studio"); DialogAddText(aboutBox, 3, 45, "\"Conceptually Similar to\":"); DialogAddText(aboutBox, 3, 52, "Threes by Asher Vollmer"); DialogAddText(aboutBox, 3, 59, "Built using TIGCC"); ClrScr(); FontSetSys(F_8x10); randomize(); short int key; for(;;){ ClrScr(); drawGrid(gameState.grid); sprintf(scoreString, "Score: %lu Hiscore: %lu by %s", gameState.score, gameState.bscore, gameState.name); if(!isGridAvailable(gameState.grid)){ if(gameState.score > gameState.bscore){ DialogDo(nameBox,CENTER,CENTER, gameState.name,NULL); gameState.bscore = gameState.score; FontSetSys(F_8x10); } gameState.score = 0; initGrid(gameState.grid); switch(PopupDo(gameOver,CENTER,CENTER,0)){ case 1: continue; break; default: goto endGame; } } ST_helpMsg(scoreString); nodraw: ST_busy(ST_IDLE); key = ngetchx(); ST_busy(ST_BUSY); ST_helpMsg(scoreString); char move = 4; if(key == KEY_UP) move = UP; else if(key == KEY_RIGHT) move = RIGHT; else if(key == KEY_DOWN) move = DOWN; else if(key == KEY_LEFT) move = LEFT; else if(key == KEY_OFF || key==KEY_ON) //Turn the calculator off during a game. Resume it later off(); else if(key == KEY_ESC){ //Brings up the pause menu switch (PopupDo(pauseMenu,CENTER,CENTER,0)){ case 1: //1. New Game gameState.score = 0; initGrid(gameState.grid); break; //case 2: //2. Options //this is a submenu case 3: //3: Exit endGame: writeSave(&gameState); memkill(0,0); break; case 4: //4: About DialogDo(aboutBox,CENTER,CENTER,NULL,NULL); //Dialog sets the font weirdly, set it back FontSetSys(F_8x10); break; case 5: //1. Toggle Animations gameState.animations = !gameState.animations; break; case 6: //2. Reset Saved Data makeSave(&gameState); break; } } else goto nodraw; if(move < 4){ if(isDirectionAvailable(gameState.grid, move)){ shiftGrid(gameState.grid,move,&gameState.score, gameState.animations); pushNewTile(gameState.grid); } else goto nodraw; } } }