From 162ab6e923cf0c065449cfc248102b5b92fac8a7 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 17 Apr 2022 15:04:55 +0200 Subject: Separated bullet generator into class and created system for bullets --- GameScreen.cpp | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'GameScreen.cpp') diff --git a/GameScreen.cpp b/GameScreen.cpp index dcae176..6dc8025 100644 --- a/GameScreen.cpp +++ b/GameScreen.cpp @@ -1,16 +1,14 @@ #include "GameScreen.h" -#include - #include #include "Bullets.h" GameScreen::GameScreen() : - m_pos {400, 300} + m_pos {400, 300}, + m_const {} { - m_const_bullets.reserve(10000); } @@ -21,27 +19,11 @@ GameScreen::update(const float dt) m_pos.x -= dt * 80; if (IsKeyDown(KEY_RIGHT)) m_pos.x += dt * 80; - m_delay += dt; - if (m_delay > TEST_INTERVAL) { - m_delay -= TEST_INTERVAL; - const int speed = 120; - const int divisions = 17; - for (double i = 0; i <= divisions; ++i) { - const double angle = (0.1 + 0.8 * i / divisions) * M_PI; - const double cos = std::cos(angle); - const double sin = std::sin(angle); - ConstantVelocityBullet bullet; - bullet.position.x = 400; - bullet.position.y = 20; - bullet.velocity.x = cos * speed; - bullet.velocity.y = sin * speed; - m_const_bullets.push_back(std::move(bullet)); - } - } - ::update(dt, m_const_bullets); + m_generator.update(dt, m_const.m_bullets); + m_const.update(dt); bool collided = false; - for (const auto& bullet : m_const_bullets) { - if (CheckCollisionCircles(m_pos, 10, bullet.position, 6)) + for (const auto& bullet : m_const.m_bullets) { + if (CheckCollisionCircles(m_pos, 9, bullet.position, bullet.radius)) collided = true; } (void) collided; @@ -52,8 +34,7 @@ void GameScreen::draw() { DrawCircle(m_pos.x, m_pos.y, 10, LIGHTGRAY); - for (const auto& bullet : m_const_bullets) - DrawCircle(bullet.position.x, bullet.position.y, 6, RED); + m_const.draw(); DrawFPS(5, 5); - DrawText(TextFormat("%d", m_const_bullets.size()), 5, 25, 20, DARKGRAY); + DrawText(TextFormat("%d", m_const.m_bullets.size()), 5, 25, 20, DARKGRAY); } -- cgit v1.1