From d1c4f6363aaf5027df7bc8ea471363ef48fba4c0 Mon Sep 17 00:00:00 2001 From: Victor Gamper Date: Wed, 10 Jun 2020 15:35:25 +0200 Subject: Added clouds and "realistic" textures --- catch.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'catch.c') diff --git a/catch.c b/catch.c index 33f5179..69ec9a4 100644 --- a/catch.c +++ b/catch.c @@ -14,10 +14,15 @@ SDL_Rect sdl_rect, sdl_rect2; bool keyPressed[SDLK_LAST]; // the images -SDL_Surface* image_chargebar, *image_chargebar_dark, *image_cat, *image_bird; +SDL_Surface* image_chargebar, *image_chargebar_dark, *image_cat, *image_bird, *image_clouds[1]; + +#ifndef PLASTIC_TEXTURES +SDL_Surface* image_grass; +#endif struct Cat cat; struct Bird bird[BIRD_COUNT]; +struct Cloud clouds[CLOUD_COUNT]; unsigned int state, menu_state, score; int ticks_to_next_second, time_left; @@ -57,7 +62,22 @@ int main(int argc, char *argv[]) { image_chargebar_dark = SDL_LoadBMP_RW(rwops,1); rwops = SDL_RWFromConstMem(cat_bmp, sizeof(cat_bmp) / sizeof(char)); image_cat = SDL_LoadBMP_RW(rwops,1); + rwops = SDL_RWFromConstMem(cloud1_bmp, sizeof(cloud1_bmp) / sizeof(char)); + image_clouds[0] = SDL_LoadBMP_RW(rwops,1); SDL_SetColorKey(image_cat, SDL_SRCCOLORKEY, SDL_MapRGB(image_cat->format, 255, 0, 255)); + SDL_SetColorKey(image_clouds[0], SDL_SRCCOLORKEY, SDL_MapRGB(image_clouds[0]->format, 255, 0, 255)); + + // load the "realistic" textures + #ifndef PLASTIC_TEXTURES + rwops = SDL_RWFromConstMem(grass_bmp, sizeof(grass_bmp) / sizeof(char)); + image_grass = SDL_LoadBMP_RW(rwops,1); + + #endif + + // initialize the clouds + for(int i = 0; iformat,0,0,200)); + #else + SDL_FillRect(screen,&sdl_rect,SDL_MapRGB(screen->format,0,165,219)); + #endif // draw the floor + #ifdef PLASTIC_TEXTURES sdl_rect.y = sdl_rect.h; sdl_rect.h = FLOOR_HEIGHT; SDL_FillRect(screen,&sdl_rect,SDL_MapRGB(screen->format,0,200,000)); + #else + sdl_rect.y = sdl_rect.h; + sdl_rect.h = FLOOR_HEIGHT; + + for(sdl_rect.x = 0; sdl_rect.x < SCREEN_WIDTH; sdl_rect.x += GRASS_TEXTURE_WIDTH) { + SDL_BlitSurface(image_grass, 0, screen, &sdl_rect); + } + #endif + + // draw the clouds + for(int i = 0; iw/2; @@ -210,7 +252,7 @@ int main(int argc, char *argv[]) { // draw the fps char fps_s[50]; // TODO this could create a buffer overflow - sprintf(fps_s, "FPS: %i", 1000 / (SDL_GetTicks() - last_fps_count_time)); + sprintf(fps_s, "FPS: %lu", 1000 / (SDL_GetTicks() - last_fps_count_time)); last_fps_count_time = SDL_GetTicks(); int length = strlen(fps_s) + 1; Font_DrawString(screen, SCREEN_WIDTH - length * 8, 24, fps_s); @@ -255,6 +297,19 @@ int main(int argc, char *argv[]) { void gameRoutine() { bool charge = keyPressed[SDLK_SPACE] && (state == STATE_GAME); + // update the clouds + static int cloudSpawnDelay = 0; + cloudSpawnDelay--; + for(int i = 0; iSCREEN_WIDTH | clouds[i].type == -1)) { + cloudSpawnDelay = 64; + clouds[i].type = 0; + clouds[i].x = (-getRandomInt(100))-32; + clouds[i].y = getRandomInt(200); + } + } + // do the physics calculation if(cat.jumping) { cat.downwardForce+=0.1; -- cgit v1.2.3