Add two new functions OutUp and OutLeft in gamecore, that judges whether the bullet is bocked by the top and bottom line or right and legt line. Then if the bullet touches the boundary, use mutiplicition to change its velocity.
if (gamecore->IsBlockedByObstacles(position_)) {
if (!rebounding_timesleft) {
should_die = true;
} else {
if (gamecore->OutUp(position)) {
position -= velocity * kSecondPerTick;
glm::vec2 tmp = glm::vec2(1.0f, -1.0f);
velocity= tmp;
rebounding_timesleft--;
} else if (gamecore->OutLeft(position)) {
position -= velocity_ kSecondPerTick;
glm::vec2 tmp = glm::vec2(-1.0f, 1.0f);
velocity_ = tmp;
rebounding_timesleft--;
} else {
glm::vec2 tmp1 = glm::vec2(-1.0f, 1.0f);
auto tmpv = velocity tmp1;
auto nextposition = position + tmp_v kSecondPerTick;
if (gamecore->IsBlockedByObstacles(nextposition)) {
glm::vec2 tmp = glm::vec2(1.0f, -1.0f);
velocity= tmp;
} else {
velocity_ = tmp_v;
}
rebounding_timesleft--;
}
}
}
void SmallBasketball::Update() {
//damagescale /= 1.3; which is the implementation of the previous exponentially declined bullets
if (test) {
ChangeDamage();
}