diff options
-rw-r--r-- | main.c | 69 | ||||
-rw-r--r-- | structures.h | 6 |
2 files changed, 75 insertions, 0 deletions
@@ -150,6 +150,59 @@ void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces) } } +static void colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint32 incr) +{ + int buffer = 0; + Uint8 r, g, b; + Uint8 rincr, gincr, bincr; /* delta */ + + SDL_GetRGB(incr, fmt, &rincr, &gincr, &bincr); + + SDL_LockSurface(surf); + + for (int y = 0; y < surf->h; ++y) { + for (int x = 0; x < surf->w; ++x) { + Uint32 pixel = obtenirPixel(surf, x, y); + + SDL_GetRGB(pixel, fmt, &r, &g, &b); + + /* red increment */ + buffer = (int)r + rincr; + if (buffer > 0xff) buffer = 0xff; + else if (buffer < 0x0) buffer = 0; + r = buffer; + + /* green increment */ + buffer = (int)g + gincr; + if (buffer > 0xff) buffer = 0xff; + else if (buffer < 0x0) buffer = 0; + g = buffer; + + /* blue increment */ + buffer = (int)b + bincr; + if (buffer > 0xff) buffer = 0xff; + else if (buffer < 0x0) buffer = 0; + b = buffer; + + pixel = SDL_MapRGB(fmt, r, g, b); + definirPixel(surf, x, y, pixel); + } + } + + SDL_UnlockSurface(surf); + SDL_SetColorKey(surf, SDL_SRCCOLORKEY, SDL_MapRGB(fmt, r, g, b)); +} + +static void colorize_every_red_surface(SURFACES *surfaces) +{ + const SDL_PixelFormat *fmt = surfaces->Pecran->format; + Uint32 red = SDL_MapRGB(fmt, 30, 0, 0); + + colorize_surface(surfaces->red_paladin, fmt, red); + colorize_surface(surfaces->red_priest, fmt, red); + colorize_surface(surfaces->red_thief, fmt, red); +} + int Fchargerimages (SURFACES *surfaces) { #define LOAD_IMAGE(_name, _path) \ @@ -164,6 +217,9 @@ int Fchargerimages (SURFACES *surfaces) LOAD_IMAGE(Ppaladin, "images/paladin.bmp"); LOAD_IMAGE(Ppretre, "images/pretre.bmp"); LOAD_IMAGE(Pvoleur, "images/voleur.bmp"); + LOAD_IMAGE(red_thief, "images/voleur.bmp"); + LOAD_IMAGE(red_paladin, "images/paladin.bmp"); + LOAD_IMAGE(red_priest, "images/pretre.bmp"); LOAD_IMAGE(Pmenujouer, "images/menu_principal/jouer.bmp"); LOAD_IMAGE(Pmenuoptions, "images/menu_principal/options.bmp"); LOAD_IMAGE(Pmenuquitter, "images/menu_principal/quitter.bmp"); @@ -186,15 +242,22 @@ int Fchargerimages (SURFACES *surfaces) //définition de la transparence alpha dans les surfaces SDL_SetColorKey(surfaces->Pgobelin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,0,255,18)); + SDL_SetColorKey(surfaces->Ppretre,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); SDL_SetColorKey(surfaces->Ppaladin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,189,31,31)); SDL_SetColorKey(surfaces->Pvoleur,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); + SDL_SetColorKey(surfaces->red_priest,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); + SDL_SetColorKey(surfaces->red_paladin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,189,31,31)); + SDL_SetColorKey(surfaces->red_thief,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); + SDL_SetColorKey(surfaces->Pcurseurennemis,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); SDL_SetColorKey(surfaces->Pcurseurallies,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); SDL_SetColorKey(surfaces->Pactive,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); SDL_SetColorKey(surfaces->Pdesactive,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); SDL_SetColorKey(surfaces->Pmort,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); + colorize_every_red_surface(surfaces); + return 0; } @@ -203,9 +266,15 @@ void Fdechargerimages (SURFACES *surfaces)//dechargement des surfaces alouées int i; SDL_FreeSurface(surfaces->Pecran); SDL_FreeSurface (surfaces->Pgobelin); + SDL_FreeSurface (surfaces->Ppaladin); SDL_FreeSurface (surfaces->Ppretre); SDL_FreeSurface (surfaces->Pvoleur); + + SDL_FreeSurface(surfaces->red_paladin); + SDL_FreeSurface(surfaces->red_priest); + SDL_FreeSurface(surfaces->red_thief); + SDL_FreeSurface (surfaces->Pmenujouer); SDL_FreeSurface (surfaces->Pmenuoptions); SDL_FreeSurface (surfaces->Pmenuquitter); diff --git a/structures.h b/structures.h index 19d0a1e..2679bfd 100644 --- a/structures.h +++ b/structures.h @@ -6,9 +6,15 @@ struct surfaces { SDL_Surface *Pecran; SDL_Surface *Pgobelin; + SDL_Surface *Ppaladin; SDL_Surface *Ppretre; SDL_Surface *Pvoleur; + + SDL_Surface *red_paladin; + SDL_Surface *red_priest; + SDL_Surface *red_thief; + SDL_Surface *Pmenuoptions; SDL_Surface *Pmenujouer; SDL_Surface *Pmenuquitter; |