WorldMap::WorldMap() : mWorld(0), mSub(0), mLevelCount(0), mSection(0), mCount(0), mNewWorld(false), //fult mWorldMax(3) { readButtons(); mMusic = "Resources/Sound/Music/Title_Screen_"; mSprite.setTexture(*ResourceManager::getInst().getTexture("Resources/Menu/WorldMenu/WorldmapBG.png")); mSprite.setPosition(0,0); readSave(); readWorld(); updateWorld(); readAnimals(); LevelManager::getInst().setDeadAnimalCollection(mDeadAnimalVector); mCurrentWorld = mWorld; mCurrentSection = mSection; mFactButton = new FactButton(sf::Vector2f(20,20), "addAnimalipedia", "Resources/Menu/AchievementMenu/faktaknapp.png", "Resources/Sound/Menu/Menu_forward.wav"); mCutscenes.push_back("Resources/Data/Cutscenes/Cutscene_2.xml"); mCutscenes.push_back("Resources/Data/Cutscenes/Cutscene_3.xml"); mCutscenes.push_back("Resources/Data/Cutscenes/Cutscene_ending.xml"); }
/*notice the default arguments for main. SDL expects main to look like that, so don't change it*/ int main(int argc, char *argv[]) { // SDL_Surface *temp = NULL; int done;// the player const Uint8 *keys;// the player /* This section starts by loading the BG as a surface and converting it to a texture This will have to change if I can manage to scroll the trexture arond the player*/ SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &mainWindow, &renderer); SDL_SetWindowTitle(mainWindow, "Nitro Hotness"); if( TTF_Init() == -1 ) { return false; } if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { return false; } InitSpriteSystem(); InitEntitySystem(entityMax); map mymap = setWorld(); ObstacleList ol = newObstacleList(); mew = newPlayer(); Obstacle Doh = newObstacle(0); Road_M Path = initRoad(); AI rival = new_AI(); GUI HUD = InitGUI(); mew.position=0; done = 0; //The music that will be played Mix_Music *music = NULL; Mix_Chunk *buzz = NULL; buzz = Mix_LoadWAV( "sfx/buzz.wav" ); readSave(&mew); showTitle(); showMain(); oldTime = 0; currentTime = 0; mytime = 0; do { oldTime = 0; currentTime = 0; mytime = 0; if( Mix_PlayingMusic() == 0 ) { //Play the music if( Mix_PlayMusic( level_music, -1 ) == -1 ) { return 1; } } SDL_Event e; SDL_PollEvent( &e ); if(&e) { //User requests quit if( e.type == SDL_QUIT ) { done = 1; } //user presses enter to go to next menu //User presses a key else if( e.type == SDL_KEYDOWN ) { //Select surfaces based on key press switch( e.key.keysym.sym ) { case SDLK_LEFT: // slog("left is down"); mew.playerX += 3; mew.accel = (mew.accel - .000001); break; case SDLK_RIGHT: // slog("right is down"); mew.playerX -= 3; mew.accel = (mew.accel - .000001); break; case SDLK_UP: // slog("up is down"); mew.accel = (mew.accel + .00007); Mix_PlayChannel( 1, buzz, 0 ); break; case SDLK_DOWN: // slog("down is down"); mew.accel = (mew.accel - .00008); break; } } else if( e.type == SDL_KEYUP ) { //Select surfaces based on key press switch( e.key.keysym.sym ) { case SDLK_RETURN : if(mew.done ==1) { Mix_HaltMusic(); if(GP == 1) { mew.done=0; lvl++; //slog("new level is %i",lvl); mew.position = 0; rival.position =0; setWorld(); Results(mew.rank,lvl); } else if (GP == 0) { mew.done=0; mew.position = 0; rival.position =0; levelSelect(); } } else { slog("too soon"); } case SDLK_LEFT: // slog("left is up"); e.type = SDLK_CLEAR; break; case SDLK_RIGHT: // slog("right is up"); e.type = SDLK_CLEAR; break; case SDLK_UP: // slog("up is up"); mew.accel = (mew.accel - .001); Mix_HaltChannel(1); e.type = SDLK_CLEAR; break; case SDLK_DOWN: // slog("down is up"); mew.accel = 0; e.type = SDLK_CLEAR; break; default: //slog("simple decel"); mew.accel = (mew.accel-0.00001); break; } } if(mew.position > rival.position) { mew.rank = 1 ; } else if( rival.position > mew.position ) { mew.rank = 2 ; } SDL_RenderClear(renderer); DrawBG(BG1,BG2); roadUpdate(Path,mymap,mew); roadDraw(Path,mymap,&mew); roadFetch(Path,mymap,&mew); checkForObstacles(ol , &mew, Doh); update_AI(&rival, &mew); UpdatePlayer(&mew); DrawGui(HUD,mew); NextFrame(); keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } } }while(!done); //Free the sound effects //Free the music Mix_FreeMusic( music ); CloseEntitySystem(); CloseSpriteSystem(); exit(0); /*technically this will end the program, but the compiler likes all functions that can return a value TO return a value*/ return 0; }
// 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; } } }