1 #include <SDL/SDL.h>
2 #include <assert.h>
3 #include <math.h>
4 #include "sekrit_lab.h"
5 #include "guru_meditation.h"
6 #include "SFont.h"
7 #include "datafun.h"
8 #include "laser.h"
9 #include "random_gen.h"
10 #include "globals.h"
11 #include "sparkles.h"
12 #include "yellifish.h"
13
14
15 /*! \brief Perform one of the tests.
16 *
17 * For debugging only!
18 *
19 * \return 0 = no valid test found, otherwise 1
20 */
perform_a_sekrit_test(char * arg)21 int perform_a_sekrit_test(char *arg) {
22 SDL_Event event;
23 int running = 1;
24
25 printf("Looking for test '%s'...\n", arg);
26 movementrate = 1.0;
27 if(strcmp(arg, "guru") == 0) {
28 SDL_FillRect(surf_screen, NULL, SDL_MapRGB(surf_screen->format, 0, 0x55, 0xAA));
29 printf("guru_display() = %d\n", guru_display_gp(surf_screen, GM_FLAGS_AUTOTIMEOUT | 2, 3, (void*)0xDEADBEA1, "Greeblies at work..."));
30 printf("guru_display() = %d\n", guru_display_gp(surf_screen, GM_FLAGS_AUTOTIMEOUT| 1 | GM_FLAGS_CHOICE, 3, (void*)0xDEADBEA1, "Alert! This needs still a lot of work!"));
31 printf("guru_display() = %d\n", guru_display_gp(surf_screen, GM_FLAGS_AUTOTIMEOUT | 0, 4, (void*)0xAA55AA55, "Normal..."));
32 printf("guru_meditation() = %d\n", guru_meditation(GM_FLAGS_DEADEND | GM_FLAGS_EXIT_VIA_TERM, 0x48454c50, (void*)0x68656c70));
33 return 1;
34 } else if(strcmp(arg, "yellifish") == 0) {
35 yellifish_t yelli1, yelli2, yelli3;
36 yellifishsubsystem_t *ysys = init_yellifish_subsystem(*iff_ctx);
37
38 init_yellifish(ysys, &yelli1, 100, 80);
39 init_yellifish(ysys, &yelli2, 150, 70);
40 init_yellifish(ysys, &yelli3, 250, 80);
41 while(running) {
42 while(SDL_PollEvent(&event)) {
43 if(event.type == SDL_MOUSEBUTTONDOWN) running = 0;
44 }
45 SDL_FillRect(surf_screen, NULL, SDL_MapRGB(surf_screen->format, 0, 0, 0));
46 display_yellifish(ysys, &yelli1, surf_screen);
47 display_yellifish(ysys, &yelli2, surf_screen);
48 display_yellifish(ysys, &yelli3, surf_screen);
49 SDL_Flip(surf_screen);
50 SDL_Delay(60);
51 }
52
53 SDL_Flip(surf_screen);
54 SDL_Delay(2600);
55 return 1;
56 } else if(strcmp(arg, "laserpointer") == 0) {
57 float positions[10];
58 float speeds[10];
59 int i;
60 int ysize2 = ysize / 2 - 3;
61
62 for(i = 0; i < 10; ++i) {
63 speeds[i] = rnd() / 100;
64 positions[i] = 0;
65 }
66
67 while(running) {
68 if(SDL_PollEvent(&event) != 0 && event.type == SDL_MOUSEBUTTONDOWN) running = 0;
69 SDL_FillRect(surf_screen, NULL, SDL_MapRGB(surf_screen->format, 0, 0, 0x13));
70 for(i = 0; i < 10; ++i) {
71 draw_random_dots(surf_screen, sinf(positions[i]) * ysize2 + ysize2 + 1, 0, xsize);
72 positions[i] += speeds[i];
73 }
74 SDL_Flip(surf_screen);
75 SDL_Delay(60);
76 }
77 return 1;
78 } else if(strcmp(arg, "sparkles") ==0) {
79 int i, j;
80 float x;
81 RD_VIDEO_TYPE *rawpixel;
82
83 while(running) {
84 if(SDL_PollEvent(&event) != 0 && event.type == SDL_MOUSEBUTTONDOWN) running = 0;
85 SDL_FillRect(surf_screen, NULL, SDL_MapRGB(surf_screen->format, 0, 0, 0x13));
86 SDL_LockSurface(surf_screen);
87 rawpixel = (RD_VIDEO_TYPE *) surf_screen->pixels;
88 for(i = 0; i < xsize; ++i) {
89 x = i / (xsize - 1.0);
90 for(j = 10; j < 50; ++j) {
91 rawpixel[surf_screen->pitch / sizeof(RD_VIDEO_TYPE) * j + i] = (RD_VIDEO_TYPE)get_life_colour(x, &hot_colours, surf_screen);
92 }
93 for(j = 110; j < 150; ++j) {
94 rawpixel[surf_screen->pitch / sizeof(RD_VIDEO_TYPE) * j + i] = (RD_VIDEO_TYPE)get_life_colour(x, &cool_colours, surf_screen);
95 }
96 }
97 SDL_UnlockSurface(surf_screen);
98 SDL_Flip(surf_screen);
99 SDL_Delay(60);
100 }
101 return 1;
102 } else if(strcmp(arg, "key_lab") ==0) {
103 unsigned int event_nr = 0, k;
104 unsigned int row = 0;
105 char buf[30][128];
106 SDL_Rect rect = { 0, 0, surf_screen->w, 20 };
107
108 restart_game();
109 assert(surf_screen != NULL);
110 assert(surf_green_block != NULL);
111 memset(buf, 0, sizeof(buf));
112 while(running) {
113 while(SDL_PollEvent(&event) == 1) {
114 row = event_nr % 30;
115 switch(event.type) {
116 case SDL_QUIT:
117 running = 0;
118 break;
119 case SDL_MOUSEBUTTONDOWN:
120 case SDL_MOUSEBUTTONUP:
121 sprintf(buf[row], "button=%d state=%d x=$%04hX y=$%04hX", event.button.button, event.button.state, event.button.x, event.button.y);
122 break;
123 case SDL_KEYDOWN:
124 case SDL_KEYUP:
125 sprintf(buf[row], "state=%d sym=$%04X", event.key.state, event.key.keysym.sym);
126 break;
127 case SDL_MOUSEMOTION:
128 //Ignore this one...
129 --event_nr;
130 break;
131 default:
132 sprintf(buf[row], "event_nr = $%x, event.type = $%x", event_nr, (unsigned int)event.type);
133 }
134 ++event_nr;
135 }
136 SDL_FillRect(surf_screen, NULL, SDL_MapRGB(surf_screen->format, 0xf, 0, 0xf));
137 SDL_SetAlpha(surf_green_block, SDL_SRCALPHA, (int) (129 + 66 * sinf(fadetimer)));
138 rect.y = row * 20;
139 SDL_BlitSurface(surf_green_block, NULL, surf_screen, &rect);
140 for(k = 0; k < 30; ++k) {
141 PutString(surf_screen, 12, k * 20, buf[k]);
142 }
143 SDL_Flip(surf_screen);
144 SDL_Delay(50);
145 fadetimer += .192;
146 }
147 return 1;
148 }
149 puts("Not found!");
150 return 0;
151 }
152
153