comparison demo.c @ 5:dcec61df1633

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 May 2015 01:58:55 +0300
parents 37b33851cfbb
children dde02bd75871
comparison
equal deleted inserted replaced
4:1b96b102f401 5:dcec61df1633
35 } 35 }
36 36
37 37
38 #define FFT_SIZE 128 38 #define FFT_SIZE 128
39 DMFFTContext fft; 39 DMFFTContext fft;
40 DMResource *teksti = NULL;
41 DMBitmapFont *font = NULL;
42
43 typedef struct
44 {
45 int layer;
46 char *filename;
47 SDL_Surface *img;
48 } DMItemDef;
49
50
51 DMItemDef items[] =
52 {
53 { 1, "viitta.png", NULL },
54 { 1, "puu_pv_1.png", NULL },
55 { 0, "puu_pv_2.png", NULL },
56 };
57
58 static const int nitems = sizeof(items) / sizeof(items[0]);
59
60
40 61
41 62
42 static int demoInit(DMEngineData *engine) 63 static int demoInit(DMEngineData *engine)
43 { 64 {
44 int i; 65 int i;
45 JSSModule *mod = NULL; 66 JSSModule *mod = NULL;
46 67 SDL_Color pal[DMFONT_NPALETTE];
68 DMResource *tmp;
69
70 // FFT init
47 dmInitializeFFT(&fft, FFT_SIZE); 71 dmInitializeFFT(&fft, FFT_SIZE);
48 72
73 // Skrolliteksti
74 if ((teksti = engineFindResource(engine, "skrolli.txt")) == NULL)
75 return DMERR_INIT_FAIL;
76
77 // Skrollerin fontti
78 if ((tmp = engineFindResource(engine, "fontti.dmf")) == NULL)
79 return DMERR_INIT_FAIL;
80
81 if ((i = dmLoadBitmapFont(tmp, &font)) != DMERR_OK)
82 return i;
83
84 for (i = 0; i < DMFONT_NPALETTE; i++)
85 {
86 pal[i].r = pal[i].g = pal[i].b = i * 8;
87 pal[i].unused = i > 0 ? 255 : 0;
88 }
89
90 dmSetBitmapFontPalette(font, pal, 0, DMFONT_NPALETTE);
91
92 // Musa
49 engineGetResModule(engine, mod, "pas2.xm"); 93 engineGetResModule(engine, mod, "pas2.xm");
50 94
51 if ((i = jssConvertModuleForPlaying(mod)) != DMERR_OK) 95 if ((i = jssConvertModuleForPlaying(mod)) != DMERR_OK)
52 { 96 {
53 dmErrorMsg("Could not convert module for playing, %d: %s\n", 97 dmErrorMsg("Could not convert module for playing, %d: %s\n",
58 jvmSetCallback(engine->jssDev, jmpExec, engine->jssPlr); 102 jvmSetCallback(engine->jssDev, jmpExec, engine->jssPlr);
59 jmpSetModule(engine->jssPlr, mod); 103 jmpSetModule(engine->jssPlr, mod);
60 jmpPlayOrder(engine->jssPlr, 0); 104 jmpPlayOrder(engine->jssPlr, 0);
61 jvmSetGlobalVol(engine->jssDev, 55); 105 jvmSetGlobalVol(engine->jssDev, 55);
62 106
107
108 // Osa kuvadatasta
109 for (i = 0; i < nitems; i++)
110 engineGetResImage(engine, items[i].img, items[i].filename);
111
63 // Jne 112 // Jne
64 srand(15); 113 srand(15);
65 114
66 return DMERR_OK; 115 return DMERR_OK;
67 } 116 }
69 118
70 static void demoShutdown(DMEngineData *engine) 119 static void demoShutdown(DMEngineData *engine)
71 { 120 {
72 (void) engine; 121 (void) engine;
73 dmEndFFT(&fft); 122 dmEndFFT(&fft);
123 dmFreeBitmapFont(font);
74 } 124 }
75 125
76 126
77 static inline float dmCX(DMEngineData *engine, const float x) 127 static inline float dmCX(DMEngineData *engine, const float x)
78 { 128 {
163 } 213 }
164 } 214 }
165 } 215 }
166 216
167 217
168
169 static int demoRender(DMEngineData *engine) 218 static int demoRender(DMEngineData *engine)
170 { 219 {
171 float t = engineGetTimeDT(engine); 220 float t = engineGetTimeDT(engine);
172
173 221
174 // 222 //
175 // Do FFT 223 // Do FFT
176 // 224 //
177 DMFFTType fftPow = 0; 225 DMFFTType fftPow = 0;
204 // Taustaskrolli 252 // Taustaskrolli
205 // 253 //
206 { 254 {
207 static SDL_Surface *tausta = NULL, 255 static SDL_Surface *tausta = NULL,
208 *aurinko = NULL, 256 *aurinko = NULL,
209 *puu1 = NULL,
210 *puu2 = NULL,
211 *bussi = NULL, 257 *bussi = NULL,
212 *rengas = NULL; 258 *rengas = NULL;
213 259
214 static DMScaledBlitFunc cblit = NULL, ablit = NULL; 260 static DMScaledBlitFunc cblit = NULL, ablit = NULL;
215 static BOOL nollattu = FALSE; 261 static BOOL nollattu = FALSE;
220 dmLerpInit(&fadeLerp, 0, 255, 3000); 266 dmLerpInit(&fadeLerp, 0, 255, 3000);
221 dmLerpInit(&fadeLerp2, 0, 255, 4000); 267 dmLerpInit(&fadeLerp2, 0, 255, 4000);
222 dmLerpInit(&fadeLerp3, 0, 1.2, 3000); 268 dmLerpInit(&fadeLerp3, 0, 1.2, 3000);
223 engineGetResImage(engine, tausta, "tausta_pv.png"); 269 engineGetResImage(engine, tausta, "tausta_pv.png");
224 engineGetResImage(engine, aurinko, "aurinko.png"); 270 engineGetResImage(engine, aurinko, "aurinko.png");
225 engineGetResImage(engine, puu1, "puu_pv_1.png");
226 engineGetResImage(engine, puu2, "puu_pv_2.png");
227 engineGetResImage(engine, bussi, "auto.png"); 271 engineGetResImage(engine, bussi, "auto.png");
228 engineGetResImage(engine, rengas, "rengas.png"); 272 engineGetResImage(engine, rengas, "rengas.png");
229 cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE); 273 cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE);
230 ablit = dmGetScaledBlitFunc(bussi->format, engine->screen->format, DMD_TRANSPARENT); 274 ablit = dmGetScaledBlitFunc(bussi->format, engine->screen->format, DMD_TRANSPARENT);
231 } 275 }
259 aurinko->w + qm2, aurinko->h + qm2, 303 aurinko->w + qm2, aurinko->h + qm2,
260 engine->screen, fadeVal); 304 engine->screen, fadeVal);
261 305
262 306
263 // Bussi ajaa sisään 307 // Bussi ajaa sisään
264 if (t > 4) 308 if (t > 14)
265 { 309 {
266 float 310 float
267 dt = engineGetTime(engine, 4), 311 dt = engineGetTime(engine, 14),
268 ajelu = dmLerpSCurveClamp(&fadeLerp3, dt), 312 ajelu = dmLerpSCurveClamp(&fadeLerp3, dt),
269 xc = dmCX(engine, -1 + ajelu), 313 xc = dmCX(engine, -1 + ajelu),
270 yc = dmCY(engine, 0.35 + sin(t * 10) * 0.005), 314 yc = dmCY(engine, 0.35 + sin(t * 10) * 0.005),
271 yc2 = yc + dmQY(engine, bussi, 0.7) + dmCY(engine, sin(t * 20) * 0.001); 315 yc2 = yc + dmQY(engine, bussi, 0.7) + dmCY(engine, sin(t * 20) * 0.001);
272 316
273 ablit(rengas, xc + dmQX(engine, bussi, 0.07), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen); 317 ablit(rengas, xc + dmQX(engine, bussi, 0.07), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen);
274 ablit(rengas, xc + dmQX(engine, bussi, 0.80), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen); 318 ablit(rengas, xc + dmQX(engine, bussi, 0.80), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen);
275 ablit(bussi, xc, yc, dmQX(engine, bussi, 1), dmQY(engine, bussi, 1), engine->screen); 319 ablit(bussi, xc, yc, dmQX(engine, bussi, 1), dmQY(engine, bussi, 1), engine->screen);
276 } 320 }
321
322
323 // Puut ym. liikennejutut
324 if (t > 10)
325 {
326 }
277 } 327 }
278 328
279 // 329 //
280 // AP logo 330 // AP logo
281 // 331 //
369 static SDL_Surface *maski = NULL; 419 static SDL_Surface *maski = NULL;
370 static BOOL nollattu = FALSE; 420 static BOOL nollattu = FALSE;
371 421
372 if (!nollattu) 422 if (!nollattu)
373 { 423 {
374 engineGetResImage(engine, maski, "maze.png"); 424 engineGetResImage(engine, maski, "maski.png");
375 cblit = dmGetScaledBlitFunc(maski->format, engine->screen->format, DMD_TRANSPARENT); 425 cblit = dmGetScaledBlitFunc(maski->format, engine->screen->format, DMD_TRANSPARENT);
376 } 426 }
377 427
378 cblit(maski, 428 cblit(maski,
379 0, 0, 429 0, 0,
380 dmQX(engine, maski, 1), 430 dmQX(engine, maski, 1),
381 dmQY(engine, maski, 1), 431 dmQY(engine, maski, 1),
382 engine->screen); 432 engine->screen);
383 } 433 }
384 434
385 return DMERR_OK; 435 if (t > 70)
386 } 436 return 1;
437 else
438 return DMERR_OK;
439 }