Trophy prototyping.
This commit is contained in:
parent
fb584735c6
commit
f867e793bd
|
@ -132,9 +132,9 @@ static void doBattle(void)
|
||||||
|
|
||||||
battle.planet.x -= ssx * 0.05;
|
battle.planet.x -= ssx * 0.05;
|
||||||
battle.planet.y -= ssy * 0.05;
|
battle.planet.y -= ssy * 0.05;
|
||||||
|
|
||||||
doObjectives();
|
doObjectives();
|
||||||
|
|
||||||
doChallenges();
|
doChallenges();
|
||||||
|
|
||||||
doHud();
|
doHud();
|
||||||
|
@ -160,9 +160,9 @@ static void doBattle(void)
|
||||||
if (battle.status == MS_IN_PROGRESS)
|
if (battle.status == MS_IN_PROGRESS)
|
||||||
{
|
{
|
||||||
doScript();
|
doScript();
|
||||||
|
|
||||||
battle.stats[STAT_TIME]++;
|
battle.stats[STAT_TIME]++;
|
||||||
|
|
||||||
if (battle.stats[STAT_TIME] % FPS == 0)
|
if (battle.stats[STAT_TIME] % FPS == 0)
|
||||||
{
|
{
|
||||||
runScriptFunction("TIME %d", battle.stats[STAT_TIME] / 60);
|
runScriptFunction("TIME %d", battle.stats[STAT_TIME] / 60);
|
||||||
|
@ -367,7 +367,7 @@ static void postBattle(void)
|
||||||
game.stats[i] += battle.stats[i];
|
game.stats[i] += battle.stats[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccuracyStats(game.stats);
|
updateAccuracyStats(game.stats);
|
||||||
|
|
||||||
if (!game.currentMission->challengeData.isChallenge)
|
if (!game.currentMission->challengeData.isChallenge)
|
||||||
|
@ -375,6 +375,11 @@ static void postBattle(void)
|
||||||
if (game.currentMission && !game.currentMission->completed)
|
if (game.currentMission && !game.currentMission->completed)
|
||||||
{
|
{
|
||||||
game.currentMission->completed = (battle.status == MS_COMPLETE || !battle.numObjectivesTotal);
|
game.currentMission->completed = (battle.status == MS_COMPLETE || !battle.numObjectivesTotal);
|
||||||
|
|
||||||
|
if (game.currentMission->completed && game.currentMission->trophyId)
|
||||||
|
{
|
||||||
|
awardTrophy(game.currentMission->trophyId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -334,3 +334,12 @@ enum
|
||||||
STAT_TIME,
|
STAT_TIME,
|
||||||
STAT_MAX
|
STAT_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
TROPHY_BRONZE,
|
||||||
|
TROPHY_SILVER,
|
||||||
|
TROPHY_GOLD,
|
||||||
|
TROPHY_PLATINUM,
|
||||||
|
TROPHY_MAX
|
||||||
|
};
|
||||||
|
|
|
@ -61,6 +61,8 @@ Mission *loadMissionMeta(char *filename)
|
||||||
|
|
||||||
mission->requires = getJSONValue(root, "requires", 0);
|
mission->requires = getJSONValue(root, "requires", 0);
|
||||||
|
|
||||||
|
mission->trophyId = getJSONValueStr(root, "trophyId", NULL);
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "epic"))
|
if (cJSON_GetObjectItem(root, "epic"))
|
||||||
{
|
{
|
||||||
mission->epic = 1;
|
mission->epic = 1;
|
||||||
|
|
|
@ -20,14 +20,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "trophies.h"
|
#include "trophies.h"
|
||||||
|
|
||||||
static int recentlyAwarded;
|
|
||||||
static void loadTrophyData(char *filename);
|
static void loadTrophyData(char *filename);
|
||||||
|
static void resetAlert(void);
|
||||||
|
|
||||||
|
static Trophy *alertTrophy;
|
||||||
|
static SDL_Texture *trophyIcons[TROPHY_MAX];
|
||||||
|
static SDL_Rect alertRect;
|
||||||
|
static float alertDX;
|
||||||
|
static int alertTimer;
|
||||||
|
|
||||||
void initTrophies(void)
|
void initTrophies(void)
|
||||||
{
|
{
|
||||||
recentlyAwarded = 0;
|
|
||||||
|
|
||||||
loadTrophyData("data/trophies/trophies.json");
|
loadTrophyData("data/trophies/trophies.json");
|
||||||
|
|
||||||
|
trophyIcons[TROPHY_BRONZE] = getTexture("gfx/trophies/bronze.png");
|
||||||
|
trophyIcons[TROPHY_SILVER] = getTexture("gfx/trophies/silver.png");
|
||||||
|
trophyIcons[TROPHY_GOLD] = getTexture("gfx/trophies/gold.png");
|
||||||
|
trophyIcons[TROPHY_PLATINUM] = getTexture("gfx/trophies/platinum.png");
|
||||||
|
|
||||||
|
resetAlert();
|
||||||
}
|
}
|
||||||
|
|
||||||
void awardTrophy(char *id)
|
void awardTrophy(char *id)
|
||||||
|
@ -41,29 +52,70 @@ void awardTrophy(char *id)
|
||||||
t->awarded = 1;
|
t->awarded = 1;
|
||||||
t->awardDate = time(NULL);
|
t->awardDate = time(NULL);
|
||||||
t->notify = 1;
|
t->notify = 1;
|
||||||
|
|
||||||
recentlyAwarded++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTrophyAlerts(void)
|
void doTrophies(void)
|
||||||
{
|
{
|
||||||
Trophy *t;
|
Trophy *t;
|
||||||
|
|
||||||
if (recentlyAwarded)
|
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
||||||
{
|
{
|
||||||
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
if (t->notify)
|
||||||
{
|
{
|
||||||
if (t->notify)
|
if (alertTrophy != t)
|
||||||
{
|
{
|
||||||
/* handle notification */
|
alertTrophy = t;
|
||||||
return;
|
playSound(SND_TROPHY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alertRect.x += alertDX;
|
||||||
|
|
||||||
|
if (alertRect.x > -50)
|
||||||
|
{
|
||||||
|
alertDX *= 0.95;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (--alertTimer <= 0)
|
||||||
|
{
|
||||||
|
t->notify = 0;
|
||||||
|
resetAlert();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void resetAlert(void)
|
||||||
|
{
|
||||||
|
alertRect.w = 300;
|
||||||
|
alertRect.h = 100;
|
||||||
|
alertRect.x = -alertRect.w;
|
||||||
|
alertRect.y = 10;
|
||||||
|
|
||||||
|
alertDX = 3;
|
||||||
|
alertTimer = FPS * 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawTrophyAlert(void)
|
||||||
|
{
|
||||||
|
if (alertTrophy)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||||
|
SDL_RenderFillRect(app.renderer, &alertRect);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(app.renderer, 64, 64, 64, SDL_ALPHA_OPAQUE);
|
||||||
|
SDL_RenderDrawRect(app.renderer, &alertRect);
|
||||||
|
|
||||||
|
drawText(alertRect.x + 5, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title);
|
||||||
|
drawText(alertRect.x + 5, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description);
|
||||||
|
|
||||||
|
blit(trophyIcons[alertTrophy->value], alertRect.x + alertRect.w - 64, alertRect.y + 10, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void drawTrophies(void)
|
void drawTrophies(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -102,8 +154,8 @@ static void loadTrophyData(char *filename)
|
||||||
memset(t, 0, sizeof(Trophy));
|
memset(t, 0, sizeof(Trophy));
|
||||||
|
|
||||||
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
|
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
|
||||||
STRNCPY(t->title, cJSON_GetObjectItem(node, "title")->valuestring, MAX_DESCRIPTION_LENGTH);
|
STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->valuestring), MAX_DESCRIPTION_LENGTH);
|
||||||
STRNCPY(t->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
|
STRNCPY(t->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
|
||||||
t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
|
t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
|
||||||
t->hidden = getJSONValue(node, "hidden", 0);
|
t->hidden = getJSONValue(node, "hidden", 0);
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,11 @@ void initLookups(void)
|
||||||
addLookup("STAT_CAPITAL_SHIPS_DESTROYED", STAT_CAPITAL_SHIPS_DESTROYED);
|
addLookup("STAT_CAPITAL_SHIPS_DESTROYED", STAT_CAPITAL_SHIPS_DESTROYED);
|
||||||
addLookup("STAT_CAPITAL_SHIPS_LOST", STAT_CAPITAL_SHIPS_LOST);
|
addLookup("STAT_CAPITAL_SHIPS_LOST", STAT_CAPITAL_SHIPS_LOST);
|
||||||
addLookup("STAT_TIME", STAT_TIME);
|
addLookup("STAT_TIME", STAT_TIME);
|
||||||
|
|
||||||
|
addLookup("TROPHY_BRONZE", TROPHY_BRONZE);
|
||||||
|
addLookup("TROPHY_SILVER", TROPHY_SILVER);
|
||||||
|
addLookup("TROPHY_GOLD", TROPHY_GOLD);
|
||||||
|
addLookup("TROPHY_PLATINUM", TROPHY_PLATINUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addLookup(char *name, long value)
|
static void addLookup(char *name, long value)
|
||||||
|
|
Loading…
Reference in New Issue