Skip to content

Commit

Permalink
Add "Need for Speed" effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedSnark committed Mar 12, 2024
1 parent bff9f01 commit bc3a839
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions GSChaos/CChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void CChaos::FeatureInit()
RegisterChaosFeature<CFeatureGravityField>();
RegisterChaosFeature<CFeatureIceSkating>();
RegisterChaosFeature<CFeatureInvertVelocity>();
RegisterChaosFeature<CFeatureNeedForSpeed>();

RegisterChaosFeature<CFeatureCombineEffects>(); // must be last!!!

Expand Down
87 changes: 87 additions & 0 deletions GSChaos/CFeatureNeedForSpeed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "includes.h"

void CFeatureNeedForSpeed::Init()
{
CChaosFeature::Init();
}

void CFeatureNeedForSpeed::ActivateFeature()
{
CChaosFeature::ActivateFeature();
m_bActivated = true;

m_flTimeToFail = gChaos.GetGlobalTime() + NFS_INIT_FAIL_TIME;
}

void CFeatureNeedForSpeed::DeactivateFeature()
{
CChaosFeature::DeactivateFeature();
m_bActivated = false;
}

void CFeatureNeedForSpeed::OnFrame(double time)
{
if (!m_bActivated)
return;

Vector velocity = (*sv_player)->v.velocity;
if (velocity.Length2D() < NFS_REQUIRED_SPEED)
{
if (gChaos.GetGlobalTime() > m_flTimeToFail)
{
Explode();
m_bActivated = false;
}
}
else
m_flTimeToFail = gChaos.GetGlobalTime() + NFS_FAIL_TIME;
}

void CFeatureNeedForSpeed::Draw()
{
if (!m_bActivated)
return;

char buffer[64];
snprintf(buffer, sizeof(buffer), "%.01f | STAY ABOVE 500 UPS!", (*sv_player)->v.velocity.Length2D());

ImGui::PushFont(gChaos.m_fontTrebuchet);

ImVec2 pos = ImVec2((ImGui::GetIO().DisplaySize.x * 0.5f) - (ImGui::CalcTextSize(buffer).x * 0.5f), ImGui::GetIO().DisplaySize.y * 0.1f);
ImGui::GetForegroundDrawList()->AddText(ImVec2(pos.x + 2, pos.y + 2), ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)), buffer);
ImGui::GetForegroundDrawList()->AddText(pos, ImGui::GetColorU32(ImVec4(1.0f, 0.627f, 0.0f, 1.0f)), buffer);

ImGui::PopFont();
}

void CFeatureNeedForSpeed::Explode() // TODO: make this thing public for every class (move to Utils.cpp)
{
if (!m_bActivated)
return;

// create explosion
edict_t* pent = CREATE_NAMED_ENTITY(MAKE_STRING("rpg_rocket"));
if (!pent)
{
// heart attack :DDD
(*sv_player)->v.health = -20;
return;
}

gEntityInterface->pfnSpawn(pent);
gEntityInterface->pfnThink(pent);

pent->v.origin = (*sv_player)->v.origin;
pent->v.angles = (*sv_player)->v.angles;
pent->v.dmg = 1000;
pent->v.dmgtime = 1.0f;
pent->v.nextthink = gpGlobals->time + 0.1f;

gEntityInterface->pfnTouch((*sv_player), pent);
gEntityInterface->pfnTouch(pent, (*sv_player));
}

const char* CFeatureNeedForSpeed::GetFeatureName()
{
return "Need for Speed";
}
47 changes: 47 additions & 0 deletions GSChaos/CFeatureNeedForSpeed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright - ScriptedSnark, 2024.
* CFeatureNeedForSpeed.h
*
* Project (GSChaos) header file
* Authors: ScriptedSnark.
* Do not delete this comment block. Respect others' work!
*/

#ifdef CFEATURENEEDFORSPEED_H_RECURSE_GUARD
#error Recursive header files inclusion detected in CFeatureNeedForSpeed.h
#else //CFEATURENEEDFORSPEED_H_RECURSE_GUARD

#define CFEATURENEEDFORSPEED_H_RECURSE_GUARD

#ifndef CFEATURENEEDFORSPEED_H_GUARD
#define CFEATURENEEDFORSPEED_H_GUARD
#pragma once

#ifdef __cplusplus

#define NFS_REQUIRED_SPEED 500.0f
#define NFS_INIT_FAIL_TIME 1.5
#define NFS_FAIL_TIME 0.35

class CFeatureNeedForSpeed : public CChaosFeature
{
void Init() override;
void ActivateFeature() override;
void DeactivateFeature() override;
void OnFrame(double time) override;
void Draw() override;
void Explode();
const char* GetFeatureName() override;
private:
bool m_bActivated;
double m_flTimeToFail;
};

#else //!__cplusplus
#error C++ compiler required to compile CFeatureNeedForSpeed.h
#endif //__cplusplus

#endif //CFEATURENEEDFORSPEED_H_GUARD

#undef CFEATURENEEDFORSPEED_H_RECURSE_GUARD
#endif //CFEATURENEEDFORSPEED_H_RECURSE_GUARD
2 changes: 2 additions & 0 deletions GSChaos/GSChaos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<ClCompile Include="CFeatureInvertVelocity.cpp" />
<ClCompile Include="CFeatureJeepy.cpp" />
<ClCompile Include="CFeatureLobotomy.cpp" />
<ClCompile Include="CFeatureNeedForSpeed.cpp" />
<ClCompile Include="CFeatureNegativeStepsize.cpp" />
<ClCompile Include="CFeatureNewGame.cpp" />
<ClCompile Include="CFeatureInvisibleEntities.cpp" />
Expand Down Expand Up @@ -214,6 +215,7 @@
<ClInclude Include="CFeatureInvertVelocity.h" />
<ClInclude Include="CFeatureJeepy.h" />
<ClInclude Include="CFeatureLobotomy.h" />
<ClInclude Include="CFeatureNeedForSpeed.h" />
<ClInclude Include="CFeatureNegativeStepsize.h" />
<ClInclude Include="CFeatureNewGame.h" />
<ClInclude Include="CFeatureInvisibleEntities.h" />
Expand Down
6 changes: 6 additions & 0 deletions GSChaos/GSChaos.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
<ClCompile Include="CFeatureInvertVelocity.cpp">
<Filter>Effects</Filter>
</ClCompile>
<ClCompile Include="CFeatureNeedForSpeed.cpp">
<Filter>Effects</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="includes.h" />
Expand Down Expand Up @@ -404,6 +407,9 @@
<ClInclude Include="CFeatureInvertVelocity.h">
<Filter>Effects</Filter>
</ClInclude>
<ClInclude Include="CFeatureNeedForSpeed.h">
<Filter>Effects</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Hooking">
Expand Down
1 change: 1 addition & 0 deletions GSChaos/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ extern bool g_bEncrypted;
#include "CFeatureGravityField.h"
#include "CFeatureIceSkating.h"
#include "CFeatureInvertVelocity.h"
#include "CFeatureNeedForSpeed.h"

#include "CFeatureCombineEffects.h"
//========================
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Additional info:
> Hyper Gravity Field
> Ice Skating
> Invert Velocity
> Need for Speed (500 ups curse)
> Combine Effects ( 3 in 1 )
```

Expand Down

0 comments on commit bc3a839

Please sign in to comment.