From add251b4ea37b57cf926b07e5e04d9b065f82a2c Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 18 Apr 2022 20:38:16 +0200 Subject: Playing around with enemies, added dumb pos manipulation --- Enemy.cpp | 10 +++++++++- Enemy.h | 1 + ExampleGenerator.cpp | 24 ++++++++++++------------ Player-inl.h | 2 +- Player.cpp | 2 +- TestStage.cpp | 18 ++++++++++++++---- TestStage.h | 4 +++- 7 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Enemy.cpp b/Enemy.cpp index 7caea31..b8329a2 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -9,7 +9,7 @@ Enemy::Enemy(std::unique_ptr generator) : - m_hold {2}, + m_hold {0}, m_position {std::make_shared()}, m_generator {std::move(generator)} { @@ -38,3 +38,11 @@ Enemy::draw() return; DrawCircle(m_position->x, m_position->y, 6, DARKGRAY); } + + +void +Enemy::set_position(const float x, const float y) +{ + m_position->x = x; + m_position->y = y; +} diff --git a/Enemy.h b/Enemy.h index ad0c99d..0a8c429 100644 --- a/Enemy.h +++ b/Enemy.h @@ -13,6 +13,7 @@ public: explicit Enemy(std::unique_ptr generator = {}); void update(float dt); void draw(); + void set_position(float x, float y); private: float m_hold; std::shared_ptr m_position; diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp index 4c86d94..76c4cb7 100644 --- a/ExampleGenerator.cpp +++ b/ExampleGenerator.cpp @@ -11,12 +11,12 @@ ExampleGenerator::ExampleGenerator(ConstantVelocityBullet::Vector& bullets) : m_bullets {bullets}, m_delay {0}, - m_interval {0.04f}, - m_cone {0.3f}, + m_interval {0.05f}, + m_cone {0.4f}, m_angle {0.3f}, - m_speed {100}, + m_speed {70}, m_shift {10}, - m_segments {2}, + m_segments {3}, m_color {240, 0, 0, 255} { } @@ -42,13 +42,13 @@ ExampleGenerator::update(const float dt) bullet.position.y = pos.y + sin * m_shift; m_bullets.push_back(std::move(bullet)); } - m_angle += dt * 1.1f; - if (m_angle >= 0.7f) { - m_angle -= 0.4f; - if (m_color.g == 0) - m_color.g = 150; - else - m_color.g = 0; - } + } + m_angle += dt * 0.5f; + if (m_angle >= 0.7f) { + m_angle -= 0.4f; + if (m_color.g == 0) + m_color.g = 120; + else + m_color.g = 0; } } diff --git a/Player-inl.h b/Player-inl.h index 10c43d1..140bfad 100644 --- a/Player-inl.h +++ b/Player-inl.h @@ -10,7 +10,7 @@ bool Player::collide(const std::vector& bullets) const { for (const auto& bullet : bullets) { - if (CheckCollisionCircles(m_position, 9, bullet.position, bullet.radius)) + if (CheckCollisionCircles(m_position, 4, bullet.position, bullet.radius)) return true; } return false; diff --git a/Player.cpp b/Player.cpp index 9e4be4d..490b810 100644 --- a/Player.cpp +++ b/Player.cpp @@ -39,7 +39,7 @@ Player::update(const float dt) void Player::draw() { - DrawCircle(m_position.x, m_position.y, 10, LIGHTGRAY); + DrawCircle(m_position.x, m_position.y, 4, LIGHTGRAY); } diff --git a/TestStage.cpp b/TestStage.cpp index cc90f19..653d3c2 100644 --- a/TestStage.cpp +++ b/TestStage.cpp @@ -1,13 +1,21 @@ #include "TestStage.h" +#include +#include + #include "ExampleGenerator.h" TestStage::TestStage() : m_player {}, - m_const {}, - m_enemy {std::make_unique(m_const.m_bullets)} + m_const {} { + m_enemies.reserve(2); + for (const float x : {200.f, 600.f}) { + Enemy enemy(std::make_unique(m_const.m_bullets)); + enemy.set_position(x, 20.f); + m_enemies.push_back(std::move(enemy)); + } } @@ -15,7 +23,8 @@ void TestStage::update(const float dt) { m_player.update(dt); - m_enemy.update(dt); + for (auto& enemy : m_enemies) + enemy.update(dt); m_const.update(dt); bool collided = m_player.collide(m_const.m_bullets); (void) collided; @@ -26,7 +35,8 @@ void TestStage::draw() { m_const.draw(); - m_enemy.draw(); + for (auto& enemy : m_enemies) + enemy.draw(); m_player.draw(); } diff --git a/TestStage.h b/TestStage.h index c5287a5..0e90ab6 100644 --- a/TestStage.h +++ b/TestStage.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "ConstantVelocity.h" #include "Enemy.h" #include "Player.h" @@ -16,5 +18,5 @@ public: private: Player m_player; ConstantVelocitySystem m_const; - Enemy m_enemy; + std::vector m_enemies; }; -- cgit v1.1