-
Notifications
You must be signed in to change notification settings - Fork 36
/
screeneffect.cpp
284 lines (238 loc) · 5.45 KB
/
screeneffect.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
#include "nx.h"
#include "screeneffect.h"
#include "screeneffect.fdh"
SE_FlashScreen flashscreen;
SE_Starflash starflash;
SE_Fade fade;
/*
void c------------------------------() {}
*/
// FlashScreen simply flashes the screen white several times,
// and is used in various places, such as when Misery casts spells.
void SE_FlashScreen::Start(void)
{
timer = -1;
flashes_left = 5;
flashstate = true;
enabled = true;
}
void SE_FlashScreen::Draw(void)
{
if (++timer >= 2)
{
timer = 0;
flashstate ^= 1;
if (!flashstate)
{
if (--flashes_left <= 0)
enabled = false;
}
}
if (flashstate)
ClearScreen(0xff, 0xff, 0xff);
}
/*
void c------------------------------() {}
*/
// Starflash is a full-screen white explosion in the shape of a '+',
// used when some bosses are defeated.
void SE_Starflash::Start(int x, int y)
{
sound(SND_EXPLOSION1);
enabled = true;
state = 0;
centerx = x;
centery = y;
size = speed = 0;
}
void SE_Starflash::Draw(void)
{
SE_Starflash * const &star = this;
int scr_x1, scr_y1, scr_x2, scr_y2;
int rel_x, rel_y;
if (state == 0)
{ // flash getting bigger
star->speed += (1 << CSF);
star->size += star->speed;
}
else
{ // flash getting smaller
star->size -= (star->size >> 3);
if (star->size < 255)
{
enabled = false;
return;
}
}
// draw the flash
rel_x = (star->centerx - map.displayed_xscroll);
rel_y = (star->centery - map.displayed_yscroll);
// draw a horizontal bar
scr_y1 = (rel_y - star->size) >> CSF;
scr_y2 = (rel_y + star->size) >> CSF;
FillRect(0, scr_y1, SCREEN_WIDTH, scr_y2, 255, 255, 255);
if (star->state == 0)
{
// draw a vertical bar
scr_x1 = (rel_x - starflash.size) >> CSF;
scr_x2 = (rel_x + starflash.size) >> CSF;
FillRect(scr_x1, 0, scr_x2, SCREEN_HEIGHT, 255, 255, 255);
// once it's big enough, switch to making it smaller
if (star->size > (1280<<CSF))
{
star->size = (SCREEN_HEIGHT << CSF);
star->state = 1;
}
}
}
/*
void c------------------------------() {}
*/
#define FADE_LAST_FRAME 15
// Fade is the fade-in/out used on every stage transistion/TRA.
// Unlike other effects, it is drawn underneath the textboxes and Nikumaru counter,
// and so isn't drawn from ScreenEffects::Draw().
SE_Fade::SE_Fade()
{
state = FS_NO_FADE;
enabled = false;
}
// start a fade in or out.
// fadedir: either FADE_IN or FADE_OUT
// sweepdir: direction to "sweep" the fade
// spr: the sprite to use for the fading
void SE_Fade::Start(int fadedir, int sweepdir, int spr)
{
if (fadedir == FADE_OUT)
{
// when fading out, the directions are reversed
switch(sweepdir)
{
case FADE_LEFT: sweepdir = FADE_RIGHT; break;
case FADE_RIGHT: sweepdir = FADE_LEFT; break;
case FADE_UP: sweepdir = FADE_DOWN; break;
case FADE_DOWN: sweepdir = FADE_UP; break;
}
}
state = FS_FADING;
enabled = true;
fade.sprite = spr;
fade.fadedir = fadedir;
fade.sweepdir = sweepdir;
fade.curframe = (fadedir == FADE_OUT) ? -FADE_LAST_FRAME : FADE_LAST_FRAME;
}
void SE_Fade::Draw(void)
{
int x, y;
#define DRAW_VCOLUMN \
{ \
if (frame >= 0) \
{ \
if (frame > FADE_LAST_FRAME) frame = FADE_LAST_FRAME; \
\
for(y=0;y<SCREEN_HEIGHT;y+=16) \
draw_sprite(x, y, fade.sprite, frame); \
} \
}
#define DRAW_HROW \
{ \
if (frame >= 0) \
{ \
if (frame > FADE_LAST_FRAME) frame = FADE_LAST_FRAME; \
\
for(x=0;x<SCREEN_WIDTH;x+=16) \
draw_sprite(x, y, fade.sprite, frame); \
} \
}
if (state == FS_NO_FADE)
{
return;
}
else if (state == FS_FADED_OUT)
{
ClearScreen(DK_BLUE);
return;
}
int frame = fade.curframe;
switch(fade.sweepdir)
{
case FADE_RIGHT:for(x=0;x<SCREEN_WIDTH;x+=16) { DRAW_VCOLUMN; frame++; } break;
case FADE_LEFT: for(x=SCREEN_WIDTH-1;x>=-16;x-=16) { DRAW_VCOLUMN; frame++; } break;
case FADE_DOWN: for(y=0;y<SCREEN_HEIGHT;y+=16) { DRAW_HROW; frame++; } break;
case FADE_UP: for(y=SCREEN_HEIGHT-1;y>=-16;y-=16) { DRAW_HROW; frame++; } break;
case FADE_CENTER:
{
int startframe = fade.curframe;
int centerx = (SCREEN_WIDTH/2)-8;
int centery = (SCREEN_HEIGHT/2)-8;
for(x=0;x<centerx+16;x+=16)
{
frame = startframe;
for(y=0;y<centery+16;y+=16)
{
if (frame >= 0)
{
if (frame > FADE_LAST_FRAME) frame = FADE_LAST_FRAME;
draw_sprite(centerx+x, centery+y, fade.sprite, frame);
draw_sprite(centerx-x, centery+y, fade.sprite, frame);
draw_sprite(centerx+x, centery-y, fade.sprite, frame);
draw_sprite(centerx-x, centery-y, fade.sprite, frame);
}
frame++;
}
startframe++;
}
}
break;
}
if (fade.fadedir == FADE_OUT)
{
fade.curframe++;
if (fade.curframe > FADE_LAST_FRAME)
state = FS_FADED_OUT;
}
else
{ // fading in--terminate fade when done
fade.curframe--;
if (fade.curframe < -20)
{
state = FS_NO_FADE;
enabled = false;
}
}
}
void SE_Fade::set_full(int dir)
{
if (dir == FADE_OUT)
{
state = FS_FADED_OUT;
fade.fadedir = FADE_OUT;
fade.sweepdir = FADE_RIGHT; // doesn't matter
fade.curframe = FADE_LAST_FRAME;
fade.sprite = SPR_FADE_DIAMOND;
}
else
{
state = FS_NO_FADE;
enabled = false;
}
}
int SE_Fade::getstate(void)
{
return this->state;
}
/*
void c------------------------------() {}
*/
void ScreenEffects::Draw(void)
{
if (starflash.enabled)
starflash.Draw();
if (flashscreen.enabled)
flashscreen.Draw();
}
void ScreenEffects::Stop()
{
starflash.enabled = false;
flashscreen.enabled = false;
}