From fd98f62956d3558c2d3e36915ce282844af0f5df Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sun, 13 Jan 2019 19:08:18 +0100 Subject: Remove uncommented code --- game.c | 2 -- level.c | 30 ++++++++---------------------- render.c | 47 ++++++----------------------------------------- 3 files changed, 14 insertions(+), 65 deletions(-) diff --git a/game.c b/game.c index ced2f60..f4ab66a 100644 --- a/game.c +++ b/game.c @@ -190,8 +190,6 @@ void game_loop(SDL_Renderer* renderer, SDL_Texture* surf_screen) // The user has now completed all of the game // Show them the winning screen - //SDL_BlitSurface( surf_title, NULL, surf_screen, NULL); // Draw menu - SDL_Surface* surf_win_screen = currentlevel.surf_winning_screen; SDL_UpdateTexture(surf_screen, NULL, surf_win_screen->pixels, surf_win_screen->pitch); diff --git a/level.c b/level.c index b00e235..4fd4277 100644 --- a/level.c +++ b/level.c @@ -66,10 +66,8 @@ struct level_struct int sx, sy; // Player X and Y starting positions // Resources - SDL_Surface * surf_entities; // Player and echidna pictures - SDL_Texture * surf_entities_tex; - SDL_Surface * surf_tiles; // Level tiles/squares - SDL_Texture * surf_tiles_tex; + SDL_Texture * surf_entities; + SDL_Texture * surf_tiles; // A various selection of losing screens SDL_Surface * surf_losingscreens[5]; @@ -103,26 +101,14 @@ void eat_until_newline( FILE *currentfile ) void level_load_resources(SDL_Renderer* renderer, struct level_struct *level ) { // Load the images for things into their own 'surfaces' - SDL_Surface* surf_entities = IMG_Load( "entities.png" ); - level->surf_entities = SDL_ConvertSurfaceFormat(surf_entities, - SDL_PIXELFORMAT_ARGB8888, 0); - - level->surf_entities_tex = SDL_CreateTextureFromSurface(renderer, - level->surf_entities); + SDL_Surface* surf_entities = IMG_Load("entities.png"); + level->surf_entities = SDL_CreateTextureFromSurface(renderer, + surf_entities); - SDL_Surface* surf_tiles = IMG_Load( "tiles.png" ); - level->surf_tiles = SDL_ConvertSurfaceFormat(surf_tiles, - SDL_PIXELFORMAT_ARGB8888, 0); - - level->surf_tiles_tex = SDL_CreateTextureFromSurface(renderer, - level->surf_tiles); + SDL_Surface* surf_tiles = IMG_Load("tiles.png"); + level->surf_tiles = SDL_CreateTextureFromSurface(renderer, + surf_tiles); - int w, h; - Uint32 format; - SDL_QueryTexture(level->surf_tiles_tex, &format, NULL, &w, &h); - printf("surf_tiles_tex: w: %d, h: %d, format: %s\n", w, h, SDL_GetPixelFormatName(format)); - // Do the same for the losing screens - SDL_Surface* surf_losing = IMG_Load("failscreen_01.png"); level->surf_losingscreens[0] = SDL_ConvertSurfaceFormat(surf_losing, SDL_PIXELFORMAT_ARGB8888, 0); diff --git a/render.c b/render.c index a713d5e..04a3105 100644 --- a/render.c +++ b/render.c @@ -87,46 +87,23 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu /// Draw this tile onto the screen //SDL_BlitSurface ( currentlevel->surf_tiles, &pixmap_crop, surf_screen, &destination ); - // TODO: use pixmap_crop with SDL_RenderCopy? - // printf("surf_tile format: %s\n", SDL_GetPixelFormatName(currentlevel->surf_tiles->format->format)); - // SDL_UpdateTexture(surf_screen, &destination, - // currentlevel->surf_tiles->pixels, - // currentlevel->surf_tiles->pitch); - - printf("pixmap_crop x: %d, y: %d, w: %d, h: %d\n", - pixmap_crop.x, pixmap_crop.y, pixmap_crop.w, pixmap_crop.h); - - printf("destination x: %d, y: %d, w: %d, h: %d\n", - destination.x, destination.y, destination.w, destination.h); - - int ret = SDL_RenderCopy(renderer, currentlevel->surf_tiles_tex, + int ret = SDL_RenderCopy(renderer, currentlevel->surf_tiles, &pixmap_crop, &destination); - printf("SDL_RenderCopy ret: %d\n", ret); if (ret < 0 ) { printf("Error (SDL): %s: %s\n", "could not render copy surf_tiles", SDL_GetError()); } - - //printf("surf_tile pitch: %d\n", currentlevel->surf_tiles->pitch); } } - // SDL_RenderPresent(renderer); - // SDL_Delay(500); - /// Entity drawing // First of all the character get_pixmap_lemon( currentlevel->player_face, &pixmap_crop ); destination.x = currentlevel->px * TILE_SIZE; destination.y = currentlevel->py * TILE_SIZE; - // Draw onto screen - //SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); - //SDL_UpdateTexture(surf_screen, &destination, - // currentlevel->surf_entities->pixels, - // currentlevel->surf_entities->pitch); - - SDL_RenderCopy(renderer, currentlevel->surf_entities_tex, + // Render onto screen + SDL_RenderCopy(renderer, currentlevel->surf_entities, &pixmap_crop, &destination); @@ -145,36 +122,24 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu destination.x = current_echidna.xpos * TILE_SIZE; destination.y = current_echidna.ypos * TILE_SIZE; - // Draw it onscreen - // SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination ); - // SDL_UpdateTexture(surf_screen, &destination, - // currentlevel->surf_entities->pixels, - // currentlevel->surf_entities->pitch); - - SDL_RenderCopy(renderer, currentlevel->surf_entities_tex, + // Render it onscreen + SDL_RenderCopy(renderer, currentlevel->surf_entities, &pixmap_crop, &destination); } } - /// Flip screen, so everything we have 'blitted' can now be seen - //SDL_Flip( surf_screen ); - - //SDL_RenderClear(renderer); - //SDL_RenderCopy(renderer, surf_screen, NULL, NULL); + // Flip screen, so everything we have 'blitted' can now be seen SDL_RenderPresent(renderer); } void render_a_losingscreen(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Texture * surf_screen ) { // Render a losing screen - //SDL_BlitSurface ( currentlevel->surf_losingscreens[0], NULL, surf_screen, NULL ); - SDL_UpdateTexture(surf_screen, NULL, currentlevel->surf_losingscreens[0]->pixels, currentlevel->surf_losingscreens[0]->pitch); - //SDL_Flip( surf_screen ); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, surf_screen, NULL, NULL); -- cgit v1.2.1-18-gbd029