diff --git a/data/Makefile.am b/data/Makefile.am index ec37ea9..1d834d5 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -135,6 +135,10 @@ nobase_dist_gamedata_DATA = images/background.png \ images/crash_2.png \ images/crash_3.png \ images/crash_4.png \ + images/gameintro.png \ + images/penguin_intro_back.png \ + images/penguin_intro_color.png \ + images/penguin_intro_front.png \ klickclack.ttf # Instalar los archivos .desktop e iconos diff --git a/data/images/gameintro.png b/data/images/gameintro.png new file mode 100644 index 0000000..75d267b Binary files /dev/null and b/data/images/gameintro.png differ diff --git a/data/images/penguin_intro_back.png b/data/images/penguin_intro_back.png new file mode 100644 index 0000000..ac3bc4e Binary files /dev/null and b/data/images/penguin_intro_back.png differ diff --git a/data/images/penguin_intro_color.png b/data/images/penguin_intro_color.png new file mode 100644 index 0000000..047aecb Binary files /dev/null and b/data/images/penguin_intro_color.png differ diff --git a/data/images/penguin_intro_front.png b/data/images/penguin_intro_front.png new file mode 100644 index 0000000..24fe97d Binary files /dev/null and b/data/images/penguin_intro_front.png differ diff --git a/po/bean-counters-classic.pot b/po/bean-counters-classic.pot index 3dc253e..21a0ca1 100644 --- a/po/bean-counters-classic.pot +++ b/po/bean-counters-classic.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: bean-counters-classic 0.1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-10-13 13:45-0500\n" +"POT-Creation-Date: 2020-01-21 08:36-0600\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,19 +17,51 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: src/beans.c:872 +#: src/beans.c:915 msgid "LIVES:" msgstr "" -#: src/beans.c:873 +#: src/beans.c:916 msgid "TRUCK:" msgstr "" -#: src/beans.c:874 +#: src/beans.c:917 msgid "SCORE:" msgstr "" -#: src/beans.c:1732 +#: src/beans.c:919 +msgid "TRY AGAIN..." +msgstr "" + +#: src/beans.c:921 +msgid "" +"TRUCK\n" +"UNLOADED!!" +msgstr "" + +#: src/beans.c:922 +msgid "NEXT TRUCK!!" +msgstr "" + +#: src/beans.c:924 +msgid "Game Over!" +msgstr "" + +#: src/beans.c:926 +msgid "" +"BEAN\n" +"COUNTERS!" +msgstr "" + +#: src/beans.c:927 +msgid "INSTRUCTIONS" +msgstr "" + +#: src/beans.c:928 +msgid "PLAY GAME!" +msgstr "" + +#: src/beans.c:2024 #, c-format msgid "" "Error: Can't initialize the video subsystem\n" @@ -37,11 +69,11 @@ msgid "" "%s\n" msgstr "" -#: src/beans.c:1743 +#: src/beans.c:2035 msgid "Bean Counters Classic" msgstr "" -#: src/beans.c:1750 +#: src/beans.c:2042 #, c-format msgid "" "Error: Can't setup 760x480 video mode.\n" @@ -49,19 +81,19 @@ msgid "" "%s\n" msgstr "" -#: src/beans.c:1759 +#: src/beans.c:2051 #, c-format msgid "" "Warning: Can't initialize the audio subsystem\n" "Continuing...\n" msgstr "" -#: src/beans.c:1768 +#: src/beans.c:2060 #, c-format msgid "Warning: Can't initialize the SDL Mixer library\n" msgstr "" -#: src/beans.c:1779 src/beans.c:1906 +#: src/beans.c:2071 src/beans.c:2218 #, c-format msgid "" "Failed to load data file:\n" @@ -70,21 +102,21 @@ msgid "" "%s\n" msgstr "" -#: src/beans.c:1806 +#: src/beans.c:2098 #, c-format msgid "" "Failed to load data file:\n" "%s\n" msgstr "" -#: src/beans.c:1862 +#: src/beans.c:2154 #, c-format msgid "" "Error: Can't initialize the SDL TTF library\n" "%s\n" msgstr "" -#: src/beans.c:1873 +#: src/beans.c:2169 #, c-format msgid "" "Failed to load font file 'Klick Clack\n" diff --git a/src/Makefile.am b/src/Makefile.am index efef331..d4d4c2f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ bean_counters_classic_SOURCES = beans.c \ sdl2_rect.c sdl2_rect.h \ draw-text.c draw-text.h \ zoom.c zoom.h \ + cp-button.c cp-button.h \ gettext.h if MACOSX diff --git a/src/beans.c b/src/beans.c index b0ee92a..56ae03e 100644 --- a/src/beans.c +++ b/src/beans.c @@ -45,6 +45,7 @@ #include "collider.h" #include "draw-text.h" #include "zoom.h" +#include "cp-button.h" #define FPS (1000/24) #define RANDOM(x) ((int) (x ## .0 * rand () / (RAND_MAX + 1.0))) @@ -92,6 +93,12 @@ typedef struct _BeanBag { /* Enumerar las imágenes */ enum { + IMG_GAMEINTRO, + + IMG_PENGUIN_INTRO_BACK, + IMG_PENGUIN_INTRO_COLOR, + IMG_PENGUIN_INTRO_FRONT, + IMG_BACKGROUND, IMG_PLATAFORM, @@ -211,6 +218,12 @@ enum { /* Los nombres de archivos */ const char *images_names[NUM_IMAGES] = { + "images/gameintro.png", + + "images/penguin_intro_back.png", + "images/penguin_intro_color.png", + "images/penguin_intro_front.png", + "images/background.png", "images/plataform.png", @@ -331,6 +344,23 @@ const char *sound_names[NUM_SOUNDS] = { "sounds/none.wav", }; +/* Para el motor de botones */ +enum { + BUTTON_NONE, + + BUTTON_UI_INSTRUCTIONS, + BUTTON_UI_PLAY_GAME, + BUTTON_CLOSE, + + NUM_BUTTONS +}; + +enum { + BLANK_UP, + BLANK_OVER, + BLANK_DOWN +}; + /* Codigos de salida */ enum { GAME_NONE = 0, /* No usado */ @@ -486,6 +516,10 @@ enum { TEXT_GAME_OVER, + TEXT_TITLE_BEAN_COUNTERS, + TEXT_INSTRUCTIONS, + TEXT_PLAY_GAME, + NUM_TEXTS }; @@ -885,9 +919,13 @@ const char *text_strings[NUM_TEXTS] = { gettext_noop ("TRY AGAIN..."), gettext_noop ("TRUCK\nUNLOADED!!"), - gettext_noop ("NEXT TRUCK!!"), + gettext_noop ("NEXT TRUCK!!"), - gettext_noop ("Game Over!") + gettext_noop ("Game Over!"), + + gettext_noop ("BEAN\nCOUNTERS!"), + gettext_noop ("INSTRUCTIONS"), + gettext_noop ("PLAY GAME!"), }; /* Prototipos de función */ @@ -899,6 +937,7 @@ SDL_Surface * set_video_mode (unsigned flags); void setup_and_color_penguin (void); void add_bag (int tipo); void delete_bag (BeanBag *p); +int map_button_in_intro (int x, int y); /* Variables globales */ SDL_Surface * screen; @@ -932,8 +971,17 @@ int main (int argc, char *argv[]) { setup (); bind_textdomain_codeset (PACKAGE, "UTF-8"); + + /* Registrar botones */ + cp_registrar_botones (NUM_BUTTONS); + cp_registrar_boton (BUTTON_UI_INSTRUCTIONS, BLANK_UP); + cp_registrar_boton (BUTTON_UI_PLAY_GAME, BLANK_UP); + //cp_registrar_boton (BUTTON_CLOSE, IMG_BUTTON_1_UP); + + cp_button_start (); + do { - //if (game_intro () == GAME_QUIT) break; + if (game_intro () == GAME_QUIT) break; if (game_loop () == GAME_QUIT) break; //if (game_finish () == GAME_QUIT) break; } while (1 == 0); @@ -942,20 +990,101 @@ int main (int argc, char *argv[]) { return EXIT_SUCCESS; } -#if 0 int game_intro (void) { int done = 0; SDL_Event event; SDLKey key; SDL_Rect rect; + int map; Uint32 last_time, now_time; + SDL_Surface *color_surface; + SDL_Rect update_rects[6]; + int num_rects; + + Uint32 color, blanco2; + SDL_Surface *trans; + + color = SDL_MapRGB (screen->format, 255, 255, 255); + trans = SDL_CreateRGBSurface (SDL_SWSURFACE | SDL_SRCALPHA, 246, 24, 32, RMASK, GMASK, BMASK, AMASK); + blanco2 = SDL_MapRGBA (trans->format, 255, 255, 255, 128); + SDL_FillRect (trans, NULL, blanco2); /* Blanco */ + + /* Precolorear el cuerpo del pingüino */ + color_surface = SDL_CreateRGBSurface (SDL_SWSURFACE, images[IMG_PENGUIN_INTRO_COLOR]->w, images[IMG_PENGUIN_INTRO_COLOR]->h, 32, RMASK, GMASK, BMASK, AMASK); + SDL_FillRect (color_surface, NULL, SDL_MapRGB (color_surface->format, penguin_colors[color_penguin].r, penguin_colors[color_penguin].g, penguin_colors[color_penguin].b)); + + SDL_BlitSurface (color_surface, NULL, images[IMG_PENGUIN_INTRO_COLOR], NULL); + + SDL_FreeSurface (color_surface); /* Predibujar todo */ - SDL_FillRect (screen, NULL, 0); + SDL_BlitSurface (images[IMG_BACKGROUND], NULL, screen, NULL); + + /* Dibujar la plataforma */ + rect.x = 0; + rect.y = 355; + rect.w = images[IMG_PLATAFORM]->w; + rect.h = images[IMG_PLATAFORM]->h; + + SDL_BlitSurface (images[IMG_PLATAFORM], NULL, screen, &rect); + + /* Dibujar el game intro */ + rect.x = 113; + rect.y = 35; + rect.w = images[IMG_GAMEINTRO]->w; + rect.h = images[IMG_GAMEINTRO]->h; + + SDL_BlitSurface (images[IMG_GAMEINTRO], NULL, screen, &rect); + + /* Dibujar el pingüino */ + rect.x = 127; + rect.y = 68; + rect.w = images[IMG_PENGUIN_INTRO_BACK]->w; + rect.h = images[IMG_PENGUIN_INTRO_BACK]->h; + + SDL_BlitSurface (images[IMG_PENGUIN_INTRO_BACK], NULL, screen, &rect); + + rect.x = 134; + rect.y = 162; + rect.w = images[IMG_PENGUIN_INTRO_COLOR]->w; + rect.h = images[IMG_PENGUIN_INTRO_COLOR]->h; + + SDL_BlitSurface (images[IMG_PENGUIN_INTRO_COLOR], NULL, screen, &rect); + + rect.x = 157; + rect.y = 239; + rect.w = images[IMG_PENGUIN_INTRO_FRONT]->w; + rect.h = images[IMG_PENGUIN_INTRO_FRONT]->h; + + SDL_BlitSurface (images[IMG_PENGUIN_INTRO_FRONT], NULL, screen, &rect); + + /* Dibujar el título */ + rect.w = texts[TEXT_TITLE_BEAN_COUNTERS]->w; + rect.h = texts[TEXT_TITLE_BEAN_COUNTERS]->h; + rect.x = 504 - (rect.w / 2); + rect.y = 92; + + SDL_BlitSurface (texts[TEXT_TITLE_BEAN_COUNTERS], NULL, screen, &rect); + + rect.w = texts[TEXT_INSTRUCTIONS]->w; + rect.h = texts[TEXT_INSTRUCTIONS]->h; + rect.x = 504 - (rect.w / 2); + rect.y = 327; + + SDL_BlitSurface (texts[TEXT_INSTRUCTIONS], NULL, screen, &rect); + + rect.w = texts[TEXT_PLAY_GAME]->w; + rect.h = texts[TEXT_PLAY_GAME]->h; + rect.x = 504 - (rect.w / 2); + rect.y = 383; + + SDL_BlitSurface (texts[TEXT_PLAY_GAME], NULL, screen, &rect); + SDL_Flip (screen); do { last_time = SDL_GetTicks (); + num_rects = 0; while (SDL_PollEvent(&event) > 0) { switch (event.type) { @@ -964,10 +1093,25 @@ int game_intro (void) { done = GAME_QUIT; break; case SDL_MOUSEMOTION: + map = map_button_in_intro (event.motion.x, event.motion.y); + cp_button_motion (map); break; case SDL_MOUSEBUTTONDOWN: + map = map_button_in_intro (event.button.x, event.button.y); + cp_button_down (map); break; case SDL_MOUSEBUTTONUP: + map = map_button_in_intro (event.button.x, event.button.y); + map = cp_button_up (map); + + switch (map) { + case BUTTON_UI_INSTRUCTIONS: + done = GAME_CONTINUE; + break; + case BUTTON_UI_PLAY_GAME: + done = GAME_CONTINUE; + break; + } break; case SDL_KEYDOWN: /* Tengo una tecla presionada */ @@ -983,7 +1127,59 @@ int game_intro (void) { } } - SDL_Flip (screen); + if (cp_button_refresh[BUTTON_UI_INSTRUCTIONS]) { + rect.x = 381; rect.y = 327; + rect.w = 246; rect.h = 24; + SDL_FillRect (screen, &rect, color); + update_rects[num_rects++] = rect; + + rect.w = texts[TEXT_INSTRUCTIONS]->w; + rect.h = texts[TEXT_INSTRUCTIONS]->h; + rect.x = 504 - (rect.w / 2); + rect.y = 327; + + SDL_BlitSurface (texts[TEXT_INSTRUCTIONS], NULL, screen, &rect); + + if (cp_button_frames[BUTTON_UI_INSTRUCTIONS] != BLANK_UP) { + rect.x = 381; + rect.y = 327; + rect.w = 246; + rect.h = 24; + + SDL_BlitSurface (trans, NULL, screen, &rect); + } + + cp_button_refresh[BUTTON_UI_INSTRUCTIONS] = 0; + } + + if (cp_button_refresh[BUTTON_UI_PLAY_GAME]) { + rect.x = 381; rect.y = 383; + rect.w = 246; rect.h = 24; + SDL_FillRect (screen, &rect, color); + update_rects[num_rects++] = rect; + + rect.w = texts[TEXT_PLAY_GAME]->w; + rect.h = texts[TEXT_PLAY_GAME]->h; + rect.x = 504 - (rect.w / 2); + rect.y = 383; + + SDL_BlitSurface (texts[TEXT_PLAY_GAME], NULL, screen, &rect); + + if (cp_button_frames[BUTTON_UI_PLAY_GAME] != BLANK_UP) { + rect.x = 381; + rect.y = 383; + rect.w = 246; + rect.h = 24; + + SDL_BlitSurface (trans, NULL, screen, &rect); + } + + cp_button_refresh[BUTTON_UI_PLAY_GAME] = 0; + } + + SDL_UpdateRects (screen, num_rects, update_rects); + + //SDL_Flip (screen); now_time = SDL_GetTicks (); if (now_time < last_time + FPS) SDL_Delay(last_time + FPS - now_time); @@ -993,6 +1189,7 @@ int game_intro (void) { return done; } +#if 0 int game_finish (void) { int done = 0; SDL_Event event; @@ -1792,7 +1989,7 @@ void setup (void) { char buffer_file[8192]; char *systemdata_path = get_systemdata_path (); Collider *c; - TTF_Font *ttf48_klickclack, *ttf52_klickclack; + TTF_Font *ttf48_klickclack, *ttf52_klickclack, *ttf40_klickclack; /* Inicializar el Video SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { @@ -1937,9 +2134,10 @@ void setup (void) { ttf24_klickclack = TTF_OpenFont (buffer_file, 24); ttf196_klickclack = TTF_OpenFont (buffer_file, 196); ttf48_klickclack = TTF_OpenFont (buffer_file, 48); + ttf40_klickclack = TTF_OpenFont (buffer_file, 40); ttf52_klickclack = TTF_OpenFont (buffer_file, 52); - if (!ttf24_klickclack || !ttf196_klickclack || !ttf48_klickclack || !ttf52_klickclack) { + if (!ttf24_klickclack || !ttf196_klickclack || !ttf48_klickclack || !ttf52_klickclack || !ttf40_klickclack) { fprintf (stderr, _("Failed to load font file 'Klick Clack\n" "The error returned by SDL is:\n" @@ -1951,9 +2149,12 @@ void setup (void) { // TODO: Favor de manejar correctamente el bind_textdomain_codeset bind_textdomain_codeset (PACKAGE, "UTF-8"); - SDL_Color negro, blanco; + SDL_Color negro, blanco, azul1; blanco.r = blanco.g = blanco.b = 255; negro.r = negro.g = negro.b = 0; + azul1.r = 0x01; + azul1.g = 0x34; + azul1.b = 0x9a; for (g = TEXT_LIVES; g <= TEXT_SCORE; g++) { texts[g] = draw_text_with_shadow (ttf24_klickclack, 2, _(text_strings[g]), blanco, negro); @@ -1964,8 +2165,13 @@ void setup (void) { texts[TEXT_NEXT_TRUCK] = draw_text_with_shadow (ttf48_klickclack, 2, _(text_strings[TEXT_NEXT_TRUCK]), blanco, negro); texts[TEXT_GAME_OVER] = draw_text_with_shadow (ttf52_klickclack, 3, _(text_strings[TEXT_GAME_OVER]), blanco, negro); + texts[TEXT_TITLE_BEAN_COUNTERS] = draw_text (ttf40_klickclack, _(text_strings[TEXT_TITLE_BEAN_COUNTERS]), &azul1); + texts[TEXT_INSTRUCTIONS] = draw_text (ttf24_klickclack, _(text_strings[TEXT_INSTRUCTIONS]), &azul1); + texts[TEXT_PLAY_GAME] = draw_text (ttf24_klickclack, _(text_strings[TEXT_PLAY_GAME]), &azul1); + TTF_CloseFont (ttf48_klickclack); TTF_CloseFont (ttf52_klickclack); + TTF_CloseFont (ttf40_klickclack); } void setup_and_color_penguin (void) { @@ -2180,3 +2386,10 @@ void delete_bag (BeanBag *p) { free (p); } + +int map_button_in_intro (int x, int y) { + if (x >= 381 && x < 627 && y >= 324 && y < 348) return BUTTON_UI_INSTRUCTIONS; + if (x >= 381 && x < 627 && y >= 380 && y < 404) return BUTTON_UI_PLAY_GAME; + return BUTTON_NONE; +} + diff --git a/src/collider.c b/src/collider.c index 5246980..e9e716e 100644 --- a/src/collider.c +++ b/src/collider.c @@ -23,6 +23,7 @@ #include #include +#include #include #include diff --git a/src/cp-button.c b/src/cp-button.c new file mode 100644 index 0000000..bb3de58 --- /dev/null +++ b/src/cp-button.c @@ -0,0 +1,104 @@ +/* + * cp-button.c + * This file is part of Thin Ice + * + * Copyright (C) 2013 - Felix Arreola Rodriguez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +int *cp_button_frames; +int *cp_button_refresh; +int cp_old_map, cp_last_button; + +void cp_registrar_botones (int n) { + cp_button_frames = malloc (sizeof (int) * n); + cp_button_refresh = malloc (sizeof (int) * n); + memset (cp_button_refresh, 0, n * sizeof (int)); +} + +void cp_registrar_boton (int n, int frame) { + cp_button_frames[n] = frame; +} + +void cp_button_start (void) { + cp_old_map = cp_last_button = 0; +} + +void cp_button_motion (int map) { + /* Motor de botones */ + if (cp_old_map == 0 && map != 0) { + if (cp_last_button == 0) { + cp_button_frames [map]++; + } else if (cp_last_button == map) { + cp_button_frames [map]++; + } + cp_button_refresh [map] = 1; + } else if (cp_old_map != 0 && map == 0) { + if (cp_last_button == 0) { + cp_button_frames [cp_old_map]--; + cp_button_refresh [cp_old_map] = 1; + } else if (cp_last_button == cp_old_map) { + cp_button_frames [cp_last_button]--; + cp_button_refresh [cp_last_button] = 1; + } + } else if (cp_old_map != map) { + if (cp_last_button == 0) { + cp_button_frames [map]++; + cp_button_refresh [map] = 1; + if (cp_old_map != 0) { + cp_button_frames [cp_old_map]--; + cp_button_refresh [cp_old_map] = 1; + } + } else if (cp_last_button == cp_old_map) { + cp_button_frames [cp_old_map]--; + cp_button_refresh [cp_old_map] = 1; + } else if (cp_last_button == map) { + cp_button_frames [map]++; + cp_button_refresh [map] = 1; + } + } + cp_old_map = map; +} + +void cp_button_down (int map) { + cp_last_button = map; + + if (cp_last_button != 0) { + cp_button_frames [cp_last_button]++; + cp_button_refresh [cp_last_button] = 1; + } +} + +int cp_button_up (int map) { + if (cp_last_button != 0) { + cp_button_frames [cp_last_button]--; + cp_button_refresh [cp_last_button] = 1; + if (map == cp_last_button) { + /* Switch del boton */ + cp_last_button = 0; + return map; + } else if (map != 0) { + cp_button_frames [map]++; + cp_button_refresh [map] = 1; + } + + cp_last_button = 0; + } + + return 0; +} diff --git a/src/cp-button.h b/src/cp-button.h new file mode 100644 index 0000000..fa48d3b --- /dev/null +++ b/src/cp-button.h @@ -0,0 +1,15 @@ +#ifndef __CP_BUTTON_H__ +#define __CP_BUTTON_H__ + +extern int *cp_button_frames; +extern int *cp_button_refresh; + +void cp_registrar_botones (int n); +void cp_registrar_boton (int n, int frame); +void cp_button_start (void); +void cp_button_motion (int map); +void cp_button_down (int map); +int cp_button_up (int map); + +#endif /* __CP_BUTTON_H__ */ +