1 /*
2 * SPEED - by Shawn Hargreaves, 1999
3 *
4 * Title screen and results display.
5 */
6
7 #include <math.h>
8 #include <stdio.h>
9 #include <allegro5/allegro.h>
10 #include <allegro5/allegro_audio.h>
11 #include <allegro5/allegro_font.h>
12 #include <allegro5/allegro_primitives.h>
13
14 #include "speed.h"
15
16
17
18 /* draws text with a dropshadow */
textout_shadow(char * msg,int x,int y,ALLEGRO_COLOR c)19 static void textout_shadow(char *msg, int x, int y, ALLEGRO_COLOR c)
20 {
21 textout_centre(font, msg, x+1, y+1, makecol(0, 0, 0));
22 textout_centre(font, msg, x, y, c);
23 }
24
25
26
27 /* display the title screen */
title_screen()28 int title_screen()
29 {
30 int SCREEN_W = al_get_display_width(screen);
31 int SCREEN_H = al_get_display_height(screen);
32 ALLEGRO_BITMAP *bmp, *b;
33 ALLEGRO_COLOR white = makecol(255, 255, 255);
34 int i, j, y;
35
36 bmp = create_memory_bitmap(SCREEN_W, SCREEN_H);
37 al_set_target_bitmap(bmp);
38 al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
39
40 for (i=0; i<SCREEN_H/2; i++) {
41 hline(0, i, SCREEN_W, makecol(0, 0, i*255/(SCREEN_H/2)));
42 hline(0, SCREEN_H-i-1, SCREEN_W, makecol(0, 0, i*255/(SCREEN_H/2)));
43 }
44
45 solid_mode();
46
47 b = create_memory_bitmap(40, 8);
48 al_set_target_bitmap(b);
49 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
50
51 textout(font, "SPEED", 0, 0, makecol(0, 0, 0));
52 stretch_sprite(bmp, b, SCREEN_W/128+8, SCREEN_H/24+8, SCREEN_W, SCREEN_H);
53
54 textout(font, "SPEED", 0, 0, makecol(0, 0, 64));
55 stretch_sprite(bmp, b, SCREEN_W/128, SCREEN_H/24, SCREEN_W, SCREEN_H);
56
57 al_set_target_bitmap(bmp);
58
59 al_destroy_bitmap(b);
60
61 textout_shadow("Simultaneous Projections", SCREEN_W/2, SCREEN_H/2-80, white);
62 textout_shadow("Employing an Ensemble of Displays", SCREEN_W/2, SCREEN_H/2-64, white);
63
64 textout_shadow("Or alternatively: Stupid Pointless", SCREEN_W/2, SCREEN_H/2-32, white);
65 textout_shadow("Effort at Establishing a Dumb Acronym", SCREEN_W/2, SCREEN_H/2-16, white);
66
67 textout_shadow("By Shawn Hargreaves, 1999", SCREEN_W/2, SCREEN_H/2+16, white);
68 textout_shadow("Written for the Allegro", SCREEN_W/2, SCREEN_H/2+48, white);
69 textout_shadow("SpeedHack competition", SCREEN_W/2, SCREEN_H/2+64, white);
70
71 al_set_target_bitmap(al_get_backbuffer(screen));
72
73 bmp = replace_bitmap(bmp);
74
75 start_retrace_count();
76
77 for (i=0; i<=SCREEN_H/16; i++) {
78 al_clear_to_color(makecol(0, 0, 0));
79
80 for (j=0; j<=16; j++) {
81 y = j*(SCREEN_H/16);
82 al_draw_bitmap_region(bmp, 0, y, SCREEN_W, i, 0, y, 0);
83 }
84
85 al_flip_display();
86
87 do {
88 poll_input_wait();
89 } while (retrace_count() < i*1024/SCREEN_W);
90 }
91
92 stop_retrace_count();
93
94 while (joy_b1 || key[ALLEGRO_KEY_SPACE] || key[ALLEGRO_KEY_ENTER] || key[ALLEGRO_KEY_ESCAPE])
95 poll_input_wait();
96
97 while (!key[ALLEGRO_KEY_SPACE] && !key[ALLEGRO_KEY_ENTER] && !key[ALLEGRO_KEY_ESCAPE] && !joy_b1) {
98 poll_input_wait();
99 al_draw_bitmap(bmp, 0, 0, 0);
100 al_flip_display();
101 }
102
103 al_destroy_bitmap(bmp);
104
105 if (key[ALLEGRO_KEY_ESCAPE])
106 return FALSE;
107
108 sfx_ping(2);
109
110 return TRUE;
111 }
112
113
114
115 /* display the results screen */
show_results()116 void show_results()
117 {
118 int SCREEN_W = al_get_display_width(screen);
119 int SCREEN_H = al_get_display_height(screen);
120 ALLEGRO_BITMAP *bmp, *b;
121 char buf[80];
122 int i, j, x;
123
124 bmp = create_memory_bitmap(SCREEN_W, SCREEN_H);
125 al_set_target_bitmap(bmp);
126
127 for (i=0; i<SCREEN_H/2; i++) {
128 hline(0, SCREEN_H/2-i-1, SCREEN_W, makecol(i*255/(SCREEN_H/2), 0, 0));
129 hline(0, SCREEN_H/2+i, SCREEN_W, makecol(i*255/(SCREEN_H/2), 0, 0));
130 }
131
132 b = create_memory_bitmap(72, 8);
133 al_set_target_bitmap(b);
134 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
135
136 textout(font, "GAME OVER", 0, 0, makecol(0, 0, 0));
137 stretch_sprite(bmp, b, 4, SCREEN_H/3+4, SCREEN_W, SCREEN_H/3);
138
139 textout(font, "GAME OVER", 0, 0, makecol(64, 0, 0));
140 stretch_sprite(bmp, b, 0, SCREEN_H/3, SCREEN_W, SCREEN_H/3);
141
142 al_destroy_bitmap(b);
143
144 al_set_target_bitmap(bmp);
145 sprintf(buf, "Score: %d", score);
146 textout_shadow(buf, SCREEN_W/2, SCREEN_H*3/4, makecol(255, 255, 255));
147
148 al_set_target_bitmap(al_get_backbuffer(screen));
149
150 bmp = replace_bitmap(bmp);
151
152 start_retrace_count();
153
154 for (i=0; i<=SCREEN_W/16; i++) {
155 al_clear_to_color(makecol(0, 0, 0));
156
157 for (j=0; j<=16; j++) {
158 x = j*(SCREEN_W/16);
159 al_draw_bitmap_region(bmp, x, 0, i, SCREEN_H, x, 0, 0);
160 }
161
162 al_flip_display();
163
164 do {
165 poll_input_wait();
166 } while (retrace_count() < i*1024/SCREEN_W);
167 }
168
169 stop_retrace_count();
170
171 while (joy_b1 || key[ALLEGRO_KEY_SPACE] || key[ALLEGRO_KEY_ENTER] || key[ALLEGRO_KEY_ESCAPE])
172 poll_input_wait();
173
174 while (!key[ALLEGRO_KEY_SPACE] && !key[ALLEGRO_KEY_ENTER] && !key[ALLEGRO_KEY_ESCAPE] && !joy_b1) {
175 poll_input_wait();
176 al_draw_bitmap(bmp, 0, 0, 0);
177 al_flip_display();
178 }
179
180 al_destroy_bitmap(bmp);
181
182 sfx_ping(2);
183 }
184
185
186
187 /* print the shutdown message */
goodbye()188 void goodbye()
189 {
190 static int data1[] =
191 {
192 0, 2, 0, 1, 2, 3, 0, 3, 5, 3, 4, 6, 0, 2, 0, 1, 2,
193 3, 0, 3, 7, 3, 5, 6, 0, 2, 0, 1, 12, 3, 9, 3, 5, 3,
194 4, 3, 2, 3, 10, 2, 10, 1, 9, 3, 5, 3, 7, 3, 5, 9
195
196 };
197
198 static int data2[] =
199 {
200 12, 3, 7, 1, 6, 1, 7, 1, 8, 3, 7, 3
201 };
202
203 ALLEGRO_SAMPLE *s1, *s2;
204 ALLEGRO_SAMPLE_ID id;
205 ALLEGRO_BITMAP *b;
206 ALLEGRO_BITMAP *screen_backbuffer;
207 char *sdata1, *sdata2;
208 int SCREEN_W, SCREEN_H;
209 int i;
210
211 if (!al_is_audio_installed()) {
212 al_destroy_display(screen);
213 screen = NULL;
214 printf("Couldn't install a digital sound driver, so no closing tune is available.\n");
215 return;
216 }
217
218 s1 = create_sample_u8(44100, 256);
219 s2 = create_sample_u8(44100, 256);
220
221 sdata1 = (char *)al_get_sample_data(s1);
222 sdata2 = (char *)al_get_sample_data(s2);
223
224 for (i=0; i<256; i++) {
225 sdata1[i] = i;
226 sdata2[i] = (i < 128) ? 255 : 0;
227 }
228
229 SCREEN_W = al_get_display_width(screen);
230 SCREEN_H = al_get_display_height(screen);
231
232 rectfill(0, 0, SCREEN_W/2, SCREEN_H/2, makecol(255, 255, 0));
233 rectfill(SCREEN_W/2, 0, SCREEN_W, SCREEN_H/2, makecol(0, 255, 0));
234 rectfill(0, SCREEN_H/2, SCREEN_W/2, SCREEN_H, makecol(0, 0, 255));
235 rectfill(SCREEN_W/2, SCREEN_H/2, SCREEN_W, SCREEN_H, makecol(255, 0, 0));
236
237 b = al_create_bitmap(168, 8);
238 al_set_target_bitmap(b);
239 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
240
241 screen_backbuffer = al_get_backbuffer(screen);
242
243 textout(font, "Happy birthday Arron!", 0, 0, makecol(0, 0, 0));
244 stretch_sprite(screen_backbuffer, b, SCREEN_W/8+4, SCREEN_H*3/8+4, SCREEN_W*3/4, SCREEN_H/4);
245
246 textout(font, "Happy birthday Arron!", 0, 0, makecol(255, 255, 255));
247 stretch_sprite(screen_backbuffer, b, SCREEN_W/8, SCREEN_H*3/8, SCREEN_W*3/4, SCREEN_H/4);
248
249 al_set_target_bitmap(screen_backbuffer);
250 al_destroy_bitmap(b);
251
252 al_flip_display();
253
254 while (key[ALLEGRO_KEY_SPACE] || key[ALLEGRO_KEY_ENTER] || key[ALLEGRO_KEY_ESCAPE])
255 poll_input_wait();
256
257 clear_keybuf();
258
259 for (i=0; i < (int)(sizeof(data1)/sizeof(int)); i += 2) {
260 al_play_sample(s1, 64/255.0, 0.0, pow(2.0, (float)data1[i]/12.0),
261 ALLEGRO_PLAYMODE_LOOP, &id);
262 rest(100*data1[i+1]);
263 al_stop_sample(&id);
264 rest(50*data1[i+1]);
265
266 if (keypressed())
267 return;
268 }
269
270 rest(500);
271
272 al_destroy_display(screen);
273 screen = NULL;
274 printf("\nAnd thanks for organising this most excellent competition...\n");
275
276 for (i=0; i < (int)(sizeof(data2)/sizeof(int)); i += 2) {
277 al_play_sample(s2, 64/255.0, 0.0, pow(2.0, (float)data2[i]/12.0),
278 ALLEGRO_PLAYMODE_LOOP, &id);
279 rest(75*data2[i+1]);
280 al_stop_sample(&id);
281 rest(25*data2[i+1]);
282
283 if (keypressed())
284 return;
285 }
286
287 rest(300);
288 putchar('\007'); fflush(stdout);
289 rest(300);
290 putchar('\007'); fflush(stdout);
291
292 al_stop_samples();
293
294 al_destroy_sample(s1);
295 al_destroy_sample(s2);
296 }
297
298