summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-07 15:04:49 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-07 15:05:25 +0100
commit7a9de9f475fcf4ba3cc4b5b6ef6b220af1c7d7bd (patch)
treee11fffe1e87f9f4adc6de79f8de95a27f8611c62 /main.c
parent347813350f6f051b49187f020eb91f3ffc65f951 (diff)
store red surfaces
at the initialization, red surfaces are generated Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'main.c')
-rw-r--r--main.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/main.c b/main.c
index 3dfd1e8..e6fc307 100644
--- a/main.c
+++ b/main.c
@@ -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);