Skip to content

Commit

Permalink
Added a kill feed event for being crushed by a wall
Browse files Browse the repository at this point in the history
Image loading uses the asset manager so it should work for all OSes now
  • Loading branch information
Ymihere03 committed Apr 9, 2024
1 parent e71adeb commit b229d57
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 67 deletions.
Binary file modified rsrc/aftershock/img/atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rsrc/img/atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ std::string AssetManager::GetOggPath(MaybePackage package, int16_t id)
return GetFullPath(package, relativePath.str());
}

std::string AssetManager::GetImagePath(MaybePackage package, std::string fileName) {
std::stringstream relativePath;
relativePath << "img" << PATHSEP << fileName;
return GetFullPath(package, relativePath.str());
}

void AssetManager::LoadEnumeratedObjectTypes()
{
std::stringstream path;
Expand Down
8 changes: 8 additions & 0 deletions src/assets/AssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ class AssetManager {
*/
static std::optional<std::shared_ptr<HullConfigRecord>> GetHull(int16_t id);

/**
* Get the image with the provided fileName, if available.
*
* @param fileName The name of the file.
* @return the full file path of the image
*/
static std::string GetImagePath(MaybePackage package, std::string fileName);

/**
* Run important operations at application start.
*/
Expand Down
6 changes: 0 additions & 6 deletions src/game/CAbstractPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,6 @@ void CAbstractPlayer::SetFreeCamState(Boolean state) {

itsGame->ToggleFreeCam(freeView);
itsFreeCam->ToggleState(freeView);

if (freeView) {
SDL_Log("Free cam toggled on!");
}
else
SDL_Log("Free cam toggled off!");
}

Boolean CAbstractPlayer::IsFreeCamAttached() {
Expand Down
3 changes: 3 additions & 0 deletions src/game/CAvaraApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ void CAvaraAppImpl::ParamLine(short index, MsgAlignment align, StringPtr param1,
case kmAKilledBPlayer:
buffa << a << " killed " << b << ".";
break;
case kmKilledByCollision:
buffa << a << " was killed by the world.";
break;
case kmUnavailableNote:
buffa << a << " is busy.";
category = MsgCategory::Error;
Expand Down
91 changes: 35 additions & 56 deletions src/game/CHUD.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CHUD.h"
#include "AssetManager.h"
#include "AbstractRenderer.h"
#include "CAbstractPlayer.h"
#include "CAvaraGame.h"
Expand Down Expand Up @@ -27,7 +28,8 @@ bool sortByScore(std::pair<PlayerScoreRecord, int> i, std::pair<PlayerScoreRecor
}

void CHUD::LoadImages(NVGcontext *ctx) {
images = nvgCreateImage(ctx, "rsrc/img/atlas.png", 0);
std::string imgPath = AssetManager::GetImagePath(NoPackage, "atlas.png");
images = nvgCreateImage(ctx, imgPath.c_str(), 0);
}

void CHUD::DrawScore(std::vector<CPlayerManager*>& thePlayers, int chudHeight, NVGcontext *ctx) {
Expand Down Expand Up @@ -735,10 +737,15 @@ void CHUD::DrawKillFeed(NVGcontext *ctx, CNetManager *net, int bufferWidth, floa
// Event player names
std::string killerName = " " + event.player;
std::string killedName = " " + event.playerTarget;
float teamColorRGB[3], teamTargetColorRGB[3];
float teamColorRGB[3], teamTargetColorRGB[3], iconLeftMargin = 23.0f;

// Get how wide the event rect needs to be
std::string eventText = killerName + " " + killedName;
if (event.weaponUsed == ksiObjectCollision) {
eventText = " " + killedName;
killerName = "";
iconLeftMargin = 11.0f;
}
nvgBeginPath(ctx);
nvgTextAlign(ctx, NVG_ALIGN_RIGHT);
nvgFontSize(ctx, fontSize);
Expand All @@ -749,7 +756,7 @@ void CHUD::DrawKillFeed(NVGcontext *ctx, CNetManager *net, int bufferWidth, floa
// Get Measurements based on text size for the total size of the event box
killEventSize[0] = killEventBounds[2] - killEventBounds[0] + 20.0f;
killEventSize[1] = killEventBounds[3] - killEventBounds[1] + 10.0f;
killEventIconXPosition = killEventKillerNameBounds[2] - killEventKillerNameBounds[0] + 23.0f; // Position the icon in the empty space
killEventIconXPosition = killEventKillerNameBounds[2] - killEventKillerNameBounds[0] + iconLeftMargin; // Position the icon in the empty space
eventPositionY = killEventPosition[1] + ((float)eventCount * (killEventSize[1] + 10.0f));

// Background box
Expand Down Expand Up @@ -781,10 +788,10 @@ void CHUD::DrawKillFeed(NVGcontext *ctx, CNetManager *net, int bufferWidth, floa
iHeight = 51.0;
break;
case ksiObjectCollision:
ix = 0.0;
ix = 173.0;
iy = 0.0;
iWidth = 0.0;
iHeight = 0.0;
iWidth = 58.0;
iHeight = 51.0;
break;
default:
ix = 0.0;
Expand All @@ -799,19 +806,25 @@ void CHUD::DrawKillFeed(NVGcontext *ctx, CNetManager *net, int bufferWidth, floa
longTeamTargetColor.ExportGLFloats(teamTargetColorRGB, 3);
float teamTargetColorPosition = killEventPosition[0] - killEventSize[0] + killEventIconXPosition + imgWidth + 15.0f;

nvgBeginPath(ctx);
nvgRect(ctx, killEventPosition[0] - killEventSize[0] + 10.0f, eventPositionY + 10.0f, 9.0, killEventSize[1] - 20.0f);
nvgFillColor(ctx, nvgRGBAf(teamColorRGB[0], teamColorRGB[1], teamColorRGB[2], 1.0));
nvgFill(ctx);
// Team color of killer
if (event.weaponUsed != ksiObjectCollision) {
nvgBeginPath(ctx);
nvgRect(ctx, killEventPosition[0] - killEventSize[0] + 10.0f, eventPositionY + 10.0f, 9.0, killEventSize[1] - 20.0f);
nvgFillColor(ctx, nvgRGBAf(teamColorRGB[0], teamColorRGB[1], teamColorRGB[2], 1.0));
nvgFill(ctx);
}

// Team color of killed
nvgBeginPath(ctx);
nvgRect(ctx, teamTargetColorPosition, eventPositionY + 10.0f, 9.0, killEventSize[1] - 20.0f);
nvgFillColor(ctx, nvgRGBAf(teamTargetColorRGB[0], teamTargetColorRGB[1], teamTargetColorRGB[2], 1.0));
nvgFill(ctx);

// Draw icon for death reason
DrawImage(ctx, images, 1.0, ix, iy, iWidth, iHeight,
killEventPosition[0] - killEventSize[0] + killEventIconXPosition, eventPositionY + 5.0f, imgWidth, killEventSize[1] - 10.0f);

// Draw display text for event
nvgBeginPath(ctx);
nvgTextAlign(ctx, NVG_ALIGN_LEFT);
nvgFontSize(ctx, fontSize);
Expand All @@ -822,57 +835,21 @@ void CHUD::DrawKillFeed(NVGcontext *ctx, CNetManager *net, int bufferWidth, floa
break;
}

case ksiScoreGoal: {
case ksiScoreGoal:
case ksiGrabBall: {
// Event player names
std::string playerName = " " + event.player;
float teamColorRGB[3];

std::string eventText;
if (event.scoreType == ksiScoreGoal) {
eventText = playerName + " scored!";
} else if (event.scoreType == ksiGrabBall) {
eventText = playerName + " has the ball!";
} else {
eventText = "";
}
// Get how wide the event rect needs to be
std::string eventText = playerName + " scored!";
nvgBeginPath(ctx);
nvgTextAlign(ctx, NVG_ALIGN_RIGHT);
nvgFontSize(ctx, fontSize);
nvgFillColor(ctx, nvgRGBA(255, 255, 255, 255));
nvgTextBounds(ctx, 0, 0, eventText.c_str(), NULL, killEventBounds); // Size of the entire rendered text

// Get Measurements based on text size for the total size of the event box
killEventSize[0] = killEventBounds[2] - killEventBounds[0] + 20.0f;
killEventSize[1] = killEventBounds[3] - killEventBounds[1] + 10.0f;
eventPositionY = killEventPosition[1] + ((float)eventCount * (killEventSize[1] + 10.0f));

// Background box
DrawShadowBox(ctx, killEventPosition[0] - killEventSize[0], eventPositionY, killEventSize[0], killEventSize[1]);
nvgBeginPath(ctx);
nvgRoundedRect(ctx, killEventPosition[0] - killEventSize[0], eventPositionY, killEventSize[0], killEventSize[1], 4.0);
nvgFillColor(ctx, BACKGROUND_COLOR);
nvgFill(ctx);

ARGBColor longTeamColor = *ColorManager::getTeamColor(event.team);
longTeamColor.ExportGLFloats(teamColorRGB, 3);

nvgBeginPath(ctx);
nvgRect(ctx, killEventPosition[0] - killEventSize[0] + 10.0f, eventPositionY + 10.0f, 9.0, killEventSize[1] - 20.0f);
nvgFillColor(ctx, nvgRGBAf(teamColorRGB[0], teamColorRGB[1], teamColorRGB[2], 1.0));
nvgFill(ctx);

nvgBeginPath(ctx);
nvgTextAlign(ctx, NVG_ALIGN_LEFT);
nvgFontSize(ctx, fontSize);
nvgFillColor(ctx, nvgRGBA(255, 255, 255, 255));
nvgText(ctx, killEventPosition[0] - killEventSize[0] + 10.0f, eventPositionY + 25.0f, eventText.c_str(), NULL);

eventCount++;
break;
}

case ksiGrabBall:
{
// Event player names
std::string playerName = " " + event.player;
float teamColorRGB[3];

// Get how wide the event rect needs to be
std::string eventText = playerName + " has the ball!";
nvgBeginPath(ctx);
nvgTextAlign(ctx, NVG_ALIGN_RIGHT);
nvgFontSize(ctx, fontSize);
Expand All @@ -894,11 +871,13 @@ void CHUD::DrawKillFeed(NVGcontext *ctx, CNetManager *net, int bufferWidth, floa
ARGBColor longTeamColor = *ColorManager::getTeamColor(event.team);
longTeamColor.ExportGLFloats(teamColorRGB, 3);

// Draw player's team color
nvgBeginPath(ctx);
nvgRect(ctx, killEventPosition[0] - killEventSize[0] + 10.0f, eventPositionY + 10.0f, 9.0, killEventSize[1] - 20.0f);
nvgFillColor(ctx, nvgRGBAf(teamColorRGB[0], teamColorRGB[1], teamColorRGB[2], 1.0));
nvgFill(ctx);

// Draw event text
nvgBeginPath(ctx);
nvgTextAlign(ctx, NVG_ALIGN_LEFT);
nvgFontSize(ctx, fontSize);
Expand Down
28 changes: 23 additions & 5 deletions src/game/CScoreKeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,27 +222,45 @@ void CScoreKeeper::Score(ScoreInterfaceReasons reason,
event.teamTarget = hitTeam;
event.damage = points;

SDL_Log("CAvaraGame::Obj Collision: player:%lu, team:%lu, hit:%lu, hitTeam:%lu, weapon: %d, reason:%lu\n", iface.playerID, iface.playerTeam, hitPlayer, iface.scoreTeam, itsGame->killReason, iface.scoreReason);

if (player >= 0 && player <= kMaxAvaraPlayers) {
iface.playerName = itsGame->itsNet->playerTable[player]->PlayerName();
if (reason == ksiKillBonus && hitPlayer >= 0 && hitPlayer <= kMaxAvaraPlayers) {
Str255 destStr;
Str255 destStr;

if (reason == ksiKillBonus && hitPlayer >= 0 && hitPlayer <= kMaxAvaraPlayers) {
// Player killed a player
localScores.player[hitPlayer].lives--;
if (hitTeam != team) {
localScores.player[player].kills++;
}
if (!itsGame->itsApp->Get(kHUDShowKillFeed)) {
iface.consoleLine = destStr;
iface.consoleJustify = static_cast<long>(MsgAlignment::Center);
itsGame->itsApp->ComposeParamLine(
destStr, kmAKilledBPlayer, iface.playerName, itsGame->itsNet->playerTable[hitPlayer]->PlayerName());
}
SDL_Log("CAvaraGame::Kill Event: player:%lu, team:%lu, hit:%lu, hitTeam:%lu, weapon: %d, reason:%lu\n", iface.playerID, iface.playerTeam, iface.scoreID, iface.scoreTeam, event.weaponUsed, iface.scoreReason);

event.scoreType = ksiKillBonus;
event.weaponUsed = itsGame->killReason;
itsGame->AddScoreNotify(event);
SDL_Log("CAvaraGame::Kill Event: player:%lu, team:%lu, hit:%lu, hitTeam:%lu, weapon: %d, reason:%lu\n", iface.playerID, iface.playerTeam, iface.scoreID, iface.scoreTeam, event.weaponUsed, iface.scoreReason);

iface.consoleLine = destStr;
iface.consoleJustify = static_cast<long>(MsgAlignment::Center);
} else if (reason == ksiKillBonus && itsGame->killReason == ksiObjectCollision) {
// Something other than a player did the killing blow
event.playerTarget = event.player;
event.teamTarget = event.team;

if (!itsGame->itsApp->Get(kHUDShowKillFeed)) {
iface.consoleLine = destStr;
iface.consoleJustify = static_cast<long>(MsgAlignment::Center);
itsGame->itsApp->ComposeParamLine(
destStr, kmKilledByCollision, itsGame->itsNet->playerTable[hitPlayer]->PlayerName(), NULL);
}

event.scoreType = ksiKillBonus;
event.weaponUsed = itsGame->killReason;
itsGame->AddScoreNotify(event);
}
} else {
iface.playerName = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/game/InfoMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum {
kmNewLatency2,
kmWaitingForPlayer,
kmAKilledBPlayer,
kmKilledByCollision,
kmFragmentAlert,
kmUnavailableNote,
kmStartFailure,
Expand Down

0 comments on commit b229d57

Please sign in to comment.