Introduces texture blending

- Makes indicator sprites transparent when the player is under them
This commit is contained in:
Linus Probert 2018-08-23 09:41:10 +02:00
parent 52913af237
commit f5a88fc10e
9 changed files with 60 additions and 8 deletions

View File

@ -787,7 +787,7 @@ render_game(void)
player_render_toplayer(gPlayer, gCamera); player_render_toplayer(gPlayer, gCamera);
} }
map_render_top_layer(gMap, gCamera); map_render_top_layer(gMap, gRoomMatrix, gCamera);
if (gPlayer->class == MAGE || gPlayer->class == PALADIN) if (gPlayer->class == MAGE || gPlayer->class == PALADIN)
roommatrix_render_mouse_square(gRoomMatrix, gCamera); roommatrix_render_mouse_square(gRoomMatrix, gCamera);
@ -885,7 +885,7 @@ run_menu(void)
SDL_RenderSetViewport(gRenderer, &menuViewport); SDL_RenderSetViewport(gRenderer, &menuViewport);
map_render(gMap, gCamera); map_render(gMap, gCamera);
map_render_mid_layer(gMap, gCamera); map_render_mid_layer(gMap, gCamera);
map_render_top_layer(gMap, gCamera); map_render_top_layer(gMap, gRoomMatrix, gCamera);
roommatrix_render_lightmap(gRoomMatrix, gCamera); roommatrix_render_lightmap(gRoomMatrix, gCamera);
SDL_RenderSetViewport(gRenderer, NULL); SDL_RenderSetViewport(gRenderer, NULL);

View File

@ -358,13 +358,13 @@ map_render_mid_layer(Map *map, Camera *cam)
} }
void void
map_render_top_layer(Map *map, Camera *cam) map_render_top_layer(Map *map, RoomMatrix *rm, Camera *cam)
{ {
LinkedList *monsterItem = map->monsters; LinkedList *monsterItem = map->monsters;
while (monsterItem != NULL) { while (monsterItem != NULL) {
Monster *monster = monsterItem->data; Monster *monster = monsterItem->data;
monsterItem = monsterItem->next; monsterItem = monsterItem->next;
monster_render_top_layer(monster, cam); monster_render_top_layer(monster, rm, cam);
} }
} }

View File

@ -107,7 +107,7 @@ void
map_render_mid_layer(Map*, Camera*); map_render_mid_layer(Map*, Camera*);
void void
map_render_top_layer(Map*, Camera*); map_render_top_layer(Map*, RoomMatrix*, Camera*);
void void
map_set_current_room(Map*, Position*); map_set_current_room(Map*, Position*);

View File

@ -680,7 +680,7 @@ monster_render(Monster *m, Camera *cam)
} }
void void
monster_render_top_layer(Monster *m, Camera *cam) monster_render_top_layer(Monster *m, RoomMatrix *rm, Camera *cam)
{ {
if (m->stats.hp <= 0) if (m->stats.hp <= 0)
return; return;
@ -688,8 +688,16 @@ monster_render_top_layer(Monster *m, Camera *cam)
if (m->behaviour == ASSASSIN && m->state.current != AGRESSIVE) if (m->behaviour == ASSASSIN && m->state.current != AGRESSIVE)
return; return;
Position mPos = position_to_matrix_coords(&m->sprite->pos);
mPos.y -= 1;
if (rm->spaces[mPos.x][mPos.y].player) {
sprite_set_alpha(m->stateIndicator.sprite, 110);
}
if (m->stateIndicator.displayCount != 0) if (m->stateIndicator.displayCount != 0)
sprite_render(m->stateIndicator.sprite, cam); sprite_render(m->stateIndicator.sprite, cam);
if (rm->spaces[mPos.x][mPos.y].player) {
sprite_set_alpha(m->stateIndicator.sprite, 255);
}
} }
void void

View File

@ -87,7 +87,7 @@ void
monster_render(Monster*, Camera*); monster_render(Monster*, Camera*);
void void
monster_render_top_layer(Monster*, Camera*); monster_render_top_layer(Monster*, RoomMatrix*, Camera*);
void void
monster_hit(Monster*, unsigned int dmg); monster_hit(Monster*, unsigned int dmg);

View File

@ -94,6 +94,24 @@ sprite_set_texture(Sprite *s, Texture *t, int index)
s->textures[index] = t; s->textures[index] = t;
} }
void
sprite_set_blend_mode(Sprite *s, SDL_BlendMode mode)
{
if (s->textures[0])
texture_set_blend_mode(s->textures[0], mode);
if (s->textures[1])
texture_set_blend_mode(s->textures[1], mode);
}
void
sprite_set_alpha(Sprite *s, Uint8 alpha)
{
if (s->textures[0])
texture_set_alpha(s->textures[0], alpha);
if (s->textures[1])
texture_set_alpha(s->textures[1], alpha);
}
void void
sprite_render(Sprite *s, Camera *cam) sprite_render(Sprite *s, Camera *cam)
{ {

View File

@ -59,6 +59,12 @@ sprite_set_texture(Sprite *, Texture *, int index);
void void
sprite_render(Sprite*, Camera*); sprite_render(Sprite*, Camera*);
void
sprite_set_blend_mode(Sprite*, SDL_BlendMode);
void
sprite_set_alpha(Sprite*, Uint8);
void void
sprite_destroy(Sprite *); sprite_destroy(Sprite *);

View File

@ -223,6 +223,20 @@ texture_load_from_text_blended(Texture *t, const char * text, SDL_Color fg, SDL_
load_from_surface(t, surface, renderer); load_from_surface(t, surface, renderer);
} }
void
texture_set_blend_mode(Texture *t, SDL_BlendMode mode)
{
assert(t->texture);
SDL_SetTextureBlendMode(t->texture, mode);
}
void
texture_set_alpha(Texture *t, Uint8 alpha)
{
assert(t->texture);
SDL_SetTextureAlphaMod(t->texture, alpha);
}
void void
texture_render(Texture *texture, SDL_Rect *box, Camera *cam) texture_render(Texture *texture, SDL_Rect *box, Camera *cam)
{ {

View File

@ -25,7 +25,7 @@
#include "position.h" #include "position.h"
#include "camera.h" #include "camera.h"
typedef struct { typedef struct Texture {
SDL_Texture *texture; SDL_Texture *texture;
TTF_Font *font; TTF_Font *font;
TTF_Font *outlineFont; TTF_Font *outlineFont;
@ -76,6 +76,12 @@ texture_load_from_text_blended(Texture*,
SDL_Color, SDL_Color,
SDL_Renderer*); SDL_Renderer*);
void
texture_set_blend_mode(Texture*, SDL_BlendMode);
void
texture_set_alpha(Texture*, Uint8);
void void
texture_render(Texture*, SDL_Rect*, Camera*); texture_render(Texture*, SDL_Rect*, Camera*);