Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shot limit on HUD #170

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/bzflag/HUDRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ void HUDRenderer::renderShots(const Player* target)
if (!target)
return;

FontManager &fm = FontManager::instance();

const ShotSlot::Vec& slotList = target->getShotSlots();

Expand Down Expand Up @@ -2069,6 +2070,41 @@ void HUDRenderer::renderShots(const Player* target)
}
}
glDisable(GL_BLEND);

// draw the number of shots left
const int& flagLimit = target->getFlagLimit();
if (flagLimit >= 0)
{
if (!flagLimitShown)
{
flagLimitStartTime = TimeKeeper::getTick();
flagLimitShown = true;
flagLimitInfo = true;
}

hudColor4f(1.0f, 1.0f, 1.0f, 0.5f); // 50%-solid white

std::string flagLimitStr = std::to_string(flagLimit);
float y = (float)indicatorTop + factors.size() * (indicatorHeight + indicatorSpace);
fm.drawString((float)indicatorLeft, y, 0, minorFontFace, minorFontSize, flagLimitStr);

if (TimeKeeper::getTick() - flagLimitStartTime >= 5.0)
flagLimitInfo = false;

if (flagLimitInfo)
{
float alpha = float(TimeKeeper::getTick() - flagLimitStartTime);
if (alpha <= 1.0f)
hudColor4f(1.0f, 1.0f, 1.0f, alpha / 2.0f); // white
else if (alpha >= 4.0f)
hudColor4f(1.0f, 1.0f, 1.0f, -(alpha - 5.0f) / 2.0f); // white
fm.drawString((float)indicatorLeft + fm.getStrLength(minorFontFace, minorFontSize, flagLimitStr + " "), y, 0, minorFontFace, minorFontSize, (flagLimit == 1) ? "shot left" : "shots left");
}
}
else
{
flagLimitShown = false;
}
}


Expand Down
4 changes: 4 additions & 0 deletions src/bzflag/HUDRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ class HUDRenderer
unsigned int lastTimeChange;
int triangleCount;
int radarTriangleCount;

bool flagLimitShown = false;
bool flagLimitInfo = false;
TimeKeeper flagLimitStartTime;
};


Expand Down
15 changes: 0 additions & 15 deletions src/bzflag/LocalPlayer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1290,21 +1290,6 @@ bool LocalPlayer::fireShot()
{
// the server is going to drop it for us now....
}
else
{
if (flagLimit % 5 == 0 || flagLimit <= 3)
{
std::string limitMessage;
if (flagLimit > 1)
limitMessage = TextUtils::format("%d shots left", flagLimit);
else if (flagLimit == 1)
limitMessage = "1 shot left";
else
limitMessage = "The flag is empty and can not be fired anymore";

addMessage(nullptr, limitMessage, 0);
}
}
}

if (gettingSound)
Expand Down
4 changes: 4 additions & 0 deletions src/bzflag/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class Player
{
return ShotSlots;
}
const int& getFlagLimit() const
{
return flagLimit;
}

float getAngularVelocity() const;
int getPhysicsDriver() const;
Expand Down
14 changes: 0 additions & 14 deletions src/bzflag/playing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2693,20 +2693,6 @@ static void handleServerMessage(bool human, uint16_t code,
// grabbed flag
playLocalSound(myTank->getFlag()->endurance != FlagEndurance::Sticky ? SFX_GRAB_FLAG : SFX_GRAB_BAD);
updateFlag(myTank->getFlag());

if (flagLimit >= 0)
{
std::string limitMessage;

if (flagLimit > 1)
limitMessage = TextUtils::format("This flag is limited to %d shots", flagLimit);
else if (flagLimit == 1)
limitMessage = "This flag is limited to 1 shot";
else
limitMessage = "This flag is empty and can not be shot";

addMessage(nullptr, limitMessage, 0);
}
}
else if (isViewTank(tank))
{
Expand Down