summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.c11
-rw-r--r--level.c21
-rw-r--r--render.c20
3 files changed, 27 insertions, 25 deletions
diff --git a/game.c b/game.c
index c9571e1..45c029f 100644
--- a/game.c
+++ b/game.c
@@ -75,7 +75,7 @@ int player_action( signed int xdiff, signed int ydiff, struct level_struct *curr
}
-int play_level(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Texture * surf_screen )
+int play_level(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Texture *surf_screen)
{
// Loop until the user completes the level
int player_status = PLAYER_IS_OK;
@@ -160,7 +160,6 @@ int play_level(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Te
void game_loop(SDL_Renderer* renderer, SDL_Texture* surf_screen)
{
-
struct level_struct currentlevel;
level_load_resources(renderer, &currentlevel ); // load pixmaps
@@ -186,7 +185,6 @@ void game_loop(SDL_Renderer* renderer, SDL_Texture* surf_screen)
// Main game loop
level_state = play_level(renderer, &currentlevel, surf_screen );
-
}
// When the game loop ends, then the user has successfully completed the level, and we can move on
@@ -195,8 +193,13 @@ 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);
+
SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, currentlevel.surf_winning_screen, NULL, NULL);
+ SDL_RenderCopy(renderer, surf_screen, NULL, NULL);
SDL_RenderPresent(renderer);
SDL_Delay(20 * 1000); // 20 * 1000msecs = 20 seconds
diff --git a/level.c b/level.c
index 0db6d88..8e47bf2 100644
--- a/level.c
+++ b/level.c
@@ -66,14 +66,14 @@ struct level_struct
int sx, sy; // Player X and Y starting positions
// Resources
- SDL_Texture * surf_entities; // Player and echidna pictures
- SDL_Texture * surf_tiles; // Level tiles/squares
+ SDL_Surface * surf_entities; // Player and echidna pictures
+ SDL_Surface * surf_tiles; // Level tiles/squares
// A various selection of losing screens
- SDL_Texture * surf_losingscreens[5];
+ SDL_Surface * surf_losingscreens[5];
// The screen to display when the game ends
- SDL_Texture * surf_winning_screen;
+ SDL_Surface * surf_winning_screen;
// Up to ten echidnas
struct echidna echidnas[10];
@@ -102,18 +102,13 @@ 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_CreateTextureFromSurface(renderer, surf_entities);
+ level->surf_entities = IMG_Load( "entities.png" );
- SDL_Surface* surf_tiles = IMG_Load( "tiles.png" );
- level->surf_tiles = SDL_CreateTextureFromSurface(renderer, surf_tiles);
+ level->surf_tiles = IMG_Load( "tiles.png" );
// Do the same for the losing screens
- SDL_Surface* surf_losingscreen = IMG_Load("failscreen_01.png");
- level->surf_losingscreens[0] = SDL_CreateTextureFromSurface(renderer, surf_losingscreen);
-
- SDL_Surface* surf_winning_screen = IMG_Load("winningscreen.png");
- level->surf_winning_screen = SDL_CreateTextureFromSurface(renderer, surf_winning_screen);
+ level->surf_losingscreens[0] = IMG_Load("failscreen_01.png");
+ level->surf_winning_screen = IMG_Load("winningscreen.png");
}
diff --git a/render.c b/render.c
index faea80f..2e8e97d 100644
--- a/render.c
+++ b/render.c
@@ -64,12 +64,10 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu
pixmap_crop.w = TILE_SIZE;
pixmap_crop.h = TILE_SIZE;
-
/// Level drawing
// ieterate through each square of the level, drawing the appropriate
// pictures for each onto the screen
-
int tilex, tiley; // Where we are up to
@@ -89,7 +87,9 @@ 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 );
- SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_tiles, 640 * sizeof (Uint32));
+ SDL_UpdateTexture(surf_screen, &destination,
+ currentlevel->surf_tiles->pixels,
+ currentlevel->surf_tiles->pitch);
}
}
@@ -101,11 +101,12 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu
// Draw onto screen
//SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination );
- SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_entities, 640 * sizeof (Uint32));
+ SDL_UpdateTexture(surf_screen, &destination,
+ currentlevel->surf_entities->pixels,
+ currentlevel->surf_entities->pitch);
// Now draw all of the echidnas
int ech_no; // Echidna number
-
for ( ech_no = 0; ech_no < 10; ech_no++ )
{
struct echidna current_echidna = currentlevel->echidnas[ech_no];
@@ -121,9 +122,10 @@ void render(SDL_Renderer* renderer, struct level_struct *currentlevel, SDL_Textu
// Draw it onscreen
// SDL_BlitSurface ( currentlevel->surf_entities, &pixmap_crop, surf_screen, &destination );
- SDL_UpdateTexture(surf_screen, &destination, currentlevel->surf_entities, 640 * sizeof (Uint32));
+ SDL_UpdateTexture(surf_screen, &destination,
+ currentlevel->surf_entities->pixels,
+ currentlevel->surf_entities->pitch);
}
-
}
/// Flip screen, so everything we have 'blitted' can now be seen
@@ -139,7 +141,9 @@ void render_a_losingscreen(SDL_Renderer* renderer, struct level_struct *currentl
// Render a losing screen
//SDL_BlitSurface ( currentlevel->surf_losingscreens[0], NULL, surf_screen, NULL );
- SDL_UpdateTexture(surf_screen, NULL, currentlevel->surf_losingscreens[0], 640 * sizeof (Uint32));
+ SDL_UpdateTexture(surf_screen, NULL,
+ currentlevel->surf_losingscreens[0]->pixels,
+ currentlevel->surf_losingscreens[0]->pitch);
//SDL_Flip( surf_screen );