12-hit grenade combo trophy. Save screenshot when trophy earned.
This commit is contained in:
parent
8ece207582
commit
03c02c01f9
|
@ -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)
|
||||
{
|
||||
|
@ -41,6 +43,11 @@ void addExplosion(float x, float y, int radius, Entity *owner)
|
|||
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);
|
||||
|
||||
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue