-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.c
106 lines (97 loc) · 2.68 KB
/
intro.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* intro.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhedeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/10 16:15:24 by mhedeon #+# #+# */
/* Updated: 2019/01/31 17:26:06 by mhedeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
void cp_tex_to_buff(t_wolf *wolf, t_texture *tex)
{
int x;
int y;
y = -1;
while (++y < SCREEN_HEIGHT)
{
x = -1;
while (++x < SCREEN_WIDTH)
wolf->buff[y * SCREEN_WIDTH + x] = 0;
}
y = -1;
while (++y < SCREEN_HEIGHT)
{
x = -1;
while (++x < SCREEN_WIDTH)
wolf->buff[y * SCREEN_WIDTH + x] = tex->pixels[y * tex->sur->w + x];
}
}
static void intro_anim_2(t_wolf *wolf, t_texture *intro, Uint32 time)
{
int x;
int y;
double boost;
boost = (8000 - (time > 8000 ? 8000 :
time)) / 8000.0;
y = -1;
while (++y < SCREEN_HEIGHT)
{
x = -1;
while (++x < SCREEN_WIDTH)
{
get_color(intro, &wolf->color, x, y);
wolf->color.r = (Uint8)(wolf->color.r * boost);
wolf->color.g = (Uint8)(wolf->color.g * boost);
wolf->color.b = (Uint8)(wolf->color.b * boost);
set_pixel_s(wolf, &wolf->color, x, y);
}
}
}
void intro_anim(t_wolf *wolf, t_texture *intro)
{
Uint32 old;
Uint32 cur;
SDL_Event e;
old = SDL_GetTicks();
cur = old;
while ((cur - old) < 8000)
{
cur = SDL_GetTicks();
intro_anim_2(wolf, intro, cur - old);
screen_upd(wolf);
if (SDL_PollEvent(&e))
{
if (KEY == SDLK_SPACE)
break ;
else if (KEY == SDLK_RETURN)
system("open https://github.com/mhedeon");
}
}
}
void intro(t_wolf *wolf)
{
t_texture intro;
Mix_Music *intro_m;
intro_m = Mix_LoadMUS("resource/sounds/music/intro.mid");
if (intro_m != NULL)
Mix_PlayMusic(intro_m, -1);
if (load_texture(&intro, "resource/img/menu/intro-1.jpg"))
{
cp_tex_to_buff(wolf, &intro);
intro_anim(wolf, &intro);
destroy_texture(&intro);
}
if (load_texture(&intro, "resource/img/menu/intro-2.jpg"))
{
cp_tex_to_buff(wolf, &intro);
intro_anim(wolf, &intro);
destroy_texture(&intro);
}
if (Mix_PlayingMusic())
Mix_HaltMusic();
if (intro_m != NULL)
Mix_FreeMusic(intro_m);
}