Adds basic skillbar rendering, now we need skills
This commit is contained in:
parent
988d0138b9
commit
738102b6e6
|
@ -93,6 +93,7 @@ add_executable(breakhack
|
||||||
src/mixer
|
src/mixer
|
||||||
src/io_util
|
src/io_util
|
||||||
src/physfsrwops
|
src/physfsrwops
|
||||||
|
src/skillbar
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(breakhack
|
target_link_libraries(breakhack
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
#include "skillbar.h"
|
||||||
|
|
||||||
typedef enum Turn_t {
|
typedef enum Turn_t {
|
||||||
PLAYER,
|
PLAYER,
|
||||||
|
@ -55,6 +56,7 @@ static Player *gPlayer = NULL;
|
||||||
static Map *gMap = NULL;
|
static Map *gMap = NULL;
|
||||||
static RoomMatrix *gRoomMatrix = NULL;
|
static RoomMatrix *gRoomMatrix = NULL;
|
||||||
static Gui *gGui = NULL;
|
static Gui *gGui = NULL;
|
||||||
|
static SkillBar *gSkillBar = NULL;
|
||||||
static Pointer *gPointer = NULL;
|
static Pointer *gPointer = NULL;
|
||||||
static unsigned int cLevel = 1;
|
static unsigned int cLevel = 1;
|
||||||
static float deltaTime = 1.0;
|
static float deltaTime = 1.0;
|
||||||
|
@ -181,6 +183,7 @@ initGame(void)
|
||||||
gCamera.renderer = gRenderer;
|
gCamera.renderer = gRenderer;
|
||||||
gRoomMatrix = roommatrix_create();
|
gRoomMatrix = roommatrix_create();
|
||||||
gGui = gui_create(gRenderer);
|
gGui = gui_create(gRenderer);
|
||||||
|
gSkillBar = skillbar_create(gRenderer);
|
||||||
item_builder_init(gRenderer);
|
item_builder_init(gRenderer);
|
||||||
gPointer = pointer_create(gRenderer);
|
gPointer = pointer_create(gRenderer);
|
||||||
particle_engine_init();
|
particle_engine_init();
|
||||||
|
@ -481,6 +484,7 @@ run_game(void)
|
||||||
RIGHT_GUI_HEIGHT, &gCamera);
|
RIGHT_GUI_HEIGHT, &gCamera);
|
||||||
|
|
||||||
SDL_RenderSetViewport(gRenderer, &skillBarViewport);
|
SDL_RenderSetViewport(gRenderer, &skillBarViewport);
|
||||||
|
skillbar_render(gSkillBar, &gCamera);
|
||||||
|
|
||||||
SDL_RenderSetViewport(gRenderer, &bottomGuiViewport);
|
SDL_RenderSetViewport(gRenderer, &bottomGuiViewport);
|
||||||
gui_render_log(gGui, BOTTOM_GUI_WIDTH,
|
gui_render_log(gGui, BOTTOM_GUI_WIDTH,
|
||||||
|
@ -600,6 +604,7 @@ void close(void)
|
||||||
|
|
||||||
roommatrix_destroy(gRoomMatrix);
|
roommatrix_destroy(gRoomMatrix);
|
||||||
gui_destroy(gGui);
|
gui_destroy(gGui);
|
||||||
|
skillbar_destroy(gSkillBar);
|
||||||
pointer_destroy(gPointer);
|
pointer_destroy(gPointer);
|
||||||
item_builder_close();
|
item_builder_close();
|
||||||
particle_engine_close();
|
particle_engine_close();
|
||||||
|
|
|
@ -16,16 +16,32 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "skillbar.h"
|
#include "skillbar.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
|
load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
static SDL_Color c_yellow = { 255, 255, 0, 255 };
|
||||||
|
|
||||||
Texture *t = texture_create();
|
Texture *t = texture_create();
|
||||||
texture_load_from_file(t, path, renderer);
|
texture_load_from_file(t, path, renderer);
|
||||||
|
t->dim.width = 16;
|
||||||
|
t->dim.height = 16;
|
||||||
ht_set(bar->textures, path, t);
|
ht_set(bar->textures, path, t);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < 4; ++i) {
|
||||||
|
char buffer[1];
|
||||||
|
Sprite *s = sprite_create();
|
||||||
|
s->pos = (Position) { i * 32 + 20, 20 };
|
||||||
|
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 8);
|
||||||
|
m_sprintf(buffer, 1, "%u", i+1);
|
||||||
|
texture_load_from_text(s->textures[0], buffer, c_yellow, renderer);
|
||||||
|
linkedlist_append(&bar->sprites, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkillBar *
|
SkillBar *
|
||||||
|
@ -33,19 +49,60 @@ skillbar_create(SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
SkillBar *bar = ec_malloc(sizeof(SkillBar));
|
SkillBar *bar = ec_malloc(sizeof(SkillBar));
|
||||||
bar->textures = ht_create(10);
|
bar->textures = ht_create(10);
|
||||||
|
bar->sprites = linkedlist_create();
|
||||||
load_texture(bar, "GUI/GUI0.png", renderer);
|
load_texture(bar, "GUI/GUI0.png", renderer);
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
render(SkillBar *bar, Camera *cam)
|
render_frame(SkillBar *bar, Camera *cam)
|
||||||
{
|
{
|
||||||
// TODO: Implement
|
static SDL_Rect c_top_left = { 1*16, 10*16, 16, 16 };
|
||||||
|
static SDL_Rect c_top_right = { 3*16, 10*16, 16, 16 };
|
||||||
|
static SDL_Rect c_bottom_left = { 1*16, 12*16, 16, 16 };
|
||||||
|
static SDL_Rect c_bottom_right = { 3*16, 12*16, 16, 16 };
|
||||||
|
|
||||||
|
Texture *t = ht_get(bar->textures, "GUI/GUI0.png");
|
||||||
|
Position p = { 0, 0 };
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < MAP_ROOM_WIDTH; ++i) {
|
||||||
|
p.x = i*32;
|
||||||
|
p.y = 0;
|
||||||
|
texture_render_clip(t, &p, &c_top_left, cam);
|
||||||
|
p.y = 16;
|
||||||
|
texture_render_clip(t, &p, &c_bottom_left, cam);
|
||||||
|
|
||||||
|
p.x = i*32 + 16;
|
||||||
|
p.y = 0;
|
||||||
|
texture_render_clip(t, &p, &c_top_right, cam);
|
||||||
|
p.y = 16;
|
||||||
|
texture_render_clip(t, &p, &c_bottom_right, cam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_sprites(SkillBar *bar, Camera *cam)
|
||||||
|
{
|
||||||
|
LinkedList *sprites = bar->sprites;
|
||||||
|
|
||||||
|
while (sprites) {
|
||||||
|
sprite_render(sprites->data, cam);
|
||||||
|
sprites = sprites->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
skillbar_render(SkillBar *bar, Camera *cam)
|
||||||
|
{
|
||||||
|
render_frame(bar, cam);
|
||||||
|
render_sprites(bar, cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
skillbar_destroy(SkillBar *bar)
|
skillbar_destroy(SkillBar *bar)
|
||||||
{
|
{
|
||||||
ht_destroy_custom(bar->textures, (void (*)(void *)) texture_destroy);
|
ht_destroy_custom(bar->textures, (void (*)(void *)) texture_destroy);
|
||||||
|
while (bar->sprites)
|
||||||
|
sprite_destroy(linkedlist_pop(&bar->sprites));
|
||||||
free(bar);
|
free(bar);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,19 @@
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "hashtable.h"
|
#include "hashtable.h"
|
||||||
|
#include "linkedlist.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
||||||
typedef struct SkillBar_t {
|
typedef struct SkillBar_t {
|
||||||
Hashtable *textures;
|
Hashtable *textures;
|
||||||
|
LinkedList *sprites;
|
||||||
} SkillBar;
|
} SkillBar;
|
||||||
|
|
||||||
SkillBar *
|
SkillBar *
|
||||||
skillbar_create(SDL_Renderer*);
|
skillbar_create(SDL_Renderer*);
|
||||||
|
|
||||||
void
|
void
|
||||||
render(SkillBar*, Camera*);
|
skillbar_render(SkillBar*, Camera*);
|
||||||
|
|
||||||
void
|
void
|
||||||
skillbar_destroy(SkillBar*);
|
skillbar_destroy(SkillBar*);
|
||||||
|
|
Loading…
Reference in New Issue