bool loadMedia() { //Loading success flag bool success = true; //Open the font gFont = TTF_OpenFont( "lazy.ttf", 28 ); if( gFont == NULL ) { printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() ); success = false; } else { //Set text color as black SDL_Color textColor = { 0, 0, 0, 255 }; //Load stop prompt texture if( !gStartPromptTexture.loadFromRenderedText( "Press S to Start or Stop the Timer", textColor ) ) { printf( "Unable to render start/stop prompt texture!\n" ); success = false; } //Load pause prompt texture if( !gPausePromptTexture.loadFromRenderedText( "Press P to Pause or Unpause the Timer", textColor ) ) { printf( "Unable to render pause/unpause prompt texture!\n" ); success = false; } } return success; }
bool loadMedia() { //Loading success flag bool success = true; //Open the font gFont = TTF_OpenFont( "lazy.ttf", 28 ); if( gFont == NULL ) { printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() ); success = false; } else { //Set text color as black SDL_Color textColor = { 0, 0, 0, 255 }; //Load prompt texture if( !gPromptTextTexture.loadFromRenderedText( "Press Enter to Reset Start Time.", textColor ) ) { printf( "Unable to render prompt texture!\n" ); success = false; } } return success; }
bool loadMedia() { //Loading success flag bool success = true; //Open the font gFont = TTF_OpenFont( "16_true_type_fonts/lazy.ttf", 28 ); if( gFont == NULL ) { printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() ); success = false; } else { //Render text SDL_Color textColor = { 0, 0, 0 }; if( !gTextTexture.loadFromRenderedText( "The quick brown fox jumps over the lazy dog", textColor ) ) { printf( "Failed to render text texture!\n" ); success = false; } } return success; }
bool loadMedia() { //Loading success flag bool success = true; //Open the font gFont = TTF_OpenFont( "assets/lazy.ttf", 28 ); if( gFont == NULL ) { printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() ); success = false; } else { //Render the prompt SDL_Color textColor = { 0, 0, 0, 0xFF }; if( !gPromptTextTexture.loadFromRenderedText( "Enter Text:", textColor ) ) { printf( "Failed to render prompt text!\n" ); success = false; } } return success; }
void Scoreboard::render( SDL_Renderer* gRenderer, TTF_Font* gFont, LTexture gTextTexture ) { string s = std::to_string( static_cast<long long>( score ) ); s = string( 10 - s.size(), ' ' ) + s; string text = "Score: " + s; gTextTexture.loadFromRenderedText( text, textColor ); gTextTexture.setBlendMode( SDL_BLENDMODE_BLEND ); gTextTexture.setAlpha( 150 ); gTextTexture.render( xPos, yPos, gRenderer ); }
bool loadMedia() { //Loading success flag bool success = true; gFont = TTF_OpenFont( "images/lazy.ttf", 22 ); if( gFont == NULL ) { printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() ); success = false; } else { //Render text SDL_Color textColor = { 0xFF, 0xFF, 0 }; if( !gPlayerLifesTexture.loadFromRenderedText( " Lifes: ", textColor, gRenderer, gFont ) ) { printf( "Failed to render text texture!\n" ); success = false; } } if( !gPlayerTexture.loadFromFile( "images/player.bmp", gRenderer ) ) { printf( "Failed to load dot texture!\n" ); success = false; } if( !gProjTexture.loadFromFile( "images/projectile.bmp", gRenderer ) ) { printf( "Failed to load dot texture!\n" ); success = false; } if( !gShipTexture.loadFromFile( "images/ship.bmp", gRenderer ) ) { printf( "Failed to load dot texture!\n" ); success = false; } if( !gLoseScreen.loadFromFile( "images/losescreen.png", gRenderer ) ) { printf( "Failed to load LoSE screen texture!\n" ); success = false; } return success; }
void loop () { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Calculate and correct fps float avgFPS = countedFrames / ( fpsTimer.getTicks() / 1000.f ); if( avgFPS > 2000000 ) { avgFPS = 0; } //Set text to be rendered timeText.str( "" ); timeText << "Average Frames Per Second " << avgFPS; //Render text if( !gFPSTextTexture.loadFromRenderedText( timeText.str().c_str(), textColor ) ) { printf( "Unable to render FPS texture!\n" ); } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render textures gFPSTextTexture.render( ( SCREEN_WIDTH - gFPSTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gFPSTextTexture.getHeight() ) / 2 ); //Update screen SDL_RenderPresent( gRenderer ); ++countedFrames; }
void loop () { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Reset start time on return keypress else if( e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_RETURN ) { startTime = SDL_GetTicks(); } } //Set text to be rendered timeText.str( "" ); timeText << "Milliseconds since start time " << SDL_GetTicks() - startTime; //Render text if( !gTimeTextTexture.loadFromRenderedText( timeText.str().c_str(), textColor ) ) { printf( "Unable to render time texture!\n" ); } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render textures gPromptTextTexture.render( ( SCREEN_WIDTH - gPromptTextTexture.getWidth() ) / 2, 0 ); gTimeTextTexture.render( ( SCREEN_WIDTH - gPromptTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gPromptTextTexture.getHeight() ) / 2 ); //Update screen SDL_RenderPresent( gRenderer ); }
int load_media(void) { /* open the font */ gFont = TTF_OpenFont("lazy.ttf", 28); if (gFont == NULL) { fprintf(stderr, "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError()); return -1; } /* set text color as black */ SDL_Color textColor = { 0, 0, 0, 255 }; /* load prompt texture */ if (gPromptTexture.loadFromRenderedText( "Please Enter to Reset Start Time.", textColor) == -1) { fprintf(stderr, "Unable to render prompt texture!\n"); return -1; } return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //Set text color as black SDL_Color textColor = { 0, 0, 0, 255 }; //The frames per second timer LTimer fpsTimer; //In memory text stream std::stringstream timeText; //Start counting frames per second int countedFrames = 0; fpsTimer.start(); //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Calculate and correct fps float avgFPS = countedFrames / ( fpsTimer.getTicks() / 1000.f ); if( avgFPS > 2000000 ) { avgFPS = 0; } //Set text to be rendered timeText.str( "" ); timeText << "Average Frames Per Second " << avgFPS; //Render text if( !gFPSTextTexture.loadFromRenderedText( timeText.str().c_str(), textColor ) ) { printf( "Unable to render FPS texture!\n" ); } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render textures gFPSTextTexture.render( ( SCREEN_WIDTH - gFPSTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gFPSTextTexture.getHeight() ) / 2 ); //Update screen SDL_RenderPresent( gRenderer ); ++countedFrames; } } } //Free resources and close SDL close(); return 0; }
int main(int argc, char *argv[]) { Tile *tiles[400]; Mobs *ghosts[4]; std::vector<Tile> coins; game.init(); game.loadMedia(); loadPlayerTex(); game.loadGhosts(ghosts); if( game.setTiles(tiles) == false) { printf("set tiles err \n"); return -1; } for(int i = 0; i < 400; ++i) { if(tiles[i]->getType() == 0) coins.push_back( Tile( tiles[i]->getBox().x, tiles[i]->getBox().y, 0 ) ); } LTexture coinTex; coinTex.loadFromFile( "Data/Art/coin.png", game.getRenderer() ); for(int i = 0; i < coins.size(); ++i) { coins[i].tileTex = &coinTex; } bool quit = false; LMenu menu( game.getRenderer() ); menu.run(); if(menu.isFinished() == 1) quit = true; Player player(32, 32); player.CurrentDirection = MovementRight; //game.setPlayerTex(player); LTimer fpsTimer; LTimer capTimer; int countedFrames = 0; int anim = 0; fpsTimer.start(); const int gameEEN_FPS = 60; const int gameEEN_TICK_PER_FRAME = 1000 / gameEEN_FPS; SDL_Event e; while( !quit ) { capTimer.start(); while( SDL_PollEvent(&e) != 0 ) { if(e.type == SDL_QUIT) { quit = true; } player.handleEvent(e); } //printf("%d, %d, %d, %d \n", leftCorn.x, leftCorn.y, leftCorn.w, leftCorn.h); //printf(" %d \n", player.CurrentDirection); game.GhostsAI(player, ghosts, tiles); game.GhostsCollision(ghosts, tiles); player.update(); SDL_Rect topBox = {player.getPlayerBox().x + 2, player.getPlayerBox().y - 20, 1, 20}; SDL_Rect rightBox = {player.getPlayerBox().x + player.getPlayerBox().w, player.getPlayerBox().y + 2, 20, 1}; SDL_Rect botBox = {player.getPlayerBox().x + 2, player.getPlayerBox().y + player.getPlayerBox().h, 1, 20}; SDL_Rect leftBox = {player.getPlayerBox().x - 20, player.getPlayerBox().y + 2, 20, 1}; SDL_Rect topBox2 = {player.getPlayerBox().x + player.playerBox.w - 4, player.getPlayerBox().y - 20, 1, 20}; SDL_Rect rightBox2 = {player.getPlayerBox().x + player.playerBox.w, player.getPlayerBox().y + player.playerBox.h - 4, 20, 1}; SDL_Rect botBox2 = {player.getPlayerBox().x + player.getPlayerBox().w - 4, player.getPlayerBox().y + player.getPlayerBox().h, 1, 20}; SDL_Rect leftBox2 = {player.getPlayerBox().x - 20, player.getPlayerBox().y + player.playerBox.h - 4, 20, 1}; if (game.Collision(player, tiles) == 1 ) { player.playerBox.x += PLAYER_SPEED; if(player.directionY == 1) player.CurrentDirection = MovementUp; if(player.directionY == 3) player.CurrentDirection = MovementDown; } if (game.Collision(player, tiles) == 2 ) { player.playerBox.x -= PLAYER_SPEED; if(player.directionY == 1) player.CurrentDirection = MovementUp; if(player.directionY == 3) player.CurrentDirection = MovementDown; } if (game.Collision(player, tiles) == 3 ) { player.playerBox.y += PLAYER_SPEED; if(player.directionX == 2) player.CurrentDirection = MovementRight; if(player.directionX == 4) player.CurrentDirection = MovementLeft; player.directionX == 0; } if (game.Collision(player, tiles) == 4 ) { player.playerBox.y -= PLAYER_SPEED; if(player.directionX == 2) player.CurrentDirection = MovementRight; if(player.directionX == 4) player.CurrentDirection = MovementLeft; player.directionX == 0; } for(int i = 0; i < 400; i++) { if(game.checkCollision( botBox, tiles[i]->getBox() ) && game.checkCollision( botBox2, tiles[i]->getBox() ) && player.turnDir == 3 && tiles[i]->getType() == 0 ) { player.CurrentDirection = MovementDown; player.turnDir = 0; break; } if(game.checkCollision( topBox, tiles[i]->getBox() ) && game.checkCollision( topBox2, tiles[i]->getBox() ) && player.turnDir == 1 && tiles[i]->getType() == 0 ) { player.CurrentDirection = MovementUp; player.turnDir = 0; break; } if(game.checkCollision( leftBox, tiles[i]->getBox() ) && game.checkCollision( leftBox2, tiles[i]->getBox() ) && player.turnDir == 4 && tiles[i]->getType() == 0 ) { player.CurrentDirection = MovementLeft; player.turnDir = 0; break; } if(game.checkCollision( rightBox, tiles[i]->getBox() ) && game.checkCollision( rightBox2, tiles[i]->getBox() ) && player.turnDir == 2 && tiles[i]->getType() == 0 ) { player.CurrentDirection = MovementRight; player.turnDir = 0; break; } } for(int i = 0; i < coins.size(); i++) { if(game.checkCollision(player.getPlayerBox(), coins[i].getBox()) && !coins[i].dead) { LTexture emptyTex; emptyTex.loadFromFile( "Data/Art/empty.png", game.getRenderer() ); coins[i].tileTex = &emptyTex; coins[i].dead = true; player.score += 10; } } if( player.getPlayerX() + player.getPlayerBox().w <= 0 && player.CurrentDirection == MovementLeft) { player.playerBox.x = SCREEN_WIDTH - 1; } if( player.getPlayerX() >= SCREEN_WIDTH && player.CurrentDirection == MovementRight ) { player.playerBox.x = 1 - player.getPlayerBox().w; } anim++; if(anim == 420) anim = 0; // // // RENDERING // // // // // // RENDERING // // // // // // RENDERING // // // // // // RENDERING // // // // // // RENDERING // // // SDL_Color textColor = { 0xff, 0x00, 0xBA }; SDL_Rect textRect = {200, 0, 64, 32}; char* pScore = new char[6]; sprintf(pScore, "%d", player.score); std::string pScoreStr; for(int i = 0; i < 3; ++i) { pScoreStr.push_back(pScore[i]); } scoreTex.loadFromRenderedText("SCORE : " + pScoreStr, textColor, game.getRenderer(), menu.font); SDL_SetRenderDrawColor( game.getRenderer(), 0x00, 0x00, 0x00, 0x00 ); SDL_RenderClear( game.getRenderer() ); //"SCORE : " + pScoreStr for(int i = 0; i < 400; i++) { //printf( "%d = %d \n ", i, tiles[i]->getType()); tiles[i]->show(game.getRenderer()); } for( int i = 0; i < coins.size(); ++i) { coins[i].show( game.getRenderer() ); } for (int i = 0; i < 4; i++){ ghosts[i]->render(game.getRenderer()); } bool pace = anim % 20 > 10; if(player.CurrentDirection == MovementLeft || player.CurrentDirection == MovementRight) { if(pace) { player.setPlayerTex(&playerTextures[0]); } else { player.setPlayerTex(&playerTextures[1]); } if(player.CurrentDirection == MovementRight) player.render(game.getRenderer(), SDL_FLIP_NONE , 32, 32); if(player.CurrentDirection == MovementLeft) player.render(game.getRenderer(), SDL_FLIP_HORIZONTAL , 32, 32); } if(player.CurrentDirection == MovementDown || player.CurrentDirection == MovementUp) { if(pace) { player.setPlayerTex(&playerTextures[2]); } else { player.setPlayerTex(&playerTextures[3]); } if(player.CurrentDirection == MovementUp) player.render(game.getRenderer(), SDL_FLIP_NONE , 32, 32); if(player.CurrentDirection == MovementDown) player.render(game.getRenderer(), SDL_FLIP_VERTICAL , 32, 32); } //SpriteSheetTexture.NewRender(player.playerBox.x, player.playerBox.y, currentClip, gRenderer); scoreTex.render(0, 0, game.getRenderer(), SDL_FLIP_NONE, 150, 40); SDL_RenderPresent( game.getRenderer() ); float avgFPS = countedFrames / ( fpsTimer.getTicks() / 1000.f ); if( avgFPS > 2000000 ) { avgFPS = 0; } ++countedFrames; int frameTicks = capTimer.getTicks(); if( frameTicks < gameEEN_TICK_PER_FRAME ) { SDL_Delay( gameEEN_TICK_PER_FRAME - frameTicks ); } } //system("pause"); return 0; }
int main( int argc, char* args[]) { SDL_Color textColor = { 255, 255, 200, 255 }; // int i = 0; int timer = 0; int direction = 1; // 1 : left moving / 2 : right bool screenHit = false; int PlayerLifes = 3; std::stringstream PlayerLifesText; if( !init() ) { printf( "Failed to initialize!\n" ); } else { if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { bool quit = false; SDL_Event e; Player player(0, SCREEN_HEIGHT - gPlayerTexture.getHeight()); player.setTex(&gPlayerTexture); gameObjects.push_back(&player); createArmy(100, 50, 0); while( !quit ) { while( SDL_PollEvent( &e ) != 0 ) { if( e.type == SDL_QUIT ) { quit = true; } //if(e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_n) //{ // PlayerLifes = 1; // deleteShips(); // createArmy(100, 50, 0); //} bool shouldShoot = player.handleEvent( e ); if (shouldShoot) addProj(player); } if(PlayerLifes <= 0) { SDL_SetRenderDrawColor( gRenderer, 0x00, 0x00, 0x00, 0x00 ); SDL_RenderClear( gRenderer ); gLoseScreen.render(0, 0, gRenderer); } else { PlayerLifesText.str(""); PlayerLifesText << "Lifes " << PlayerLifes; gPlayerLifesTexture.loadFromRenderedText( PlayerLifesText.str().c_str(), textColor, gRenderer, gFont ); if( timer > 100 ) timer = 0; timer += 1; if( timer % 3 == 0) { if(ifScreenEndHit()) { screenHit = true; direction += 1; } movingShips(direction, screenHit); if(screenHit) screenHit = false; } if( timer % 50 == 0) { shipFire(); } ifProjCollShip(); projCollPlayer(player, PlayerLifes); //cout << PlayerLifes << endl; for(std::list<GameObject*>::iterator it = gameObjects.begin(); it != gameObjects.end();) { if( (*it)->alive == true ) (*it)->update(); ++it; } for(vector<Projectile*>::iterator it = shipProjects.begin(); it != shipProjects.end(); ++it) { if( (*it)->alive == true) (*it)->move(); } // RENDERING SDL_SetRenderDrawColor( gRenderer, 0x00, 0x00, 0x00, 0x00 ); SDL_RenderClear( gRenderer ); for(vector<Projectile*>::iterator it = shipProjects.begin(); it != shipProjects.end(); ++it) { if( (*it)->alive == true) (*it)->render(gRenderer); } for(std::list<GameObject*>::iterator it = gameObjects.begin(); it != gameObjects.end();) { if ((*it)->alive == true ) (*it)->render(gRenderer); ++it; } for(vector<vector<Ships*>>::iterator it = ships.begin(); it != ships.end(); ++it ) { for(vector<Ships*>::iterator itt = (*it).begin(); itt != (*it).end(); ++itt) { if( (*itt)->alive == true ) (*itt)->render(gRenderer); } } } gPlayerLifesTexture.render(5, 5, gRenderer); SDL_RenderPresent( gRenderer ); //deleteDeadShips(); m } } } close(); //system("pause"); return 0; }
//Displays the actual game with car handling void Application::gameStart(std::fstream& fileToRead, int& choosenCar) { if (gWindow != NULL) { if (!loadMedia(choosenCar)) { printf("Failed to load media!\n"); } } //Main loop flag bool quit = false; //Event handler SDL_Event e; SDL_Color textColor = { 0xFF, 0xFF, 0xFF, 0xFF }; LTexture timeTexture; int timeTemp = gameData.getTime(); const int mapFinishX = 870; const int mapFinishY = 620; bool firstRun = true; switch (choosenCar) { case CAR_ONE: gCarTexture = gFirstCarTexture; break; case CAR_TWO: gCarTexture = gSecondCarTexture; break; case CAR_THREE: gCarTexture = gThirdCarTexture; break; } //The car that will be moving around on the screen Car car(choosenCar, gCarTexture.getWidth(), gCarTexture.getHeight(), startingAngle, map.getDifficulty()); SDL_Rect* wall = map.getObstacles(); gameData.setStartGame(obj.getCurrentTime(obj.getCurrentDateTime())); if (isMusicOn) { car.loadSounds(); } //While application is running while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //Handle input for the car car.handleEvent(e); if (onMusicButton->handleEvent(&e)) { checkMusicInGame(car, e); } } if (firstRun) { loadingScreen(gRenderer, timeTexture, textColor, car); firstRun = false; } //Clear screen SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); gBackgroundTexture.render(*gRenderer, 0, 0); timeTexture.render(*gRenderer, 620, 10); renderMusicButton(); if (SDL_GetTicks() - startTimeTemp >= ONE_SECOND) { if (!timeTexture.loadFromRenderedText(timer(timeTemp), textColor, *gRenderer)) { printf("Unable to render time texture!\n"); } timer(timeTemp--); startTimeTemp = SDL_GetTicks(); } //test the obstacles //drawObstaclesHelper(*gRenderer, wall, map.getObstaclesNumber()); //Move the car and check collision car.move(wall, map.getObstaclesNumber(), SCREEN_HEIGHT, SCREEN_WIDTH); if (timeTemp < 0) { //YOU LOSE caseYouLose(fileToRead); return; } else if (car.getCarX() >= mapFinishX && car.getCarY() >= mapFinishY) { //YOU WIN caseYouWin(fileToRead); return; } //Render car car.render(gCarTexture, gSpeedMeter, gSpeedMeterClips, *gRenderer); //UPDATE SCREEN SDL_RenderPresent(gRenderer); } }
bool loadMedia() { //Text rendering color SDL_Color textColor = { 0, 0, 0, 0xFF }; SDL_Color highlightColor = { 0xFF, 0, 0, 0xFF }; //Loading success flag bool success = true; //Open the font gFont = TTF_OpenFont( "33_file_reading_and_writing/lazy.ttf", 28 ); if( gFont == NULL ) { printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() ); success = false; } else { //Render the prompt if( !gPromptTextTexture.loadFromRenderedText( "Enter Data:", textColor ) ) { printf( "Failed to render prompt text!\n" ); success = false; } } //Open file for reading in binary SDL_RWops* file = SDL_RWFromFile( "33_file_reading_and_writing/nums.bin", "r+b" ); //File does not exist if( file == NULL ) { printf( "Warning: Unable to open file! SDL Error: %s\n", SDL_GetError() ); //Create file for writing file = SDL_RWFromFile( "33_file_reading_and_writing/nums.bin", "w+b" ); if( file != NULL ) { printf( "New file created!\n" ); //Initialize data for( int i = 0; i < TOTAL_DATA; ++i ) { gData[ i ] = 0; SDL_RWwrite( file, &gData[ i ], sizeof(Sint32), 1 ); } //Close file handler SDL_RWclose( file ); } else { printf( "Error: Unable to create file! SDL Error: %s\n", SDL_GetError() ); success = false; } } //File exists else { //Load data printf( "Reading file...!\n" ); for( int i = 0; i < TOTAL_DATA; ++i ) { SDL_RWread( file, &gData[ i ], sizeof(Sint32), 1 ); } //Close file handler SDL_RWclose( file ); } //Initialize data textures gDataTextures[ 0 ].loadFromRenderedText( std::to_string( (_Longlong)gData[ 0 ] ), highlightColor ); for( int i = 1; i < TOTAL_DATA; ++i ) { gDataTextures[ i ].loadFromRenderedText( std::to_string( (_Longlong)gData[ i ] ), textColor ); } return success; }
int main(int argc, char* args[]) { if (!init()) { printf("Failed to initialize!\n"); } else { if (!loadMedia()) { printf("Failed to load media!\n"); } else { bool quit = false; SDL_Event e; LTexture word; SDL_Color textColor = { 0, 0, 0, 255 }; std::stringstream timeText; LButton* ptrButton[NUMBER_OF_BUTTON]; for (int i = 0; i < NUMBER_OF_BUTTON; ++i) { ptrButton[i] = &gButton[i]; } bool temp[NUMBER_OF_BUTTON] = { false }; while (!quit) { while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } for (int i = 0; i < NUMBER_OF_BUTTON; ++i) { temp[i] = ptrButton[i]->handleEvent(e); } for (int i = 0; i < NUMBER_OF_TILE * 4; i++) { gTile[i].handleEvent(e); } //Handle window events gWindow.handleEvent(e); if (gWindow.isMinimized()) { gTimer.pause(); } else { gTimer.unpause(); } } logicButtons(temp); // for (int i = 0; i < 5; ++i){ // for (int g = 0; g < 6; ++g){ // board.unblock(i, g); // } // } // for (int i = 0; i < 5; ++i){ // for (int g = 0; g < 6; ++g){ // board.unblock(i, g); // } // } if (!gWindow.isMinimized()) { SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); renderTexture(&gSceneTexture, 0, 0, gWindow.getWidth(), gWindow.getHeight()); for (int i = 0; i < NUMBER_OF_BUTTON; ++i) { ptrButton[i]->setPosition(650, 50 + 40 * i); ptrButton[i]->renderButton(); } timeText.str(""); timeText << "Time: " << std::fixed << std::setprecision(1) << (gTimer.getTicks() / 1000.f); //Render text if (!word.loadFromRenderedText(timeText.str().c_str(), textColor)) { printf("Unable to render time texture!\n"); } word.render(20, 550); if (gPtrHelp == NULL) { if (board.isStarted()) { drowGame(board); } } else { gPtrHelp->render(25, 50); } SDL_RenderPresent(gRenderer); } } } } close(); return 0; }
int main( int argc, char* args[] ){ //Start up SDL and create window if(!init()){ printf( "Failed to initialize!\n" ); } else{ //Load media if(!loadMedia()){ printf( "Failed to load media!\n" ); } else{ //Main loop flag bool quit = false; //Event handler SDL_Event e; //In memory text stream stringstream timeText; //Start global timer gTimer.start(); //The frames per second timer LTimer fpsTimer; //Start counting frames per second int countedFrames = 0; fpsTimer.start(); //Count of balls in screen int nBalls = 4; //Set text color as black SDL_Color textColor = {0, 0, 0, 255}; //loadBalls in vector gBalls loadBalls(nBalls); //While application is running while(!quit){ //Handle events on queue while(SDL_PollEvent(&e) != 0){ //User requests quit if(e.type == SDL_QUIT){ quit = true; } } //Clear screen SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); //The ball in the center of the screen to which all other ball collides with Ball ball(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 0, 0); ball.render(); //Calculate and correct fps float avgFPS = countedFrames/(fpsTimer.getTicks()/1000.f); if(avgFPS > 2000000){ avgFPS = 0; } //Set text to be rendered timeText.str(""); timeText << "Average Frames Per Second " << avgFPS; //Render text if(!gFPSTextTexture.loadFromRenderedText(timeText.str().c_str(), textColor)){ printf("Unable to render FPS texture!\n"); } gFPSTextTexture.render((SCREEN_WIDTH-gFPSTextTexture.getWidth())/2, 0); //Move and render the balls inside the vector gBalls for(int i = 0; i < nBalls; i++){ //bug: Needs to include all the balls inside the gBalls for the move method gBalls.at(i).move(ball.getCollider()); gBalls.at(i).render(); } //Update screen SDL_RenderPresent(gRenderer); ++countedFrames; } } } //Free resources and close SDL close(); return 0; }
//Does a countdown before the start of the race void Application::loadingScreen(SDL_Renderer* gRenderer, LTexture& timeTexture, SDL_Color& textColor, Car &car) { LTexture one, two, three; if (!one.loadFromFile("img/One.png", gRenderer)) { printf("Failed to load one.png !\n"); } if (!two.loadFromFile("img/Two.png", gRenderer)) { printf("Failed to load two.png!\n"); } if (!three.loadFromFile("img/Three.png", gRenderer)) { printf("Failed to load three.png !\n"); } Mix_HaltMusic(); beep = Mix_LoadWAV("sounds/beep.wav"); go = Mix_LoadWAV("sounds/go.wav"); if (beep == NULL) { printf("Failed to load beep.wav !\n"); } if (go == NULL) { printf("Failed to load go.wav !\n"); } for (int i = 3; i > 0; i--) { //Clear screen SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); gBackgroundTexture.render(*gRenderer, 0, 0); renderMusicButton(); switch (i) { case 1: one.render(*gRenderer, 0, 0); break; case 2: two.render(*gRenderer, 0, 0); break; case 3: three.render(*gRenderer, 0, 0); break; } timeTexture.loadFromRenderedText(timer(gameData.getTime()), textColor, *gRenderer); car.render(gCarTexture, gSpeedMeter, gSpeedMeterClips, *gRenderer); timeTexture.render(*gRenderer, 620, 10); if (isMusicOn) { Mix_PlayChannel(-1, beep, 0); } SDL_RenderPresent(gRenderer); SDL_Delay(1000); } if (isMusicOn) { Mix_PlayChannel(-1, go, 0); } }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //Set text color as black SDL_Color textColor = { 0, 0, 0, 0xFF }; //The current input text. std::string inputText = "Some Text"; gInputTextTexture.loadFromRenderedText( inputText.c_str(), textColor ); //Enable text input SDL_StartTextInput(); //While application is running while( !quit ) { //The rerender text flag bool renderText = false; //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Special key input else if( e.type == SDL_KEYDOWN ) { //Handle backspace if( e.key.keysym.sym == SDLK_BACKSPACE && inputText.length() > 0 ) { //lop off character inputText.pop_back(); renderText = true; } //Handle copy else if( e.key.keysym.sym == SDLK_c && SDL_GetModState() & KMOD_CTRL ) { SDL_SetClipboardText( inputText.c_str() ); } //Handle paste else if( e.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL ) { inputText = SDL_GetClipboardText(); renderText = true; } } //Special text input event else if( e.type == SDL_TEXTINPUT ) { //Not copy or pasting if( !( ( e.text.text[ 0 ] == 'c' || e.text.text[ 0 ] == 'C' ) && ( e.text.text[ 0 ] == 'v' || e.text.text[ 0 ] == 'V' ) && SDL_GetModState() & KMOD_CTRL ) ) { //Append character inputText += e.text.text; renderText = true; } } } //Rerender text if needed if( renderText ) { //Text is not empty if( inputText != "" ) { //Render new text gInputTextTexture.loadFromRenderedText( inputText.c_str(), textColor ); } //Text is empty else { //Render space texture gInputTextTexture.loadFromRenderedText( " ", textColor ); } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render text textures gPromptTextTexture.render( ( SCREEN_WIDTH - gPromptTextTexture.getWidth() ) / 2, 0 ); gInputTextTexture.render( ( SCREEN_WIDTH - gInputTextTexture.getWidth() ) / 2, gPromptTextTexture.getHeight() ); //Update screen SDL_RenderPresent( gRenderer ); } //Disable text input SDL_StopTextInput(); } } //Free resources and close SDL close(); return 0; }
//Displays rules and how to play instructions void Application::instructionsScreen() { if (gWindow == NULL) { printf("Failed to load media!\n"); } //Main loop flag bool quit = false; //Text Color SDL_Color textColor = { 0x00, 0xCC, 0xFF }; //Back button Button back(160, 50, 370, 600); //Textures LTexture backgroundTexture; LTexture arrows; LTexture backText; LTexture instructions; LTexture instructionsTwo; LTexture instructionsUp; LTexture instructionsBack; LTexture instructionsLeft; LTexture instructionsLeftOne; LTexture instructionsLeftTwo; LTexture instructionsRight; LTexture instructionsRightOne; LTexture instructionsRightTwo; LTexture instructionsChoice; LTexture slogan; LTexture sloganTwo; //-------------BUTTON SET POS & BCKGROUND---------- backgroundTexture.loadFromFile("img/menu.png", gRenderer); back.loadMedia("img/buttons/button.png", *gRenderer); arrows.loadFromFile("img/arrowKeys.png", gRenderer); //------------------TEXT LOADING------------------- backText.loadFromRenderedText("Back", textColor, *gRenderer); instructions.loadFromRenderedText("The goal is to reach the finish line before the time runs out!", textColor, *gRenderer); instructionsTwo.loadFromRenderedText("Get moving around using the arrow keys as follows :", textColor, *gRenderer); instructionsUp.loadFromRenderedText("Up - accelerate the car towards it's fornt.", textColor, *gRenderer); instructionsBack.loadFromRenderedText("Down - start driving the car in reverse.", textColor, *gRenderer); instructionsLeftOne.loadFromRenderedText("Left:", textColor, *gRenderer); instructionsLeft.loadFromRenderedText("Hold it at least 0.3 sec and release", textColor, *gRenderer); instructionsLeftTwo.loadFromRenderedText("to turn the car in this direction.", textColor, *gRenderer); instructionsRightOne.loadFromRenderedText("Right:", textColor, *gRenderer); instructionsRight.loadFromRenderedText("Hold it atleast 0.3 sec and release", textColor, *gRenderer); instructionsRightTwo.loadFromRenderedText("to turn the car in this direction.", textColor, *gRenderer); slogan.loadFromRenderedText("Good luck!", textColor, *gRenderer); sloganTwo.loadFromRenderedText("And may the Gods be ever in your favour!", textColor, *gRenderer); instructionsChoice.loadFromRenderedText("When you choose your car, press enter to begin the game", textColor, *gRenderer); //Event handler SDL_Event e; //While application is running while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = true; } else if (onMusicButton->handleEvent(&e)) { if (isMusicOn) { isMusicOn = false; Mix_PauseMusic(); } else { isMusicOn = true; Mix_ResumeMusic(); } } else if (e.key.keysym.sym == SDLK_ESCAPE) { return; } else if (e.type == SDL_MOUSEBUTTONUP) { if (back.handleEvent(&e)) { return; } } } //--------------CLEAR SCREEN----------- SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); //---------------RENDER TEXT---------------- backgroundTexture.render(*gRenderer, 0, 0); arrows.render(*gRenderer, ((SCREEN_WIDTH - arrows.getWidth()) / 2), 200); back.render(*gRenderer); backText.render(*gRenderer, ((SCREEN_WIDTH - backText.getWidth()) / 2), 614); instructions.render(*gRenderer, ((SCREEN_WIDTH - instructions.getWidth()) / 2), 50); instructionsTwo.render(*gRenderer, ((SCREEN_WIDTH - instructionsTwo.getWidth()) / 2), 100); instructionsUp.render(*gRenderer, ((SCREEN_WIDTH - instructionsUp.getWidth()) / 2), 150); instructionsBack.render(*gRenderer, ((SCREEN_WIDTH - instructionsUp.getWidth()) / 2), 370); instructionsLeft.render(*gRenderer, 0, 230); instructionsLeftOne.render(*gRenderer, ((SCREEN_WIDTH - instructionsLeftOne.getWidth()) / 6), 200); instructionsLeftTwo.render(*gRenderer, 10, 270); instructionsRight.render(*gRenderer, 540, 230); instructionsRightOne.render(*gRenderer, 680, 200); instructionsRightTwo.render(*gRenderer, 560, 270); slogan.render(*gRenderer, ((SCREEN_WIDTH - slogan.getWidth()) / 2), 510); sloganTwo.render(*gRenderer, ((SCREEN_WIDTH - sloganTwo.getWidth()) / 2), 540); instructionsChoice.render(*gRenderer, ((SCREEN_WIDTH - instructionsChoice.getWidth()) / 2), 450); if (isMusicOn) { onMusicButton->render(*gRenderer); } else { offMusicButton->render(*gRenderer); } //------------- UPDATE SCREEN---------------- SDL_RenderPresent(gRenderer); } }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //Set text color as black SDL_Color textColor = { 0, 0, 0, 255 }; //The application timer LTimer timer; //In memory text stream std::stringstream timeText; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Reset start time on return keypress else if( e.type == SDL_KEYDOWN ) { //Start/stop if( e.key.keysym.sym == SDLK_s ) { if( timer.isStarted() ) { timer.stop(); } else { timer.start(); } } //Pause/unpause else if( e.key.keysym.sym == SDLK_p ) { if( timer.isPaused() ) { timer.unpause(); } else { timer.pause(); } } } } //Set text to be rendered timeText.str( "" ); timeText << "Seconds since start time " << ( timer.getTicks() / 1000.f ) ; //Render text if( !gTimeTextTexture.loadFromRenderedText( timeText.str().c_str(), textColor ) ) { printf( "Unable to render time texture!\n" ); } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render textures gStartPromptTexture.render( ( SCREEN_WIDTH - gStartPromptTexture.getWidth() ) / 2, 0 ); gPausePromptTexture.render( ( SCREEN_WIDTH - gPausePromptTexture.getWidth() ) / 2, gStartPromptTexture.getHeight() ); gTimeTextTexture.render( ( SCREEN_WIDTH - gTimeTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gTimeTextTexture.getHeight() ) / 2 ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
//Displays last ten games on screen void Application::lastTenGamesScreen(std::fstream& fileToRead) { if (gWindow == NULL) { printf("Unable to open window"); } bool quit = false; //Main loop flag SDL_Color textColor = { 0x00, 0xCC, 0xFF }; LTexture backgroundTexture; Button back(160, 50, 370, 600); LTexture backText; LTexture description; std::string descriptionText = "Player Credit"; descriptionText.append(" "); descriptionText.append("Time"); descriptionText.append(" "); descriptionText.append("Player Bet"); descriptionText.append(" "); descriptionText.append("Player Win"); descriptionText.append(" "); descriptionText.append("Difficulty"); std::vector<PreviousGame> lastTenGames = lastTenGamesManager.readLastTenGames(fileToRead); LTexture lastTenGamesCredit[10]; LTexture lastTenGamesTime[10]; LTexture lastTenGamesBet[10]; LTexture lastTenGamesWin[10]; LTexture lastTenGamesDiff[10]; for (int i = 0; i < 10; i++) { std::string tempCredit = std::to_string((int)lastTenGames[i].getCredit()); std::string tempTime = std::to_string(lastTenGames[i].getTime()); std::string tempBet = std::to_string((int)lastTenGames[i].getPlayerBet()); std::string tempWin = std::to_string((int)lastTenGames[i].getPlayerWin()); std::string tempDiff = lastTenGames[i].getDifficulty(); lastTenGamesCredit[i].loadFromRenderedText(tempCredit, textColor, *gRenderer); lastTenGamesTime[i].loadFromRenderedText(tempTime, textColor, *gRenderer); lastTenGamesBet[i].loadFromRenderedText(tempBet, textColor, *gRenderer); lastTenGamesWin[i].loadFromRenderedText(tempWin, textColor, *gRenderer); lastTenGamesDiff[i].loadFromRenderedText(tempDiff, textColor, *gRenderer); } //----------------TEXTURES LOADING ------------------ backgroundTexture.loadFromFile("img/menu.png", gRenderer); back.setPosition(370, 600); back.loadMedia("img/buttons/button.png", *gRenderer); //------------------TEXT LOADING------------------- backText.loadFromRenderedText("Back", textColor, *gRenderer); description.loadFromRenderedText(descriptionText, textColor, *gRenderer); //Event handler SDL_Event e; //While application is running while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = true; } else if (onMusicButton->handleEvent(&e)) { checkMusic(); } else if (e.key.keysym.sym == SDLK_ESCAPE) { return; } else if (e.type == SDL_MOUSEBUTTONUP) { if (back.handleEvent(&e)) { return; } } } //--------------CLEAR SCREEN----------- SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); //---------------RENDER TEXT---------------- backgroundTexture.render(*gRenderer, 0, 0); back.render(*gRenderer); backText.render(*gRenderer, ((SCREEN_WIDTH - backText.getWidth()) / 2), 614); description.render(*gRenderer, 20, 60); int xPos = 0; for (int i = 0; i < 10; i++) { if (lastTenGames[i].getCredit() < 10) { lastTenGamesCredit[i].render(*gRenderer, 85, (xPos + 100)); } else { lastTenGamesCredit[i].render(*gRenderer, 80, (xPos + 100)); } lastTenGamesTime[i].render(*gRenderer, 240, (xPos + 100)); if (lastTenGames[i].getPlayerBet() < 10) { lastTenGamesBet[i].render(*gRenderer, 417, (xPos + 100)); } else { lastTenGamesBet[i].render(*gRenderer, 410, (xPos + 100)); } lastTenGamesWin[i].render(*gRenderer, 630, (xPos + 100)); if (lastTenGames[i].getDifficulty() != "Medium") { lastTenGamesDiff[i].render(*gRenderer, 795, (xPos + 100)); } else { lastTenGamesDiff[i].render(*gRenderer, 780, (xPos + 100)); } xPos += 45; } renderMusicButton(); //------------- UPDATE SCREEN---------------- SDL_RenderPresent(gRenderer); } }
//User chooses preferred car int Application::chooseCar(SDL_Renderer* gRenderer) { if (gWindow == NULL) { printf("Failed to load screen!\n"); } //Main loop flag bool quit = false; SDL_Color textColor = { 0x00, 0xCC, 0xFF }; Button back(160, 50, 370, 600); LTexture backgroundTexture; LTexture header; LTexture cursor; LTexture attributesCarOne; LTexture attributesCarTwo; LTexture attributesCarThree; LTexture backText; LTexture text; LTexture carOne; LTexture carTwo; LTexture carThree; int cursorX = 190; int cursorY = 90; //--------------BACKGROUND IMG----------------- backgroundTexture.loadFromFile("img/menu.png", gRenderer); //--------------CURSOR IMG -------------------- cursor.loadFromFile("img/cars/cursor.png", gRenderer); //----------------ATTRIBUTES-------------- attributesCarOne.loadFromFile("img/cars/fastest.png", gRenderer); attributesCarTwo.loadFromFile("img/cars/medium.png", gRenderer); attributesCarThree.loadFromFile("img/cars/slowest.png", gRenderer); //-------------BUTTON SET POS & BCKGROUND---------- back.setPosition(370, 600); back.loadMedia("img/buttons/button.png", *gRenderer); //---------------CAR PICTURES---------------- carOne.loadFromFile("img/cars/carOneLarge.png", gRenderer); carTwo.loadFromFile("img/cars/carTwoLarge.png", gRenderer); carThree.loadFromFile("img/cars/carThreeLarge.png", gRenderer); //------------------TEXT LOADING------------------- backText.loadFromRenderedText("Back", textColor, *gRenderer); header.loadFromRenderedText("Choose your vehicle", textColor, *gRenderer); //Event handler SDL_Event e; //While application is running while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = true; } else if (onMusicButton->handleEvent(&e)) { checkMusic(); } else if (e.type == SDL_MOUSEBUTTONUP) { if (back.handleEvent(&e)) { return 0; } } else if (e.type == SDL_KEYUP) { switch (e.key.keysym.sym) { case SDLK_RIGHT: cursorX += 200; if (cursorX > 590) { cursorX = 590; } break; case SDLK_LEFT: cursorX -= 200; if (cursorX < 190) { cursorX = 190; } break; case SDLK_RETURN: if (cursorX == 190) { return 1; } else if (cursorX == 390) { return 2; } else { return 3; } break; case SDLK_ESCAPE: return 0; break; default: break; } } } //--------------CLEAR SCREEN----------- SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); //---------------RENDER TEXT AND TEXTURES---------------- backgroundTexture.render(*gRenderer, 0, 0); header.render(*gRenderer, ((SCREEN_WIDTH - header.getWidth()) / 2), 30); back.render(*gRenderer); backText.render(*gRenderer, ((SCREEN_WIDTH - backText.getWidth()) / 2), 614); carOne.render(*gRenderer, 200, 100); carTwo.render(*gRenderer, 400, 100); carThree.render(*gRenderer, 600, 100); cursor.render(*gRenderer, cursorX, cursorY); renderMusicButton(); if (cursorX == 190) { attributesCarOne.render(*gRenderer, ((SCREEN_WIDTH - attributesCarOne.getWidth()) / 2), 300); } else if (cursorX == 390) { attributesCarTwo.render(*gRenderer, ((SCREEN_WIDTH - attributesCarTwo.getWidth()) / 2), 300); } else { attributesCarThree.render(*gRenderer, ((SCREEN_WIDTH - attributesCarThree.getWidth()) / 2), 300); } //------------- UPDATE SCREEN---------------- SDL_RenderPresent(gRenderer); } return 0; }
int main(int argc, char *argv[]) { int quit = 0; /* event handler */ SDL_Event event; /* set text color as black */ SDL_Color textColor = { 0, 0, 0, 255 }; /* current time start time */ Uint32 startTime = 0; char timeText[128]; /* starts up SDL and create window */ if (init_sdl() == -1) { fprintf(stderr, "Failed to initialize SDL!\n"); return -1; } /* load media */ if (load_media() == -1) { fprintf(stderr, "Failed to load media!\n"); return -2; } /* main loop */ while (quit == 0) { /* handle events on queue */ while (SDL_PollEvent(&event) != 0) { /* users request quit */ if (event.type == SDL_QUIT) quit = 1; /* reset start time on return key press */ else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) { startTime = SDL_GetTicks(); } } /* set text to be rendered */ snprintf(timeText, sizeof(timeText), "%d", SDL_GetTicks() - startTime); /* render text */ if (gTimeTextTexture.loadFromRenderedText(timeText, textColor) == -1) fprintf(stderr, "Unable to render time texture!\n"); /* clear screen */ SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); /* render texture */ gPromptTexture.render((SCREEN_WIDTH - gPromptTexture.getWidth()) / 2, 0); gTimeTextTexture.render((SCREEN_WIDTH - gTimeTextTexture.getWidth()) / 2, (SCREEN_HEIGHT - gTimeTextTexture.getHeight()) / 2); /* update screen */ SDL_RenderPresent(gRenderer); } /* free resources and close */ close_sdl(); return 0; }