Skip to content

Commit

Permalink
Error names
Browse files Browse the repository at this point in the history
  • Loading branch information
Matqyou committed Dec 14, 2024
1 parent 930c28c commit 98b1147
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 78 deletions.
69 changes: 25 additions & 44 deletions src/game/entities/characters/character/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ Character::Character(GameWorld* world,
m_HealthRed = { 255, 0, 0, 255 };
m_HealthBlack = { 0, 0, 0, 255 };

m_ErrorText = new TextSurface(m_World->GameWindow()->Assetz(),
m_World->GameWindow()->Assetz()->TextHandler()->GetMainFont(),
"m_ErrorText", { 255, 255, 255 });
// TODO: make vector of weapons instead of array
}

Expand Down Expand Up @@ -608,11 +611,10 @@ void Character::DrawHealthbar() {
Drawing* Render = m_World->GameWindow()->Render();

// Render health bar
// if (m_HealthComponent.IsFullHealth())
// return;
if (m_HealthComponent.IsFullHealth())
return;

m_HealthBar.SetColor(m_HealthbarColor.r, m_HealthbarColor.g, m_HealthbarColor.b, m_HealthbarColor.a);
std::cout << FStringColors("Color(%i, %i, %i, %i)", m_HealthbarColor.r, m_HealthbarColor.g, m_HealthbarColor.b, m_HealthbarColor.a) << std::endl;
Texture* HealthPlate = m_ErrorStatuses.ConfusingHealth.IsActive() ? m_HealthBar.GetTexture() : m_HealthBar.UpdateTexture();

int HealthBarW = HealthPlate->GetWidth() - 20; // Make the health bar slightly smaller
Expand Down Expand Up @@ -757,7 +759,6 @@ void Character::DrawNameplate() {
Render->RenderTextureCamera(CoordinateTexture->SDLTexture(), nullptr, CoordinateRect);
}

// TODO when switching guns ammo text renders again, to prevent this save each ammo count texture on the gun
void Character::DrawAmmoCounter() {
Drawing* Render = m_World->GameWindow()->Render();

Expand All @@ -777,41 +778,25 @@ void Character::DrawAmmoCounter() {
}

void Character::DrawErrorName() {
if (!m_ErrorStatuses.AnyActive(2.0))
return;

Drawing* Render = m_World->GameWindow()->Render();
// char msg[64];
// // Changes the "msg" to whatever Error has been picked up( not else if's cuz then it wouldnt update on new pickup
// // aka, this is so it overrides the last msg too)
// if (ReverseMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Reverse Movement\"");
// else if (ConfusingHPMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Confusing HP\"");
// else if (InvincibleMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Invincible\"");
// else if (SpikyMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Spiky\"");
// else if (HealersMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Healers paradise\"");
// else if (RangedMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Ranged\"");
// else if (IsSlowMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Slow down\"");
// else if (RecoilMSG)
// std::snprintf(msg, sizeof(msg), "ERROR activated \"Dangerous recoil\"");
//
// m_ErrorText = new TextSurface(m_World->GameWindow()->Assetz(),
// m_World->GameWindow()->Assetz()->TextHandler()->GetMainFont(),
// msg, { 255, 255, 255 });
// m_ErrorText->SetText(msg);
// Texture* ErrorTexture = m_ErrorText->RequestUpdate();
//
// int Text_h = ErrorTexture->GetWidth();
// int Text_w = ErrorTexture->GetHeight();
// double Zoom = Render->GetZoom();
// SDL_Rect ErrorRect = { int(m_Core.Pos.x - 100 - (Text_w / Zoom)),
// int(m_Core.Pos.y - 50),
// int(Text_h / Zoom),
// int(Text_w / Zoom) };
// Render->RenderTextureCamera(ErrorTexture->SDLTexture(), nullptr, ErrorRect);
auto error_message = FString("Error %s activated", m_ErrorStatuses.GetLastActivated()->Name());

if (m_ErrorText->GetText() != error_message) {
m_ErrorText->SetText(error_message);
m_ErrorText->FlagForUpdate();
}

Texture* ErrorTexture = m_ErrorText->RequestUpdate();
int Text_w = ErrorTexture->GetWidth();
int Text_h = ErrorTexture->GetHeight();
SDL_Rect ErrorRect = { int(m_Core.Pos.x - (double)Text_w / 2.0),
int(m_Core.Pos.y - 50.0),
int(Text_w),
int(Text_h) };
Render->RenderTextureCamera(ErrorTexture->SDLTexture(), nullptr, ErrorRect);
}

void Character::Event(const SDL_Event& currentEvent) {
Expand Down Expand Up @@ -912,18 +897,14 @@ void Character::Draw() {
m_NameplateColor = m_HandColor;

DrawHook();
DrawHands(); // originally here
DrawHands();
DrawCharacter();
// DrawHands(); //
DrawHealthbar();
DrawNameplate();
DrawErrorIcons();

if (m_CurrentWeapon)
DrawAmmoCounter();

// Only draws the Error names, if the timers havent been going down for any more than 2 seconds
// 1000(Most Error activity time)-120(2 seconds)
if (m_ErrorStatuses.AnyActive(2.0))
DrawErrorName();
DrawErrorName();
}
19 changes: 13 additions & 6 deletions src/game/error/ErrorStatuses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ void ErrorFrames::CreateFramesUI(std::vector<ErrorStatusEffect*>& group) {
const int frame_size = 64;
const int iterate_size = frame_size + spacing;

const int container_width = spacing + iterate_size * num_elements;
const int container_height = spacing + iterate_size;


int index = -1;
for (auto effect : group) {
Expand Down Expand Up @@ -71,12 +70,20 @@ ErrorStatuses::ErrorStatuses(Interface* interface, Character* parent, bool gui)
m_Parent = parent;
m_Gui = gui;

m_LastActivatedEffect = nullptr;
m_Drawing = interface->GameWindow()->Render();

if (gui) m_Frames.CreateFramesUI(m_Effects);
else m_Frames.CreateFrames(m_Effects);
}

bool ErrorStatuses::AnyActive() {
for (auto effect : m_Effects)
if (effect->IsActive())
return true;
return false;
}

bool ErrorStatuses::AnyActive(double from_seconds_ago) {
GameReference* game_window = m_Interface->GameWindow();

Expand Down Expand Up @@ -104,11 +111,11 @@ void ErrorStatuses::Tick() {
}

void ErrorStatuses::Draw() {
if (!m_Gui) Draw1();
else Draw2();
if (!m_Gui) DrawIngame();
else DrawAsGUI();
}

void ErrorStatuses::Draw1() {
void ErrorStatuses::DrawIngame() {
if (m_Parent == nullptr)
return;

Expand Down Expand Up @@ -154,7 +161,7 @@ void ErrorStatuses::Draw1() {
}
}

void ErrorStatuses::Draw2() {
void ErrorStatuses::DrawAsGUI() {
if (m_Parent == nullptr)
return;

Expand Down
10 changes: 8 additions & 2 deletions src/game/error/ErrorStatuses.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ErrorStatuses : public InterfaceElement {
Drawing* m_Drawing;
bool m_Gui; // temp

ErrorStatusEffect* m_LastActivatedEffect;
std::vector<ErrorStatusEffect*> m_Effects;
ErrorFrames m_Frames;

Expand All @@ -45,8 +46,8 @@ class ErrorStatuses : public InterfaceElement {

static LoadedTexture sTextureFrame;

void Draw1(); // temp
void Draw2(); // temp
void DrawIngame(); // temp
void DrawAsGUI(); // temp

public:
ErrorBulletFrenzy BulletFrenzy;
Expand All @@ -64,11 +65,16 @@ class ErrorStatuses : public InterfaceElement {
ErrorStatuses(Interface* interface, Character* parent, bool gui);

// Getting
[[nodiscard]] ErrorStatusEffect* GetLastActivated() { return m_LastActivatedEffect; }
[[nodiscard]] std::vector<ErrorStatusEffect*>& Group() { return m_Effects; }

// Generating
bool AnyActive();
bool AnyActive(double from_seconds_ago);

// Setting
void SetLastActivated(ErrorStatusEffect* effect) { m_LastActivatedEffect = effect; }

// Ticking
void Tick();
void Draw() override;
Expand Down
7 changes: 5 additions & 2 deletions src/game/error/base/ErrorStatusEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include "ErrorStatusEffect.h"
#include "../ErrorStatuses.h"

ErrorStatusEffect::ErrorStatusEffect(ErrorType type,
ErrorStatusEffect::ErrorStatusEffect(ErrorStatuses* parent,
ErrorType type,
const char* name,
Texture* texture,
ErrorStatuses* parent,
unsigned long long effect_duration) {
m_Parent = parent;
m_Type = type;
m_Name = name;
m_Texture = texture;
m_Effectee = nullptr;
m_EffectDuration = effect_duration;
Expand All @@ -22,6 +24,7 @@ ErrorStatusEffect::ErrorStatusEffect(ErrorType type,
}

void ErrorStatusEffect::Activate() {
m_Parent->SetLastActivated(this);
if (m_EffectDuration == 0)
return;

Expand Down
4 changes: 3 additions & 1 deletion src/game/error/base/ErrorStatusEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ErrorStatusEffect {
private:
ErrorStatuses* m_Parent;
ErrorType m_Type;
const char* m_Name;
Texture* m_Texture;
Entity* m_Effectee;
unsigned long long m_EffectDuration;
Expand All @@ -19,10 +20,11 @@ class ErrorStatusEffect {
bool m_Active;

public:
ErrorStatusEffect(ErrorType type, Texture* texture, ErrorStatuses* parent, unsigned long long effect_duration);
ErrorStatusEffect(ErrorStatuses* parent, ErrorType type, const char* name, Texture* texture, unsigned long long effect_duration);

// Getting
[[nodiscard]] ErrorType GetType() const { return m_Type; }
[[nodiscard]] const char* Name() const { return m_Name; }
[[nodiscard]] Texture* GetTexture() const { return m_Texture; }
[[nodiscard]] Entity* GetEffectee() const { return m_Effectee; }
[[nodiscard]] unsigned long long GetActivatedTimestamp() const { return m_ActivatedTimestamp; }
Expand Down
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorBulletFrenzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorBulletFrenzy::sTextureBulletFrenzy("icons.bullet_frenzy");

ErrorBulletFrenzy::ErrorBulletFrenzy(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::BULLET_FRENZY,
: ErrorStatusEffect(parent,
ErrorType::BULLET_FRENZY,
"Bullet frenzy",
sTextureBulletFrenzy.GetTexture(),
parent,
3000) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorCantHear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorCantHear::sTextureCantHear("icons.cant_hear");

ErrorCantHear::ErrorCantHear(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::I_CANT_HEAR,
: ErrorStatusEffect(parent,
ErrorType::I_CANT_HEAR,
"I Can't Hear",
sTextureCantHear.GetTexture(),
parent,
3000) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorConfusingHealth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorConfusingHealth::sTextureConfusingHealth("icons.confusing_health");

ErrorConfusingHealth::ErrorConfusingHealth(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::CONFUSING_HP,
: ErrorStatusEffect(parent,
ErrorType::CONFUSING_HP,
"Confusing Health",
sTextureConfusingHealth.GetTexture(),
parent,
1500) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorDangerousRecoil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorDangerousRecoil::sTextureDangerousRecoil("icons.dangerous_recoil");

ErrorDangerousRecoil::ErrorDangerousRecoil(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::DANGEROUS_RECOIL,
: ErrorStatusEffect(parent,
ErrorType::DANGEROUS_RECOIL,
"Dangerous Recoil",
sTextureDangerousRecoil.GetTexture(),
parent,
3000) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorDisoriented.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorDisoriented::sTextureDisoriented("icons.disoriented");

ErrorDisoriented::ErrorDisoriented(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::DISORIANTED,
: ErrorStatusEffect(parent,
ErrorType::DISORIANTED,
"Disoriented",
sTextureDisoriented.GetTexture(),
parent,
1500) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorHealersParadise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorHealersParadise::sTextureHealersParadise("icons.healers_paradise");

ErrorHealersParadise::ErrorHealersParadise(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::HEALERS_PARADISE,
: ErrorStatusEffect(parent,
ErrorType::HEALERS_PARADISE,
"Healers Paradise",
sTextureHealersParadise.GetTexture(),
parent,
1500) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorInvincible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorInvincible::sTextureInvincible("icons.invincible");

ErrorInvincible::ErrorInvincible(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::INVINCIBLE,
: ErrorStatusEffect(parent,
ErrorType::INVINCIBLE,
"Invincible",
sTextureInvincible.GetTexture(),
parent,
1500) {

}
Expand Down
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorRangedFists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorRangedFists::sTextureRangedFists("icons.ranged_fists");

ErrorRangedFists::ErrorRangedFists(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::RANGED,
: ErrorStatusEffect(parent,
ErrorType::RANGED,
"Ranged Fists",
sTextureRangedFists.GetTexture(),
parent,
3000) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorSlowdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorSlowdown::sTextureSlowdown("icons.slowdown");

ErrorSlowdown::ErrorSlowdown(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::SLOW_DOWN,
: ErrorStatusEffect(parent,
ErrorType::SLOW_DOWN,
"Slowdown",
sTextureSlowdown.GetTexture(),
parent,
1500) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorSpiky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorSpiky::sTextureSpiky("icons.spiky");

ErrorSpiky::ErrorSpiky(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::SPIKY,
: ErrorStatusEffect(parent,
ErrorType::SPIKY,
"Spiky",
sTextureSpiky.GetTexture(),
parent,
3000) {

}
5 changes: 3 additions & 2 deletions src/game/error/effect/ErrorTeleport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
LoadedTexture ErrorTeleport::sTextureTeleport("icons.teleport");

ErrorTeleport::ErrorTeleport(ErrorStatuses* parent)
: ErrorStatusEffect(ErrorType::TELEPORT,
: ErrorStatusEffect(parent,
ErrorType::TELEPORT,
"Teleportation",
sTextureTeleport.GetTexture(),
parent,
3000) {

}
Loading

0 comments on commit 98b1147

Please sign in to comment.