bool CircleTest(const sf::Sprite& Object1, const sf::Sprite& Object2) { sf::Vector2f Obj1Size = GetSpriteSize(Object1); sf::Vector2f Obj2Size = GetSpriteSize(Object2); float Radius1 = (Obj1Size.x + Obj1Size.y) / 4; float Radius2 = (Obj2Size.x + Obj2Size.y) / 4; sf::Vector2f Distance = GetSpriteCenter(Object1)-GetSpriteCenter(Object2); return (Distance.x * Distance.x + Distance.y * Distance.y <= (Radius1 + Radius2) * (Radius1 + Radius2)); }
bool IsReachedHero(Sprite & hero, Sprite & boss) { Vector2f heroPos = GetSpriteCenter(hero); Vector2f bossPos = GetSpriteCenter(boss); //cout << "DIFF " << bossPos.x - heroPos.x << " " << bossPos.y + 10.f - heroPos.y << endl; if (abs(bossPos.x - heroPos.x) < 15.f && abs(bossPos.y + 10.f - heroPos.y) < 15.f) { return true; } return false; }
bool IsBossAbleToShoot(Sprite & hero, Sprite & boss) { Vector2f heroPos = GetSpriteCenter(hero); Vector2f bossPos = GetSpriteCenter(boss); //cout << "DIFF " << bossPos.x - heroPos.x << " " << bossPos.y + 10.f - heroPos.y << endl; //cout << "ABILITY " << bossPos.x - heroPos.x << " " << heroPos.y - bossPos.y << " " << endl; if (abs(bossPos.x - heroPos.x) < 130.f && (heroPos.y - bossPos.y < 100.f) && (heroPos.y - bossPos.y >= 0)) { return true; } return false; }
bool IsBossNearMapCenter(Sprite & boss) { Vector2f pos = GetSpriteCenter(boss); //cout << "BOSS POS " << pos.x << " " << pos.y << " TO " << LEVEL1_CENTER_POS.x << " " << LEVEL1_CENTER_POS.y << " CHECK " << abs(pos.x - LEVEL1_CENTER_POS.x + 32) << " " << abs(pos.y - LEVEL1_CENTER_POS.y + 32) << endl; if (abs(pos.x - LEVEL1_CENTER_POS.x) <= 15.f && abs(pos.y - LEVEL1_CENTER_POS.y) <= 15.f) { return true; } return false; }
void CheckBossExplosion(Boss & boss, vector<Explosion> & explosionList, int level) { if (level == 1) { Vector2f bossPos = GetSpriteCenter(boss.sprite); for (Explosion & explosion : explosionList) { if (explosion.currentFrame > 12) { if (abs(bossPos.x - (explosion.pos.x + 120)) < 120 && (abs(bossPos.y - (explosion.pos.y + 70)) < 120)) boss.health -= DMG_ITEM[6]; } } } }
void ComputeBossDirection(Boss & boss, FloatRect & rect, Sprite & hero) { Vector2f heroPos = GetSpriteCenter(hero); //Vector2f bossPos = { rect.left + rect.width / 2.f, rect.top + rect.height / 2.f }; Vector2f bossPos = GetSpriteCenter(boss.sprite); if (boss.eventType == STOMP_FOR_ZOMBIES) { boss.dir = NONE; } else if (boss.eventType == SHOOT) { boss.dir = NONE; if (heroPos.x <= bossPos.x) { boss.lastSide = LEFT; } else boss.lastSide = RIGHT; } else { if (boss.eventType == MOVE_OUT) { heroPos = LEVEL1_CENTER_POS;//{ 12 * 64, 6 * 64 }; } Direction dirOld = boss.dir; Vector2f distance = { abs(heroPos.x - bossPos.x), abs(heroPos.y - bossPos.y) }; if (distance.x > 5 || distance.y > 5) { //TODO: check left-right dir zombie sprite bug (almost) if ((distance.x > 3 && distance.y > 3) && (distance.x / distance.y > 0.9) && (distance.y / distance.x < 1.1)) { if (heroPos.x >= bossPos.x && heroPos.y >= bossPos.y) boss.dir = DOWNRIGHT; else if (heroPos.x >= bossPos.x && heroPos.y < bossPos.y) boss.dir = UPRIGHT; else if (heroPos.x < bossPos.x && heroPos.y >= bossPos.y) boss.dir = DOWNLEFT; else if (heroPos.x < bossPos.x && heroPos.y < bossPos.y) boss.dir = UPLEFT; } else if (distance.x >= distance.y) { if (heroPos.x > bossPos.x) boss.dir = RIGHT; else boss.dir = LEFT; } else if (distance.x < distance.y) { if (heroPos.y > bossPos.y) boss.dir = DOWN; else boss.dir = UP; } } if ((boss.lastSide == LEFT) && (boss.dir == UPRIGHT || boss.dir == RIGHT || boss.dir == DOWNRIGHT)) { boss.lastSide = RIGHT; } else if ((boss.lastSide == RIGHT) && (boss.dir == UPLEFT || boss.dir == LEFT || boss.dir == DOWNLEFT)) { boss.lastSide = LEFT; } } }