Skip to content

Commit

Permalink
Fixes: #5 Creates a creditscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidityC committed Aug 12, 2018
1 parent 2a80434 commit 3f1cdf8
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 31 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 0 additions & 9 deletions TODO.txt

This file was deleted.

2 changes: 2 additions & 0 deletions src/gamestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

typedef enum GameState_t {
MENU,
CREDITS,
SCORE_SCREEN,
PLAYING,
IN_GAME_MENU,
GAME_OVER,
Expand Down
3 changes: 1 addition & 2 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ gui_log(const char *fmt, ...)
{
char buffer[200];
char *new_message;
unsigned int i;
char tstamp[10];

va_list args;
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/item_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
57 changes: 39 additions & 18 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "settings.h"
#include "actiontextbuilder.h"
#include "input.h"
#include "screen.h"

typedef enum Turn_t {
PLAYER,
Expand All @@ -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;
Expand Down Expand Up @@ -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 },
};

Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -385,36 +399,35 @@ 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)) {
if (mixer_toggle_sound())
gui_log("Sound enabled");
else
gui_log("Sound disabled");
return true;
}

return false;
}

static bool
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -653,6 +671,7 @@ void run(void)
run_game();
break;
case MENU:
case CREDITS:
run_menu();
break;
case QUIT:
Expand Down Expand Up @@ -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);

Expand Down
108 changes: 108 additions & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <[email protected]>
*
* 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 changes: 37 additions & 0 deletions src/screen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <[email protected]>
*
* 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);

0 comments on commit 3f1cdf8

Please sign in to comment.