Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 981dc3467e | |||
| 42af029a26 | |||
| 2e5dfc609a | |||
| ba6d2b758d | |||
| 12dd1d21de | |||
| e5dba6604b | |||
| 52d3cb3ebf | |||
| 68b0175b3d | |||
| 0e0a486c01 | |||
| 2cfbe0f785 |
@@ -23,6 +23,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
|
void renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
|
||||||
|
std::string parseColors(std::string text, std::map<int, glm::vec4>& colorChanges, glm::vec4 originalColor);
|
||||||
|
|
||||||
Font* font;
|
Font* font;
|
||||||
GLuint VAO, VBO;
|
GLuint VAO, VBO;
|
||||||
|
|||||||
@@ -40,5 +40,17 @@ private:
|
|||||||
};
|
};
|
||||||
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||||
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
||||||
|
//class
|
||||||
|
enum class PlayerClass {
|
||||||
|
Assault,
|
||||||
|
Defender,
|
||||||
|
Sniper,
|
||||||
|
None
|
||||||
|
};
|
||||||
|
//helper methods
|
||||||
|
bool DoesPlayerHaveMaxAmmo(EntityWrapper &player);
|
||||||
|
PlayerClass DetermineClass(EntityWrapper &player);
|
||||||
|
void SetPlayerAmmo(EntityWrapper &player, int ammoGain);
|
||||||
|
int GetPlayerMaxAmmo(EntityWrapper &player);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,23 +7,23 @@ TextPass::TextPass()
|
|||||||
|
|
||||||
void TextPass::Initialize()
|
void TextPass::Initialize()
|
||||||
{
|
{
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &VAO);
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
m_TextProgram = ResourceManager::Load<ShaderProgram>("#TextProgram");
|
m_TextProgram = ResourceManager::Load<ShaderProgram>("#TextProgram");
|
||||||
m_TextProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Text.vert.glsl")));
|
m_TextProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Text.vert.glsl")));
|
||||||
m_TextProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Text.frag.glsl")));
|
m_TextProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Text.frag.glsl")));
|
||||||
m_TextProgram->Compile();
|
m_TextProgram->Compile();
|
||||||
m_TextProgram->BindFragDataLocation(0, "sceneColor");
|
m_TextProgram->BindFragDataLocation(0, "sceneColor");
|
||||||
m_TextProgram->BindFragDataLocation(1, "bloomColor");
|
m_TextProgram->BindFragDataLocation(1, "bloomColor");
|
||||||
m_TextProgram->Link();
|
m_TextProgram->Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextPass::Update()
|
void TextPass::Update()
|
||||||
@@ -33,81 +33,180 @@ void TextPass::Update()
|
|||||||
|
|
||||||
void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
|
void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
|
||||||
{
|
{
|
||||||
GLERROR("Derp1");
|
GLERROR("Derp1");
|
||||||
TextPassState* state = new TextPassState(frameBuffer.GetHandle());
|
TextPassState* state = new TextPassState(frameBuffer.GetHandle());
|
||||||
for (auto &job : scene.Jobs.Text) {
|
for (auto &job : scene.Jobs.Text) {
|
||||||
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
||||||
if (textJob) {
|
if (textJob) {
|
||||||
|
|
||||||
renderText(textJob->Content, textJob->Resource, textJob->Alignment, textJob->Color, textJob->Matrix, scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix());
|
renderText(textJob->Content, textJob->Resource, textJob->Alignment, textJob->Color, textJob->Matrix, scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GLERROR("Derp2");
|
GLERROR("Derp2");
|
||||||
delete state;
|
delete state;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TextPass::parseColors(std::string text, std::map<int, glm::vec4>& colorChanges, glm::vec4 originalColor)
|
||||||
|
{
|
||||||
|
std::string parsedString = text;
|
||||||
|
glm::vec4 newColor = originalColor;
|
||||||
|
bool colorChange = false;
|
||||||
|
|
||||||
|
for (std::string::const_iterator c = parsedString.begin(); c != parsedString.end(); c++) {
|
||||||
|
if (*c == char(92)) { // Backlash
|
||||||
|
if ((c + 1) != parsedString.end()) {
|
||||||
|
if (*(c + 1) == char('C')) { // C for Color
|
||||||
|
if ((c + 7) != parsedString.end()) {
|
||||||
|
bool hasCorrectFormat = true;
|
||||||
|
|
||||||
|
for (std::string::const_iterator colorC = c + 2; colorC != c + 8; colorC++) {
|
||||||
|
if (*colorC < '0' || *colorC > 'F') {
|
||||||
|
hasCorrectFormat = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasCorrectFormat == true) {
|
||||||
|
colorChange = true;
|
||||||
|
|
||||||
|
std::array<int, 3> hexToInt = {
|
||||||
|
std::stoi(std::string(c + 2, c + 4), 0, 16),
|
||||||
|
std::stoi(std::string(c + 4, c + 6), 0, 16),
|
||||||
|
std::stoi(std::string(c + 6, c + 8), 0, 16)
|
||||||
|
};
|
||||||
|
|
||||||
|
newColor = glm::vec4(
|
||||||
|
float(hexToInt[0]) / 255.f,
|
||||||
|
float(hexToInt[1]) / 255.f,
|
||||||
|
float(hexToInt[2]) / 255.f,
|
||||||
|
newColor.a);
|
||||||
|
|
||||||
|
parsedString.erase(c, (c + 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(c + 1) == char('A')) { // A for Alpha
|
||||||
|
if ((c + 3) != parsedString.end()) {
|
||||||
|
bool hasCorrectFormat = true;
|
||||||
|
|
||||||
|
for (std::string::const_iterator colorC = c + 2; colorC != c + 4; colorC++) {
|
||||||
|
if (*colorC < '0' || *colorC > 'F') {
|
||||||
|
hasCorrectFormat = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasCorrectFormat == true) {
|
||||||
|
colorChange = true;
|
||||||
|
|
||||||
|
int hexToInt = std::stoi(std::string(c + 2, c + 4), 0, 16);
|
||||||
|
|
||||||
|
newColor = glm::vec4(
|
||||||
|
newColor.r,
|
||||||
|
newColor.g,
|
||||||
|
newColor.b,
|
||||||
|
float(hexToInt) / 255.f);
|
||||||
|
|
||||||
|
parsedString.erase(c, (c + 4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*(c + 1) >= '1' && *(c + 1) <= '9') || *(c + 1) == 'B' || *(c + 1) == 'E' || *(c + 1) == 'F') { // Icons
|
||||||
|
if (*(c + 1) >= '1' && *(c + 1) <= '9') {
|
||||||
|
parsedString.replace(c, (c + 2), 1, (*(c + 1) - 48));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parsedString.replace(c, (c + 2), 1, (*(c + 1) - 55));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colorChange) {
|
||||||
|
colorChanges[c - parsedString.begin()] = newColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return parsedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
|
||||||
{
|
{
|
||||||
GLfloat penX = 0;
|
GLfloat penX = 0;
|
||||||
GLfloat penY = 0;
|
GLfloat penY = 0;
|
||||||
GLfloat scale = 1.0/font->FontSize;
|
GLfloat scale = 1.0 / font->FontSize;
|
||||||
|
|
||||||
GLfloat stringWidth = 0.f;
|
GLfloat stringWidth = 0.f;
|
||||||
|
|
||||||
for (std::string::const_iterator c = text.begin(); c != text.end(); c++) {
|
std::map<int, glm::vec4> colorChanges;
|
||||||
Font::Character ch = font->m_Characters[*c];
|
std::string parsedText = parseColors(text, colorChanges, color);
|
||||||
stringWidth += (ch.Advance >> 6) * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(alignment == TextJob::AlignmentEnum::Center) {
|
for (std::string::const_iterator c = parsedText.begin(); c != parsedText.end(); c++) {
|
||||||
penX = -stringWidth/2.f;
|
Font::Character ch = font->m_Characters[*c];
|
||||||
} else if (alignment == TextJob::AlignmentEnum::Right) {
|
stringWidth += (ch.Advance >> 6) * scale;
|
||||||
penX = -stringWidth;
|
}
|
||||||
} else {
|
|
||||||
penX = 0;
|
if (alignment == TextJob::AlignmentEnum::Center) {
|
||||||
}
|
penX = -stringWidth / 2.f;
|
||||||
|
}
|
||||||
|
else if (alignment == TextJob::AlignmentEnum::Right) {
|
||||||
|
penX = -stringWidth;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
penX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_TextProgram->Bind();
|
m_TextProgram->Bind();
|
||||||
glUniform4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "textColor"), 1, glm::value_ptr(color));
|
glUniform4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "textColor"), 1, glm::value_ptr(color));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
|
||||||
for (std::string::const_iterator c = text.begin(); c != text.end(); c++) {
|
for (std::string::const_iterator c = parsedText.begin(); c != parsedText.end(); c++) {
|
||||||
Font::Character ch = font->m_Characters[*c];
|
|
||||||
|
|
||||||
GLfloat xpos = penX + ch.Bearing.x * scale;
|
auto it = colorChanges.find(c - parsedText.begin());
|
||||||
GLfloat ypos = penY - (ch.Size.y - ch.Bearing.y) * scale;
|
if (it != colorChanges.end()) {
|
||||||
|
glUniform4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "textColor"), 1, glm::value_ptr(it->second));
|
||||||
|
}
|
||||||
|
|
||||||
GLfloat w = ch.Size.x * scale;
|
Font::Character ch = font->m_Characters[*c];
|
||||||
GLfloat h = ch.Size.y * scale;
|
|
||||||
|
|
||||||
GLfloat vertices[6][4] = {
|
GLfloat xpos = penX + ch.Bearing.x * scale;
|
||||||
{ xpos, ypos + h, 0.0, 0.0 },
|
GLfloat ypos = penY - (ch.Size.y - ch.Bearing.y) * scale;
|
||||||
{ xpos, ypos, 0.0, 1.0 },
|
|
||||||
{ xpos + w, ypos, 1.0, 1.0 },
|
|
||||||
|
|
||||||
{ xpos, ypos + h, 0.0, 0.0 },
|
GLfloat w = ch.Size.x * scale;
|
||||||
{ xpos + w, ypos, 1.0, 1.0 },
|
GLfloat h = ch.Size.y * scale;
|
||||||
{ xpos + w, ypos + h, 1.0, 0.0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, ch.TextureID);
|
GLfloat vertices[6][4] = {
|
||||||
|
{ xpos, ypos + h, 0.0, 0.0 },
|
||||||
|
{ xpos, ypos, 0.0, 1.0 },
|
||||||
|
{ xpos + w, ypos, 1.0, 1.0 },
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
{ xpos, ypos + h, 0.0, 0.0 },
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
{ xpos + w, ypos, 1.0, 1.0 },
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
{ xpos + w, ypos + h, 1.0, 0.0 }
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
};
|
||||||
penX += (ch.Advance >> 6) * scale; // Bitshift by 6 to get value in pixels (2^6 = 64)
|
|
||||||
}
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
GLERROR("Text rendering Error");
|
glBindTexture(GL_TEXTURE_2D, ch.TextureID);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
penX += (ch.Advance >> 6) * scale; // Bitshift by 6 to get value in pixels (2^6 = 64)
|
||||||
|
}
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
GLERROR("Text rendering Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
|
|
||||||
//erase the current element (somePickup)
|
//erase the current element (somePickup)
|
||||||
it = m_ETriggerTouchVector.erase(it);
|
it = m_ETriggerTouchVector.erase(it);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +47,7 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
m_PickupAtMaximum.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
|
if (!DoesPlayerHaveMaxAmmo(it->player)) {
|
||||||
DoPickup(it->player, it->trigger);
|
DoPickup(it->player, it->trigger);
|
||||||
m_PickupAtMaximum.erase(it);
|
m_PickupAtMaximum.erase(it);
|
||||||
break;
|
break;
|
||||||
@@ -56,6 +55,58 @@ void AmmoPickupSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool AmmoPickupSystem::DoesPlayerHaveMaxAmmo(EntityWrapper &player) {
|
||||||
|
PlayerClass playerClass = DetermineClass(player);
|
||||||
|
if (playerClass == PlayerClass::Defender) {
|
||||||
|
return !((int)player["DefenderWeapon"]["Ammo"] < (int)player["DefenderWeapon"]["MaxAmmo"]);
|
||||||
|
} else if (playerClass == PlayerClass::Sniper) {
|
||||||
|
return !((int)player["SniperWeapon"]["Ammo"] < (int)player["SniperWeapon"]["MaxAmmo"]);
|
||||||
|
} else if (playerClass == PlayerClass::Assault) {
|
||||||
|
return !((int)player["AssaultWeapon"]["Ammo"] < (int)player["AssaultWeapon"]["MaxAmmo"]);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void AmmoPickupSystem::SetPlayerAmmo(EntityWrapper &player, int ammoGain) {
|
||||||
|
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
|
||||||
|
|
||||||
|
PlayerClass playerClass = DetermineClass(player);
|
||||||
|
if (playerClass == PlayerClass::Defender) {
|
||||||
|
(int&)player["DefenderWeapon"]["Ammo"] = std::min((int)player["DefenderWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||||
|
} else if (playerClass == PlayerClass::Sniper) {
|
||||||
|
(int&)player["SniperWeapon"]["Ammo"] = std::min((int)player["SniperWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||||
|
} else if (playerClass == PlayerClass::Assault) {
|
||||||
|
(int&)player["AssaultWeapon"]["Ammo"] = std::min((int)player["AssaultWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
|
||||||
|
} else {
|
||||||
|
//unknown class - ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int AmmoPickupSystem::GetPlayerMaxAmmo(EntityWrapper &player) {
|
||||||
|
PlayerClass playerClass = DetermineClass(player);
|
||||||
|
if (playerClass == PlayerClass::Defender) {
|
||||||
|
return (int)player["DefenderWeapon"]["MaxAmmo"];
|
||||||
|
} else if (playerClass == PlayerClass::Sniper) {
|
||||||
|
return (int)player["SniperWeapon"]["MaxAmmo"];
|
||||||
|
} else if (playerClass == PlayerClass::Assault) {
|
||||||
|
return (int)player["AssaultWeapon"]["MaxAmmo"];
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AmmoPickupSystem::PlayerClass AmmoPickupSystem::DetermineClass(EntityWrapper &player)
|
||||||
|
{
|
||||||
|
//determine the class based on what component the inflictor-player has
|
||||||
|
if (m_World->HasComponent(player.ID, "DashAbility")) {
|
||||||
|
return PlayerClass::Assault;
|
||||||
|
}
|
||||||
|
if (m_World->HasComponent(player.ID, "ShieldAbility")) {
|
||||||
|
return PlayerClass::Defender;
|
||||||
|
}
|
||||||
|
if (m_World->HasComponent(player.ID, "SprintAbility")) {
|
||||||
|
return PlayerClass::Sniper;
|
||||||
|
}
|
||||||
|
return PlayerClass::None;
|
||||||
|
}
|
||||||
|
|
||||||
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||||
{
|
{
|
||||||
@@ -63,7 +114,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//TODO: add other weapontypes
|
//TODO: add other weapontypes
|
||||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
if (DetermineClass(e.Entity) == PlayerClass::None) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!e.Trigger.HasComponent("AmmoPickup")) {
|
if (!e.Trigger.HasComponent("AmmoPickup")) {
|
||||||
@@ -71,7 +122,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//if at maxammo, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger
|
//if at maxammo, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger
|
||||||
if ((int)e.Entity["AssaultWeapon"]["Ammo"] >= (int)e.Entity["AssaultWeapon"]["MaxAmmo"]) {
|
if (DoesPlayerHaveMaxAmmo(e.Entity)) {
|
||||||
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -85,19 +136,16 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//TODO: add other weapontypes
|
//TODO: add other weapontypes
|
||||||
if (!e.Player.HasComponent("AssaultWeapon")) {
|
if (DetermineClass(e.Player) == PlayerClass::None) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int maxWeaponAmmo = (int)e.Player["AssaultWeapon"]["MaxAmmo"];
|
|
||||||
int& currentAmmo = (int)e.Player["AssaultWeapon"]["Ammo"];
|
|
||||||
//cant pick up ammopacks if you are already at MaxAmmo
|
//cant pick up ammopacks if you are already at MaxAmmo
|
||||||
if (currentAmmo >= maxWeaponAmmo) {
|
if (DoesPlayerHaveMaxAmmo(e.Player)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SetPlayerAmmo(e.Player, e.AmmoGain);
|
||||||
|
|
||||||
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
|
return true;
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||||
@@ -119,7 +167,7 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
|||||||
if (!trigger.Valid()) {
|
if (!trigger.Valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int maxWeaponAmmo = (int)player["AssaultWeapon"]["MaxAmmo"];
|
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
|
||||||
int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
|
int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
|
||||||
|
|
||||||
Events::AmmoPickup ePlayerAmmoPickup;
|
Events::AmmoPickup ePlayerAmmoPickup;
|
||||||
|
|||||||
Reference in New Issue
Block a user