/
nantonenko95
/
raylib-introduction
Обзор
Документация
Войти
/
nantonenko95
/
raylib-introduction
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/weapon.cpp
46 строк
1 KB
Nikita
Enhanced shooting
10 ноя 2024, 16:02
10 ноя 2024, 16:02
dfd9f30
Код
Авторство
О чём код?
#include "weapon.h" #include <algorithm> #include <iostream> #include <ranges> void Weapon::shoot(Vec2 diraction) { if (fireTimeElapsed > fireDelay()) { fireTimeElapsed = 0.0f; auto proj = Projectile(projectileColor, projectileRadius, diraction * projectileSpeed); proj.position = position + projSpawnOffset; projectileList.push_back(proj); } } void Weapon::update() { fireTimeElapsed += GetFrameTime(); std::ranges::for_each(projectileList, [](auto &proj) { proj.update(); }); if (projDeleteCnt < projDeletePeriodFrames) { projDeleteCnt++; return; } projDeleteCnt = 0; auto projToRemoveEnd = std::remove_if(projectileList.begin(), projectileList.end(), [this](const auto &proj) { return position.distanceTo(proj.position) > projDeleteDistance; }); projectileList.erase(projToRemoveEnd, projectileList.end()); } float Weapon::fireDelay() const { return 1 / fireRate; } void Weapon::drawProjectiles() { std::ranges::for_each(projectileList, [](auto proj) { proj.draw(); }); }