Skip to content

Commit

Permalink
Merge pull request #40 from Faunsce/development
Browse files Browse the repository at this point in the history
[BugFix] Fix issues with text not rendering
  • Loading branch information
anastasia-v-r authored Nov 18, 2019
2 parents 14e232f + ff3eda9 commit 396f784
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 64 deletions.
62 changes: 62 additions & 0 deletions src/Entities/Boss.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "Boss.hpp"
#include "Bullet.hpp"

void Boss::move(const sf::Time& elapsedTime) {
// Keep in place
if (boss.getPosition().x > ((GlobalData::TRUE_MODE.width / 3) * 2))
goRight = false;
else if (boss.getPosition().x < ((GlobalData::TRUE_MODE.width / 3)))
goRight = true;
// Move
if (goRight)
boss.move(speed * elapsedTime.asSeconds(), 0);
else
boss.move(-speed * elapsedTime.asSeconds(), 0);
}

void Boss::fire(const sf::Time& elapsedTime, std::vector<Bullet>& bullets) {
if (timeBank.asSeconds() > fireRate) {
float speed = 500.0f;
float size = 15.0f;
float angVel;
float dmg = 1;
if (goRight)
angVel = -40.0f;
else
angVel = 40.0f;
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(boss.getRadius(), boss.getRadius()), 135.0f, speed, angVel, dmg, size, bul1));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(boss.getRadius() / 2, boss.getRadius()), 157.5f, speed, angVel, dmg, size, bul2));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(0.0f, boss.getRadius()), 180.0f, speed, angVel, dmg, size, bul1));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(-boss.getRadius() / 2, boss.getRadius()), 202.5f, speed, angVel, dmg, size, bul2));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(-boss.getRadius(), boss.getRadius()), 225.0f, speed, angVel, dmg, size, bul1));
timeBank -= (sf::seconds)(fireRate);
}
else {
timeBank += elapsedTime;
}
}

bool Boss::detectCollide(std::vector<Bullet>& bullets) {
auto [x2, y2] = boss.getPosition();
float bRad = boss.getRadius();
for (auto& bullet : bullets) {
auto [x1, y1] = bullet.getPos();
if (bullet.getVal() && std::sqrt(std::pow(y2 - y1, 2) + std::pow(x2 - x1, 2)) < (bRad + bullet.getRadius())) {
bullet.invalidate();
hp -= bullet.getDmg();
if (hp < (iHp * 0.75f) && hp >= (iHp * 0.50f)) {
boss.setFillColor(sf::Color::Yellow);
}
else if (hp < (iHp * 0.50f) && hp >= (iHp * 0.25f)) {
boss.setFillColor(sf::Color(255, 98, 0));
}
else if (hp < (iHp * 0.25f) && hp >= 1.0f) {
boss.setFillColor(sf::Color::Red);
}
else if (hp < 1) {
return true;
}
}
}
return false;
}
68 changes: 6 additions & 62 deletions src/Entities/boss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,14 @@ class Boss : public sf::Drawable
boss.setOrigin(boss.getRadius(), boss.getRadius());
}
// Processors
void move(const sf::Time& elapsedTime) {
// Keep in place
if (boss.getPosition().x > ((GlobalData::TRUE_MODE.width / 3) * 2))
goRight = false;
else if (boss.getPosition().x < ((GlobalData::TRUE_MODE.width / 3)))
goRight = true;
// Move
if (goRight)
boss.move(speed * elapsedTime.asSeconds(), 0);
else
boss.move(-speed * elapsedTime.asSeconds(), 0);
}
void fire(const sf::Time& elapsedTime, std::vector<Bullet>& bullets) {
if (timeBank.asSeconds() > fireRate) {
float speed = 500.0f;
float size = 15.0f;
float angVel;
float dmg = 1;
if (goRight)
angVel = -40.0f;
else
angVel = 40.0f;
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(boss.getRadius(), boss.getRadius()), 135.0f, speed, angVel, dmg, size, bul1));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(boss.getRadius() / 2, boss.getRadius()), 157.5f, speed, angVel, dmg, size, bul2));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(0.0f, boss.getRadius()), 180.0f, speed, angVel, dmg, size, bul1));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(-boss.getRadius() / 2, boss.getRadius()), 202.5f, speed, angVel, dmg, size, bul2));
bullets.push_back(Bullet(boss.getPosition() + sf::Vector2f(-boss.getRadius(), boss.getRadius()), 225.0f, speed, angVel, dmg, size, bul1));
timeBank -= (sf::seconds)(fireRate);
} else {
timeBank += elapsedTime;
}
}
bool detectCollide(std::vector<Bullet>& bullets) {
auto [x2, y2] = boss.getPosition();
float bRad = boss.getRadius();
for (auto& bullet : bullets) {
auto [x1, y1] = bullet.getPos();
if ( bullet.getVal() && std::sqrt(std::pow(y2 - y1, 2) + std::pow(x2 - x1, 2)) < (bRad + bullet.getRadius()) ) {
bullet.invalidate();
hp -= bullet.getDmg();
if (hp < (iHp * 0.75f) && hp >= (iHp * 0.50f)) {
boss.setFillColor(sf::Color::Yellow);
} else if (hp < (iHp * 0.50f) && hp >= (iHp * 0.25f)) {
boss.setFillColor(sf::Color(255, 98, 0));
} else if (hp < (iHp * 0.25f) && hp >= 1.0f) {
boss.setFillColor(sf::Color::Red);
} else if (hp < 1) {
return true;
}
}
}
return false;
}
void move(const sf::Time& /* elapsedTime */);
void fire(const sf::Time& /* elapsedTime */, std::vector<Bullet>& /* bullets */);
bool detectCollide(std::vector<Bullet>& /* bullets */);
// Getters
int getHp() const {
return hp;
}
sf::Vector2f getPos() const {
return boss.getPosition();
}
inline int getHp() const { return hp; }
inline sf::Vector2f getPos() const { return boss.getPosition(); }
// Draw
virtual void draw(sf::RenderTarget& window, sf::RenderStates states) const {
window.draw(boss, states);
}
inline virtual void draw(sf::RenderTarget& window, sf::RenderStates states) const { window.draw(boss, states); }
private:
sf::CircleShape boss;
int iHp;
Expand Down
2 changes: 1 addition & 1 deletion src/States/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GameState::GameState(std::queue<std::pair<StateChange, StateID>>& pendingChanges
, timeModifier{ 1.0f } {
if (!font.loadFromFile("assets/Global/font/OpenSans-Regular.ttf"))
std::cout << "Font Failed to load" << std::endl;
sf::Text hp("HP : ", font, 30);
hp = sf::Text("HP : ", font, 30);
}

void GameState::input(sf::Event evnt, bool& close, sf::RenderWindow& window, sf::View& view) {
Expand Down
2 changes: 1 addition & 1 deletion src/States/IntroState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ IntroState::IntroState(std::queue<std::pair<StateChange, StateID>>& pendingChang
button.setFillColor(sf::Color::Yellow);
if (!font.loadFromFile("assets/Global/font/OpenSans-Regular.ttf"))
std::cout << "Font Failed to load" << std::endl;
sf::Text text("Intro!", font, 30);
text = sf::Text("Intro!", font, 30);
std::cout << (std::string)text.getString() << std::endl;
text.setPosition(sf::Vector2f(GlobalData::TRUE_WIDTH / 2, GlobalData::TRUE_HEIGHT / 2));
}
Expand Down

0 comments on commit 396f784

Please sign in to comment.