forked from DusteDdk/Wizznic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredits.c
301 lines (249 loc) · 8.66 KB
/
credits.c
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
/************************************************************************
* This file is part of Wizznic. *
* Copyright 2009-2011 Jimmy Christensen <[email protected]> *
* Wizznic 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 3 of the License, or *
* (at your option) any later version. *
* *
* Wizznic 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 Foobar. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************/
#include "credits.h"
#include "waveimg.h"
#include "pixel.h"
#include "text.h"
#include "list.h"
#include "particles.h"
#include "defs.h"
#include "settings.h"
#define MSGSTATE_TITLE_SLIDING_IN 0
#define MSGSTATE_NAME_SLIDING_IN 1
#define MSGSTATE_NAME_DECREASE_WAVE 2
#define MSGSTATE_NAME_SHAKING 3
#define MSGSTATE_NEXT_MSG 4
struct msg_s {
SDL_Surface *surfTitle;
wavingImage_t nameWaving;
int state;
int stateTicks;
SDL_Rect rTitle;
SDL_Rect nWander;
};
typedef struct msg_s msg_t;
static msg_t* cm; //Current msg.
static int currentMsgIndex; //in list
static listItem* msgList;
static int ticksToNextPs=0;
static psysSet_t ps;
SDL_Rect r; //Used to shake the name
msg_t* initMsg(const char* strTitle, const char* strName,SDL_Surface* screen)
{
msg_t* t = malloc(sizeof(msg_t));
//Create surface
t->surfTitle = SDL_CreateRGBSurface(SDL_SWSURFACE, (getCharSize(FONTSMALL)[0]*strlen(strTitle)),(getCharSize(FONTSMALL)[1]), (setting()->bpp*8), screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0xff000000);
t->nameWaving.img = SDL_CreateRGBSurface(SDL_SWSURFACE, (getCharSize(FONTMEDIUM)[0]*strlen(strName)),(getCharSize(FONTMEDIUM)[1]),(setting()->bpp*8), screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,0xff000000);
t->nameWaving.screen=screen;
SDL_FillRect(t->surfTitle, 0, SDL_MapRGB(t->surfTitle->format, 0,255,255));
SDL_FillRect(t->nameWaving.img, 0, SDL_MapRGB(t->nameWaving.img->format, 0,255,255));
//Render text to surface
txtWrite(t->surfTitle, FONTSMALL, strTitle, 0,0);
txtWrite(t->nameWaving.img, FONTMEDIUM, strName, 0,0);
SDL_Surface* tempSurf;
tempSurf=SDL_DisplayFormat(t->surfTitle);
SDL_FreeSurface(t->surfTitle);
SDL_SetColorKey( tempSurf, SDL_SRCCOLORKEY, SDL_MapRGB( tempSurf->format, 0, 0xFF, 0xFF ) );
t->surfTitle=tempSurf;
tempSurf=SDL_DisplayFormat(t->nameWaving.img);
SDL_FreeSurface(t->nameWaving.img);
SDL_SetColorKey( tempSurf, SDL_SRCCOLORKEY, SDL_MapRGB( tempSurf->format, 0, 0xFF, 0xFF ) );
t->nameWaving.img=tempSurf;
t->stateTicks=0;
return(t);
}
void setCurrent()
{
cm=(msg_t*)listGetItemData(msgList,currentMsgIndex);
cm->state=MSGSTATE_TITLE_SLIDING_IN;
cm->rTitle.w=0;
cm->rTitle.h=0;
cm->rTitle.x=321;
cm->rTitle.y=HSCREENH+15;
cm->nameWaving.x= -(cm->nameWaving.img->w);
cm->nameWaving.y=HSCREENH+35;
cm->nameWaving.rotations=2+(cm->nameWaving.img->w/100);
cm->nameWaving.amount=35;
cm->nameWaving.speed=50;
//Setup particle system
ps.layer=PSYS_LAYER_TOP;
ps.vel=100;
ps.life=200;
ps.lifeVar=100;
ps.numParticles=0;
ps.fade=0;
ps.gravity=0;
ps.bounce=0;
ps.srcRect.x=0;
ps.srcRect.y=0;
}
void freeMsg(msg_t* msg)
{
SDL_FreeSurface( msg->surfTitle );
SDL_FreeSurface( msg->nameWaving.img );
free(msg);
}
void initCredits(SDL_Surface* screen)
{
printf("initCredits();\n");
msgList=initList();
listAddData(msgList, (void*)initMsg("Website","wizznic.sf.net", screen));
listAddData(msgList, (void*)initMsg("Code/Gfx/Sfx","Jimmy Christensen", screen));
listAddData(msgList, (void*)initMsg("Gfx","ViperMD", screen));
listAddData(msgList, (void*)initMsg("Music","Sean Hawk", screen));
listAddData(msgList, (void*)initMsg("Thx","Farox", screen));
listAddData(msgList, (void*)initMsg("Thx","bMan", screen));
listAddData(msgList, (void*)initMsg("Thx","KML", screen));
listAddData(msgList, (void*)initMsg("Thx","Neil L", screen));
listAddData(msgList, (void*)initMsg("Greetings","GP32X.com", screen));
listAddData(msgList, (void*)initMsg("Greetings","freegamedev.net", screen));
listAddData(msgList, (void*)initMsg("Greetings","Qubodup", screen));
//Set current
currentMsgIndex=0;
setCurrent();
printf("credits initialized.\n");
}
void clearCredits()
{
printf("clearCredits();\n");
listItem* it=msgList;
while( (it=it->next) )
{
cm = (msg_t*)it->data;
freeMsg(cm);
}
freeList(msgList);
clearParticles();
}
void drawTitle(SDL_Surface* screen, msg_t* m)
{
ticksToNextPs += getTicks();
if(ticksToNextPs > 60)
{
ticksToNextPs=0;
ps.layer=PSYS_LAYER_TOP;
ps.bounce=0;
ps.x=m->rTitle.x;
ps.y=m->rTitle.y;
ps.srcImg=m->surfTitle;
ps.srcRect.w=m->surfTitle->w;
ps.srcRect.h=m->surfTitle->h;
spawnParticleSystem( &ps );
}
SDL_BlitSurface( m->surfTitle, 0, screen, &m->rTitle );
}
void runCredits(SDL_Surface* screen)
{
switch(cm->state)
{
case MSGSTATE_TITLE_SLIDING_IN:
cm->rTitle.x -= 10;
if( cm->rTitle.x <= (HSCREENW-(cm->surfTitle->w/2)) )
{
cm->rTitle.x=(HSCREENW-(cm->surfTitle->w/2));
cm->stateTicks += getTicks();
//wait 250 ms
if(cm->stateTicks >= 250)
{
cm->state=MSGSTATE_NAME_SLIDING_IN;
cm->stateTicks=0;
}
}
drawTitle(screen, cm);
break;
case MSGSTATE_NAME_SLIDING_IN:
//Draw title
drawTitle(screen, cm);
//Slide in name
cm->nameWaving.x += 7;
if( cm->nameWaving.x >= ( HSCREENW-cm->nameWaving.img->w/2 ) )
{
cm->nameWaving.x = ( HSCREENW-cm->nameWaving.img->w/2 );
cm->state=MSGSTATE_NAME_DECREASE_WAVE;
}
waveImg( &cm->nameWaving );
break;
case MSGSTATE_NAME_DECREASE_WAVE:
//Draw title
SDL_BlitSurface( cm->surfTitle, 0, screen, &cm->rTitle );
cm->stateTicks += getTicks();
if(cm->stateTicks > 0)
{
cm->stateTicks=0;
cm->nameWaving.amount--;
if(cm->nameWaving.amount==0)
{
cm->stateTicks=0;
cm->state=MSGSTATE_NAME_SHAKING;
//Set
r.x=cm->nameWaving.x;
r.y=cm->nameWaving.y;
}
}
waveImg( &cm->nameWaving );
break;
case MSGSTATE_NAME_SHAKING:
if(cm->stateTicks<500)
SDL_BlitSurface( cm->surfTitle, 0, screen, &cm->rTitle );
//shake
cm->nWander.x=((rand()%6000)-3000)/1000;
cm->nWander.y=((rand()%4000)-2000)/1000;
if( abs(cm->nameWaving.x - (r.x+cm->nWander.x)) > 5) cm->nWander.x *=-1;
if( abs(cm->nameWaving.y - (r.y+cm->nWander.y)) > 3) cm->nWander.y *=-1;
r.x += cm->nWander.x;
r.y += cm->nWander.y;
if(cm->stateTicks <1500)
SDL_BlitSurface( cm->nameWaving.img, 0, screen, &r );
cm->stateTicks += getTicks();
if(cm->stateTicks >= 500 && cm->stateTicks-getTicks() <= 500)
{
ps.layer=PSYS_LAYER_TOP;
ps.vel=200;
ps.life=1000;
ps.lifeVar=500;
spawnParticleSystem( &ps );
spawnParticleSystem( &ps );
spawnParticleSystem( &ps );
spawnParticleSystem( &ps );
} else if(cm->stateTicks >= 1500 && cm->stateTicks-getTicks() <= 1500)
{
ps.layer=PSYS_LAYER_TOP;
ps.vel=400;
ps.life=1500;
ps.lifeVar=500;
ps.x=cm->nameWaving.x;
ps.y=cm->nameWaving.y;
ps.srcImg=cm->nameWaving.img;
ps.srcRect.w=cm->nameWaving.img->w;
ps.srcRect.h=cm->nameWaving.img->h;
spawnParticleSystem( &ps );
spawnParticleSystem( &ps );
} else if(cm->stateTicks > 3000)
{
//Next
cm->state=MSGSTATE_NEXT_MSG;
}
break;
case MSGSTATE_NEXT_MSG:
//Update current msg
currentMsgIndex++;
if(currentMsgIndex == listSize(msgList))
currentMsgIndex=0;
setCurrent();
break;
};
}