Skip to content

Commit

Permalink
Add times to end screens
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Sep 7, 2021
1 parent 22bd0a2 commit d4dbf69
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 161 deletions.
7 changes: 7 additions & 0 deletions src/animated_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ void AnimatedCounterDraw(const AnimatedCounter *a, const struct vec2i pos)
sprintf(buf, "%d", a->current);
FontStr(buf, pos2);
}
void AnimatedCounterTimeDraw(const AnimatedCounter *a, const struct vec2i pos)
{
const struct vec2i pos2 = FontStr(a->prefix, pos);
char buf[256];
sprintf(buf, "%d:%02d", a->current / 60, a->current % 60);
FontStr(buf, pos2);
}
41 changes: 21 additions & 20 deletions src/animated_counter.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/*
Copyright (c) 2018, 2021 Cong Xu
All rights reserved.
Copyright (c) 2018, 2021 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

Expand All @@ -40,3 +40,4 @@ void AnimatedCounterTerminate(AnimatedCounter *a);
// Return whether animation has finished
bool AnimatedCounterUpdate(AnimatedCounter *a, const int ticks);
void AnimatedCounterDraw(const AnimatedCounter *a, const struct vec2i pos);
void AnimatedCounterTimeDraw(const AnimatedCounter *a, const struct vec2i pos);
13 changes: 13 additions & 0 deletions src/briefing_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ typedef struct
const PlayerData *Pd;
AnimatedCounter Score;
AnimatedCounter Total;
AnimatedCounter Time;
AnimatedCounter TimeTotal;
AnimatedCounter HealthResurrection;
AnimatedCounter ButcherNinjaFriendly;
} PlayerSummaryDrawData;
Expand Down Expand Up @@ -477,6 +479,7 @@ static void MissionSummaryOnEnter(GameLoopData *data)

CA_FOREACH(PlayerData, p, gPlayerDatas)
ApplyBonuses(p, bonus);
p->Totals.TimeTicks += mData->m->time;
CA_FOREACH_END()
}

Expand Down Expand Up @@ -524,6 +527,10 @@ static void MissionSummaryOnEnter(GameLoopData *data)
mData->pDatas[idx].Pd = pd;
mData->pDatas[idx].Score = AnimatedCounterNew("Score: ", pd->Stats.Score);
mData->pDatas[idx].Total = AnimatedCounterNew("Total: ", pd->Totals.Score);
mData->pDatas[idx].Time =
AnimatedCounterNew("Time: ", mData->m->time / FPS_FRAMELIMIT);
mData->pDatas[idx].TimeTotal = AnimatedCounterNew(
"Total Time: ", pd->Totals.TimeTicks / FPS_FRAMELIMIT);
if (pd->survived)
{
const int healthBonus = GetHealthBonus(pd);
Expand Down Expand Up @@ -575,6 +582,8 @@ static GameLoopResult MissionSummaryUpdate(GameLoopData *data, LoopRunner *l)
{
done = AnimatedCounterUpdate(&mData->pDatas[i].Score, 1) && done;
done = AnimatedCounterUpdate(&mData->pDatas[i].Total, 1) && done;
done = AnimatedCounterUpdate(&mData->pDatas[i].Time, 1) && done;
done = AnimatedCounterUpdate(&mData->pDatas[i].TimeTotal, 1) && done;
done = AnimatedCounterUpdate(
&mData->pDatas[i].HealthResurrection, 1) &&
done;
Expand Down Expand Up @@ -853,6 +862,10 @@ static void DrawPlayerSummary(
textPos.y += FontH();
AnimatedCounterDraw(&data->Total, textPos);
textPos.y += FontH();
AnimatedCounterTimeDraw(&data->Time, textPos);
textPos.y += FontH();
AnimatedCounterTimeDraw(&data->TimeTotal, textPos);
textPos.y += FontH();
sprintf(
s, "Missions: %d", data->Pd->missions + (data->Pd->survived ? 1 : 0));
FontStr(s, textPos);
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/hud/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static void DrawDeathmatchScores(HUD *hud)
int maxKills = 0;
CA_FOREACH(const PlayerData, p, gPlayerDatas)
maxLives = MAX(maxLives, p->Lives);
maxKills = MAX(maxKills, p->Stats.Kills);
maxKills = MAX(maxKills, (int)p->Stats.Kills);
CA_FOREACH_END()
CA_FOREACH(const PlayerData, p, gPlayerDatas)
// Player name; red if dead
Expand All @@ -275,7 +275,7 @@ static void DrawDeathmatchScores(HUD *hud)
FontStrOpt(buf, svec2i(0, y), opts);

// kills; cyan if most kills
opts.Mask = p->Stats.Kills == maxKills ? colorCyan : colorWhite;
opts.Mask = (int)p->Stats.Kills == maxKills ? colorCyan : colorWhite;
opts.Pad.x = killsColumn;
sprintf(buf, "%d", p->Stats.Kills);
FontStrOpt(buf, svec2i(0, y), opts);
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/net_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2017, 2019-2020 Cong Xu
Copyright (c) 2014-2017, 2019-2021 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -40,7 +40,7 @@

#define NET_LISTEN_PORT 34219

#define NET_PROTOCOL_VERSION 10
#define NET_PROTOCOL_VERSION 11

// Messages

Expand Down
Loading

0 comments on commit d4dbf69

Please sign in to comment.