]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/collider.h
Implement a simple physics system in Bassteroids
[libs/game.git] / examples / bassteroids / source / collider.h
1 #ifndef COLLIDER_H_
2 #define COLLIDER_H_
3
4 #include <msp/game/component.h>
5 #include <msp/linal/vector.h>
6
7 enum class ColliderType
8 {
9         CIRCLE,
10         BOX
11 };
12
13 struct ColliderSetup
14 {
15         ColliderType type = ColliderType::CIRCLE;
16         union
17         {
18                 float radius = 1.0f;
19                 Msp::LinAl::Vector<float, 2> size;
20         };
21 };
22
23
24 class Collider: public Msp::Game::Component
25 {
26 public:
27         using Setup = ColliderSetup;
28
29 private:
30         Setup setup;
31
32 public:
33         Collider(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
34
35         ColliderType get_type() const { return setup.type; }
36         float get_radius() const { return (setup.type==ColliderType::CIRCLE ? setup.radius : 0.0f); }
37         Msp::LinAl::Vector<float, 2> get_size() const { return (setup.type==ColliderType::BOX ? setup.size : Msp::LinAl::Vector<float, 2>()); }
38 };
39
40 #endif