Fixes: #5 Creates a creditscreen

This commit is contained in:
Linus Probert 2018-08-12 09:13:18 +02:00
parent 2a80434547
commit 3f1cdf8a12
9 changed files with 208 additions and 31 deletions

View File

@ -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

18
CREDITS.md Normal file
View File

@ -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

View File

@ -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 )

View File

@ -21,6 +21,8 @@
typedef enum GameState_t {
MENU,
CREDITS,
SCORE_SCREEN,
PLAYING,
IN_GAME_MENU,
GAME_OVER,

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

108
src/screen.c Normal file
View File

@ -0,0 +1,108 @@
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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);
}

37
src/screen.h Normal file
View File

@ -0,0 +1,37 @@
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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);