HitBox added. acceleration of collision detection in 20 times.

master
Vectozavr 2021-11-04 13:05:21 +07:00
parent 1ad591ed04
commit c12fcc857d
3 changed files with 7 additions and 7 deletions

View File

@ -10,10 +10,10 @@ using namespace std;
int main() { int main() {
Shooter game; Shooter game;
//game.create(1280, 720, ShooterConsts::PROJECT_NAME); game.create(1280, 720, ShooterConsts::PROJECT_NAME);
//game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); //game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen);
game.create(2048, 1152, ShooterConsts::PROJECT_NAME, false); //game.create(2048, 1152, ShooterConsts::PROJECT_NAME, true);
//game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); //game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen);
return 0; return 0;

View File

@ -162,7 +162,7 @@ void Engine::printDebugInfo() const {
Vec2D{xPos, yPos + height + height * i}, Vec2D{xPos, yPos + height + height * i},
{static_cast<sf::Uint8>(255 * width / timerWidth), {static_cast<sf::Uint8>(255 * width / timerWidth),
static_cast<sf::Uint8>(255 * (1 - width / timerWidth)), static_cast<sf::Uint8>(255 * (1 - width / timerWidth)),
0, 100}); 0, 150});
screen->drawText( screen->drawText(
@ -170,7 +170,7 @@ void Engine::printDebugInfo() const {
std::to_string((int) (1.0 / timer.elapsedMilliseconds())) + " / s \t (" + std::to_string((int) (1.0 / timer.elapsedMilliseconds())) + " / s \t (" +
std::to_string((int) (100 * timer.elapsedMilliseconds() / totalTime)) + "%)", std::to_string((int) (100 * timer.elapsedMilliseconds() / totalTime)) + "%)",
Vec2D{xPos + 10, yPos + height * i + 5}, 30, Vec2D{xPos + 10, yPos + height * i + 5}, 30,
sf::Color(0, 0, 0, 100)); sf::Color(0, 0, 0, 200));
i++; i++;
timeSum += timer.elapsedMilliseconds(); timeSum += timer.elapsedMilliseconds();
@ -183,13 +183,13 @@ void Engine::printDebugInfo() const {
Vec2D{xPos, yPos + height + height * i}, Vec2D{xPos, yPos + height + height * i},
{static_cast<sf::Uint8>(255 * width / timerWidth), {static_cast<sf::Uint8>(255 * width / timerWidth),
static_cast<sf::Uint8>(255 * (1 - width / timerWidth)), static_cast<sf::Uint8>(255 * (1 - width / timerWidth)),
0, 100}); 0, 150});
screen->drawText("other:\t" + std::to_string((int) (1.0 / (totalTime - timeSum))) + " / s \t (" + screen->drawText("other:\t" + std::to_string((int) (1.0 / (totalTime - timeSum))) + " / s \t (" +
std::to_string((int) (100 * (totalTime - timeSum) / totalTime)) + "%)", std::to_string((int) (100 * (totalTime - timeSum) / totalTime)) + "%)",
Vec2D{xPos + 10, yPos + height * i + 5}, 30, Vec2D{xPos + 10, yPos + height * i + 5}, 30,
sf::Color(0, 0, 0, 100)); sf::Color(0, 0, 0, 200));
} }
} }

View File

@ -17,7 +17,7 @@ HitBox::HitBox(const Mesh &mesh) {
void HitBox::_addIfUnique(const Vec3D &point) { void HitBox::_addIfUnique(const Vec3D &point) {
bool addPoint = true; bool addPoint = true;
for(const auto& p : _hitBox) { for(const auto& p : _hitBox) {
if((p - point).sqrAbs() < Consts::EPS) { if(p == point) {
addPoint = false; addPoint = false;
} }
} }