-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetailObject.cpp
More file actions
218 lines (208 loc) · 5.38 KB
/
DetailObject.cpp
File metadata and controls
218 lines (208 loc) · 5.38 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
209
210
211
212
213
214
215
216
217
218
#include "DetailObject.h"
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h) : GameObject(textureSheet, x, y) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = height;
srcRect.w = width;
srcRect.x = 0;
srcRect.y = 0;
sy = 0;
sx = 0;
frames = 0;
animated = false;
delayTime = 0;
objectID = ID;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, bool anim, int frame, int delay) : GameObject(textureSheet, x, y) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = height;
srcRect.w = width;
srcRect.x = 0;
srcRect.y = 0;
frames = frame;
animated = anim;
delayTime = delay;
objectID = ID;
sy = 0;
sx = 0;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, int sw, int sh, bool anim, int frame, int delay, bool loops) : GameObject(textureSheet, x, y) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = height;
srcRect.w = width;
srcRect.x = 0;
srcRect.y = 0;
srcRect.h = sh;
srcRect.w = sw;
frames = frame;
animated = anim;
delayTime = delay;
objectID = ID;
loop = loops;
sy = sh;
sx = sw;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, int sw, int sh) : GameObject(textureSheet, x, y) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = sh;
srcRect.w = sw;
srcRect.x = 0;
srcRect.y = 0;
frames = 0;
animated = false;
delayTime = 0;
objectID = ID;
sy = sh;
sx = sw;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, bool offs) : GameObject(textureSheet, x, y, offs) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = height;
srcRect.w = width;
srcRect.x = 0;
srcRect.y = 0;
sy = 0;
sx = 0;
frames = 0;
animated = false;
delayTime = 0;
objectID = ID;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, int sw, int sh, bool offs) : GameObject(textureSheet, x, y, offs) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = sh;
srcRect.w = sw;
srcRect.x = 0;
srcRect.y = 0;
frames = 0;
animated = false;
delayTime = 0;
objectID = ID;
sy = sh;
sx = sw;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, bool offs, bool anim, int frame, int delay) : GameObject(textureSheet, x, y, offs) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = height;
srcRect.w = width;
srcRect.x = 0;
srcRect.y = 0;
frames = frame;
animated = anim;
delayTime = delay;
objectID = ID;
sy = 0;
sx = 0;
aniInit = false;
aniCounter = 0;
}
DetailObject::DetailObject(std::string ID, const char* textureSheet, int x, int y, int w, int h, int sw, int sh, bool offs, bool anim, int frame, int delay, bool looper) : GameObject(textureSheet, x, y, offs) {
width = w;
height = h;
destRect.h = h;
destRect.w = w;
srcRect.h = height;
srcRect.w = width;
srcRect.x = 0;
srcRect.y = 0;
srcRect.h = sh;
srcRect.w = sw;
frames = frame;
animated = anim;
delayTime = delay;
objectID = ID;
loop = looper;
sy = sh;
sx = sw;
aniInit = false;
aniCounter = 0;
}
void DetailObject::moveObjectTo(int x, int y) {
xPos = x;
yPos = y;
}
void DetailObject::moveObject(int x, int y) {
xPos += x;
yPos += y;
}
void DetailObject::update() {
static int offSet = 0;//static_cast<int>((SDL_GetTicks() / (delayTime)) % frames);
if (animated == true) {
if (loop == true) {
if (frames > 1) {
srcRect.x = srcRect.w * static_cast<int>((SDL_GetTicks() / (delayTime)) % frames);
}
}
else if (loop == false) {
if (aniInit == false) {
//offSet = static_cast<int>((SDL_GetTicks() / (delayTime)) % frames);
offSet = static_cast<int>((aniCounter / (delayTime)) % frames);
aniInit = true;
}
if (frames > 1) {
if (aniCounter < frames * delayTime) {
//std::cout << "aniCounter: " << aniCounter << std::endl;
/*if ((static_cast<int>((SDL_GetTicks() / (delayTime)) % frames) - offSet) >= 0) {
srcRect.x = srcRect.w * (static_cast<int>((SDL_GetTicks() / (delayTime)) % frames) - offSet);
}
else {
srcRect.x = srcRect.w * ((static_cast<int>((SDL_GetTicks() / (delayTime)) % frames) - offSet) + frames);
}*/
if (aniCounter % delayTime == 0&&aniCounter>0) {
std::cout << "moving animation" << std::endl;
std::cout << "srcRect: " << srcRect.x << std::endl;
srcRect.x = aniCounter/delayTime*srcRect.w; //* ((static_cast<int>((aniCounter / (delayTime)) % frames) - offSet) + frames);
std::cout << "srcRect: " << srcRect.x << std::endl;
}
aniCounter++;
}
}
}
}
else if (aniInit == true) {
std::cout << "reset ofofset";
offSet = 0;
srcRect.x = sx;
srcRect.y = sy;
aniInit = false;
}
destRect.x = xPos;
destRect.y = yPos;
destRect.w = width;
destRect.h = height;
}
void DetailObject::setObjectID(std::string newid) {
objectID = newid;
}