diff --git a/data/Makefile.am b/data/Makefile.am index 7d94b88..36b52d2 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -136,6 +136,7 @@ nobase_dist_gamedata_DATA = images/background.png \ images/crash_3.png \ images/crash_4.png \ images/gameintro.png \ + images/gamefinish.png \ images/penguin_intro_back.png \ images/penguin_intro_color.png \ images/penguin_intro_front.png \ diff --git a/data/images/gamefinish.png b/data/images/gamefinish.png new file mode 100644 index 0000000..2e0f89b Binary files /dev/null and b/data/images/gamefinish.png differ diff --git a/src/beans.c b/src/beans.c index 153ebda..55907f9 100644 --- a/src/beans.c +++ b/src/beans.c @@ -75,6 +75,7 @@ /* Enumerar las imágenes */ enum { IMG_GAMEINTRO, + IMG_GAMEFINISH, IMG_PENGUIN_INTRO_BACK, IMG_PENGUIN_INTRO_COLOR, @@ -205,6 +206,7 @@ enum { /* Los nombres de archivos */ const char *images_names[NUM_IMAGES] = { "images/gameintro.png", + "images/gamefinish.png", "images/penguin_intro_back.png", "images/penguin_intro_color.png", @@ -370,6 +372,8 @@ enum { BUTTON_NEXT_PAGE, BUTTON_EXPLAIN_PLAY_GAME, + BUTTON_GET_BONUS, + NUM_BUTTONS }; @@ -565,6 +569,10 @@ enum { TEXT_ONE_UP, + TEXT_CONGRATULATIONS, + TEXT_BONUS, + TEXT_GET_PAID, + NUM_TEXTS }; @@ -594,6 +602,10 @@ const char *text_strings[NUM_TEXTS] = { gettext_noop ("Click left mouse button when at the red platform to\ndrop off bags (if you have any)."), gettext_noop ("1 Up"), + + gettext_noop ("CONGRATULATIONS!!!"), + gettext_noop ("All the trucks have been unloaded! You are a\nperfect employee! You get a 60 coin bonus!"), + gettext_noop ("CLICK HERE to GET PAID!!!"), }; const SDL_Color penguin_colors[18] = { @@ -649,6 +661,7 @@ void add_bag (int tipo); void delete_bag (BeanBag *p); int map_button_in_intro (int x, int y); int map_button_in_explain (int x, int y, int escena); +int map_button_in_game (int x, int y, int next_level); /* Variables globales */ SDL_Surface * screen; @@ -690,13 +703,13 @@ int main (int argc, char *argv[]) { cp_registrar_boton (BUTTON_UI_PLAY_GAME, BLANK_UP); cp_registrar_boton (BUTTON_NEXT_PAGE, BLANK_UP); cp_registrar_boton (BUTTON_EXPLAIN_PLAY_GAME, BLANK_UP); + cp_registrar_boton (BUTTON_GET_BONUS, BLANK_UP); cp_button_start (); do { if (game_intro () == GAME_QUIT) break; if (game_loop () == GAME_QUIT) break; - //if (game_finish () == GAME_QUIT) break; } while (1 == 0); SDL_Quit (); @@ -1222,66 +1235,13 @@ int game_explain (void) { return done; } -#if 0 -int game_finish (void) { - int done = 0; - SDL_Event event; - SDLKey key; - SDL_Rect rect; - Uint32 last_time, now_time; - - /* Predibujar todo */ - SDL_FillRect (screen, NULL, 0); - SDL_Flip (screen); - - do { - last_time = SDL_GetTicks (); - - while (SDL_PollEvent(&event) > 0) { - /* fprintf (stdout, "Evento: %i\n", event.type);*/ - switch (event.type) { - case SDL_QUIT: - /* Vamos a cerrar la aplicación */ - done = GAME_QUIT; - break; - case SDL_MOUSEMOTION: - break; - case SDL_MOUSEBUTTONDOWN: - break; - case SDL_MOUSEBUTTONUP: - break; - case SDL_KEYDOWN: - /* Tengo una tecla presionada */ - key = event.key.keysym.sym; - - if (key == SDLK_F11 || (key == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT))) { - SDL_WM_ToggleFullScreen (screen); - } - if (key == SDLK_ESCAPE) { - done = GAME_QUIT; - } - break; - } - } - - SDL_Flip (screen); - - now_time = SDL_GetTicks (); - if (now_time < last_time + FPS) SDL_Delay(last_time + FPS - now_time); - - } while (!done); - - return done; -} -#endif - int game_loop (void) { int done = 0; SDL_Event event; SDLKey key; Uint32 last_time, now_time; SDL_Rect rect; - int penguinx, handposx; + int penguinx, handposx, handposy; BeanBag *thisbag, *nextbag; int bags = 0; @@ -1306,6 +1266,13 @@ int game_loop (void) { char buffer[20]; SDL_Surface *numbers[3][20]; double z; + int map; + Uint32 blanco2; + SDL_Surface *trans; + + trans = SDL_CreateRGBSurface (SDL_SWSURFACE | SDL_SRCALPHA, texts[TEXT_GET_PAID]->w, texts[TEXT_GET_PAID]->h, 32, RMASK, GMASK, BMASK, AMASK); + blanco2 = SDL_MapRGBA (trans->format, 255, 255, 255, 128); + SDL_FillRect (trans, NULL, blanco2); /* Blanco */ SDL_Color negro, blanco, amarillo; blanco.r = blanco.g = blanco.b = 255; @@ -1385,9 +1352,21 @@ int game_loop (void) { } } } + map = map_button_in_game (event.button.x, event.button.y, next_level_visible); + cp_button_down (map); break; case SDL_MOUSEBUTTONUP: - /* Tengo un mouse Up */ + map_button_in_game (event.button.x, event.button.y, next_level_visible); + map = cp_button_up (map); + + switch (map) { + case BUTTON_GET_BONUS: + done = 1; + break; + /*case BUTTON_EXPLAIN_PLAY_GAME: + done = 1; + break;*/ + } break; case SDL_KEYDOWN: /* Tengo una tecla presionada */ @@ -1403,9 +1382,13 @@ int game_loop (void) { } } - if (bags < 6 && next_level_visible == NO_NEXT_LEVEL) { - SDL_GetMouseState (&handposx, NULL); + SDL_GetMouseState (&handposx, &handposy); + /* Debido a que ignoramos eventos, hay que manejar el mouse motion aquí */ + map = map_button_in_game (handposx, handposy, next_level_visible); + cp_button_motion (map); + + if (bags < 6 && next_level_visible == NO_NEXT_LEVEL) { penguinx = handposx; if (penguinx < 190) { penguinx = 190; @@ -1640,7 +1623,7 @@ int game_loop (void) { } thisbag = nextbag; - } + } /* Fin del recorrer bolsas */ SDL_BlitSurface (images[IMG_BACKGROUND], NULL, screen, NULL); @@ -1912,7 +1895,53 @@ int game_loop (void) { animacion++; } - if (next_level_visible == NEXT_LEVEL) { + if (next_level_visible == GAME_WIN) { + /* Dibujar la pantalla de fin */ + rect.x = 144; + rect.y = 59; + rect.w = images[IMG_GAMEFINISH]->w; + rect.h = images[IMG_GAMEFINISH]->h; + + SDL_BlitSurface (images[IMG_GAMEFINISH], NULL, screen, &rect); + + rect.x = 144 + (images[IMG_GAMEFINISH]->w - texts[TEXT_CONGRATULATIONS]->w) / 2; + rect.y = 93; + rect.w = texts[TEXT_CONGRATULATIONS]->w; + rect.h = texts[TEXT_CONGRATULATIONS]->h; + + SDL_BlitSurface (texts[TEXT_CONGRATULATIONS], NULL, screen, &rect); + + rect.x = 144 + (images[IMG_GAMEFINISH]->w - texts[TEXT_BONUS]->w) / 2; + rect.y = 162; + rect.w = texts[TEXT_BONUS]->w; + rect.h = texts[TEXT_BONUS]->h; + + SDL_BlitSurface (texts[TEXT_BONUS], NULL, screen, &rect); + + rect.x = 144 + (images[IMG_GAMEFINISH]->w - texts[TEXT_GET_PAID]->w) / 2; + rect.y = 293; + rect.w = texts[TEXT_GET_PAID]->w; + rect.h = texts[TEXT_GET_PAID]->h; + + SDL_BlitSurface (texts[TEXT_GET_PAID], NULL, screen, &rect); + + if (cp_button_frames[BUTTON_GET_BONUS] != BLANK_UP) { + rect.x = 144 + (images[IMG_GAMEFINISH]->w - texts[TEXT_GET_PAID]->w) / 2;; + rect.y = 293; + rect.w = trans->w; + rect.h = trans->h; + + SDL_BlitSurface (trans, NULL, screen, &rect); + } + + /* Dibujar el camión normal */ + rect.x = 568; + rect.y = 72; + rect.w = images[IMG_TRUCK]->w; + rect.h = images[IMG_TRUCK]->h; + + SDL_BlitSurface (images[IMG_TRUCK], NULL, screen, &rect); + } else if (next_level_visible == NEXT_LEVEL) { if (animacion == 0) { if (use_sound) Mix_PlayChannel (-1, sounds[SND_TRUCK], 0); } else if (animacion == 56) { @@ -2014,6 +2043,8 @@ int game_loop (void) { } } + SDL_FreeSurface (trans); + return done; } /* Set video mode: */ @@ -2034,6 +2065,7 @@ void setup (void) { char *systemdata_path = get_systemdata_path (); Collider *c; TTF_Font *ttf48_klickclack, *ttf52_klickclack, *ttf40_klickclack, *ttf18_burbank; + TTF_Font *ttf35_klickclack, *ttf26_klickclack; /* Inicializar el Video SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { @@ -2180,8 +2212,11 @@ void setup (void) { ttf48_klickclack = TTF_OpenFont (buffer_file, 48); ttf40_klickclack = TTF_OpenFont (buffer_file, 40); ttf52_klickclack = TTF_OpenFont (buffer_file, 52); + ttf35_klickclack = TTF_OpenFont (buffer_file, 35); + ttf26_klickclack = TTF_OpenFont (buffer_file, 26); - if (!ttf24_klickclack || !ttf196_klickclack || !ttf48_klickclack || !ttf52_klickclack || !ttf40_klickclack) { + if (!ttf24_klickclack || !ttf196_klickclack || !ttf48_klickclack || !ttf52_klickclack || + !ttf40_klickclack || !ttf35_klickclack || !ttf26_klickclack) { fprintf (stderr, _("Failed to load font file 'Klick Clack'\n" "The error returned by SDL is:\n" @@ -2246,10 +2281,16 @@ void setup (void) { texts[TEXT_ONE_UP] = draw_text_with_shadow (ttf44_comiccrazy, 3, _(text_strings[TEXT_ONE_UP]), amarillo, negro); + texts[TEXT_CONGRATULATIONS] = draw_text (ttf35_klickclack, _(text_strings[TEXT_CONGRATULATIONS]), &azul1); + texts[TEXT_BONUS] = draw_text (ttf18_burbank, _(text_strings[TEXT_BONUS]), &azul1); + texts[TEXT_GET_PAID] = draw_text (ttf26_klickclack, _(text_strings[TEXT_GET_PAID]), &azul1); + TTF_CloseFont (ttf18_burbank); TTF_CloseFont (ttf48_klickclack); TTF_CloseFont (ttf52_klickclack); TTF_CloseFont (ttf40_klickclack); + TTF_CloseFont (ttf35_klickclack); + TTF_CloseFont (ttf26_klickclack); } void setup_and_color_penguin (void) { @@ -2477,3 +2518,14 @@ int map_button_in_explain (int x, int y, int escena) { return BUTTON_NONE; } +int map_button_in_game (int x, int y, int next_level) { + int sub_x; + if (next_level == GAME_WIN) { + sub_x = 144 + (images[IMG_GAMEFINISH]->w - texts[TEXT_GET_PAID]->w) / 2; + if (x >= sub_x && x < sub_x + texts[TEXT_GET_PAID]->w && y >= 293 && y < 293 + texts[TEXT_GET_PAID]->h) { + return BUTTON_GET_BONUS; + } + } + return BUTTON_NONE; +} +