Mercurial > hg > demos > bussi
diff demo.c @ 3:37b33851cfbb
Joo.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 May 2015 01:39:04 +0300 |
parents | 496b9ab9238c |
children | dcec61df1633 |
line wrap: on
line diff
--- a/demo.c Thu May 21 23:30:51 2015 +0300 +++ b/demo.c Fri May 22 01:39:04 2015 +0300 @@ -98,51 +98,6 @@ } -typedef struct -{ - char *filename; - float xc, yc; - SDL_Surface *img; -} DMTextItem; - - -static DMTextItem textItems[] = -{ - { "text01.png", 0.05, 0.10, NULL }, - { "text02.png", 0.10, 0.30, NULL }, - { "text03.png", 0.60, 0.30, NULL }, - { "text04.png", 0.20, 0.60, NULL }, - { "text05.png", 0.30, 0.70, NULL }, -}; - -static const int ntextItems = sizeof(textItems) / sizeof(textItems[0]); - - -static DMTextItem textItems2[] = -{ - { "text11.png", 0.05, 0.10, NULL }, - { "text02.png", 0.30, 0.25, NULL }, - { "text12.png", 0.10, 0.40, NULL }, - { "text13.png", 0.20, 0.60, NULL }, - { "text14.png", 0.30, 0.70, NULL }, -}; - -static const int ntextItems2 = sizeof(textItems2) / sizeof(textItems2[0]); - - -static DMTextItem textItems3[] = -{ - { "teki.png" , 0.25, 0.20, NULL }, - { "mitvit.png" , 0.05, 0.40, NULL }, - { "ja.png" , 0.05, 0.65, NULL }, - { "kemisti.png", 0.15, 0.65, NULL }, -}; - -static const int ntextItems3 = sizeof(textItems3) / sizeof(textItems3[0]); - - - - #define DM_RADIAL_BLUR(YC, XC) \ DMVector p1 = { xc, yc, 0, 0 }, p2 = { cx, cy, 0, 0 }, v; \ dm_vector_sub_r(&v, &p2, &p1); \ @@ -210,48 +165,15 @@ } -static int hitlerText(DMEngineData *engine, const int dt, float fftPow, DMTextItem *items, const int nitems, BOOL *nollattu) -{ - int i, vis; - if (!(*nollattu)) - { - for (i = 0; i < nitems; i++) - engineGetResImage(engine, items[i].img, items[i].filename); - - *nollattu = TRUE; - } - - float q = fftPow * 0.05f; - vis = dt / 1000; - for (i = 0; i < nitems; i++) - { - DMTextItem *item = &items[i]; - if (i < vis) - { - dmScaledBlitSurface32to32TransparentGA( - item->img, - dmCX(engine, item->xc - q), - dmCY(engine, item->yc - q), - - dmQX(engine, item->img, 1.0f + q * 2.0f), - dmQY(engine, item->img, 1.0f + q * 2.0f), - - engine->screen, - - 100 + 80 * fftPow); - } - } - - return DMERR_OK; -} - static int demoRender(DMEngineData *engine) { float t = engineGetTimeDT(engine); - static DMScaledBlitFunc cblit = NULL; + + // // Do FFT + // DMFFTType fftPow = 0; BOOL fftOK = FALSE; static DMFFTType fftAmp[FFT_SIZE / 2]; @@ -277,29 +199,188 @@ dmConvertFFTtoPowerAndSum(&fft, fftData, fftAmp, 1.0, &fftPow, 0.00004f); } - // Demokoodi - if (t < 5) + + // + // Taustaskrolli + // { - // Alkufeidi sisään - int dt = engineGetTime(engine, 0); + static SDL_Surface *tausta = NULL, + *aurinko = NULL, + *puu1 = NULL, + *puu2 = NULL, + *bussi = NULL, + *rengas = NULL; + + static DMScaledBlitFunc cblit = NULL, ablit = NULL; + static BOOL nollattu = FALSE; + static DMLerpContext fadeLerp, fadeLerp2, fadeLerp3; + + if (!nollattu) + { + dmLerpInit(&fadeLerp, 0, 255, 3000); + dmLerpInit(&fadeLerp2, 0, 255, 4000); + dmLerpInit(&fadeLerp3, 0, 1.2, 3000); + engineGetResImage(engine, tausta, "tausta_pv.png"); + engineGetResImage(engine, aurinko, "aurinko.png"); + engineGetResImage(engine, puu1, "puu_pv_1.png"); + engineGetResImage(engine, puu2, "puu_pv_2.png"); + engineGetResImage(engine, bussi, "auto.png"); + engineGetResImage(engine, rengas, "rengas.png"); + cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE); + ablit = dmGetScaledBlitFunc(bussi->format, engine->screen->format, DMD_TRANSPARENT); + } + + int x1 = - ((int)dmQX(engine, tausta, t * 0.2) % tausta->w), + x2 = x1 + tausta->w; + + int fadeVal; + if (t < 3 || t > 64) + { + if (t < 3) + fadeVal = dmLerpSCurveClamp(&fadeLerp, engineGetTime(engine, 0)); + else + fadeVal = dmLerpSCurveClamp(&fadeLerp2, engineGetTime(engine, 64)); + + dmClearSurface(engine->screen, dmMapRGB(engine->screen, 0,0,0)); + dmScaledBlitSurface32to32TransparentGA(tausta, x1, 0, tausta->w, tausta->h, engine->screen, fadeVal); + dmScaledBlitSurface32to32TransparentGA(tausta, x2, 0, tausta->w, tausta->h, engine->screen, fadeVal); + } + else + { + fadeVal = 255; + cblit(tausta, x1, 0, tausta->w, tausta->h, engine->screen); + cblit(tausta, x2, 0, tausta->w, tausta->h, engine->screen); + } + + float qm = sin(t * 0.1 + fftPow * 5) * 15, qm2 = qm*2; + dmScaledBlitSurface32to32TransparentGA(aurinko, + dmCX(engine, 0.8 - dmLerpSCurveClamp(&fadeLerp3, engineGetTime(engine, 0) * 0.01) * 0.3 ) - qm, + dmCY(engine, 0.05) - qm, + aurinko->w + qm2, aurinko->h + qm2, + engine->screen, fadeVal); + + + // Bussi ajaa sisään + if (t > 4) + { + float + dt = engineGetTime(engine, 4), + ajelu = dmLerpSCurveClamp(&fadeLerp3, dt), + xc = dmCX(engine, -1 + ajelu), + yc = dmCY(engine, 0.35 + sin(t * 10) * 0.005), + yc2 = yc + dmQY(engine, bussi, 0.7) + dmCY(engine, sin(t * 20) * 0.001); + + ablit(rengas, xc + dmQX(engine, bussi, 0.07), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen); + ablit(rengas, xc + dmQX(engine, bussi, 0.80), yc2, dmQX(engine, rengas, 1), dmQY(engine, rengas, 1), engine->screen); + ablit(bussi, xc, yc, dmQX(engine, bussi, 1), dmQY(engine, bussi, 1), engine->screen); + } + } + + // + // AP logo + // + if (t > 4 && t < 8) + { + int dt = engineGetTime(engine, 4); static DMLerpContext fadeLerp; - static SDL_Surface *tausta = NULL; + static SDL_Surface *logo = NULL; static BOOL nollattu = FALSE; if (!nollattu) { - engineGetResImage(engine, tausta, "tausta_pv.png"); - cblit = dmGetScaledBlitFunc(tausta->format, engine->screen->format, DMD_NONE); + dmLerpInit(&fadeLerp, 0, 255, 1000); + engineGetResImage(engine, logo, "ap.png"); + nollattu = TRUE; + } + + int fadeVal; + if (dt < 1000) + fadeVal = dmLerpSCurveClamp(&fadeLerp, dt); + else + if (dt > 3000) + fadeVal = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000); + else + fadeVal = 255; - dmLerpInit(&fadeLerp, 0, 255, 5000); + dmScaledBlitSurface32to32TransparentGA(logo, + dmQX(engine, logo, 0.2), + dmQY(engine, logo, 0.3), + dmQX(engine, logo, 1), + dmQY(engine, logo, 1), + engine->screen, fadeVal); + } + + // + // BUSSI logo + // + if (t > 10 && t < 14) + { + int dt = engineGetTime(engine, 10); + static DMLerpContext fadeLerp; + static SDL_Surface *logo = NULL, *logo2 = NULL; + static BOOL nollattu = FALSE; + if (!nollattu) + { + dmLerpInit(&fadeLerp, 0, 255, 1000); + engineGetResImage(engine, logo, "bussi_logo.png"); + engineGetResImage(engine, logo2, "dosa.png"); nollattu = TRUE; } - dmClearSurface(engine->screen, dmMapRGB(engine->screen, 0,0,0)); + int fadeVal, fadeVal2; + if (dt < 1000) + fadeVal = dmLerpSCurveClamp(&fadeLerp, dt); + else + if (dt > 3000) + fadeVal = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000); + else + fadeVal = 255; + + if (dt > 1000) + { + if (dt < 2000) + fadeVal2 = dmLerpSCurveClamp(&fadeLerp, dt - 1000); + else + if (dt > 3000) + fadeVal2 = 255 - dmLerpSCurveClamp(&fadeLerp, dt - 3000); + else + fadeVal2 = 255; + } + else + fadeVal2 = 0; - dmScaledBlitSurface32to32TransparentGA(tausta, - 0, - 0, + dmScaledBlitSurface32to32TransparentGA(logo, + dmCX(engine, 0.10), + dmCY(engine, 0.2), + dmQX(engine, logo, 1), + dmQY(engine, logo, 1), + engine->screen, fadeVal); + + dmScaledBlitSurface32to32TransparentGA(logo2, + dmCX(engine, 0.6), + dmCY(engine, 0.6), + dmQX(engine, logo2, 1), + dmQY(engine, logo2, 1), + engine->screen, fadeVal2); + } + + { + static DMScaledBlitFunc cblit = NULL; + static SDL_Surface *maski = NULL; + static BOOL nollattu = FALSE; + + if (!nollattu) + { + engineGetResImage(engine, maski, "maze.png"); + cblit = dmGetScaledBlitFunc(maski->format, engine->screen->format, DMD_TRANSPARENT); + } + + cblit(maski, + 0, 0, + dmQX(engine, maski, 1), + dmQY(engine, maski, 1), + engine->screen); + } return DMERR_OK; }