From f51dbd0669453290fb167caa7de8578cfcb7f7fd Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 28 Feb 2012 13:35:39 +0100 Subject: [PATCH] Use a better way to create images of ships taking damage. The old technique was to overlay a semi-transparent red rectangle over an existing ship image, and then make 50% red pixels transparent. For some reason, the transparency is not working correctly. Instead, don't overlay anything, but set the red component of all non-black pixels to the maximum value. --- code/resources.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/resources.cpp b/code/resources.cpp index 191f1f3..60299c0 100644 --- a/code/resources.cpp +++ b/code/resources.cpp @@ -81,19 +81,19 @@ void loadGameGraphics() fclose(fp); /* - Overlay a red alpha surface onto + Create images of ships being hit that show a lot of red */ - SDL_Surface *hitRect; for (int i = SHIP_HIT_INDEX ; i < MAX_SHIPSHAPES ; i++) { if (shipShape[i - SHIP_HIT_INDEX] == NULL) continue; shipShape[i] = createSurface(shipShape[i - SHIP_HIT_INDEX]->w, shipShape[i- SHIP_HIT_INDEX]->h); blit(shipShape[i - SHIP_HIT_INDEX], 0, 0, shipShape[i]); - hitRect = alphaRect(shipShape[i]->w, shipShape[i]->h, 255, 0, 0); - blit(hitRect, 0, 0, shipShape[i]); - SDL_SetColorKey(shipShape[i], (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(shipShape[i]->format, 127, 0, 0)); - SDL_FreeSurface(hitRect); + uint32_t *p = (uint32_t *)shipShape[i]->pixels; + for(int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++) + if(p[j]) + p[j] |= shipShape[i]->format->Rmask; + SDL_SetColorKey(shipShape[i], (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(shipShape[i]->format, 0, 0, 0)); } strcpy(string, "data/resources_all.dat");