diff --git a/src/combat/explosions.c b/src/combat/explosions.c index 7bbdf41..0f3a3f5 100644 --- a/src/combat/explosions.c +++ b/src/combat/explosions.c @@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "explosions.h" static SDL_Rect radiusRect; +static unsigned int killTimer = 0; +static unsigned int numKilled = 0; void addExplosion(float x, float y, int radius, Entity *owner) { @@ -40,6 +42,11 @@ void addExplosion(float x, float y, int radius, Entity *owner) radiusRect.y = (int) (y - radius); radiusRect.w = radius * 2; radiusRect.h = radius * 2; + + if (killTimer < SDL_GetTicks()) + { + numKilled = 0; + } candidates = getAllEntsWithin(radiusRect.x, radiusRect.y, radiusRect.w, radiusRect.h, NULL); @@ -80,9 +87,20 @@ void addExplosion(float x, float y, int radius, Entity *owner) { e->dx = rrnd(-radius / 8, radius / 8); e->dy = rrnd(-5, 0); + + if (owner->type == ET_BOB) + { + numKilled++; + killTimer = SDL_GetTicks() + 1000; + } } } } } } + + if (numKilled >= 12) + { + awardTrophy("GRENADE_COMBO"); + } } diff --git a/src/combat/explosions.h b/src/combat/explosions.h index 514b36f..8b7ef4a 100644 --- a/src/combat/explosions.h +++ b/src/combat/explosions.h @@ -27,5 +27,6 @@ extern void playSound(int snd, int ch); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern int getDistance(int x1, int y1, int x2, int y2); extern void swapSelf(Entity *e); +extern void awardTrophy(char *id); extern Game game; diff --git a/src/game/trophies.c b/src/game/trophies.c index 33d3b26..91b698c 100644 --- a/src/game/trophies.c +++ b/src/game/trophies.c @@ -106,7 +106,7 @@ Trophy *getTrophy(char *id) } } - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "No such trophy '%s'", t->id); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "No such trophy '%s'", id); exit(1); } @@ -146,6 +146,7 @@ void doTrophyAlerts(void) if (alertTimer <= 0) { + saveScreenshot(alertTrophy->id); alertTrophy->notify = 0; resetAlert(); } diff --git a/src/game/trophies.h b/src/game/trophies.h index 28fc575..ba91022 100644 --- a/src/game/trophies.h +++ b/src/game/trophies.h @@ -35,6 +35,7 @@ extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int extern void blitRectRotated(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, float angle); extern Texture *getTexture(const char *filename); extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center); +extern void saveScreenshot(char *name); extern Colors colors; extern Game game; diff --git a/src/system/draw.c b/src/system/draw.c index b0adfca..a218a88 100644 --- a/src/system/draw.c +++ b/src/system/draw.c @@ -253,3 +253,23 @@ static void initColor(SDL_Color *c, int r, int g, int b) c->b = b; c->a = 255; } + +void saveScreenshot(char *name) +{ + char filename[MAX_FILENAME_LENGTH]; + SDL_Surface *screenshot; + + if (name != NULL) + { + sprintf(filename, "%s/%s.bmp", app.saveDir, name); + } + else + { + sprintf(filename, "%s/%d.bmp", app.saveDir, SDL_GetTicks()); + } + + screenshot = SDL_CreateRGBSurface(0, SCREEN_WIDTH, SCREEN_HEIGHT, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + SDL_RenderReadPixels(app.renderer, NULL, SDL_PIXELFORMAT_ARGB8888, screenshot->pixels, screenshot->pitch); + SDL_SaveBMP(screenshot, filename); + SDL_FreeSurface(screenshot); +}