1 /************************************************************************
2 * This file is part of Wizznic. *
3 * Copyright 2009-2015 Jimmy Christensen <dusted@dusted.dk> *
4 * Wizznic is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * Wizznic is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with Wizznic. If not, see <http://www.gnu.org/licenses/>. *
16 ************************************************************************/
17
18 #include "transition.h"
19 #include "pixel.h"
20 #include "ticks.h"
21 #include "list/list.h"
22 #include "particles.h"
23
24 struct transition_s {
25 SDL_Surface* sur;
26 int_fast8_t type;
27 int time;
28 int timeLeft;
29 int_fast8_t reverse;
30 };
31
32 typedef struct transition_s transition_t;
33
34 transition_t t;
35
initTransition()36 void initTransition()
37 {
38 t.sur=NULL;
39 t.timeLeft=0;
40 t.time=0;
41 t.sur=NULL;
42 }
43
44 #define _TRANSITION_TYPE_ROLL 253
45
startTransition(SDL_Surface * scr,uint_fast8_t type,uint_fast16_t time)46 void startTransition(SDL_Surface* scr, uint_fast8_t type, uint_fast16_t time)
47 {
48 struct psysSet_s psys;
49
50 t.type=(type==TRANSITION_TYPE_RANDOM)?rand()%NUM_TRANSITIONS:type;
51 t.time=time;
52 t.timeLeft=t.time;
53 t.reverse=0;
54
55 if( t.sur != NULL )
56 {
57 SDL_FreeSurface(t.sur);
58 }
59
60 switch( t.type )
61 {
62 case TRANSITION_TYPE_DISSOLVE:
63 clearParticles();
64 psys.bounce=0;
65 psys.fade=0;
66 psys.gravity=0;
67 psys.layer=PSYS_LAYER_TOP;
68 psys.life=time;
69 psys.lifeVar=time;
70 psys.srcImg=scr;
71 psys.x=(HSCREENW-160);
72 psys.y=(HSCREENH-120);
73 psys.srcRect.x=(HSCREENW-160);
74 psys.srcRect.y=(HSCREENH-120);
75 psys.srcRect.w=320;
76 psys.srcRect.h=240;
77 psys.vel=0;
78
79 spawnParticleSystem(&psys);
80 break;
81 case TRANSITION_TYPE_ROLL_IN:
82 case TRANSITION_TYPE_CURTAIN_DOWN:
83 t.reverse=1;
84 t.sur = SDL_ConvertSurface( scr, scr->format, scr->flags );
85 t.sur->flags=0x00;
86 break;
87 case TRANSITION_TYPE_ROLL_OUT:
88 case TRANSITION_TYPE_CURTAIN_UP:
89 t.sur = SDL_ConvertSurface( scr, scr->format, scr->flags );
90 //Some surfaces has flags set that prevent propper blitting
91 t.sur->flags=0x00;
92 break;
93 }
94 }
95
runTransition(SDL_Surface * scr)96 void runTransition(SDL_Surface* scr)
97 {
98 int x;
99 if( t.timeLeft == 0 )
100 return;
101
102 t.timeLeft -= getTicks();
103 if( t.timeLeft < 1 )
104 t.timeLeft=0;
105
106 SDL_Rect r,rr;
107 SDL_Surface* tmpSurf;
108
109 switch(t.type)
110 {
111 case TRANSITION_TYPE_CURTAIN_UP:
112 case TRANSITION_TYPE_CURTAIN_DOWN:
113 rr.x=(HSCREENW-160);
114 x=((float)(t.timeLeft)/(float)(t.time))*(float)(240);
115
116 r.x=(HSCREENW-160);
117 r.w=(320);
118
119
120 if( !t.reverse )
121 {
122 r.h=x;
123 r.y=(HSCREENH-120);
124 rr.y=(HSCREENH-120);
125 } else {
126 r.h=HSCREENH+120;
127 r.y=HSCREENH+120-x;
128 rr.y=HSCREENH+120-x;
129 }
130 SDL_BlitSurface(t.sur, &r, scr, &rr );
131 break;
132 case TRANSITION_TYPE_DISSOLVE:
133 runParticles(scr);
134 break;
135 case TRANSITION_TYPE_ROLL_IN:
136 x=((float)(t.timeLeft)/(float)(t.time))*(float)(320);
137
138 tmpSurf = SDL_ConvertSurface( scr, scr->format, scr->flags );
139 tmpSurf->flags=0x00;
140 r.y=(HSCREENH-120);
141 rr.y=(HSCREENH-120);
142 r.h=240;
143 rr.h=240;
144
145 rr.x=HSCREENW+160-x;
146 r.x = (HSCREENW-160);
147 r.w = x;
148 SDL_BlitSurface(t.sur, &r, scr, &rr );
149
150 rr.x=HSCREENW-160;
151 r.x = HSCREENW-160+x;
152 r.w = 320-x;
153 SDL_BlitSurface(tmpSurf,&r, scr, &rr );
154
155 SDL_FreeSurface(tmpSurf);
156 break;
157
158 case TRANSITION_TYPE_ROLL_OUT:
159 x=((float)(t.timeLeft)/(float)(t.time))*(float)(320);
160
161 tmpSurf = SDL_ConvertSurface( scr, scr->format, scr->flags );
162 tmpSurf->flags=0x00;
163 r.y=(HSCREENH-120);
164 rr.y=(HSCREENH-120);
165 r.h=240;
166 rr.h=240;
167
168 rr.x=HSCREENW-160;
169 r.x = (HSCREENW+160)-x;
170 r.w = x;
171 SDL_BlitSurface(t.sur, &r, scr, &rr );
172
173 rr.x=HSCREENW-160+x;
174 r.x = HSCREENW-160;
175 r.w = 320-x;
176 SDL_BlitSurface(tmpSurf,&r, scr, &rr );
177
178 SDL_FreeSurface(tmpSurf);
179 break;
180
181 }
182 }
183
transitionActive()184 int_fast8_t transitionActive()
185 {
186 return(t.timeLeft<1?0:1);
187 }
188