blobwarsAttrition/src/game/stats.c

171 lines
5.3 KiB
C
Raw Normal View History

2018-02-19 09:28:42 +01:00
/*
Copyright (C) 2018 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stats.h"
static int page;
static float maxPages;
static char *statDescription[STAT_MAX];
static Texture *atlasTexture;
static Atlas *left;
static Atlas *right;
void initStats(void)
{
page = 0;
maxPages = STAT_TIME_PLAYED;
maxPages /= STATS_PER_PAGE;
maxPages = ceil(maxPages);
2018-03-02 09:09:04 +01:00
statDescription[STAT_MISSIONS_COMPLETE] = _("Missions complete");
2018-02-19 09:28:42 +01:00
statDescription[STAT_KEYS_FOUND] = _("Keys found");
statDescription[STAT_CELLS_FOUND] = _("Power cells found");
statDescription[STAT_HEARTS_FOUND] = _("Hearts found");
statDescription[STAT_TARGETS_DEFEATED] = _("Targets defeated");
statDescription[STAT_MIAS_RESCUED] = _("MIAs rescued");
statDescription[STAT_DEATHS] = _("Deaths");
statDescription[STAT_SHOTS_FIRED] = _("Shots fired");
statDescription[STAT_SHOTS_HIT] = _("Shots hit");
2018-03-02 09:09:04 +01:00
statDescription[STAT_SHOT_ACCURACY] = _("Accuracy");
statDescription[STAT_EYE_DROID_EXPLOSION_KILLS] = _("EyeDroid explosion kills");
statDescription[STAT_GRENADE_COMBO] = _("Best grenade combo");
2018-02-19 09:28:42 +01:00
statDescription[STAT_FLY_TIME] = _("Time spent flying");
statDescription[STAT_SWIM_TIME] = _("Time spent swimming");
statDescription[STAT_CHERRIES_PICKED_UP] = _("Cherries picked up");
statDescription[STAT_BATTERIES_PICKED_UP] = _("Batteries picked up");
statDescription[STAT_WEAPONS_PICKED_UP] = _("Weapons picked up");
statDescription[STAT_ENEMIES_KILLED] = _("Enemies killed");
statDescription[STAT_MISSIONS_PLAYED] = _("Missions played");
2018-03-02 09:09:04 +01:00
statDescription[STAT_PERCENT_COMPLETE] = _("Percent complete");
2018-02-19 09:28:42 +01:00
statDescription[STAT_TIME_PLAYED] = _("Time played");
atlasTexture = getTexture("gfx/atlas/atlas.png");
left = getImageFromAtlas("gfx/ui/left.png");
right = getImageFromAtlas("gfx/ui/right.png");
}
2018-03-02 09:09:04 +01:00
void initStatsDisplay(void)
{
int gameDone, gameTotal;
gameDone = game.stats[STAT_MISSIONS_COMPLETE] + game.stats[STAT_MIAS_RESCUED] + game.stats[STAT_TARGETS_DEFEATED] + game.stats[STAT_KEYS_FOUND] + game.stats[STAT_HEARTS_FOUND] + game.stats[STAT_CELLS_FOUND];
gameTotal = game.totalMissions + game.totalMIAs + game.totalTargets + game.totalKeys + game.totalHearts + game.totalCells;
2018-03-04 18:02:53 +01:00
game.stats[STAT_SHOT_ACCURACY] = getPercent(game.stats[STAT_SHOTS_HIT], game.stats[STAT_SHOTS_FIRED]);
2018-03-02 09:09:04 +01:00
game.stats[STAT_PERCENT_COMPLETE] = getPercent(gameDone, gameTotal);
}
2018-02-19 09:28:42 +01:00
void doStats(void)
{
if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT])
{
2018-02-25 13:23:00 +01:00
playSound(SND_MENU_NAV, 0);
2018-02-19 09:28:42 +01:00
page = limit(page - 1, 0, maxPages - 1);
app.keyboard[SDL_SCANCODE_LEFT] = 0;
clearControl(CONTROL_LEFT);
}
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
{
2018-02-25 13:23:00 +01:00
playSound(SND_MENU_NAV, 0);
2018-02-19 09:28:42 +01:00
page = limit(page + 1, 0, maxPages - 1);
2018-02-19 23:32:14 +01:00
app.keyboard[SDL_SCANCODE_RIGHT] = 0;
2018-02-19 09:28:42 +01:00
clearControl(CONTROL_RIGHT);
}
doWidgets();
}
void drawStats(void)
{
int i, y, startIndex;
SDL_Rect r;
2018-12-22 22:53:19 +01:00
drawRect(0, 0, app.config.winWidth, app.config.winHeight, 0, 0, 0, 128);
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
2018-02-19 09:28:42 +01:00
r.w = 500;
2018-03-02 09:29:36 +01:00
r.h = 500;
2018-12-22 22:53:19 +01:00
r.x = (UI_WIDTH / 2) - r.w / 2;
r.y = (UI_HEIGHT / 2) - r.h / 2;
2018-02-19 09:28:42 +01:00
2018-02-19 09:32:15 +01:00
drawRect(r.x, r.y, r.w, r.h, 0, 0, 0, 192);
drawOutlineRect(r.x, r.y, r.w, r.h, 200, 200, 200, 255);
2018-02-19 09:28:42 +01:00
2018-12-22 22:53:19 +01:00
drawText(UI_WIDTH / 2, r.y + 5, 28, TA_CENTER, colors.white, "Stats");
2018-02-19 09:28:42 +01:00
2018-12-22 22:53:19 +01:00
drawText(UI_WIDTH / 2, r.y + 45, 16, TA_CENTER, colors.lightGrey, "Page %d / %d", page + 1, (int)maxPages);
2018-02-19 09:28:42 +01:00
if (page > 0)
{
2018-12-22 22:53:19 +01:00
blitRect(atlasTexture->texture, UI_WIDTH / 2 - 100, r.y + 25, &left->rect, 1);
2018-02-19 09:28:42 +01:00
}
if (page < maxPages - 1)
{
2018-12-22 22:53:19 +01:00
blitRect(atlasTexture->texture, UI_WIDTH / 2 + 100, r.y + 25, &right->rect, 1);
2018-02-19 09:28:42 +01:00
}
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
2018-03-02 09:29:36 +01:00
SDL_RenderDrawLine(app.renderer, r.x, r.y + 80, r.x + r.w, r.y + 80);
2018-02-19 09:28:42 +01:00
2018-03-02 09:29:36 +01:00
y = 210;
2018-02-19 09:28:42 +01:00
startIndex = (page * STATS_PER_PAGE);
for (i = startIndex ; i < startIndex + STATS_PER_PAGE ; i++)
{
if (i < STAT_TIME_PLAYED)
{
drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]);
switch (i)
{
2018-03-02 09:09:04 +01:00
case STAT_SHOT_ACCURACY:
case STAT_PERCENT_COMPLETE:
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d%%", game.stats[i]);
break;
2018-02-19 09:28:42 +01:00
case STAT_SWIM_TIME:
case STAT_FLY_TIME:
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%s", timeToString(game.stats[i] / FPS, 0));
break;
default:
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]);
break;
}
y += 40;
}
}
2018-03-02 09:29:36 +01:00
drawText(r.x + 20, r.y + r.h - 95, 18, TA_LEFT, colors.white, statDescription[STAT_TIME_PLAYED]);
drawText(r.x + r.w - 20, r.y + r.h - 95, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME_PLAYED], 1));
2018-02-19 09:28:42 +01:00
drawWidgets();
2018-12-22 22:53:19 +01:00
SDL_SetRenderTarget(app.renderer, app.backBuffer);
2018-02-19 09:28:42 +01:00
}