From 2afb8090e341a23a46cffd2d78cc3ad6001db834 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 22 Feb 2018 15:42:43 +0100 Subject: [PATCH] Initial skillbar code --- src/defines.h | 7 +++++-- src/main.c | 8 +++++++- src/skillbar.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/skillbar.h | 39 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/skillbar.c create mode 100644 src/skillbar.h diff --git a/src/defines.h b/src/defines.h index 2e5b53e..3e71fae 100644 --- a/src/defines.h +++ b/src/defines.h @@ -35,14 +35,17 @@ #define GAME_VIEW_WIDTH (MAP_ROOM_WIDTH * TILE_DIMENSION) #define GAME_VIEW_HEIGHT (MAP_ROOM_HEIGHT * TILE_DIMENSION) +#define SKILL_BAR_WIDTH GAME_VIEW_WIDTH +#define SKILL_BAR_HEIGHT 32 + #define RIGHT_GUI_WIDTH (10 * SPRITE_DIMENSION) -#define RIGHT_GUI_HEIGHT GAME_VIEW_HEIGHT +#define RIGHT_GUI_HEIGHT (GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT) #define BOTTOM_GUI_HEIGHT (10 * SPRITE_DIMENSION) #define BOTTOM_GUI_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH) #define SCREEN_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH) -#define SCREEN_HEIGHT (GAME_VIEW_HEIGHT + BOTTOM_GUI_HEIGHT) +#define SCREEN_HEIGHT (RIGHT_GUI_HEIGHT + BOTTOM_GUI_HEIGHT) /* Windows and compile crap */ #ifdef _WIN32 diff --git a/src/main.c b/src/main.c index 70617db..cc9e6c5 100644 --- a/src/main.c +++ b/src/main.c @@ -65,6 +65,7 @@ static Timer *menuTimer = NULL; static GameState gGameState; static Camera gCamera; static SDL_Rect gameViewport; +static SDL_Rect skillBarViewport; static SDL_Rect bottomGuiViewport; static SDL_Rect rightGuiViewport; static SDL_Rect menuViewport; @@ -156,7 +157,10 @@ initViewports(void) gameViewport = (SDL_Rect) { 0, 0, GAME_VIEW_WIDTH, GAME_VIEW_HEIGHT }; - bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT, + skillBarViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT, + SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT }; + + bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT, BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH }; rightGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0, @@ -476,6 +480,8 @@ run_game(void) gui_render_panel(gGui, RIGHT_GUI_WIDTH, RIGHT_GUI_HEIGHT, &gCamera); + SDL_RenderSetViewport(gRenderer, &skillBarViewport); + SDL_RenderSetViewport(gRenderer, &bottomGuiViewport); gui_render_log(gGui, BOTTOM_GUI_WIDTH, BOTTOM_GUI_HEIGHT, &gCamera); diff --git a/src/skillbar.c b/src/skillbar.c new file mode 100644 index 0000000..d9e296d --- /dev/null +++ b/src/skillbar.c @@ -0,0 +1,51 @@ +/* + * 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 "skillbar.h" +#include "texture.h" +#include "util.h" + +static void +load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) +{ + Texture *t = texture_create(); + texture_load_from_file(t, path, renderer); + ht_set(bar->textures, path, t); +} + +SkillBar * +skillbar_create(SDL_Renderer *renderer) +{ + SkillBar *bar = ec_malloc(sizeof(SkillBar)); + bar->textures = ht_create(10); + load_texture(bar, "GUI/GUI0.png", renderer); + return bar; +} + +void +render(SkillBar *bar, Camera *cam) +{ + // TODO: Implement +} + +void +skillbar_destroy(SkillBar *bar) +{ + ht_destroy_custom(bar->textures, (void (*)(void *)) texture_destroy); + free(bar); +} diff --git a/src/skillbar.h b/src/skillbar.h new file mode 100644 index 0000000..4955919 --- /dev/null +++ b/src/skillbar.h @@ -0,0 +1,39 @@ +/* + * 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 . + */ + +#ifndef SKILLBAR_H_ +#define SKILLBAR_H_ + +#include "SDL.h" +#include "hashtable.h" +#include "camera.h" + +typedef struct SkillBar_t { + Hashtable *textures; +} SkillBar; + +SkillBar * +skillbar_create(SDL_Renderer*); + +void +render(SkillBar*, Camera*); + +void +skillbar_destroy(SkillBar*); + +#endif // SKILLBAR_H_