3 #include <fastgraf.h>
\r
6 #include <time.h> /* FOR RANDOM */
\r
8 #include "tiles.h" /* DUE TO R AND C CHEATS */
\r
9 #include "fx.h" /* FOR FADING STUFF */
\r
10 #include "version.h" /* INFO ON THIS VERSION */
\r
11 #include "keys.h" /* KEY AND SCANCODE DEFINITIONS */
\r
13 extern int far *topography; /* BACKGROUND TILE LIST (ARRAY) */
\r
14 extern int far *terrain; /* FOREGROUND TILE LIST (ARRAY) */
\r
15 extern int view_x, view_y; /* VIEW AREA (UPPER LEFT CORNER) */
\r
16 extern int viewpage; /* CURRENTLY VIEWED PAGE */
\r
17 extern int world_type; /* TENDENCY TO GRASS */
\r
19 extern int edgemode; /* BLOCKY GRASS/DIRT OR EDGED? */
\r
20 extern int animatemode;
\r
21 extern int frogmode;
\r
22 extern int frogwatchmode;
\r
26 /* PROTOTYPES FOR INTERNAL FUNCTIONS */
\r
27 void time_test (void);
\r
28 void cheat (int type);
\r
29 void toggle_mode (int type);
\r
30 void make_world (int type);
\r
31 void view_tile_page (void);
\r
32 void move_view (void);
\r
33 int keycheck (void);
\r
34 void init_all (void);
\r
35 void gogofrog (void);
\r
38 void main (int argc, char *argv[])
\r
40 char quitting_time=0; /* QUIT PROGRAM LOOP */
\r
50 printf ("Loading ... [Escape quits] ... [Type ROADS /? for more keys!]\n");
\r
51 init_all(); /* INITIALIZE ALL SYSTEMS */
\r
53 while (!quitting_time) /* LOOP FOREVER */
\r
55 quitting_time=keycheck(); /* CHECK FOR REGULAR KEYS */
\r
56 if (animatemode) animate(); /* PERFORM ALL ANIMATIONS */
\r
59 program_shutdown("Thank you for running ROADS!", 0);
\r
62 #define TIMETEST_LENGTH 10 /* TIME TEST LENGTH IN SECONDS */
\r
66 * Performs time testing to try and guess a FPS.
\r
69 void time_test (void)
\r
73 int frames_shown[2];
\r
75 for (x=0; x<2; x++) /* TEST TWICE, ONCE WITH ANIMATION */
\r
77 while (redraw(SCROLL_UL)); /* SCROLL UPPER LEFT TO START */
\r
78 fg_music ("L64FAC.AE.B$");
\r
79 frames_shown[x]=0; dir=0;
\r
80 end_time=TIMETEST_LENGTH*182/10;
\r
81 end_time+=fg_getclock();
\r
83 while (fg_getclock()<end_time)
\r
89 case 0: if (!redraw (SCROLL_DR )) dir++; break;
\r
90 case 1: if (!redraw (SCROLL_UP )) dir++; break;
\r
91 case 2: if (!redraw (SCROLL_DL )) dir++; break;
\r
92 case 3: if (!redraw (SCROLL_RIGHT)) dir++; break;
\r
93 case 4: if (!redraw (SCROLL_UL )) dir++; break;
\r
94 case 5: if (!redraw (SCROLL_DOWN )) dir++; break;
\r
95 case 6: if (!redraw (SCROLL_UR )) dir++; break;
\r
96 case 7: if (!redraw (SCROLL_LEFT )) dir=0; break;
\r
99 if (x==0) animate(); /* ANIMATION ON FIRST TEST ONLY */
\r
103 program_shutdown ("",-1); /* DON'T EXIT YET */
\r
104 printf ("%d Frames in %i seconds (%i FPS) with animation\n",
\r
105 frames_shown[0], TIMETEST_LENGTH, frames_shown[0]/TIMETEST_LENGTH);
\r
106 printf ("%d Frames in %i seconds (%i FPS) without animation\n",
\r
107 frames_shown[1], TIMETEST_LENGTH, frames_shown[1]/TIMETEST_LENGTH);
\r
113 * Turns on cheats (fills screen with anims for testing)
\r
116 void cheat (int type)
\r
123 for (x=0; x<WORLD_TILES_TOTAL; x++)
\r
124 terrain[x]=ANM_FIRE;
\r
126 animatewhilefading=0;
\r
128 animatewhilefading=1;
\r
134 for (x=0; x<WORLD_TILES_TOTAL; x++)
\r
135 if (!isroad(terrain[x])) terrain[x]=ANM_FIRE;
\r
137 animatewhilefading=0; /* DON'T ANIMATE IN FADES -- TOO MANY ANIMS! */
\r
139 animatewhilefading=1;
\r
145 * Toggles modes on and off (animation, edging, etc.)
\r
148 void toggle_mode (int type)
\r
152 animatemode=!animatemode;
\r
153 fg_music ("L64G.AG.A$");
\r
158 edgemode=!edgemode;
\r
159 fg_music ("S1L20B..G..F..$");
\r
168 keyboardmode=!keyboardmode;
\r
169 fg_music ("L40BABAGFG.$");
\r
173 frogwatchmode=!frogwatchmode;
\r
174 fg_music ("O1L30D.ED.A$");
\r
180 * Initializes the world, foreground and/or background.
\r
183 void make_world (int type)
\r
208 * Shows the contents of the tile page. Hit any key to fade back.
\r
211 void view_tile_page (void)
\r
216 fg_setvpage (TILEPAGE);
\r
222 fg_intkey (&key1, &key2);
\r
224 } while (!(key1+key2)); /* DO LOOP WHILE KEYS ARE NOT HIT */
\r
229 fg_setvpage (viewpage);
\r
235 * Scans for arrow keys and scrolls the view area in reaction to them.
\r
238 void move_view (void)
\r
240 static char left=0, right=0, up=0, down=0; /* KEYBOARD VARS */
\r
242 /* CHECK FOR ARROWS BEING PRESSED */
\r
243 if (fg_kbtest(SCAN_RIGHT)) right++; else right=0;
\r
244 if (fg_kbtest(SCAN_LEFT)) left++; else left=0;
\r
245 if (fg_kbtest(SCAN_UP)) up++; else up=0;
\r
246 if (fg_kbtest(SCAN_DOWN)) down++; else down=0;
\r
248 /* MAKE SURE COUNTERS DON'T GO TOO HIGH */
\r
249 if (right>100) right=100;
\r
250 if (left>100) left=100;
\r
251 if (up>100) up=100;
\r
252 if (down>100) down=100;
\r
254 /* IF "TAP" KEYBOARD MODE IS ON, DON'T MOVE UNTIL KEYS RELEASED */
\r
255 if (keyboardmode && (right>1 || left>1 || up>1 || down>1)) return;
\r
257 /* MOVE, CHECKING FOR DIAGONAL MOVEMENT FIRST */
\r
258 if (up && right) redraw (SCROLL_UR);
\r
259 else if (down && left) redraw (SCROLL_DL);
\r
260 else if (up && left) redraw (SCROLL_UL);
\r
261 else if (down && right) redraw (SCROLL_DR);
\r
262 else if (right) redraw (SCROLL_RIGHT);
\r
263 else if (left) redraw (SCROLL_LEFT);
\r
264 else if (up) redraw (SCROLL_UP);
\r
265 else if (down) redraw (SCROLL_DOWN);
\r
270 * Initializes all systems and brings display up.
\r
273 void init_all (void)
\r
275 fg_kbinit(1); /* LATCH LOW-LEVEL KEYBOARD HANDLER */
\r
276 randomize(); /* ALLOW RANDOMIZATIONS */
\r
278 init_anim(); /* CALL BEFORE WORLD CREATION */
\r
279 init_data(); /* CALL BEFORE WORLD CREATION */
\r
280 init_world(); /* RANDOMIZE THE WORLD */
\r
281 init_video(); /* SET OUR VIDEO MODE ETC. */
\r
283 fade_init(); /* ALLOW FADING */
\r
284 fade_blackout(); /* SET ALL COLORS TO BLACK */
\r
285 redraw(REFRESH); /* DRAW THE SCREEN (UNSEEN) */
\r
286 fade_in_all(); /* FADE IN SCREEN */
\r
291 * Keycheck checks all keys and reacts upon them.
\r
292 * Returns 1 if a key has indicated the user has requested to quit.
\r
295 int keycheck (void)
\r
297 if (fg_kbtest(SCAN_T)) time_test();
\r
298 if (fg_kbtest(SCAN_C)) cheat (0);
\r
299 if (fg_kbtest(SCAN_R)) cheat (1);
\r
300 if (fg_kbtest(SCAN_A)) toggle_mode(0);
\r
301 if (fg_kbtest(SCAN_E)) toggle_mode(1);
\r
302 if (fg_kbtest(SCAN_K)) toggle_mode(2);
\r
303 if (fg_kbtest(SCAN_W)) toggle_mode(3);
\r
304 if (fg_kbtest(SCAN_F))
\r
306 fg_music ("L50O4BAFDEF.$");
\r
309 case 1: frogmode=2; break;
\r
310 case 3: frogmode=0; break;
\r
313 if (fg_kbtest(SCAN_G)) /* RERANDOMIZE GRASS/DIRT TENDENCY */
\r
315 world_type=random(100);
\r
316 fg_music ("S1L20C..B..A..$");
\r
318 if (fg_kbtest(SCAN_SPACE)) make_world (0);
\r
319 if (fg_kbtest(SCAN_B)) make_world (1);
\r
320 if (fg_kbtest(SCAN_ENTER)) make_world (2);
\r
321 if (fg_kbtest(SCAN_S)) view_tile_page();
\r
323 move_view(); /* RESPOND TO ARROW KEYS MOVING VIEW */
\r
325 if (fg_kbtest(SCAN_ESC) || fg_kbtest(SCAN_Q)) /* ESCAPE TO QUIT */
\r