summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--GameScreen.cpp6
-rw-r--r--Player-inl.h17
-rw-r--r--Player.h5
3 files changed, 23 insertions, 5 deletions
diff --git a/GameScreen.cpp b/GameScreen.cpp
index 774956e..4315060 100644
--- a/GameScreen.cpp
+++ b/GameScreen.cpp
@@ -16,11 +16,7 @@ GameScreen::update(const float dt)
m_player.update(dt);
m_generator.update(dt);
m_const.update(dt);
- bool collided = false;
- for (const auto& bullet : m_const.m_bullets) {
- if (CheckCollisionCircles(m_player.m_position, 9, bullet.position, bullet.radius))
- collided = true;
- }
+ bool collided = m_player.collide(m_const.m_bullets);
(void) collided;
}
diff --git a/Player-inl.h b/Player-inl.h
new file mode 100644
index 0000000..10c43d1
--- /dev/null
+++ b/Player-inl.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <vector>
+
+#include <raylib.h>
+
+
+template<typename T>
+bool
+Player::collide(const std::vector<T>& bullets) const
+{
+ for (const auto& bullet : bullets) {
+ if (CheckCollisionCircles(m_position, 9, bullet.position, bullet.radius))
+ return true;
+ }
+ return false;
+}
diff --git a/Player.h b/Player.h
index f0d4d10..b138edd 100644
--- a/Player.h
+++ b/Player.h
@@ -1,5 +1,7 @@
#pragma once
+#include <vector>
+
#include <raylib.h>
@@ -8,5 +10,8 @@ struct Player
Player();
void update(float dt);
void draw();
+ template<typename T> bool collide(const std::vector<T>& bullets) const;
Vector2 m_position;
};
+
+#include "Player-inl.h"