diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-01-31 12:08:02 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-01-31 12:08:02 -0500 |
commit | 908f792db6fdc04fde4b48e8873767edd5d59cea (patch) | |
tree | e1ec1659bfe9d7389d1dbc52aaa7045fdb652279 | |
parent | f648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e (diff) | |
download | tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.gz tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.bz2 tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.zip |
Made use of new sprite sheet data!
-rw-r--r-- | res/lucas.png | bin | 10009 -> 90846 bytes | |||
-rw-r--r-- | res/lucas_anim.txt | 66 | ||||
-rw-r--r-- | res/lucas_frames.txt | 403 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/renderer.cpp | 5 | ||||
-rw-r--r-- | src/sprite.cpp | 45 | ||||
-rw-r--r-- | src/sprite.h | 14 |
7 files changed, 491 insertions, 44 deletions
diff --git a/res/lucas.png b/res/lucas.png index c059f96..dd053e5 100644 --- a/res/lucas.png +++ b/res/lucas.png | |||
Binary files differ | |||
diff --git a/res/lucas_anim.txt b/res/lucas_anim.txt index 19b1d67..daef503 100644 --- a/res/lucas_anim.txt +++ b/res/lucas_anim.txt | |||
@@ -1,34 +1,34 @@ | |||
1 | ../res/lucas.png | 1 | ../res/lucas.png |
2 | 17,26 | 2 | ../res/lucas_frames.txt |
3 | still[down]: 1 | 3 | still[down]: 0 |
4 | still[left]: 4 | 4 | still[down_left]: 1 |
5 | still[down_left]: 7 | 5 | still[left]: 2 |
6 | still[down_right]: 10 | 6 | still[up_left]: 3 |
7 | still[up]: 13 | 7 | still[up]: 4 |
8 | still[right]: 16 | 8 | still[up_right]: 5 |
9 | still[up_left]: 19 | 9 | still[right]: 6 |
10 | still[up_right]: 22 | 10 | still[down_right]: 7 |
11 | walk[down]: 0,1,2 | 11 | walk[down]: 40,0,48 |
12 | walk[left]: 3,4,5 | 12 | walk[down_left]: 41,1,49 |
13 | walk[down_left]: 6,7,8 | 13 | walk[left]: 42,2,50 |
14 | walk[down_right]: 9,10,11 | 14 | walk[up_left]: 43,3,51 |
15 | walk[up]: 12,13,14 | 15 | walk[up]: 44,4,52 |
16 | walk[right]: 15,16,17 | 16 | walk[up_right]: 45,5,53 |
17 | walk[up_left]: 18,19,20 | 17 | walk[right]: 46,6,54 |
18 | walk[up_right]: 21,22,23 | 18 | walk[down_right]: 47,7,55 |
19 | crouch[down]: 24 | 19 | crouch[down]: 107 |
20 | crouch[down_left]: 25 | 20 | crouch[down_left]: 108 |
21 | crouch[left]: 26 | 21 | crouch[left]: 109 |
22 | crouch[up_left]: 27 | 22 | crouch[up_left]: 110 |
23 | crouch[up]: 28 | 23 | crouch[up]: 111 |
24 | crouch[up_right]: 29 | 24 | crouch[up_right]: 112 |
25 | crouch[right]: 30 | 25 | crouch[right]: 113 |
26 | crouch[down_right]: 31 | 26 | crouch[down_right]: 114 |
27 | run[down]: 32,33,34,35 | 27 | run[down]: 67,75,83,91 |
28 | run[right]: 36,37,38,39 | 28 | run[down_left]: 68,76,84,92 |
29 | run[down_right]: 40,41,42,43 | 29 | run[left]: 69,77,85,93 |
30 | run[up_right]: 44,45,46,47 | 30 | run[up_left]: 70,78,86,94 |
31 | run[up]: 48,49,50,51 | 31 | run[up]: 71,79,87,95 |
32 | run[left]: 52,53,54,55 | 32 | run[up_right]: 72,80,88,96 |
33 | run[up_left]: 56,57,58,59 | 33 | run[right]: 73,81,89,97 |
34 | run[down_left]: 60,61,62,63 \ No newline at end of file | 34 | run[down_right]: 74,82,90,98 \ No newline at end of file |
diff --git a/res/lucas_frames.txt b/res/lucas_frames.txt new file mode 100644 index 0000000..e64d1e1 --- /dev/null +++ b/res/lucas_frames.txt | |||
@@ -0,0 +1,403 @@ | |||
1 | 32,64 cell size | ||
2 | 10 frames per row | ||
3 | 399 frames | ||
4 | |||
5 | 16,32,8,32 | ||
6 | 16,32,8,32 | ||
7 | 16,32,8,32 | ||
8 | 16,32,8,32 | ||
9 | 16,32,9,32 | ||
10 | 16,32,9,32 | ||
11 | 16,32,9,32 | ||
12 | 16,32,9,32 | ||
13 | 16,32,8,32 | ||
14 | 16,32,8,32 | ||
15 | 16,32,8,32 | ||
16 | 16,32,8,32 | ||
17 | 16,32,9,32 | ||
18 | 16,32,9,32 | ||
19 | 16,32,9,32 | ||
20 | 16,32,9,32 | ||
21 | 16,24,8,24 | ||
22 | 16,24,9,24 | ||
23 | 17,32,10,32 | ||
24 | 16,24,8,24 | ||
25 | 16,24,8,24 | ||
26 | 16,24,9,24 | ||
27 | 17,32,7,32 | ||
28 | 16,24,8,24 | ||
29 | 16,24,8,24 | ||
30 | 16,24,9,24 | ||
31 | 17,24,10,24 | ||
32 | 16,24,8,24 | ||
33 | 16,24,9,24 | ||
34 | 16,24,9,24 | ||
35 | 17,24,7,24 | ||
36 | 16,24,8,24 | ||
37 | 17,24,9,24 | ||
38 | 16,24,9,24 | ||
39 | 17,24,10,24 | ||
40 | 16,24,8,24 | ||
41 | 17,24,9,24 | ||
42 | 16,24,9,24 | ||
43 | 17,24,7,24 | ||
44 | 16,24,8,24 | ||
45 | 16,24,8,24 | ||
46 | 16,24,8,24 | ||
47 | 16,24,8,24 | ||
48 | 16,24,8,24 | ||
49 | 16,24,9,24 | ||
50 | 16,24,9,24 | ||
51 | 16,24,9,24 | ||
52 | 16,24,9,24 | ||
53 | 17,24,9,24 | ||
54 | 16,24,8,24 | ||
55 | 16,24,8,24 | ||
56 | 16,24,8,24 | ||
57 | 17,24,9,24 | ||
58 | 16,24,9,24 | ||
59 | 16,24,9,24 | ||
60 | 16,24,9,24 | ||
61 | 16,32,8,32 | ||
62 | 16,32,8,32 | ||
63 | 16,32,8,32 | ||
64 | 16,32,8,32 | ||
65 | 17,32,9,32 | ||
66 | 16,32,9,32 | ||
67 | 16,32,9,32 | ||
68 | 16,32,9,32 | ||
69 | 16,24,8,24 | ||
70 | 16,24,8,24 | ||
71 | 16,24,7,24 | ||
72 | 16,32,8,32 | ||
73 | 16,32,8,32 | ||
74 | 16,32,8,32 | ||
75 | 16,32,8,32 | ||
76 | 16,32,8,32 | ||
77 | 16,32,8,32 | ||
78 | 16,32,8,32 | ||
79 | 16,32,8,32 | ||
80 | 16,24,8,24 | ||
81 | 16,24,8,24 | ||
82 | 16,24,8,24 | ||
83 | 16,24,8,24 | ||
84 | 16,24,8,24 | ||
85 | 16,24,8,24 | ||
86 | 16,24,8,24 | ||
87 | 16,24,8,24 | ||
88 | 17,32,9,32 | ||
89 | 16,32,8,32 | ||
90 | 16,32,8,32 | ||
91 | 16,32,8,32 | ||
92 | 17,32,8,32 | ||
93 | 16,32,8,32 | ||
94 | 16,32,8,32 | ||
95 | 16,32,8,32 | ||
96 | 17,24,9,24 | ||
97 | 16,24,8,24 | ||
98 | 16,24,8,24 | ||
99 | 16,24,8,24 | ||
100 | 17,24,8,24 | ||
101 | 16,24,8,24 | ||
102 | 16,24,8,24 | ||
103 | 16,24,8,24 | ||
104 | 16,24,8,24 | ||
105 | 16,24,8,24 | ||
106 | 16,24,8,24 | ||
107 | 16,24,8,24 | ||
108 | 16,24,8,24 | ||
109 | 16,24,8,24 | ||
110 | 16,24,8,24 | ||
111 | 16,24,8,24 | ||
112 | 16,24,8,24 | ||
113 | 16,24,8,24 | ||
114 | 16,24,8,24 | ||
115 | 16,24,8,24 | ||
116 | 16,24,8,24 | ||
117 | 16,24,8,24 | ||
118 | 16,24,8,24 | ||
119 | 16,24,8,24 | ||
120 | 16,24,8,24 | ||
121 | 32,32,16,32 | ||
122 | 32,32,16,32 | ||
123 | 32,32,16,32 | ||
124 | 32,32,16,32 | ||
125 | 32,24,16,24 | ||
126 | 32,24,16,24 | ||
127 | 16,24,8,24 | ||
128 | 16,32,8,33 | ||
129 | 16,32,8,32 | ||
130 | 16,32,8,31 | ||
131 | 16,32,8,33 | ||
132 | 16,32,8,32 | ||
133 | 16,32,8,31 | ||
134 | 17,32,9,33 | ||
135 | 17,32,9,32 | ||
136 | 17,32,9,31 | ||
137 | 17,32,12,14 | ||
138 | 17,32,12,14 | ||
139 | 16,32,9,15 | ||
140 | 16,32,9,15 | ||
141 | 16,32,5,15 | ||
142 | 16,32,5,15 | ||
143 | 16,32,5,15 | ||
144 | 16,32,5,15 | ||
145 | 16,32,3,16 | ||
146 | 16,32,3,16 | ||
147 | 16,32,4,16 | ||
148 | 16,32,4,16 | ||
149 | 16,32,6,18 | ||
150 | 16,32,6,18 | ||
151 | 16,32,8,18 | ||
152 | 16,32,8,18 | ||
153 | 16,32,8,20 | ||
154 | 16,32,8,20 | ||
155 | 16,32,10,16 | ||
156 | 16,32,10,16 | ||
157 | 32,24,16,6 | ||
158 | 32,24,20,10 | ||
159 | 32,16,26,8 | ||
160 | 32,24,22,21 | ||
161 | 16,32,8,25 | ||
162 | 32,24,10,21 | ||
163 | 32,16,6,10 | ||
164 | 32,24,12,10 | ||
165 | 16,32,9,32 | ||
166 | 32,32,17,32 | ||
167 | 32,24,17,24 | ||
168 | 16,24,9,24 | ||
169 | 32,32,17,32 | ||
170 | 17,32,9,32 | ||
171 | 32,32,17,32 | ||
172 | 16,32,8,29 | ||
173 | 16,32,8,29 | ||
174 | 16,32,8,29 | ||
175 | 16,32,8,29 | ||
176 | 16,24,8,21 | ||
177 | 16,24,8,21 | ||
178 | 16,32,8,29 | ||
179 | 16,32,8,29 | ||
180 | 16,32,8,29 | ||
181 | 16,32,8,29 | ||
182 | 16,32,8,29 | ||
183 | 16,32,8,29 | ||
184 | 16,32,8,29 | ||
185 | 16,32,8,29 | ||
186 | 16,32,8,29 | ||
187 | 32,32,16,32 | ||
188 | 32,32,16,29 | ||
189 | 32,32,16,29 | ||
190 | 32,32,16,29 | ||
191 | 32,32,16,29 | ||
192 | 32,32,16,32 | ||
193 | 32,32,16,32 | ||
194 | 16,32,8,32 | ||
195 | 16,32,8,32 | ||
196 | 16,32,8,32 | ||
197 | 16,32,9,32 | ||
198 | 16,32,9,32 | ||
199 | 16,32,9,35 | ||
200 | 16,32,9,35 | ||
201 | 16,32,6,36 | ||
202 | 16,32,6,36 | ||
203 | 16,32,2,36 | ||
204 | 16,32,2,36 | ||
205 | 16,32,2,36 | ||
206 | 16,32,2,36 | ||
207 | 16,32,0,37 | ||
208 | 16,32,0,37 | ||
209 | 16,32,1,37 | ||
210 | 16,32,1,37 | ||
211 | 16,32,3,39 | ||
212 | 16,32,3,39 | ||
213 | 16,32,5,39 | ||
214 | 16,32,5,39 | ||
215 | 16,32,5,41 | ||
216 | 16,32,5,41 | ||
217 | 16,32,7,37 | ||
218 | 16,32,7,37 | ||
219 | 16,32,4,14 | ||
220 | 16,32,4,14 | ||
221 | 16,32,7,15 | ||
222 | 16,32,7,15 | ||
223 | 16,32,11,15 | ||
224 | 16,32,11,15 | ||
225 | 16,32,11,15 | ||
226 | 16,32,11,15 | ||
227 | 16,32,13,16 | ||
228 | 16,32,13,16 | ||
229 | 16,32,12,16 | ||
230 | 16,32,12,16 | ||
231 | 16,32,10,18 | ||
232 | 16,32,10,18 | ||
233 | 16,32,8,18 | ||
234 | 16,32,8,18 | ||
235 | 16,32,8,20 | ||
236 | 16,32,8,20 | ||
237 | 16,32,6,16 | ||
238 | 16,32,6,16 | ||
239 | 16,32,9,32 | ||
240 | 16,32,8,32 | ||
241 | 16,32,8,32 | ||
242 | 16,32,8,32 | ||
243 | 16,32,8,32 | ||
244 | 32,16,16,16 | ||
245 | 16,32,10,28 | ||
246 | 16,32,7,32 | ||
247 | 16,32,8,32 | ||
248 | 32,32,16,32 | ||
249 | 32,32,16,32 | ||
250 | 16,32,9,32 | ||
251 | 32,32,9,32 | ||
252 | 32,32,17,32 | ||
253 | 32,32,17,32 | ||
254 | 32,32,17,32 | ||
255 | 16,32,8,32 | ||
256 | 16,32,8,32 | ||
257 | 16,32,9,32 | ||
258 | 16,32,9,32 | ||
259 | 16,32,8,32 | ||
260 | 16,32,8,32 | ||
261 | 16,32,8,32 | ||
262 | 16,32,8,31 | ||
263 | 16,32,8,32 | ||
264 | 17,39,9,40 | ||
265 | 17,54,9,56 | ||
266 | 17,53,9,55 | ||
267 | 17,64,9,70 | ||
268 | 18,63,6,69 | ||
269 | 17,64,7,70 | ||
270 | 18,64,7,70 | ||
271 | 17,64,9,70 | ||
272 | 16,64,8,70 | ||
273 | 17,63,9,69 | ||
274 | 18,64,11,70 | ||
275 | 16,63,9,68 | ||
276 | 17,64,11,70 | ||
277 | 16,63,12,69 | ||
278 | 17,39,9,40 | ||
279 | 17,38,9,39 | ||
280 | 17,37,9,37 | ||
281 | 16,40,8,40 | ||
282 | 16,37,8,37 | ||
283 | 17,53,9,77 | ||
284 | 17,45,9,83 | ||
285 | 17,36,9,86 | ||
286 | 16,32,9,87 | ||
287 | 16,23,8,86 | ||
288 | 32,24,16,89 | ||
289 | 17,24,8,94 | ||
290 | 32,32,16,101 | ||
291 | 17,24,8,95 | ||
292 | 32,32,16,100 | ||
293 | 32,24,17,89 | ||
294 | 32,24,17,85 | ||
295 | 32,24,17,79 | ||
296 | 32,18,19,65 | ||
297 | 32,16,19,60 | ||
298 | 32,16,18,60 | ||
299 | 32,16,18,15 | ||
300 | 32,24,14,22 | ||
301 | 16,24,8,24 | ||
302 | 16,24,9,23 | ||
303 | 16,24,10,24 | ||
304 | 16,32,8,32 | ||
305 | 16,32,8,32 | ||
306 | 16,32,8,32 | ||
307 | 16,24,8,24 | ||
308 | 16,24,8,24 | ||
309 | 18,32,11,32 | ||
310 | 17,24,10,24 | ||
311 | 18,32,11,32 | ||
312 | 17,24,10,24 | ||
313 | 16,32,11,32 | ||
314 | 17,24,11,24 | ||
315 | 16,32,11,32 | ||
316 | 17,24,11,24 | ||
317 | 16,32,13,32 | ||
318 | 16,32,15,32 | ||
319 | 16,32,17,33 | ||
320 | 16,32,19,33 | ||
321 | 17,24,21,26 | ||
322 | 17,24,23,26 | ||
323 | 17,24,25,27 | ||
324 | 17,24,27,28 | ||
325 | 16,32,29,36 | ||
326 | 16,32,31,37 | ||
327 | 16,32,33,38 | ||
328 | 16,32,35,39 | ||
329 | 16,32,37,39 | ||
330 | 16,32,39,38 | ||
331 | 16,32,41,37 | ||
332 | 16,32,43,36 | ||
333 | 16,32,43,35 | ||
334 | 16,32,45,34 | ||
335 | 16,32,46,33 | ||
336 | 16,32,48,32 | ||
337 | 16,32,50,30 | ||
338 | 16,32,52,28 | ||
339 | 16,32,53,25 | ||
340 | 16,32,54,22 | ||
341 | 16,32,55,20 | ||
342 | 16,32,56,17 | ||
343 | 17,32,57,11 | ||
344 | 17,32,57,6 | ||
345 | 17,32,59,1 | ||
346 | 16,32,8,32 | ||
347 | 16,32,8,32 | ||
348 | 16,32,8,32 | ||
349 | 16,32,8,32 | ||
350 | 16,32,8,32 | ||
351 | 16,32,8,32 | ||
352 | 16,32,8,32 | ||
353 | 16,32,8,32 | ||
354 | 16,24,8,24 | ||
355 | 16,32,8,32 | ||
356 | 32,32,16,32 | ||
357 | 32,32,16,32 | ||
358 | 32,32,16,32 | ||
359 | 32,32,16,32 | ||
360 | 32,32,16,32 | ||
361 | 8,8,4,8 | ||
362 | 8,8,4,8 | ||
363 | 8,8,3,8 | ||
364 | 16,32,8,32 | ||
365 | 32,32,16,32 | ||
366 | 32,32,16,32 | ||
367 | 32,32,16,32 | ||
368 | 16,24,8,18 | ||
369 | 16,24,8,18 | ||
370 | 16,24,8,18 | ||
371 | 16,24,8,18 | ||
372 | 16,24,8,18 | ||
373 | 16,32,8,26 | ||
374 | 16,32,8,26 | ||
375 | 16,32,8,26 | ||
376 | 16,32,8,26 | ||
377 | 16,32,8,26 | ||
378 | 16,32,8,26 | ||
379 | 16,32,8,26 | ||
380 | 16,32,8,26 | ||
381 | 16,32,8,26 | ||
382 | 32,32,16,26 | ||
383 | 32,32,16,26 | ||
384 | 32,32,16,26 | ||
385 | 32,32,16,26 | ||
386 | 32,32,16,26 | ||
387 | 32,32,16,26 | ||
388 | 32,32,16,26 | ||
389 | 16,32,8,26 | ||
390 | 32,16,16,12 | ||
391 | 16,32,8,32 | ||
392 | 16,32,9,32 | ||
393 | 17,32,8,32 | ||
394 | 16,24,10,26 | ||
395 | 16,24,10,26 | ||
396 | 16,24,11,26 | ||
397 | 16,24,11,26 | ||
398 | 16,31,10,33 | ||
399 | 16,32,9,34 | ||
400 | 16,32,8,34 | ||
401 | 16,24,9,25 | ||
402 | 16,24,9,24 | ||
403 | 16,32,8,32 | ||
diff --git a/src/main.cpp b/src/main.cpp index f9db18d..65b322e 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -12,6 +12,8 @@ void loop(Renderer& renderer) { | |||
12 | int lucasSprite = game.addSprite(Sprite("../res/lucas_anim.txt", renderer)); | 12 | int lucasSprite = game.addSprite(Sprite("../res/lucas_anim.txt", renderer)); |
13 | int lucasSprite2 = game.addSprite(Sprite("../res/lucas_anim.txt", renderer)); | 13 | int lucasSprite2 = game.addSprite(Sprite("../res/lucas_anim.txt", renderer)); |
14 | 14 | ||
15 | game.moveSprite(lucasSprite, {32,32}); | ||
16 | |||
15 | Party party; | 17 | Party party; |
16 | party.addMember(game, lucasSprite); | 18 | party.addMember(game, lucasSprite); |
17 | party.addMember(game, lucasSprite2); | 19 | party.addMember(game, lucasSprite2); |
diff --git a/src/renderer.cpp b/src/renderer.cpp index 18b8ed8..931e699 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -49,8 +49,9 @@ void Renderer::render(Game& game) { | |||
49 | SDL_RenderClear(ren_.get()); | 49 | SDL_RenderClear(ren_.get()); |
50 | 50 | ||
51 | for (const Sprite& sprite : game.getSpritesByY() | game.spriteView()) { | 51 | for (const Sprite& sprite : game.getSpritesByY() | game.spriteView()) { |
52 | SDL_Rect src { sprite.getFrame() * sprite.size().w(), 0, sprite.size().w(), sprite.size().h() }; | 52 | const SpriteFrame& frame = sprite.getFrame(); |
53 | SDL_Rect dest { sprite.loc().x(), sprite.loc().y(), sprite.size().w(), sprite.size().h() }; | 53 | const SDL_Rect& src = frame.srcRect; |
54 | SDL_Rect dest { sprite.loc().x() - frame.center.x(), sprite.loc().y() - frame.center.y(), frame.size.w(), frame.size.h() }; | ||
54 | SDL_RenderCopy(ren_.get(), textures_.at(sprite.getTextureId()).get(), &src, &dest); | 55 | SDL_RenderCopy(ren_.get(), textures_.at(sprite.getTextureId()).get(), &src, &dest); |
55 | } | 56 | } |
56 | 57 | ||
diff --git a/src/sprite.cpp b/src/sprite.cpp index c52807a..b84f4ce 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp | |||
@@ -12,14 +12,53 @@ Sprite::Sprite(std::string_view filename, Renderer& renderer) { | |||
12 | } | 12 | } |
13 | 13 | ||
14 | char ch; | 14 | char ch; |
15 | std::string line; | ||
15 | 16 | ||
16 | std::string imagename; | 17 | std::string imagename; |
17 | datafile >> imagename; | 18 | datafile >> imagename; |
18 | textureId_ = renderer.loadImageFromFile(imagename); | 19 | textureId_ = renderer.loadImageFromFile(imagename); |
19 | 20 | ||
20 | datafile >> size_.w(); | 21 | std::string framefilename; |
21 | datafile >> ch; //, | 22 | datafile >> framefilename; |
22 | datafile >> size_.h(); | 23 | |
24 | std::ifstream framefile(framefilename); | ||
25 | if (!framefile.is_open()) { | ||
26 | throw std::invalid_argument("Could not find frame datafile: " + framefilename); | ||
27 | } | ||
28 | |||
29 | vec2i cellSize; | ||
30 | framefile >> cellSize.w(); | ||
31 | framefile >> ch; //, | ||
32 | framefile >> cellSize.h(); | ||
33 | std::getline(framefile, line); // cell size | ||
34 | |||
35 | int framesPerRow; | ||
36 | framefile >> framesPerRow; | ||
37 | std::getline(framefile, line); // frames per row | ||
38 | |||
39 | int numFrames; | ||
40 | framefile >> numFrames; | ||
41 | std::getline(framefile, line); // frames | ||
42 | std::getline(framefile, line); // blank | ||
43 | |||
44 | for (int i=0; i<numFrames; i++) { | ||
45 | SpriteFrame f; | ||
46 | framefile >> f.size.w(); | ||
47 | framefile >> ch; //, | ||
48 | framefile >> f.size.h(); | ||
49 | framefile >> ch; //, | ||
50 | framefile >> f.center.x(); | ||
51 | framefile >> ch; //, | ||
52 | framefile >> f.center.y(); | ||
53 | std::getline(framefile, line); // blank | ||
54 | |||
55 | f.srcRect.x = (i % framesPerRow) * cellSize.w(); | ||
56 | f.srcRect.y = (i / framesPerRow) * cellSize.h(); | ||
57 | f.srcRect.w = f.size.w(); | ||
58 | f.srcRect.h = f.size.h(); | ||
59 | |||
60 | frames_.push_back(std::move(f)); | ||
61 | } | ||
23 | 62 | ||
24 | std::string animLine; | 63 | std::string animLine; |
25 | std::getline(datafile, animLine); // blank | 64 | std::getline(datafile, animLine); // blank |
diff --git a/src/sprite.h b/src/sprite.h index 82ea90c..dc26fad 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
@@ -8,6 +8,12 @@ | |||
8 | #include "renderer.h" | 8 | #include "renderer.h" |
9 | #include "vector.h" | 9 | #include "vector.h" |
10 | 10 | ||
11 | struct SpriteFrame { | ||
12 | SDL_Rect srcRect; | ||
13 | vec2i center; | ||
14 | vec2i size; | ||
15 | }; | ||
16 | |||
11 | class Sprite { | 17 | class Sprite { |
12 | public: | 18 | public: |
13 | 19 | ||
@@ -21,11 +27,7 @@ public: | |||
21 | 27 | ||
22 | vec2i& loc() { return loc_; } | 28 | vec2i& loc() { return loc_; } |
23 | 29 | ||
24 | const vec2i& size() const { return size_; } | 30 | const SpriteFrame& getFrame() const { return frames_.at(animations_[curAnim_][curFrame_]); } |
25 | |||
26 | vec2i& size() { return size_; } | ||
27 | |||
28 | int getFrame() const { return animations_[curAnim_][curFrame_]; } | ||
29 | 31 | ||
30 | void setDirection(Direction dir); | 32 | void setDirection(Direction dir); |
31 | 33 | ||
@@ -41,11 +43,11 @@ private: | |||
41 | 43 | ||
42 | int textureId_; | 44 | int textureId_; |
43 | vec2i loc_ { 0, 0 }; | 45 | vec2i loc_ { 0, 0 }; |
44 | vec2i size_; | ||
45 | Direction curDir_ = Direction::down; | 46 | Direction curDir_ = Direction::down; |
46 | std::string state_; | 47 | std::string state_; |
47 | int curAnim_ = 0; | 48 | int curAnim_ = 0; |
48 | int curFrame_ = 0; | 49 | int curFrame_ = 0; |
50 | std::vector<SpriteFrame> frames_; | ||
49 | std::vector<std::vector<int>> animations_; | 51 | std::vector<std::vector<int>> animations_; |
50 | std::map<std::string, std::map<Direction, int>> stateDirToAnim_; | 52 | std::map<std::string, std::map<Direction, int>> stateDirToAnim_; |
51 | }; | 53 | }; |