|
|
|
@ -53,17 +53,48 @@ void TripleBallBonus::activate(Arkanoid& game)
|
|
|
|
|
int numBalls = game.m_balls.size();
|
|
|
|
|
std::list<Ball>::iterator it = game.m_balls.begin();
|
|
|
|
|
|
|
|
|
|
bool isSlowed = false;
|
|
|
|
|
bool toApply = true;
|
|
|
|
|
Effect* slowing_effect = nullptr;
|
|
|
|
|
for (auto it = game.m_effects.begin(); it != game.m_effects.end();) {
|
|
|
|
|
if ((*it)->effectId == 0) {
|
|
|
|
|
isSlowed = true;
|
|
|
|
|
slowing_effect = *it;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < numBalls; i++)
|
|
|
|
|
{
|
|
|
|
|
float angle = rand() % 1000 * (2 * M_PI / 1000);
|
|
|
|
|
float vx = Ball::initialVelocity * sin(angle);
|
|
|
|
|
float vy = Ball::initialVelocity * cos(angle);
|
|
|
|
|
float angle, vx, vy;
|
|
|
|
|
if (game.isMaxBalls()) {
|
|
|
|
|
toApply = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (toApply) {
|
|
|
|
|
angle = rand() % 1000 * (2 * M_PI / 1000);
|
|
|
|
|
vx = Ball::initialVelocity * sin(angle);
|
|
|
|
|
vy = Ball::initialVelocity * cos(angle);
|
|
|
|
|
game.addBall({game.m_initialBall.radius, (*it).position, {vx, vy}});
|
|
|
|
|
|
|
|
|
|
if (isSlowed) {
|
|
|
|
|
slowing_effect->activate(game.m_balls.back());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (game.isMaxBalls()) {
|
|
|
|
|
toApply = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (toApply) {
|
|
|
|
|
angle = rand() % 1000 * (2 * M_PI / 1000);
|
|
|
|
|
vx = Ball::initialVelocity * sin(angle);
|
|
|
|
|
vy = Ball::initialVelocity * cos(angle);
|
|
|
|
|
game.addBall({game.m_initialBall.radius, (*it).position, {vx, vy}});
|
|
|
|
|
if (isSlowed) {
|
|
|
|
|
slowing_effect->activate(game.m_balls.back());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
@ -90,8 +121,10 @@ void EnlargePaddleBonus::draw(sf::RenderWindow& window) const
|
|
|
|
|
|
|
|
|
|
void EnlargePaddleBonus::activate(Arkanoid& game)
|
|
|
|
|
{
|
|
|
|
|
if (game.m_paddle.size.x < 300) {
|
|
|
|
|
game.m_paddle.size.x *= 1.5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnlargePaddleBonus::~EnlargePaddleBonus() {}
|
|
|
|
|
|
|
|
|
@ -113,8 +146,10 @@ void ShrinkPaddleBonus::draw(sf::RenderWindow& window) const
|
|
|
|
|
}
|
|
|
|
|
void ShrinkPaddleBonus::activate(Arkanoid& game)
|
|
|
|
|
{
|
|
|
|
|
if (game.m_paddle.size.x > 40) {
|
|
|
|
|
game.m_paddle.size.x *= 0.8;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShrinkPaddleBonus::~ShrinkPaddleBonus() {}
|
|
|
|
|
|
|
|
|
@ -137,9 +172,20 @@ void SlowingBonus::draw(sf::RenderWindow& window) const
|
|
|
|
|
}
|
|
|
|
|
void SlowingBonus::activate(Arkanoid& game)
|
|
|
|
|
{
|
|
|
|
|
game.m_effects.push_back(new SlowingEffect(game.m_time, 10));
|
|
|
|
|
bool isAlreadySlowed = false;
|
|
|
|
|
for (auto it = game.m_effects.begin(); it != game.m_effects.end();) {
|
|
|
|
|
if ((*it)->effectId == 0) {
|
|
|
|
|
(*it)->mDuration += mDuration;
|
|
|
|
|
isAlreadySlowed = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
if (!isAlreadySlowed) {
|
|
|
|
|
game.m_effects.push_back(new SlowingEffect(game.m_time, mDuration));
|
|
|
|
|
game.m_effects.back()->activate(game);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SlowingBonus::~SlowingBonus() {}
|
|
|
|
|
|
|
|
|
@ -147,7 +193,7 @@ SlowingBonus::~SlowingBonus() {}
|
|
|
|
|
* Effects
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
Effect::Effect(double start_time, double duration) : mStartTime(start_time), mDuration(duration) {};
|
|
|
|
|
Effect::Effect(char id, double start_time, double duration) : effectId(id), mStartTime(start_time), mDuration(duration) {};
|
|
|
|
|
|
|
|
|
|
bool Effect::isExpired(double time) {
|
|
|
|
|
if (mStartTime + mDuration > time)
|
|
|
|
@ -155,27 +201,30 @@ bool Effect::isExpired(double time) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SlowingEffect::SlowingEffect(double start_time, double duration) : Effect(start_time, duration) {};
|
|
|
|
|
SlowingEffect::SlowingEffect(double start_time, double duration) : Effect(0, start_time, duration) {};
|
|
|
|
|
|
|
|
|
|
void SlowingEffect::activate(Arkanoid& game) {
|
|
|
|
|
std::cout << "Activated slow motion" << std::endl;
|
|
|
|
|
for (Ball& ball : game.m_balls)
|
|
|
|
|
{
|
|
|
|
|
//std::cout << "meow" << std::endl;
|
|
|
|
|
if (!(ball.affectedBy & 0b00000001)) {
|
|
|
|
|
ball.affectedBy |= 0b00000001;
|
|
|
|
|
//if (!(ball.affectedBy & 0b00000001)) {
|
|
|
|
|
//ball.affectedBy |= 0b00000001;
|
|
|
|
|
ball.velocity = sf::Vector2f{ball.velocity.x * mSlowingFactor, ball.velocity.y * mSlowingFactor};
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void SlowingEffect::activate(Ball& ball) {
|
|
|
|
|
//if (!(ball.affectedBy & 0b00000001)) {
|
|
|
|
|
//ball.affectedBy |= 0b00000001;
|
|
|
|
|
ball.velocity = sf::Vector2f{ball.velocity.x * mSlowingFactor, ball.velocity.y * mSlowingFactor};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SlowingEffect::deactivate(Arkanoid& game) {
|
|
|
|
|
std::cout << "Deactivated slow motion" << std::endl;
|
|
|
|
|
for (Ball& ball : game.m_balls)
|
|
|
|
|
{
|
|
|
|
|
if (ball.affectedBy & 0b00000001) {
|
|
|
|
|
//if (ball.affectedBy & 0b00000001) {
|
|
|
|
|
ball.velocity = sf::Vector2f{ball.velocity.x / mSlowingFactor, ball.velocity.y / mSlowingFactor};
|
|
|
|
|
ball.affectedBy &= 0b11111110;
|
|
|
|
|
}
|
|
|
|
|
// ball.affectedBy &= 0b11111110;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|