-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuyoAnimations.cpp
377 lines (342 loc) · 10.3 KB
/
PuyoAnimations.cpp
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* FloboPuyo
* Copyright (C) 2004
* Florent Boudet <flobo@ios-software.com>,
* Jean-Christophe Hoelt <jeko@ios-software.com>,
* Guillaume Borios <gyom@ios-software.com>
*
* iOS Software <http://www.ios-software.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*/
#include "PuyoAnimations.h"
#include "AnimatedPuyo.h"
#include "PuyoView.h"
#include "IosImgProcess.h"
#include "SDL_Painter.h"
extern "C" {
#include "audio.h"
}
/* not clean, but basta */
extern SDL_Painter painter;
extern IIM_Surface *puyoEyes;
extern IIM_Surface *puyoEye[3];
extern IIM_Surface *puyoEyesSwirl[4];
extern IIM_Surface *shrinkingPuyo[5][5];
extern IIM_Surface *explodingPuyo[5][5];
/* Base class implementation */
Animation::Animation()
{
finishedFlag = false;
enabled = true;
}
bool Animation::isFinished() const
{
return finishedFlag;
}
bool Animation::isEnabled() const
{
return enabled;
}
/* Neutral falling animation */
IIM_Surface *NeutralAnimation::neutral = NULL;
NeutralAnimation::NeutralAnimation(AnimatedPuyo &puyo, int delay) : PuyoAnimation(puyo)
{
if (neutral == NULL) {
neutral = PuyoView::getSurfaceForState(PUYO_NEUTRAL);
}
this->X = attachedPuyo.getScreenCoordinateX();
this->Y = attachedPuyo.getScreenCoordinateY();
this->currentY = attachedPuyo.getAttachedView()->getScreenCoordinateY(0);
step = 0;
this->delay = delay;
attachedPuyo.getAttachedView()->disallowCycle();
}
void NeutralAnimation::cycle()
{
if (delay >=0) {
delay--;
}
else {
currentY += (int)step;
step += 0.5;
if (currentY >= Y) {
audio_sound_play(sound_bim[random() % 2]);
finishedFlag = true;
attachedPuyo.getAttachedView()->allowCycle();
}
}
}
void NeutralAnimation::draw(int)
{
SDL_Rect drect;
drect.x = X;
drect.y = currentY;
drect.w = neutral->w;
drect.h = neutral->h;
painter.requestDraw(neutral, &drect);
}
/* Animation synchronization helper */
AnimationSynchronizer::AnimationSynchronizer()
{
currentCounter = 0;
currentUsage = 0;
}
void AnimationSynchronizer::push()
{
currentCounter++;
}
void AnimationSynchronizer::pop()
{
currentCounter--;
}
bool AnimationSynchronizer::isSynchronized()
{
return (currentCounter <= 0);
}
void AnimationSynchronizer::incrementUsage()
{
currentUsage++;
}
void AnimationSynchronizer::decrementUsage()
{
currentUsage--;
if (currentUsage == 0)
delete this;
}
/* Companion turning around main puyo animation */
TurningAnimation::TurningAnimation(AnimatedPuyo &companionPuyo, int vector,
bool counterclockwise) : PuyoAnimation(companionPuyo)
{
this->counterclockwise = counterclockwise;
companionVector = vector;
targetSurface = attachedPuyo.getAttachedView()->getSurfaceForPuyo(&attachedPuyo);
cpt = 0;
angle = 0;
step = (3.14 / 2) / 4;
}
void TurningAnimation::cycle()
{
if (cpt == 0) {
audio_sound_play(sound_fff);
}
cpt++;
angle += step;
if (cpt == 4)
finishedFlag = true;
}
void TurningAnimation::draw(int semiMove)
{
if (targetSurface == NULL)
return;
X = attachedPuyo.getScreenCoordinateX();
Y = attachedPuyo.getScreenCoordinateY();
float offsetA = sin(angle) * TSIZE;
float offsetB = cos(angle) * TSIZE * (counterclockwise ? -1 : 1);
SDL_Rect drect, drect2;
drect.w = targetSurface->w;
drect.h = targetSurface->h;
drect.y = -semiMove * TSIZE / 2;
switch (companionVector) {
case 0:
drect.x = (short)(X - offsetB);
drect.y += (short)(Y + offsetA - TSIZE);
break;
case 1:
drect.x = (short)(X - offsetA + TSIZE);
drect.y += (short)(Y - offsetB);
break;
case 2:
drect.x = (short)(X + offsetB);
drect.y += (short)(Y - offsetA + TSIZE);
break;
case 3:
drect.x = (short)(X + offsetA - TSIZE);
drect.y += (short)(Y + offsetB);
break;
case -3:
drect.x = (short)(X + offsetB);
drect.y += (short)(Y + offsetA - TSIZE);
break;
}
drect2 = drect;
painter.requestDraw(targetSurface, &drect);
painter.requestDraw(puyoEyes, &drect2);
}
/* Puyo falling and bouncing animation */
const int FallingAnimation::BOUNCING_OFFSET_NUM = 12;
const int FallingAnimation::BOUNCING_OFFSET[] = { -1, -3, -5, -4, -2, 0, -6, -9, -11, -9, -6, 0 };
FallingAnimation::FallingAnimation(AnimatedPuyo &puyo, int originY, int xOffset, int yOffset) : PuyoAnimation(puyo)
{
this->xOffset = xOffset;
this->yOffset = yOffset;
this->step = 0/*step*/;
this->X = (attachedPuyo.getPuyoX()*TSIZE) + xOffset;
this->Y = (originY*TSIZE) + yOffset;
puyoFace = PuyoView::getSurfaceForState(attachedPuyo.getPuyoState());
bouncing = BOUNCING_OFFSET_NUM - 1;
if (originY == attachedPuyo.getPuyoY()) {
bouncing = -1;
}
attachedPuyo.getAttachedView()->disallowCycle();
}
void FallingAnimation::cycle()
{
Y += step++;
if (Y >= (attachedPuyo.getPuyoY()*TSIZE) + yOffset)
{
bouncing--;
if (bouncing < 0) {
finishedFlag = true;
audio_sound_play(sound_bam1);
attachedPuyo.getAttachedView()->allowCycle();
}
else {
if (BOUNCING_OFFSET[bouncing] == 0)
audio_sound_play(sound_bam1);
}
Y = (attachedPuyo.getPuyoY()*TSIZE) + yOffset;
}
}
void FallingAnimation::draw(int)
{
if (puyoFace) {
SDL_Rect drect;
drect.x = X;
drect.y = Y + (bouncing>=0?BOUNCING_OFFSET[bouncing]:0);
// drect.y = -semiMove() * TSIZE / 2;
drect.w = puyoFace->w;
drect.h = puyoFace->h;
painter.requestDraw(puyoFace, &drect);
if (attachedPuyo.getPuyoState() != PUYO_NEUTRAL)
painter.requestDraw(puyoEyesSwirl[(bouncing/2)%4], &drect);
}
}
/* Puyo exploding and vanishing animation */
VanishAnimation::VanishAnimation(AnimatedPuyo &puyo, int delay, int xOffset, int yOffset, AnimationSynchronizer *synchronizer) : PuyoAnimation(puyo)
{
puyoFace = PuyoView::getSurfaceForState(attachedPuyo.getPuyoState());
this->xOffset = xOffset;
this->yOffset = yOffset;
this->X = (attachedPuyo.getPuyoX()*TSIZE) + xOffset;
this->Y = (attachedPuyo.getPuyoY()*TSIZE) + yOffset;
this->color = attachedPuyo.getPuyoState();
if (color > PUYO_EMPTY)
color -= PUYO_BLUE;
iter = 0;
once = false;
enabled = false;
this->synchronizer = synchronizer;
synchronizer->incrementUsage();
synchronizer->push();
this->delay = delay;
attachedPuyo.getAttachedView()->disallowCycle();
}
VanishAnimation::~VanishAnimation()
{
synchronizer->decrementUsage();
}
void VanishAnimation::cycle()
{
if (once == false) {
once = true;
synchronizer->pop();
}
else if (synchronizer->isSynchronized()) {
enabled = true;
iter ++;
if (iter == 20 + delay) {
attachedPuyo.getAttachedView()->allowCycle();
}
else if (iter == 50 + delay) {
finishedFlag = true;
attachedPuyo.setVisible(false);
}
}
}
void VanishAnimation::draw(int)
{
if (iter < (10 + delay)) {
if (puyoFace && (iter % 2 == 0)) {
SDL_Rect drect;
drect.x = X;
drect.y = Y;
drect.w = puyoFace->w;
drect.h = puyoFace->h;
painter.requestDraw(puyoFace, &drect);
if (color != PUYO_NEUTRAL)
painter.requestDraw(puyoEyes, &drect);
}
}
else {
if (puyoFace) {
SDL_Rect drect, xrect;
drect.x = X;
drect.y = Y;// + (2.5 * pow(iter - 16, 2) - 108);
drect.w = puyoFace->w;
drect.h = puyoFace->h;
int iter2 = iter - 10 - delay;
int shrinkingImage = (iter - 10 - delay) / 4;
if (shrinkingImage < 4) {
painter.requestDraw(shrinkingPuyo[shrinkingImage][color], &drect);
int xrectY = Y + (int)(2.5 * pow(iter - 16 - delay, 2) - 108);
xrect.w = explodingPuyo[shrinkingImage][color]->w;
xrect.h = explodingPuyo[shrinkingImage][color]->h;
xrect.x = X - iter2 * iter2;
xrect.y = xrectY;
painter.requestDraw(explodingPuyo[shrinkingImage][color], &xrect);
xrect.x = X - iter2;
xrect.y = xrectY + iter2;
painter.requestDraw(explodingPuyo[shrinkingImage][color], &xrect);
xrect.x = X + iter2;
xrect.y = xrectY + iter2;
painter.requestDraw(explodingPuyo[shrinkingImage][color], &xrect);
xrect.x = X + iter2 * iter2;
xrect.y = xrectY;
painter.requestDraw(explodingPuyo[shrinkingImage][color], &xrect);
}
}
}
}
VanishSoundAnimation::VanishSoundAnimation(int phase, AnimationSynchronizer *synchronizer)
{
once = false;
step = 0;
this->phase = phase;
this->synchronizer = synchronizer;
synchronizer->incrementUsage();
synchronizer->push();
}
VanishSoundAnimation::~VanishSoundAnimation()
{
synchronizer->decrementUsage();
}
void VanishSoundAnimation::cycle()
{
if (once == false) {
once = true;
synchronizer->pop();
}
else if (synchronizer->isSynchronized()) {
step++;
if (step == 1) {
audio_sound_play(sound_splash[phase>7?7:phase]);
finishedFlag = true;
}
}
}
void VanishSoundAnimation::draw(int)
{
// do nothing
}