-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteractable.cpp
More file actions
208 lines (166 loc) · 5.5 KB
/
Copy pathInteractable.cpp
File metadata and controls
208 lines (166 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//Interactable.cpp
#include "Interactable.h"
#include <sdlUtility/Strings.h>
using namespace sdlUtility;
namespace sdlObjects {
void Interactable::AcquireSize(float Width, float Height) {
if (Width < 0) Width = AcquiredSize.X();
if (Height < 0) Height = AcquiredSize.Y();
AcquiredSize = Vector2(Width, Height);
}
float Interactable::CollisionHeight() {
if (CollisionSize.Y()) return CollisionSize.Y(); else return AcquiredSize.Y();
}
float Interactable::CollisionWidth() {
if (CollisionSize.X()) return CollisionSize.X(); else return AcquiredSize.X();
}
void Interactable::DropAt(float X, float Y) {
AcquiredPosition = Vector2(X, Y);
}
float Interactable::dHeight() {
return Height(2)-Height(1);
}
float Interactable::dWidth() {
return Width(2)-Width(1);
}
float Interactable::dX() {
return X(2)-X(1);
}
float Interactable::dY() {
return Y(2)-Y(1);
}
void Interactable::EnableCollision(bool State, std::string CollisionMap) {
Collision = State;
if (!CollisionSize.X() && !CollisionSize.Y()) {
CollisionSize = AcquiredSize;
}
if (CollisionMap != "") {
int Tiles = Strings::FindTotalOf(';', CollisionMap);
for (int i=0; i<Tiles; i++) {
int Tile = Strings::StringTo<int>(CollisionMap, ';', i);
this->CollisionMap.push_back(Tile);
}
}
}
void Interactable::EnableInteraction(bool State) {
Interactive = State;
}
void Interactable::EnableMoving(bool State) {
Movable = State;
}
void Interactable::EnableResizing(bool State) {
Resizable = State;
}
float Interactable::Height(int State) {
if (State == 2 && TargetSize.Y() != 0) {
return TargetSize.Y();
} else if (State == 3) {
return Size.Y();
} else {
if (Size.Y() < 0) return AcquiredSize.Y(); else return Size.Y();
}
}
float Interactable::InputHeight() {
if (InputSize.Y()) return InputSize.Y(); else return AcquiredSize.Y();
}
float Interactable::InputWidth() {
if (InputSize.X()) return InputSize.X(); else return AcquiredSize.X();
}
bool Interactable::IsCollidable(int Tile) {
if (Tile > 0) return CollisionMap[Tile-1]; else return Collision;
}
bool Interactable::IsDriven() {
return (TargetPosition.X() || TargetPosition.Y());
}
bool Interactable::IsInteractive() {
return Interactive;
}
bool Interactable::IsMovable() {
return Movable;
}
bool Interactable::IsResizable() {
return Resizable;
}
Interactable::Interactable() {
Sector = 0.f;
Position = Vector2(-1, -1);
Size = Vector2(-1, -1);
Shape = Shapes::Rectangle;
Interactive = true;
Collision = Movable = Resizable = false;
}
void Interactable::MoveBy(float X, float Y) {
if (TargetPosition == Vector2(0, 0)) TargetPosition = AcquiredPosition;
TargetPosition += Vector2(X, Y);
}
void Interactable::MoveTo(float X, float Y) {
TargetPosition = Vector2(X, Y);
}
void Interactable::NudgeBy(float X, float Y) {
AcquiredPosition += Vector2(X, Y);
}
float Interactable::Radius() {
return (AcquiredSize.X()+AcquiredSize.Y())/2.f;
}
void Interactable::Relax(int Axis) {
if (Axis == Axis::X) {
TargetPosition = Vector2(0, TargetPosition.Y());
} else if (Axis == Axis::Y) {
TargetPosition = Vector2(TargetPosition.X(), 0);
} else if (Axis == Axis::XY) {
TargetPosition = Vector2(0, 0);
}
}
void Interactable::RelaxSize() {
TargetSize = Vector2(0, 0);
}
void Interactable::ResizeCollisionTo(float Width, float Height) {
CollisionSize = Vector2(Width, Height);
}
void Interactable::ResizeInputTo(float Width, float Height) {
InputSize = Vector2(Width, Height);
}
void Interactable::ResizeTo(float Width, float Height) {
if (Width < 0) Width = Size.X();
if (Height < 0) Height = Size.Y();
Size = Vector2(Width, Height);
}
float Interactable::Section() {
return Sector;
}
void Interactable::Section(float Sector) {
this->Sector = Sector;
}
void Interactable::StretchBy(float Width, float Height) {
TargetSize += Vector2(Width, Height);
}
void Interactable::StretchTo(float Width, float Height) {
if (Width < 0) Width = TargetSize.X();
if (Height < 0) Height = TargetSize.Y();
TargetSize = Vector2(Width, Height);
}
float Interactable::Width(int State) {
if (State == 2 && TargetSize.X() != 0) {
return TargetSize.X();
} else if (State == 3) {
return Size.X();
} else {
if (Size.X() < 0) return AcquiredSize.X(); else return Size.X();
}
}
float Interactable::X(int State) {
if (State == 2 && TargetPosition.X() != 0) {
return TargetPosition.X();
} else return AcquiredPosition.X();
}
float Interactable::Y(int State) {
if (State == 2 && TargetPosition.Y() != 0) {
return TargetPosition.Y();
} else return AcquiredPosition.Y();
}
Interactable::~Interactable() {
Sector = 0.f;
Shape = 0;
Collision = Interactive = Movable = Resizable = false;
}
}