-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bff9f01
commit bc3a839
Showing
7 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters