From 3f1cdf8a1265ab88749ea1631603c3f2c6f5b81c Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 12 Aug 2018 09:13:18 +0200 Subject: [PATCH] Fixes: #5 Creates a creditscreen --- CMakeLists.txt | 1 + CREDITS.md | 18 ++++++++ TODO.txt | 9 ---- src/gamestate.h | 2 + src/gui.c | 3 +- src/item_builder.c | 4 +- src/main.c | 57 ++++++++++++++++-------- src/screen.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ src/screen.h | 37 ++++++++++++++++ 9 files changed, 208 insertions(+), 31 deletions(-) create mode 100644 CREDITS.md delete mode 100644 TODO.txt create mode 100644 src/screen.c create mode 100644 src/screen.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d708945..30d42d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,7 @@ add_executable(breakhack src/animation src/trap src/artifact + src/screen ) # Sqlite has some warnings that I we don't need to see diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..dfe1990 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,18 @@ +- Game - +-------- +Code: Linus Probert + liquidityc.github.io + @LiquidityC + +- Graphics - +------------ +Palette: DawnBringer + +- Music and Sound - +------------------- +Music: Eric Matyas + www.soundimage.org +Sound: Eric Matyas + www.soundimage.org + ArtisticDuded + opengameart.org/users/artisticdude diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 9d658d6..0000000 --- a/TODO.txt +++ /dev/null @@ -1,9 +0,0 @@ -o Creat some nice room modifiers - - Falling floor tiles - -- Credit screen showing music and graphics guys: - - Music: http://soundimage.org/ (Eric Matyas) - - SFX (Eric Matyas & https://opengameart.org/users/artisticdude & ZapSplat.com) - - Graphics: (see README) - -Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun ) diff --git a/src/gamestate.h b/src/gamestate.h index 50b03e4..5e8a52f 100644 --- a/src/gamestate.h +++ b/src/gamestate.h @@ -21,6 +21,8 @@ typedef enum GameState_t { MENU, + CREDITS, + SCORE_SCREEN, PLAYING, IN_GAME_MENU, GAME_OVER, diff --git a/src/gui.c b/src/gui.c index 2bf3ae1..63b15cf 100644 --- a/src/gui.c +++ b/src/gui.c @@ -513,7 +513,6 @@ gui_log(const char *fmt, ...) { char buffer[200]; char *new_message; - unsigned int i; char tstamp[10]; va_list args; @@ -531,7 +530,7 @@ gui_log(const char *fmt, ...) log_data.count = log_data.len; free(log_data.log[0]); log_data.log[0] = NULL; - for (i = 0; i < log_data.count - 1; ++i) { + for (size_t i = 0; i < log_data.count - 1; ++i) { log_data.log[i] = log_data.log[i+1]; log_data.log[i+1] = NULL; } diff --git a/src/item_builder.c b/src/item_builder.c index 57658e7..e4be90e 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -81,11 +81,11 @@ pickup_dagger(Item *item, Player *player) static Item * create_item(const char *path0, const char *path1, SDL_Rect clip, void (*cb)(Item*, Player*)) { - Texture *t0 = NULL, *t1 = NULL; Item *item; item = item_create(); - t0 = texturecache_add(path0); + Texture *t0 = texturecache_add(path0); + Texture *t1 = NULL; if (path1) t1 = texturecache_add(path1); diff --git a/src/main.c b/src/main.c index 56b7b48..ef68194 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,7 @@ #include "settings.h" #include "actiontextbuilder.h" #include "input.h" +#include "screen.h" typedef enum Turn_t { PLAYER, @@ -63,14 +64,15 @@ static RoomMatrix *gRoomMatrix = NULL; static Gui *gGui = NULL; static SkillBar *gSkillBar = NULL; static Pointer *gPointer = NULL; -static unsigned int cLevel = 1; -static float deltaTime = 1.0; -static double renderScale = 1.0; static Menu *mainMenu = NULL; static Menu *inGameMenu = NULL; static Timer *menuTimer = NULL; +static Camera *gCamera = NULL; +static Screen *creditsScreen = NULL; +static unsigned int cLevel = 1; +static float deltaTime = 1.0; +static double renderScale = 1.0; static GameState gGameState; -static Camera *gCamera; static SDL_Rect gameViewport; static SDL_Rect skillBarViewport; static SDL_Rect bottomGuiViewport; @@ -311,11 +313,19 @@ createInGameGameOverMenu(void) createMenu(&inGameMenu, menu_items, 3); } +static void +viewCredits(void *unused) +{ + UNUSED(unused); + gGameState = CREDITS; +} + static void initMainMenu(void) { struct MENU_ITEM menu_items[] = { { "PLAY", startGame }, + { "CREDITS", viewCredits }, { "QUIT", exitGame }, }; @@ -324,8 +334,9 @@ initMainMenu(void) gMap = map_lua_generator_single_room__run(cLevel, gRenderer); - createMenu(&mainMenu, menu_items, 2); + createMenu(&mainMenu, menu_items, 3); mixer_play_music(MENU_MUSIC); + creditsScreen = screen_create_credits(gRenderer); } static void @@ -342,10 +353,13 @@ resetGame(void) { SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); - if (mainMenu) { + if (mainMenu) menu_destroy(mainMenu); - mainMenu = NULL; - } + mainMenu = NULL; + + if (creditsScreen) + screen_destroy(creditsScreen); + creditsScreen = NULL; if (!inGameMenu) initInGameMenu(); @@ -385,25 +399,27 @@ init(void) return true; } -static bool +static void handle_main_input(void) { if (gGameState == PLAYING || gGameState == IN_GAME_MENU || gGameState == GAME_OVER) { - if (input_key_is_pressed(&input, KEY_ESC)) { + if (input_key_is_pressed(&input, KEY_ESC)) toggleInGameMenu(NULL); - return true; - } } + if (gGameState == CREDITS && input_key_is_pressed(&input, KEY_ESC)) + gGameState = MENU; + else if (gGameState == MENU && input_key_is_pressed(&input, KEY_ESC)) + gGameState = QUIT; + if (input_modkey_is_pressed(&input, KEY_CTRL_M)) { if (mixer_toggle_music(&gGameState)) gui_log("Music enabled"); else gui_log("Music disabled"); - return true; } if (input_modkey_is_pressed(&input, KEY_CTRL_S)) { @@ -411,10 +427,7 @@ handle_main_input(void) gui_log("Sound enabled"); else gui_log("Sound disabled"); - return true; } - - return false; } static bool @@ -612,7 +625,7 @@ run_menu(void) } menu_update(mainMenu, &input); - if (gGameState != MENU) + if (gGameState != MENU && gGameState != CREDITS) return; SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0); @@ -623,7 +636,12 @@ run_menu(void) roommatrix_render_lightmap(gRoomMatrix, gCamera); SDL_RenderSetViewport(gRenderer, NULL); - menu_render(mainMenu, gCamera); + + if (gGameState == MENU) + menu_render(mainMenu, gCamera); + else if (gGameState == CREDITS) + screen_render(creditsScreen, gCamera); + pointer_render(gPointer, gCamera); SDL_RenderPresent(gRenderer); @@ -653,6 +671,7 @@ void run(void) run_game(); break; case MENU: + case CREDITS: run_menu(); break; case QUIT: @@ -688,6 +707,8 @@ void close(void) map_destroy(gMap); if (mainMenu) menu_destroy(mainMenu); + if (creditsScreen) + screen_destroy(creditsScreen); if (inGameMenu) menu_destroy(inGameMenu); diff --git a/src/screen.c b/src/screen.c new file mode 100644 index 0000000..a8c2bef --- /dev/null +++ b/src/screen.c @@ -0,0 +1,108 @@ +/* + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert + * + * 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 "screen.h" +#include "util.h" + +static Screen * +screen_create(void) +{ + Screen *screen = ec_malloc(sizeof(Screen)); + screen->textures = linkedlist_create(); + screen->sprites = linkedlist_create(); + return screen; +} + +static Sprite * +create_text_sprite(const char *msg, int x, int y, SDL_Renderer *renderer) +{ + Sprite *s = sprite_create(); + sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 14, 1); + texture_load_from_text(s->textures[0], msg, C_BLUE, C_WHITE, renderer); + s->pos = (Position) { x, y }; + s->fixed = true; + s->dim = s->textures[0]->dim; + return s; +} + +Screen * +screen_create_credits(SDL_Renderer *renderer) +{ + int x = 20; + int y = 50; + unsigned int columnOffset = 160; + + Screen *screen = screen_create(); + linkedlist_push(&screen->sprites, create_text_sprite("- Game -", x, y, renderer)); + y += 30; + linkedlist_push(&screen->sprites, create_text_sprite("Code:", x, y, renderer)); + linkedlist_push(&screen->sprites, create_text_sprite("Linus Probert", x + columnOffset, y, renderer)); + y += 20; + linkedlist_push(&screen->sprites, create_text_sprite("liquidityc.github.io", x + columnOffset, y, renderer)); + y += 20; + linkedlist_push(&screen->sprites, create_text_sprite("@LiquidityC", x + columnOffset, y, renderer)); + + y += 60; + linkedlist_push(&screen->sprites, create_text_sprite(" - Graphics -", x, y, renderer)); + y += 30; + linkedlist_push(&screen->sprites, create_text_sprite("Palette:", x, y, renderer)); + linkedlist_push(&screen->sprites, create_text_sprite("DawnBringer", x + columnOffset, y, renderer)); + + y += 60; + linkedlist_push(&screen->sprites, create_text_sprite(" - Music and Sound -", x, y, renderer)); + y += 30; + linkedlist_push(&screen->sprites, create_text_sprite("Music:", x, y, renderer)); + linkedlist_push(&screen->sprites, create_text_sprite("Eric Matyas", x + columnOffset, y, renderer)); + y += 20; + linkedlist_push(&screen->sprites, create_text_sprite("www.soundimage.org", x + columnOffset, y, renderer)); + y += 30; + linkedlist_push(&screen->sprites, create_text_sprite("Sound:", x, y, renderer)); + linkedlist_push(&screen->sprites, create_text_sprite("Eric Matyas", x + columnOffset, y, renderer)); + y += 20; + linkedlist_push(&screen->sprites, create_text_sprite("www.soundimage.org", x + columnOffset, y, renderer)); + y += 30; + linkedlist_push(&screen->sprites, create_text_sprite("ArtisticDuded", x + columnOffset, y, renderer)); + y += 20; + linkedlist_push(&screen->sprites, create_text_sprite("opengameart.org/users/artisticdude", x + columnOffset, y, renderer)); + return screen; +} + +void +screen_render(Screen *screen, Camera *cam) +{ + LinkedList *textures = screen->textures; + while (textures) { + texture_render(textures->data, NULL, cam); + textures = textures->next; + } + LinkedList *sprites = screen->sprites; + while (sprites) { + sprite_render(sprites->data, cam); + sprites = sprites->next; + } +} + +void +screen_destroy(Screen *screen) +{ + while (screen->textures) + texture_destroy(linkedlist_pop(&screen->textures)); + while (screen->sprites) + sprite_destroy(linkedlist_pop(&screen->sprites)); + free(screen); +} diff --git a/src/screen.h b/src/screen.h new file mode 100644 index 0000000..fbccdd7 --- /dev/null +++ b/src/screen.h @@ -0,0 +1,37 @@ +/* + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert + * + * 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 . + */ +#pragma once + +#include "texture.h" +#include "linkedlist.h" +#include "sprite.h" +#include "camera.h" + +typedef struct Screen { + LinkedList *sprites; + LinkedList *textures; +} Screen; + +Screen * +screen_create_credits(SDL_Renderer*); + +void +screen_render(Screen *screen, Camera *cam); + +void +screen_destroy(Screen *screen);