Introduces texture blending
- Makes indicator sprites transparent when the player is under them
This commit is contained in:
parent
52913af237
commit
f5a88fc10e
|
@ -787,7 +787,7 @@ render_game(void)
|
|||
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)
|
||||
roommatrix_render_mouse_square(gRoomMatrix, gCamera);
|
||||
|
@ -885,7 +885,7 @@ run_menu(void)
|
|||
SDL_RenderSetViewport(gRenderer, &menuViewport);
|
||||
map_render(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);
|
||||
|
||||
SDL_RenderSetViewport(gRenderer, NULL);
|
||||
|
|
|
@ -358,13 +358,13 @@ map_render_mid_layer(Map *map, Camera *cam)
|
|||
}
|
||||
|
||||
void
|
||||
map_render_top_layer(Map *map, Camera *cam)
|
||||
map_render_top_layer(Map *map, RoomMatrix *rm, Camera *cam)
|
||||
{
|
||||
LinkedList *monsterItem = map->monsters;
|
||||
while (monsterItem != NULL) {
|
||||
Monster *monster = monsterItem->data;
|
||||
monsterItem = monsterItem->next;
|
||||
monster_render_top_layer(monster, cam);
|
||||
monster_render_top_layer(monster, rm, cam);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ void
|
|||
map_render_mid_layer(Map*, Camera*);
|
||||
|
||||
void
|
||||
map_render_top_layer(Map*, Camera*);
|
||||
map_render_top_layer(Map*, RoomMatrix*, Camera*);
|
||||
|
||||
void
|
||||
map_set_current_room(Map*, Position*);
|
||||
|
|
|
@ -680,7 +680,7 @@ monster_render(Monster *m, Camera *cam)
|
|||
}
|
||||
|
||||
void
|
||||
monster_render_top_layer(Monster *m, Camera *cam)
|
||||
monster_render_top_layer(Monster *m, RoomMatrix *rm, Camera *cam)
|
||||
{
|
||||
if (m->stats.hp <= 0)
|
||||
return;
|
||||
|
@ -688,8 +688,16 @@ monster_render_top_layer(Monster *m, Camera *cam)
|
|||
if (m->behaviour == ASSASSIN && m->state.current != AGRESSIVE)
|
||||
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)
|
||||
sprite_render(m->stateIndicator.sprite, cam);
|
||||
if (rm->spaces[mPos.x][mPos.y].player) {
|
||||
sprite_set_alpha(m->stateIndicator.sprite, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -87,7 +87,7 @@ void
|
|||
monster_render(Monster*, Camera*);
|
||||
|
||||
void
|
||||
monster_render_top_layer(Monster*, Camera*);
|
||||
monster_render_top_layer(Monster*, RoomMatrix*, Camera*);
|
||||
|
||||
void
|
||||
monster_hit(Monster*, unsigned int dmg);
|
||||
|
|
18
src/sprite.c
18
src/sprite.c
|
@ -94,6 +94,24 @@ sprite_set_texture(Sprite *s, Texture *t, int index)
|
|||
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
|
||||
sprite_render(Sprite *s, Camera *cam)
|
||||
{
|
||||
|
|
|
@ -59,6 +59,12 @@ sprite_set_texture(Sprite *, Texture *, int index);
|
|||
void
|
||||
sprite_render(Sprite*, Camera*);
|
||||
|
||||
void
|
||||
sprite_set_blend_mode(Sprite*, SDL_BlendMode);
|
||||
|
||||
void
|
||||
sprite_set_alpha(Sprite*, Uint8);
|
||||
|
||||
void
|
||||
sprite_destroy(Sprite *);
|
||||
|
||||
|
|
|
@ -223,6 +223,20 @@ texture_load_from_text_blended(Texture *t, const char * text, SDL_Color fg, SDL_
|
|||
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
|
||||
texture_render(Texture *texture, SDL_Rect *box, Camera *cam)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "position.h"
|
||||
#include "camera.h"
|
||||
|
||||
typedef struct {
|
||||
typedef struct Texture {
|
||||
SDL_Texture *texture;
|
||||
TTF_Font *font;
|
||||
TTF_Font *outlineFont;
|
||||
|
@ -76,6 +76,12 @@ texture_load_from_text_blended(Texture*,
|
|||
SDL_Color,
|
||||
SDL_Renderer*);
|
||||
|
||||
void
|
||||
texture_set_blend_mode(Texture*, SDL_BlendMode);
|
||||
|
||||
void
|
||||
texture_set_alpha(Texture*, Uint8);
|
||||
|
||||
void
|
||||
texture_render(Texture*, SDL_Rect*, Camera*);
|
||||
|
||||
|
|
Loading…
Reference in New Issue