diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/mappable.h | 146 | ||||
-rw-r--r-- | src/components/ponderable.h | 23 |
2 files changed, 165 insertions, 4 deletions
diff --git a/src/components/mappable.h b/src/components/mappable.h new file mode 100644 index 0000000..7530919 --- /dev/null +++ b/src/components/mappable.h | |||
@@ -0,0 +1,146 @@ | |||
1 | #ifndef MAPPABLE_H_0B0316FB | ||
2 | #define MAPPABLE_H_0B0316FB | ||
3 | |||
4 | #include <map> | ||
5 | #include "component.h" | ||
6 | #include "renderer.h" | ||
7 | #include "map.h" | ||
8 | |||
9 | class MappableComponent : public Component { | ||
10 | public: | ||
11 | |||
12 | class Boundary { | ||
13 | public: | ||
14 | |||
15 | enum class Type { | ||
16 | wall, | ||
17 | wrap, | ||
18 | teleport, | ||
19 | reverse, | ||
20 | platform, | ||
21 | danger | ||
22 | }; | ||
23 | |||
24 | Boundary( | ||
25 | double axis, | ||
26 | double lower, | ||
27 | double upper, | ||
28 | Type type) : | ||
29 | axis_(axis), | ||
30 | lower_(lower), | ||
31 | upper_(upper), | ||
32 | type_(type) | ||
33 | { | ||
34 | } | ||
35 | |||
36 | inline double getAxis() const | ||
37 | { | ||
38 | return axis_; | ||
39 | } | ||
40 | |||
41 | inline double getLower() const | ||
42 | { | ||
43 | return lower_; | ||
44 | } | ||
45 | |||
46 | inline double getUpper() const | ||
47 | { | ||
48 | return upper_; | ||
49 | } | ||
50 | |||
51 | inline Type getType() const | ||
52 | { | ||
53 | return type_; | ||
54 | } | ||
55 | |||
56 | private: | ||
57 | |||
58 | double axis_; | ||
59 | double lower_; | ||
60 | double upper_; | ||
61 | Type type_; | ||
62 | }; | ||
63 | |||
64 | MappableComponent( | ||
65 | Texture tileset, | ||
66 | Texture font) : | ||
67 | tileset_(std::move(tileset)), | ||
68 | font_(std::move(font)) | ||
69 | { | ||
70 | } | ||
71 | |||
72 | using asc_boundaries_type = | ||
73 | std::multimap< | ||
74 | double, | ||
75 | Boundary, | ||
76 | std::less<double>>; | ||
77 | |||
78 | using desc_boundaries_type = | ||
79 | std::multimap< | ||
80 | double, | ||
81 | Boundary, | ||
82 | std::greater<double>>; | ||
83 | |||
84 | inline size_t getMapId() const | ||
85 | { | ||
86 | return mapId_; | ||
87 | } | ||
88 | |||
89 | inline void setMapId(size_t v) | ||
90 | { | ||
91 | mapId_ = v; | ||
92 | } | ||
93 | |||
94 | inline desc_boundaries_type& getLeftBoundaries() | ||
95 | { | ||
96 | return leftBoundaries_; | ||
97 | } | ||
98 | |||
99 | inline asc_boundaries_type& getRightBoundaries() | ||
100 | { | ||
101 | return rightBoundaries_; | ||
102 | } | ||
103 | |||
104 | inline desc_boundaries_type& getUpBoundaries() | ||
105 | { | ||
106 | return upBoundaries_; | ||
107 | } | ||
108 | |||
109 | inline asc_boundaries_type& getDownBoundaries() | ||
110 | { | ||
111 | return downBoundaries_; | ||
112 | } | ||
113 | |||
114 | inline const Texture& getTileset() const | ||
115 | { | ||
116 | return tileset_; | ||
117 | } | ||
118 | |||
119 | inline void setTileset(Texture v) | ||
120 | { | ||
121 | tileset_ = std::move(v); | ||
122 | } | ||
123 | |||
124 | inline const Texture& getFont() const | ||
125 | { | ||
126 | return font_; | ||
127 | } | ||
128 | |||
129 | inline void setFont(Texture v) | ||
130 | { | ||
131 | font_ = std::move(v); | ||
132 | } | ||
133 | |||
134 | private: | ||
135 | |||
136 | size_t mapId_ = -1; | ||
137 | |||
138 | desc_boundaries_type leftBoundaries_; | ||
139 | asc_boundaries_type rightBoundaries_; | ||
140 | desc_boundaries_type upBoundaries_; | ||
141 | asc_boundaries_type downBoundaries_; | ||
142 | Texture tileset_; | ||
143 | Texture font_; | ||
144 | }; | ||
145 | |||
146 | #endif /* end of include guard: MAPPABLE_H_0B0316FB */ | ||
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index dfbf908..ac759b6 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h | |||
@@ -6,13 +6,27 @@ | |||
6 | class PonderableComponent : public Component { | 6 | class PonderableComponent : public Component { |
7 | public: | 7 | public: |
8 | 8 | ||
9 | enum class state { | 9 | enum class Type { |
10 | vacuumed, | ||
11 | freefalling | ||
12 | }; | ||
13 | |||
14 | enum class State { | ||
10 | grounded, | 15 | grounded, |
11 | jumping, | 16 | jumping, |
12 | falling, | 17 | falling, |
13 | dropping | 18 | dropping |
14 | }; | 19 | }; |
15 | 20 | ||
21 | PonderableComponent(Type type) : type_(type) | ||
22 | { | ||
23 | } | ||
24 | |||
25 | inline Type getType() const | ||
26 | { | ||
27 | return type_; | ||
28 | } | ||
29 | |||
16 | inline double getVelocityX() const | 30 | inline double getVelocityX() const |
17 | { | 31 | { |
18 | return velX_; | 32 | return velX_; |
@@ -53,12 +67,12 @@ public: | |||
53 | accelY_ = v; | 67 | accelY_ = v; |
54 | } | 68 | } |
55 | 69 | ||
56 | inline state getState() const | 70 | inline State getState() const |
57 | { | 71 | { |
58 | return state_; | 72 | return state_; |
59 | } | 73 | } |
60 | 74 | ||
61 | inline void setState(state arg) | 75 | inline void setState(State arg) |
62 | { | 76 | { |
63 | state_ = arg; | 77 | state_ = arg; |
64 | } | 78 | } |
@@ -69,7 +83,8 @@ private: | |||
69 | double velY_ = 0.0; | 83 | double velY_ = 0.0; |
70 | double accelX_ = 0.0; | 84 | double accelX_ = 0.0; |
71 | double accelY_ = 0.0; | 85 | double accelY_ = 0.0; |
72 | state state_ = state::grounded; | 86 | Type type_ = Type::vacuumed; |
87 | State state_ = State::grounded; | ||
73 | }; | 88 | }; |
74 | 89 | ||
75 | #endif /* end of include guard: TANGIBLE_H_746DB3EE */ | 90 | #endif /* end of include guard: TANGIBLE_H_746DB3EE */ |