Initial skillbar code

This commit is contained in:
Linus Probert 2018-02-22 15:42:43 +01:00
parent 4f75378a73
commit 2afb8090e3
4 changed files with 102 additions and 3 deletions

View File

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

View File

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

51
src/skillbar.c Normal file
View File

@ -0,0 +1,51 @@
/*
* 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 "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);
}

39
src/skillbar.h Normal file
View File

@ -0,0 +1,39 @@
/*
* 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/>.
*/
#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_