1 #include <allegro.h>
2 #include "../include/menus.h"
3 #include "../include/global.h"
4 #include "../include/defines.h"
5 #include "../include/music.h"
6
7
8 static int _id = DEMO_STATE_INTRO;
9 static float duration;
10 static float progress;
11 static int already_played_midi;
12
id(void)13 static int id(void)
14 {
15 return _id;
16 }
17
18
init(void)19 static void init(void)
20 {
21 duration = 4.0f;
22 progress = 0.0f;
23 already_played_midi = 0;
24 set_palette(demo_data[DEMO_MENU_PALETTE].dat);
25 }
26
27
update(void)28 static int update(void)
29 {
30 int c;
31
32 progress += 1.0f / logic_framerate;
33
34 if (progress >= duration) {
35 return DEMO_STATE_MAIN_MENU;
36 }
37
38 if (keypressed()) {
39 c = readkey() >> 8;
40 clear_keybuf();
41
42 if (c == KEY_ESC) {
43 return DEMO_STATE_EXIT;
44 }
45
46 return DEMO_STATE_MAIN_MENU;
47 }
48
49 return id();
50 }
51
52
draw(BITMAP * canvas)53 static void draw(BITMAP *canvas)
54 {
55 int c, x, y, offx, offy;
56 static char logo_text1[] = "Allegro";
57 static char logo_text2[] = "";
58 /* XXX commented out because the font doesn't contain the characters for
59 * anything other than "Allegro 4.2"
60 */
61 /* static char logo_text2[] = "4.2"; */
62
63 if (progress < 0.5f) {
64 c = (int)(255 * progress / 0.5f);
65 clear_to_color(canvas, makecol(c, c, c));
66 } else {
67 if (!already_played_midi) {
68 play_music(DEMO_MIDI_INTRO, 0);
69 already_played_midi = 1;
70 }
71
72 c = 255;
73 clear_to_color(canvas, makecol(c, c, c));
74
75 x = SCREEN_W / 2;
76 y = SCREEN_H / 2 - 3 * text_height(demo_font_logo) / 2;
77
78 offx = 0;
79 if (progress < 1.0f) {
80 offx =
81 (int)(text_length(demo_font_logo, logo_text1) *
82 (1.0f - 2.0f * (progress - 0.5f)));
83 }
84
85 demo_textprintf_centre(canvas, demo_font_logo_m, x + 6 - offx,
86 y + 5, makecol(128, 128, 128), -1, logo_text1);
87 demo_textprintf_centre(canvas, demo_font_logo, x - offx, y, -1, -1,
88 logo_text1);
89
90 if (progress >= 1.5f) {
91 y += 3 * text_height(demo_font_logo) / 2;
92 offy = 0;
93 if (progress < 2.0f) {
94 offy = (int)((SCREEN_H - y) * (1.0f - 2.0f * (progress - 1.5f)));
95 }
96
97 demo_textprintf_centre(canvas, demo_font_logo_m, x + 6,
98 y + 5 + offy, makecol(128, 128, 128), -1,
99 logo_text2);
100 demo_textprintf_centre(canvas, demo_font_logo, x, y + offy, -1, -1,
101 logo_text2);
102 }
103 }
104 }
105
106
create_intro(GAMESTATE * state)107 void create_intro(GAMESTATE * state)
108 {
109 state->id = id;
110 state->init = init;
111 state->update = update;
112 state->draw = draw;
113 }
114