From 2773854a3e749512826fa8b71b77e754be79836f Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 18 Apr 2022 11:05:24 +0200 Subject: Renamed bullets header to simply ConstantVelocity --- Bullets.cpp | 42 ------------------------------------------ Bullets.h | 31 ------------------------------- CMakeLists.txt | 2 +- ConstantVelocity.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ ConstantVelocity.h | 31 +++++++++++++++++++++++++++++++ ExampleGenerator.cpp | 2 +- ExampleGenerator.h | 2 +- GameScreen.h | 2 +- 8 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 Bullets.cpp delete mode 100644 Bullets.h create mode 100644 ConstantVelocity.cpp create mode 100644 ConstantVelocity.h diff --git a/Bullets.cpp b/Bullets.cpp deleted file mode 100644 index 62b6ea3..0000000 --- a/Bullets.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "Bullets.h" - -#include - - -ConstantVelocitySystem::ConstantVelocitySystem() : - ConstantVelocitySystem(10000) -{ -} - - -ConstantVelocitySystem::ConstantVelocitySystem(int reserved) -{ - m_bullets.reserve(reserved); -} - - -void -ConstantVelocitySystem::update(const float dt) -{ - const int max_height = GetScreenHeight() + MARGIN; - const int min_width = 0 - MARGIN; - const int max_width = GetScreenWidth() + MARGIN; - auto it = m_bullets.begin(); - while (it != m_bullets.end()) { - auto& bullet = *it; - bullet.position.x += bullet.velocity.x * dt; - bullet.position.y += bullet.velocity.y * dt; - if (bullet.position.y > max_height || bullet.position.x < min_width || bullet.position.x > max_width) - it = m_bullets.erase(it); - else - ++it; - } -} - - -void -ConstantVelocitySystem::draw() -{ - for (const auto& bullet : m_bullets) - DrawCircle(bullet.position.x, bullet.position.y, bullet.radius, bullet.color); -} diff --git a/Bullets.h b/Bullets.h deleted file mode 100644 index 3970aff..0000000 --- a/Bullets.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -#include - - -static constexpr float MARGIN {40}; - - -struct ConstantVelocityBullet; - - -struct ConstantVelocitySystem -{ - ConstantVelocitySystem(); - explicit ConstantVelocitySystem(int reserved); - void update(float dt); - void draw(); - std::vector m_bullets; -}; - - -struct ConstantVelocityBullet -{ - using Vector = std::vector; - Vector2 position; - Vector2 velocity; - float radius; - Color color; -}; diff --git a/CMakeLists.txt b/CMakeLists.txt index 8867e78..32c3787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ endif() find_package(raylib 3 REQUIRED) add_executable( ${PROJECT_NAME} - Bullets.cpp + ConstantVelocity.cpp ExampleGenerator.cpp Game.cpp GameScreen.cpp diff --git a/ConstantVelocity.cpp b/ConstantVelocity.cpp new file mode 100644 index 0000000..37f3c3d --- /dev/null +++ b/ConstantVelocity.cpp @@ -0,0 +1,42 @@ +#include "ConstantVelocity.h" + +#include + + +ConstantVelocitySystem::ConstantVelocitySystem() : + ConstantVelocitySystem(10000) +{ +} + + +ConstantVelocitySystem::ConstantVelocitySystem(int reserved) +{ + m_bullets.reserve(reserved); +} + + +void +ConstantVelocitySystem::update(const float dt) +{ + const int max_height = GetScreenHeight() + MARGIN; + const int min_width = 0 - MARGIN; + const int max_width = GetScreenWidth() + MARGIN; + auto it = m_bullets.begin(); + while (it != m_bullets.end()) { + auto& bullet = *it; + bullet.position.x += bullet.velocity.x * dt; + bullet.position.y += bullet.velocity.y * dt; + if (bullet.position.y > max_height || bullet.position.x < min_width || bullet.position.x > max_width) + it = m_bullets.erase(it); + else + ++it; + } +} + + +void +ConstantVelocitySystem::draw() +{ + for (const auto& bullet : m_bullets) + DrawCircle(bullet.position.x, bullet.position.y, bullet.radius, bullet.color); +} diff --git a/ConstantVelocity.h b/ConstantVelocity.h new file mode 100644 index 0000000..3970aff --- /dev/null +++ b/ConstantVelocity.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include + + +static constexpr float MARGIN {40}; + + +struct ConstantVelocityBullet; + + +struct ConstantVelocitySystem +{ + ConstantVelocitySystem(); + explicit ConstantVelocitySystem(int reserved); + void update(float dt); + void draw(); + std::vector m_bullets; +}; + + +struct ConstantVelocityBullet +{ + using Vector = std::vector; + Vector2 position; + Vector2 velocity; + float radius; + Color color; +}; diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp index bcead95..3e1598b 100644 --- a/ExampleGenerator.cpp +++ b/ExampleGenerator.cpp @@ -5,7 +5,7 @@ #include -#include "Bullets.h" +#include "ConstantVelocity.h" ExampleGenerator::ExampleGenerator(ConstantVelocityBullet::Vector& bullets) : diff --git a/ExampleGenerator.h b/ExampleGenerator.h index 25c4ce3..16c9fc2 100644 --- a/ExampleGenerator.h +++ b/ExampleGenerator.h @@ -2,7 +2,7 @@ #include -#include "Bullets.h" +#include "ConstantVelocity.h" #include "Generator.h" diff --git a/GameScreen.h b/GameScreen.h index 144bd82..11d5b73 100644 --- a/GameScreen.h +++ b/GameScreen.h @@ -2,7 +2,7 @@ #include -#include "Bullets.h" +#include "ConstantVelocity.h" #include "ExampleGenerator.h" #include "Player.h" #include "Screen.h" -- cgit v1.1